2019-10-10 21:26:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-03 19:23:45 -05:00
|
|
|
module DiscourseSubscriptions
|
2019-10-10 21:26:01 -04:00
|
|
|
class CustomersController < ::ApplicationController
|
2019-12-03 19:23:45 -05:00
|
|
|
include DiscourseSubscriptions::Stripe
|
2019-10-10 21:26:01 -04:00
|
|
|
|
|
|
|
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 20:31:19 -04:00
|
|
|
render_json_dump customer
|
|
|
|
|
|
|
|
rescue ::Stripe::InvalidRequestError => e
|
2019-12-11 17:59:38 -05:00
|
|
|
render_json_error e.message
|
2019-10-25 20:31:19 -04:00
|
|
|
end
|
2019-10-10 21:26:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|