2019-10-10 21:26:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscoursePatrons
|
|
|
|
class CustomersController < ::ApplicationController
|
|
|
|
include DiscoursePatrons::Stripe
|
|
|
|
|
|
|
|
before_action :set_api_key
|
|
|
|
|
|
|
|
def create
|
2019-10-25 20:31:19 -04:00
|
|
|
begin
|
|
|
|
customer = ::Stripe::Customer.create(
|
|
|
|
email: current_user.email,
|
|
|
|
source: params[:source]
|
|
|
|
)
|
2019-10-10 21:26:01 -04:00
|
|
|
|
2019-10-25 22:01:49 -04:00
|
|
|
DiscoursePatrons::Customer.create_customer(
|
|
|
|
current_user,
|
|
|
|
customer
|
2019-10-25 20:31:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
render_json_dump customer
|
|
|
|
|
|
|
|
rescue ::Stripe::InvalidRequestError => e
|
|
|
|
return render_json_error e.message
|
|
|
|
end
|
2019-10-10 21:26:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|