#maks.piechota
1 messages · Page 1 of 1 (latest)
Hey! Which event(s) are you using?
so far, invoice.paid for checkout session only
but now I want to add payment link
for non-users
so if they pay, I want to create a new account for them
Hmm, well the recommendation would be to use checkout.session.completed event and that payload would include a payment_link field: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_link
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Otherwise you'd probably need to set some subscription_data[metadata] which would be present on invoice.paid events
ok but does checkout.session.completed mean that the invoice is paid
or I need to somehow check first webhook
and then wait for the another
and I guess they can come in reversed order right? (i.e. invoice.paid first)
if the payment inside Checkout used an Invoice(like it's the first payment of a subscription) then yes the Invoice was paid during the CheckoutSession and the checkout.session.completed event means it was paid.
i dont understand
in some cases, then the customer pays (like its not the first payment of a subscription) then the invoice is not used?
Invoices are a specific API object and integration in Stripe yes, not all payments use them. It depends what exactly you're using the PaymentLink to pay for.
An Invoice is not the same thing as a 'receipt', maybe that's your confusion.
you can just process a PaymentIntent directly, for example. Invoices are not a core part of every payment API at Stripe, they're a specific object and product for specific types of payment. So I'd take a step back a little, I'm not sure how I can add clarity here.
ok
so how do I ensure
that if I create payment link
within stripe dashboard
for specific product (subscprition)
the customer will get his invoice
well if you're using Subscriptions then every payment will be processed via an Invoice.
ok, now i understand my question wasn't specific enough that I mean 'next payments for the subscription'
ok
so the payment link
will trigger the same invoice.paid
event
and I cannot differentiate if it comes from my created checkout session or from the external payment link?
I don't really understand, sorry. What is an "external payment link" in this context?
be polite please.
as for differenciating, I think it's possible but will be a little tricky/fiddly, let me think.
I suppose the most sensible way would be
- receive invoice.paid
- check if
billing_reason:"create_subscription" - get the subscription ID from
invoice.subscription - check via https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-subscription if there's an associated CheckoutSession
- for the results, check if the Session is associated with a PaymentLink(https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_link is set) or not(the field is null) for a direct CheckoutSession you create.
Some other options like saving the CheckoutSession ID in your database after you create them, which means you could skip that last check and instead check if you recognise the ID. Or adding subscription_data[metadata] when you create CheckoutSessions which your system can understand to mean "I created this", and checking for the presence of that.
Or you could not really care about the differenciation and just fulfill the subscription, it depends on the use case.