discourse-subscriptions/app/controllers/discourse_donations/charges_controller.rb

29 lines
720 B
Ruby
Raw Normal View History

2017-02-21 18:21:42 -05:00
require_dependency 'discourse'
2017-02-23 21:23:11 -05:00
module DiscourseDonations
class ChargesController < ActionController::Base
2017-02-21 18:21:42 -05:00
include CurrentUser
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
currency = SiteSetting.discourse_donations_currency
2017-02-27 21:23:23 -05:00
customer = Stripe::Customer.create(
2017-02-21 18:21:42 -05:00
:email => current_user.email,
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
2017-02-21 18:21:42 -05:00
:amount => params[:amount],
:description => 'Consumer Defender',
:currency => currency
)
2017-02-21 19:12:19 -05:00
render :json => charge
end
end
end