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

38 lines
807 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-04-04 19:49:57 -04:00
if email.nil? || email.empty?
response = {}
else
2017-04-06 00:22:22 -04:00
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
response = payment.charge(email, params)
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
def email
params[:email] || current_user.try(:email)
end
end
end