M
M
Max2016-06-03 16:36:11
Ruby on Rails
Max, 2016-06-03 16:36:11

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

It fires on the show action of the places_controller when the page for booking a place is opened (if @place.status == false).
The response from the server handles payments_controller:
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 you look closely, you can see that in the middle of this method there is another one that checks whether the payment was successful, and changes the value of the @place.status attribute from false to true.
But this method doesn't work.
The view has this code:
<% 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 %>

It shows or hides the payment button depending on @place.status
I have little idea what the code in payments_controller does, I would be grateful if someone tells me how to process the response or the request itself if I send it wrong.
In short, the payment is made, but after the payment, the status of the payment in the database does not change.
PS. This is all the code associated with liqpay, maybe I didn’t finish something

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question