2017-02-21 18:21:42 -05:00
|
|
|
require_dependency 'discourse'
|
|
|
|
|
2017-02-23 21:23:11 -05:00
|
|
|
module DiscourseDonations
|
2017-02-16 00:29:42 -05:00
|
|
|
class ChargesController < ActionController::Base
|
2017-02-21 18:21:42 -05:00
|
|
|
include CurrentUser
|
|
|
|
|
2017-02-16 00:29:42 -05:00
|
|
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
|
|
|
|
|
|
|
def create
|
2017-04-04 19:49:57 -04:00
|
|
|
if email.nil? || email.empty?
|
|
|
|
response = {}
|
2017-04-03 22:00:23 -04:00
|
|
|
else
|
2017-04-06 00:22:22 -04:00
|
|
|
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
|
|
|
response = payment.charge(email, params)
|
2017-04-03 22:00:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
render :json => response
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-04-06 00:22:22 -04:00
|
|
|
def secret_key
|
|
|
|
SiteSetting.discourse_donations_secret_key
|
|
|
|
end
|
|
|
|
|
|
|
|
def stripe_options
|
|
|
|
{
|
|
|
|
description: SiteSetting.discourse_donations_description,
|
|
|
|
currency: SiteSetting.discourse_donations_currency
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-04-03 22:00:23 -04:00
|
|
|
def email
|
|
|
|
params[:email] || current_user.try(:email)
|
2017-02-16 00:29:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|