This file contains 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
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 |
This file contains 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
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' | |
} |