discourse-subscriptions/app/controllers/customers_controller.rb

29 lines
594 B
Ruby
Raw Normal View History

# 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-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
end
end
end