Created
March 28, 2014 00:39
-
-
Save delba/9822518 to your computer and use it in GitHub Desktop.
Processing payment in a queue
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 StripeCharger | |
include Sidekiq::Worker | |
def perform(charge_id) | |
@charge = Charge.find(charge_id) | |
begin | |
stripe_charge = Stripe::Charge.create(charge_params) | |
@charge.update stripe: stripe_charge.to_json | |
rescue Stripe::CardError => e | |
logger.error e | |
end | |
end | |
private | |
def charge_params | |
{ | |
amount: @charge.amount, | |
currency: @charge.currency, | |
card: @charge.card_token, | |
description: @charge.id | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment