31 lines
639 B
Ruby
Raw Normal View History

2017-04-06 14:16:05 +10:00
module DiscourseDonations
class Stripe
2017-05-02 09:47:23 +10:00
attr_reader :charge, :currency, :description
2017-04-06 14:16:05 +10: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-07 03:22:53 +10:00
source: opts[:stripeToken]
2017-04-06 14:16:05 +10:00
)
2017-04-19 10:43:40 +10:00
@charge = ::Stripe::Charge.create(
2017-04-06 14:16:05 +10:00
customer: customer.id,
amount: opts[:amount],
2017-05-02 09:47:23 +10:00
description: description,
currency: currency
2017-04-06 14:16:05 +10:00
)
2017-04-19 10:43:40 +10:00
@charge
end
def successful?
@charge[:paid]
2017-04-06 14:16:05 +10:00
end
end
end