implement service
This commit is contained in:
parent
316dc61af5
commit
392478adf3
|
@ -10,20 +10,8 @@ module DiscourseDonations
|
|||
if email.nil? || email.empty?
|
||||
response = {}
|
||||
else
|
||||
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
||||
currency = SiteSetting.discourse_donations_currency
|
||||
|
||||
customer = Stripe::Customer.create(
|
||||
:email => email,
|
||||
:source => params[:stripeToken]
|
||||
)
|
||||
|
||||
response = Stripe::Charge.create(
|
||||
:customer => customer.id,
|
||||
:amount => params[:amount],
|
||||
:description => SiteSetting.discourse_donations_description,
|
||||
:currency => currency
|
||||
)
|
||||
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
||||
response = payment.charge(email, params)
|
||||
end
|
||||
|
||||
render :json => response
|
||||
|
@ -31,6 +19,17 @@ module DiscourseDonations
|
|||
|
||||
private
|
||||
|
||||
def secret_key
|
||||
SiteSetting.discourse_donations_secret_key
|
||||
end
|
||||
|
||||
def stripe_options
|
||||
{
|
||||
description: SiteSetting.discourse_donations_description,
|
||||
currency: SiteSetting.discourse_donations_currency
|
||||
}
|
||||
end
|
||||
|
||||
def email
|
||||
params[:email] || current_user.try(:email)
|
||||
end
|
||||
|
|
|
@ -7,6 +7,8 @@ module DiscourseDonations
|
|||
|
||||
before do
|
||||
SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo')
|
||||
SiteSetting.stubs(:discourse_donations_description).returns('charity begins at discourse plugin')
|
||||
SiteSetting.stubs(:discourse_donations_currency).returns('AUD')
|
||||
end
|
||||
|
||||
it 'responds ok for anonymous users' do
|
||||
|
|
Loading…
Reference in New Issue