#PyroFiire
1 messages · Page 1 of 1 (latest)
Hi there
$subscription = $this->stripeService->getClient()->subscriptions->create([
'customer' => $purchase->getOwner()->get('field_stripe_id')->value,
'items' => [
[
'price_data' => [
'unit_amount' => 5000,
'currency' => 'eur',
'product' => 'prod_O0rkYXhkhCsuNI',
'recurring' => [
'interval' => 'month',
'interval_count' => 3,
],
],
'quantity' => 1,
'metadata' => []
]
],
// 'add_invoice_items' => [ // basic products
// ['price' => '{{ONE_TIME_PRICE_ID}}']
// ],
'payment_behavior' => 'default_incomplete',
'payment_settings' => [
'save_default_payment_method' => 'on_subscription'
],
'expand' => ['latest_invoice.payment_intent'],
]);
You would retrieve the PaymentIntent and expand the invoice.subscription to get the Subscription
Are you familiar with expansion?
I use this code for create the subscription before payment
No, i saw in my create Subscription the expand key, but i not really undestand this
Recommend giving a read through https://stripe.com/docs/expand in that case
thanks, i will read this
When the user arrives on the payment page, I've either created a paymentIntent directly because the shopping cart doesn't contain a subscription, or I've created a subscription and used the paymentIntent associated with the invoice.
My goal is to be able to know within the payment_intent.succeeded weebhook whether it's linked to a subscription or not, in order to generate invoices (on my website, not in Stripe).
Do you think this is possible with this webhook only, or do I have to use invoice.paid for subscriptions?
I'd like to use a common webhook to generate my invoices
Otherwise, I run the risk of having duplicates because subscriptions trigger both payment_intent.succeeded and invoice.paid.
but if I've understood correctly, thanks to the expand, I should be able to know whether the paymentIntent contains a subscription or not. So I wouldn't need to use the invoice.paid webhook. right?
Correct
In your webhook handler when you get a payment_intent.succeeded webhook you retrieve that PaymentIntent. If all you want to know is whether it is associated with an Invoice then you don't have to even use expand
You just look at the invoice property on the PaymentIntent
Nor would you need to retrieve the PaymentIntent in this case
If you want the specifics of the Subscription itself then you do need to retrieve the PaymentIntent and expand invoice.subscription
Ok i undestand thank you very much.
I have one last question. How can I find out with the payment_intent, i.e. the subscription. If it's the first time the customer pays, or if it's a recurrence with a direct debit?
Easist way is to look at the description of the PaymentIntent
If it is the first PaymentIntent the desciption will be Subscription creation
Otherwise it will be Subscription update
Ok, I had seen this field but I was a little afraid that this character string would change over time since it's a description field.
We wouldn't change it without letting you know well in advance
And I don't think we would ever really change it
That would break a lot of integrations if we change it
Since other folks do already rely on this
All right then. Thank you very much for your help. Have a nice day/evening