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-02-27 21:23:23 -05:00
|
|
|
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
2017-03-06 23:21:51 -05:00
|
|
|
currency = SiteSetting.discourse_donations_currency
|
2017-02-27 21:23:23 -05:00
|
|
|
|
2017-02-16 00:29:42 -05:00
|
|
|
customer = Stripe::Customer.create(
|
2017-02-21 18:21:42 -05:00
|
|
|
:email => current_user.email,
|
2017-02-16 00:29:42 -05:00
|
|
|
:source => params[:stripeToken]
|
|
|
|
)
|
|
|
|
|
|
|
|
charge = Stripe::Charge.create(
|
|
|
|
:customer => customer.id,
|
2017-02-21 18:21:42 -05:00
|
|
|
:amount => params[:amount],
|
2017-02-16 00:29:42 -05:00
|
|
|
:description => 'Consumer Defender',
|
2017-03-06 23:21:51 -05:00
|
|
|
:currency => currency
|
2017-02-16 00:29:42 -05:00
|
|
|
)
|
2017-03-06 23:21:51 -05:00
|
|
|
|
2017-02-21 19:12:19 -05:00
|
|
|
render :json => charge
|
2017-02-16 00:29:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|