Created
October 25, 2020 10:22
-
-
Save kinsomicrote/cf02a91381b11b91ecb9954ff66c72f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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