Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kinsomicrote/cf02a91381b11b91ecb9954ff66c72f0 to your computer and use it in GitHub Desktop.
Save kinsomicrote/cf02a91381b11b91ecb9954ff66c72f0 to your computer and use it in GitHub Desktop.
require 'httparty'
class TransactionsController < ApplicationController
def paystack
@order = Order.find_by(ref_no: params[:ref])
amount = @order.price
ref = @order.ref_no
response = HTTParty.get("https://api.paystack.co/transaction/verify/#{ref}",
headers: { "Authorization"=> "Bearer #{Rails.application.credentials.dig(:paystack, :secret_key)}",
"content-type" => "application/json"})
paid = response['data']['amount']/100
status = response['data']['status']
if paid == amount && status == 'success'
@order.update!(status: true, country: @country, payment_method: "PAYSTACK" )
render json: {message: "Payment successful"}
flash[:success] = "Payment successful"
else
render json: {message: "Payment was unsuccessful"}, status: :unprocessable_entity
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment