discourse-subscriptions/app/services/discourse_donations/stripe.rb

30 lines
673 B
Ruby
Raw Normal View History

2017-04-06 00:16:05 -04:00
module DiscourseDonations
class Stripe
def initialize(secret_key, opts)
::Stripe.api_key = secret_key
@description = opts[:description]
@currency = opts[:currency]
end
def charge(email, opts)
customer = ::Stripe::Customer.create(
email: email,
2017-04-06 13:22:53 -04:00
source: opts[:stripeToken]
2017-04-06 00:16:05 -04:00
)
2017-04-18 20:43:40 -04:00
@charge = ::Stripe::Charge.create(
2017-04-06 00:16:05 -04:00
customer: customer.id,
amount: opts[:amount],
description: @description,
currency: @currency
)
2017-04-19 21:09:59 -04:00
@charge[:message] = @charge[:outcome][:seller_message] if @charge[:outcome]
2017-04-18 20:43:40 -04:00
@charge
end
def successful?
@charge[:paid]
2017-04-06 00:16:05 -04:00
end
end
end