Paystack gem for Ruby api only application
Simply add this line to your application's Gemfile:
gem 'paystackapi'And then execute:
bundle installOr install it yourself as:
gem install paystackapiYou may need to install Dotenv to set you environmental variables. Set the requirements in your controller files where needed.
require 'paystackapi' require 'dotenv/load'def validate_payment paystack_ref = params[:reference_code] # get payment ref after initializing payment from the frontend verify = Paystackapi::PaystackTransactions.verify(paystack_ref) end Paystackapi::PaystackTransactions.list # list all transactions Paystackapi::PaystackTransactions.totals # show transaction totals Paystackapi::PaystackTransactions.list_single(arg) # list single transaction Paystackapi::PaystackTransactions.charge(arg) # charge authorization from carddef customers customerEmail = params[:customer_email] customer = Paystackapi::PaystackCustomers.create(customerEmail) end Paystackapi::PaystackCustomers.list #list all customers Paystackapi::PaystackCustomers.list_single(arg) #get by iddef plans createPlan = { CustomerName = params[:name] interval = params[:interval] amount = params[:amount] } customer = Paystackapi::PaystackPlans.create(createPlan) end Paystackapi::PaystackPlans.list #list all paystack plans Paystackapi::PaystackPlans.list_single(arg) #get by id Paystackapi::PaystackPlans.update(arg) #update plan by iddef subscription createSub = { CustomerToken = "CUS_xnxdt6s1zg1f4nx" planCode = "PLN_gx2wn530m0i3w3m" } customer = Paystackapi::PaystackSubscription.create(createSub) end Paystackapi::PaystackSubscription.list #list all subs Paystackapi::PaystackSubscription.list_single(arg) #get subs by id Paystackapi::PaystackSubscription.disable #disable subs Paystackapi::PaystackSubscription.enable #enable subsdef transfer createTrans = { type = "nuban" #use params[:something] to get the parameters from your endpoint name = "Raz" description = "Razite" account_number = "01000000419" bank_code = "044" currency = "NGN" } transfer = Paystackapi::PaystackTransfer.generate(createTrans) end Paystackapi::PaystackTransfer.list_reciept #list all transfers Reciept Paystackapi::PaystackTransfer.update_reciept(arg, arg) #update reciept Paystackapi::PaystackTransfer.initailize(arg) #initalize a transfer (triggers an otp here) Paystackapi::PaystackTransfer.list_transfer #list all transfers Paystackapi::PaystackTransfer.finalize(arg) #finalize a transferPaystackapi::PaystackBank.list_banks #list all Nigerian BanksPlease feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
I'm Sam, find me on twitter.
The gem is available as open source under the terms of the MIT License.