Skip to content

Instantly share code, notes, and snippets.

@dngst
dngst / subscriptions_controller.rb
Last active February 15, 2024 12:59
Make use of the Paystack service
class SubscriptionsController < ApplicationController
before_action :initialize_paystack_service
rescue_from SocketError, with: :handle_offline
def handle_payments
if customer_exists
initialize_transaction
else
create_customer
end
@dngst
dngst / paystack_service.rb
Last active November 14, 2023 01:47
Communicate with the Paystack API
class PaystackService
include HTTParty
base_uri 'https://api.paystack.co'
def initialize(secret_key)
@headers = {
'Authorization' => "Bearer #{secret_key}",
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}