2017-02-22 10:21:42 +11:00
|
|
|
require_dependency 'discourse'
|
|
|
|
|
2017-02-24 13:23:11 +11:00
|
|
|
module DiscourseDonations
|
2017-02-16 16:29:42 +11:00
|
|
|
class ChargesController < ActionController::Base
|
2017-02-22 10:21:42 +11:00
|
|
|
include CurrentUser
|
|
|
|
|
2017-02-16 16:29:42 +11:00
|
|
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
|
|
|
|
|
|
|
def create
|
2017-04-05 09:49:57 +10:00
|
|
|
if email.nil? || email.empty?
|
|
|
|
response = {}
|
2017-04-04 12:00:23 +10:00
|
|
|
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
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json => response
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def email
|
|
|
|
params[:email] || current_user.try(:email)
|
2017-02-16 16:29:42 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|