mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-07 23:12:33 +00:00
create a customer when a payment happens
This commit is contained in:
parent
92f6569f9f
commit
fcfd2be41b
@ -11,12 +11,22 @@ module DiscourseSubscriptions
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
begin
|
begin
|
||||||
|
customer = ::Stripe::Customer.create(
|
||||||
|
email: current_user.email,
|
||||||
|
)
|
||||||
|
|
||||||
|
DiscourseSubscriptions::Customer.create(
|
||||||
|
user_id: current_user.id,
|
||||||
|
customer_id: customer[:id],
|
||||||
|
)
|
||||||
|
|
||||||
payment = ::Stripe::PaymentIntent.create(
|
payment = ::Stripe::PaymentIntent.create(
|
||||||
payment_method_types: ['card'],
|
payment_method_types: ['card'],
|
||||||
payment_method: params[:payment_method],
|
payment_method: params[:payment_method],
|
||||||
amount: params[:amount],
|
amount: params[:amount],
|
||||||
currency: params[:currency],
|
currency: params[:currency],
|
||||||
confirm: true
|
confirm: true,
|
||||||
|
customer: customer[:id],
|
||||||
)
|
)
|
||||||
|
|
||||||
render_json_dump payment
|
render_json_dump payment
|
||||||
|
@ -25,12 +25,17 @@ module DiscourseSubscriptions
|
|||||||
|
|
||||||
describe "create" do
|
describe "create" do
|
||||||
it "creates a payment intent" do
|
it "creates a payment intent" do
|
||||||
|
::Stripe::Customer.expects(:create).with(
|
||||||
|
email: user.email
|
||||||
|
).returns(id: 'cus_87653')
|
||||||
|
|
||||||
::Stripe::PaymentIntent.expects(:create).with(
|
::Stripe::PaymentIntent.expects(:create).with(
|
||||||
payment_method_types: ['card'],
|
payment_method_types: ['card'],
|
||||||
payment_method: 'pm_123',
|
payment_method: 'pm_123',
|
||||||
amount: '999',
|
amount: '999',
|
||||||
currency: 'gdp',
|
currency: 'gdp',
|
||||||
confirm: true
|
confirm: true,
|
||||||
|
customer: 'cus_87653'
|
||||||
)
|
)
|
||||||
|
|
||||||
post "/s/payments.json", params: {
|
post "/s/payments.json", params: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user