Reputation: 320
Does someone know or have an of how explain me how does ngx-stripe works to make a subscription.
I try to make it with cURL but i can't.
I can make the token card but what's next?
I have mi frontend with Angular and my backend with laravel.
I undestand that I need to make the token, then the customer and at last the subscription. but I don't know how, I already read the docs but I'm still stuck
Upvotes: 1
Views: 2244
Reputation: 3240
The main steps for creating a subscription in Stripe are to:
You would only be able to use ngx-stripe for the second step (collecting a payment method) and potentially for cases where the fourth step (creating a subscription) requires authentication due to SCA. To start, I would follow the ngx-stripe docs for creating a Token:
https://richnologies.gitbook.io/ngx-stripe/examples#create-token
But, instead of calling this.stripeService.createToken
, I would instead call this.stripeService.createPaymentMethod
:
this.stripeService
.createPaymentMethod({
type: 'card',
card: this.card.element,
billing_details: { name },
})
.subscribe((result) => {
if (result.paymentMethod) {
// Send the payment method to your server
console.log(result.paymentMethod.id);
} else if (result.error) {
// Error creating the token
console.log(result.error.message);
}
});
PaymentMethods are Stripe's newer recommend path for collecting payment details.
After creating the PaymentMethod you would then need to send the PaymentMethod ID to your server. In your server, you would create a Customer and save the PaymentMethod to it:
Using Stripe
Using Laravel Cashier
At this point you will have a Stripe Customer with a saved PaymentMethod. The last step would be to create a subscription for that Customer:
Using Stripe
Using Laravel Cashier
That's the gist!
Upvotes: 8