Answer the question
In order to leave comments, you need to log in
How to process a response from liqpay?
Hello, please tell me how to process the response from liqpay, maybe there is a ready-made example?
At the moment there is this method:
def check_payment_status
if @place.status == false
@liqpay_request = Liqpay::Request.new(
:amount => @searched_film_session_price,
:currency => 'UAH',
:description => "#{@place_title}, Place number: #{@place.place_number}, date: #{@place.session_date}, time: #{@place.session_time}",
:order_id => @place.id,
:sandbox => 1,
:result_url => place_url(@place)
# :server_url => liqpay_payment_place_url(@place)
)
end
end
class PaymentsController < ApplicationController
protect_from_forgery :except => :liqpay_payment
def liqpay_payment
@liqpay_response = Liqpay::Response.new(params)
@place = Place.find(@liqpay_response.order_id)
@place.data = {}
(Liqpay::Response::ATTRIBUTES - %w(public_key sender_phone transaction_id)).each do |attribute|
@place.data[attribute] = @liqpay_response.send(attribute)
end
check_response_status
redirect_to @place
rescue Liqpay::InvalidResponse
render text: 'Payment error', status: 500
end
private
def check_response_status
if @liqpay_response.success? && @liqpay_reponse.amount == @Place.price
@place.update_attributes!(:status => true)
else
@place.update_attributes!(:status => false)
end
end
end
<% if @place.status == false %>
<p>If you have paid already, the response didn't come in yet from LiqPAY. Refresh this page later.</p>
<%=liqpay_button @liqpay_request %>
<% elsif @place.status == true %>
<p>Payment succeeded.</p>
<% else %>
<p>Payment failed.</p>
<% end %>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question