Following a guide for my server (Firebase) they charge the user with :
const payment = await stripe.paymentIntents.create(
{
amount,
currency,
customer,
payment_method,
off_session: false,
confirm: true,
confirmation_method: 'manual',
},
{ idempotencyKey }
);
Now in all Stripe examples, they use something like:
const subscription = await stripe.subscriptions.create({
customer: '{{CUSTOMER_ID}}',
items: [{
price: '{{RECURRING_PRICE_ID}}',
}],
add_invoice_items: [{
price: '{{PRICE_ID}}',
}],
});
I am trying to understand :
paymentIntent does ? and how it relate to a subscription ? ( for me it just charge the user and its not clear if this is one time charge or a subscription )Reading the docs doesn't help since it is full of so much information and options without a clean flow.
A PaymentIntent is an object used to collect payment one time. A Subscription is a higher level concept that represents a relationship between a Customer and some recurring Price they will pay on an interval.
When a Subscription renews, there is an Invoice generated which will use an underlying PaymentIntent to collect money for that renewal.
When you create a Product in the dashboard, it will have one or more Prices. A Product would be something like "Starter" or "Pro" and the Prices related to each Product represent the currency (USD), amount to charge (1000) and some interval at which the Price should recur at if any. Note: Prices can also be used for one time purchases with Checkout.
In this video about the new Customer portal, we cover modeling your business with Prices and it might be helpful here: https://www.youtube.com/watch?v=u8H6awDJVpM&list=PLy1nL-pvL2M6IYfRCmhOPcyC70zJqFoCs&index=2&t=0s
We need to create a subscription not a payment intent. When the subscription is created we get the client_secret for initiating the payment process: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With