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

31 lines
639 B
Ruby
Raw Normal View History

2017-04-06 00:16:05 -04:00
module DiscourseDonations
class Stripe
2017-05-01 19:47:23 -04:00
attr_reader :charge, :currency, :description
2017-04-06 00:16:05 -04:00
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],
2017-05-01 19:47:23 -04:00
description: description,
currency: currency
2017-04-06 00:16:05 -04:00
)
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