#.abishek
1 messages ยท Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
๐ happy to help
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
let me know if you need any more help
and if I wanted to get the payment method used for the Checkout Session, is that easy to do or do I have to dig into the payment_intent or invoice objects?
yes unfortunately you'd have to dig in
ok, thank you
how do I set the expand for items in an array. For example, on the CheckoutSession's lineItems, if they are a subscription, I want to expand the subscription object
wud this work
$expand = [
'line_items.data.price',
'line_items.data.subscription',
'customer.invoice_settings.default_payment_method',
'customer.default_source'
];
yes it should
ok, thank you. let me test it out. I don't know if it is a good idea to expand all the required data in one go or if do another API query
I'm not sure you need customer.default_source
this will soon be deprecated
it's just here because of backwards compatibility and we used to have some of our internal integrations that still rely on it
had to do it because of this https://docs.stripe.com/api/subscriptions/object#subscription_object-default_payment_method, because I have some customers for whom this is still true.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yeah I see
i had to end up doing this
$stripePaymentMethod = $stripeTransaction->payment_method ??
$stripeTransaction->invoice->default_payment_method ??
$stripeTransaction->invoice->default_source ??
$stripeTransaction->customer->invoice_settings->default_payment_method ??
$stripeTransaction->customer->default_source;
because our app has some old subscriptions
so this is the only way to retrieve the payment method for those subscriptions
i am assuming that is the true order for the check
what is the best practice for #1209802867477848104 message
also, would you be able to answer specific question to PHP SDK?
here you can see the order
https://docs.stripe.com/api/subscriptions/object#subscription_object-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
on the PHP SDK, the Checkout session has the object line_items. This returns a Collection Object. I wanted to see if there was a way to filter the line_items that are only of type Subscription
ok, thank you
usually collection classes have a where or filter methods that can be used to do that stuff, was hoping something like that is there
I'm not sure to be honest, you can always try and see if it works
btw, not sure if I need sleep, but https://docs.stripe.com/api/checkout/sessions/object on the right where the session object is depicted in JSON, the line_items don't exist there
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
is it just me?
yes because this needs to be expanded otherwise it wouldn't show
ok
this change was made to have faster responses when calling the checkout session
or when sending the webhook event
ok
after the Stripe Checkout is completed, I am processing some stuff on the checkout.session.complete, but I am also subscription to subscription.created webhook. On the subscription.created webhook, is there a property that indicates that this subscription was created using a checkout session id?
you shouldn't use customer.subscription.created for this
instead what you need to listen to is the invoice.paid events
invoice.paid wouldn't trigger if the checkout session has items that aren't recurring
it would for subscriptions
that's what you're looking for
so basically in checkout.session.completed if mode is subscription then you can ignore the event
and just wait for the invoice.paid event
ok, because our cart feature has the option to include both one-off items and recurring items together
once you receive that, you check the billing_reason and if it's subscription_create then it means there's a new subscription
once they add stuff to the cart, then we redirect the user to Stripe Checkout
yes this means you need to create a subscription mode Checkout Session
and the one-off payments would be added to the 1st invoice
as if you are manually creating a subscription with https://docs.stripe.com/api/subscriptions/create#create_subscription-add_invoice_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
the one-off don't recur monthly, is that still ok
yes as I said it will only be on the first invoice
ok
ok, just confirming again, invoice.paid won't trigger if the CheckoutSession has only one-off items
in that case, I have to use the checkout.session.completed right?
hi! I'm taking over this thread.
thank you @hazy star
yes that sounds correct. but I recommend testing all of this in test mode to make sure it works as expected.
will customer.subscription.created only be triggered if the payment for the subscription is completed?
and what about the scenario of a subscription has a trial? which webhook would you use if using Stripe Checkout?
if you are using Checkout Session, I would always listen to checkout.session.completed
ok
any idea if PHP SDK has a method to convert the payload received on webhook to convert to its specific object. For example, on the checkout.session.completed, convert the payload to the Checkout\Session object?
Well the checkout.session.completed does contain a Checkout Session payload.
right, but want to convert the json object on the request to Checkout Session object.
not sure if I am saying this right.
Well you would do something like $checkout = $event->data->object, and then in the $checkout variable you have a Checkout Session object and can access all its properties
ok, thank you
happy to help ๐
on https://docs.stripe.com/billing/subscriptions/webhooks, it says that customer.subscription.deleted is called when the subscription ends. got a question about this
sure, what's the question?
this doesn't trigger if a subscription is paused and never unpaused?
will it always stay in this state or will it get deleted at certain point?
correct, in this case the Subscription is not deleted, so customer.subscription.deleted won't trigger
will it always stay in this state
yes, unless you make an API request to change this
ok, in this case, I need to listen to the subscription.updated webhook. correct?
to know when the Subscription is paused? yes.
ok
customer.subscription.updated
but not deleted right? even if I try to retrieve an expired checkout session, I would still get the object right?
correct, but users wouldn't be able to access the url
ok and this applies to any object in Stripe right? for example, if a subscription ends, the customer.subscription.deleted is called, but I can still retrieve that object using the subscription id, right. Its like a soft delete
correct
if the checkoutsession mode is PAYMENT, do we have to use a similar logic like for subscriptions https://docs.stripe.com/api/subscriptions/object#subscription_object-default_payment_method
or will $checkoutSession->payment_intent->payment_method suffice?
Why you want to use the mode payment with checkout Session and Subscription ?
what is the exact use case ?
we are storing the payment method used for the session
our cart has the option to have both one-off items and subscription on the same checkout flow
so if the mode for the checkout session is PAYMENT I need to get the payment method from the payment_intent object. If the mode is SUBSCRIPTION, I need to use the invoice object from the checkout session
our cart has the option to have both one-off items and subscription on the same checkout flow
The you need to use the modeSUBSCRIPTIONand notPAYMENTas you have at least one recurring item
there are chances that the cart can just have one-off items as well
then you use the mode payment
right now I am doing this
if ($checkoutSession->mode === Session::MODE_PAYMENT) {
$paymentMethod = $checkoutSession->payment_intent->payment_method ??
$checkoutSession->customer->invoice_settings->default_payment_method ??
$checkoutSession->customer->default_source;
} else {
$paymentMethod = $checkoutSession->invoice->default_payment_method ??
$checkoutSession->invoice->default_source ??
$checkoutSession->customer->invoice_settings->default_payment_method ??
$checkoutSession->customer->default_source;
}
you make a condition check before creating the Checkout Session
this is part of the webhook
sorry if I did not mention this
this is after the checkout is completed and I need to retrieve the payment method used for the session
i am using the checkout.session.completed webhook
Yes that's good
but you can't use a PaymentMethod create from a Chekcout with mode payment for future usage
is it possible that https://docs.stripe.com/api/payment_intents/object#payment_intent_object-payment_method could be null
if you want to collect the payment for future usage you need to use setup mode
i don't think I will use the setup mode
just the payment and subscription based on what is on the cart
Yes, if the payment_intent is not completed yet
when using Subscirpiton mode you can use the payment method as a default payment method for the customer
but not in the case of Payment
to put it clearly, if the checkout is complete and the checkout session mode is PAYMENT are there chances of checkoutsession->payment_intent->payment_method to be null ?
No I don't think so.
do I still need to check for the customer.invoice_settings if the mode is PAYMENT, like I have done above
Why you want to check that field if the checkout session is already completed ?
which field are you referring to on the last message?
customer.invoice_settings
This thread has been ongoing for almost ~3 hours at this point. What specifically are you trying to achieve?
there are multiple questions in this thread which have already been solved, but the last one was in relation to getting the payment method from the checkout session
It'd be set on either the payment_intent or the subscription depending on the mode of the session
Checkout doesn't automatically set customer[invoice_settings][default_payment_method]
just to give you an overview, our app has a custom cart functionality, that supports adding both recurring and one-off items. We set the mode for the CheckoutSession when we create it based on the items on the Cart. So if it has atleast one recurring product, then we set the mode to SUBSCRIPTION else PAYMENT. We never set the mode to FUTURE. Once the checkout is completed, we use the checkout.session.completed webhook to process the checkout and convert our cart to an Order. In this process, we also want to store what payment method was used by the customer for processing the checkout
When doing this, we check if the mode is PAYMENT or SUBSCRIPTION
if the mode is PAYMENT we use the session->payment_intent->payment_method object
but if the mode is SUBSCRIPTION we use a logic to get the payment method
And for mode: 'subscription' you can use subscription[default_payment_method]
because session->invoice->default_payment_method and session->invoice->default_source returns null at times
which is why we added this functionality
if ($checkoutSession->mode === Session::MODE_PAYMENT) {
$stripePaymentMethod = $checkoutSession->payment_intent->payment_method ??
$checkoutSession->customer->invoice_settings->default_payment_method ??
$checkoutSession->customer->default_source;
} else {
$stripePaymentMethod = $checkoutSession->invoice->default_payment_method ??
$checkoutSession->invoice->default_source ??
$checkoutSession->customer->invoice_settings->default_payment_method ??
$checkoutSession->customer->default_source;
}
if ($stripePaymentMethod instanceof PaymentMethod) {
$userPaymentMethod = $user->saveUsingStripePaymentMethod($stripePaymentMethod);
} else {
$userPaymentMethod = $user->saveUsingStripeCard($stripePaymentMethod);
}
return $userPaymentMethod;
Seems overly elaborate when you just need to check the field I stated
its elaborate, because we have some subscriptions on our end where that field is null
some old subscriptions return the card object
Sure, but that won't ever happen on new subscriptions created by Checkout
So if is this a webhook handler listening for checkout.session.completed events the the old subscriptions are irrelevant no?
the old subscriptions also used Stripe Checkout, so this was an additional check
so you are saying subscription[default_payment_method] will always have a value on checkout.session.completed
I don't need all these checks anymore
Assuming payment details are provided on the session payment page, yes
this should be sufficient?
if ($checkoutSession->mode === Session::MODE_PAYMENT) {
$stripePaymentMethod = $checkoutSession->payment_intent->payment_method;
} else {
$stripePaymentMethod = $checkoutSession->invoice->default_payment_method;
}
return $user->saveUsingStripePaymentMethod($stripePaymentMethod);
isn't that the only way to complete the session if the mode is either PAYMENT or SUBSCRIPTION
Well not if you enable free trials without payment details: https://docs.stripe.com/payments/checkout/free-trials
ah ok, we don't run that risk right now,
subscription -> default_payment_method
do I need to loop through the invoice line items to get the default_payment_method from the subscription object?
as I mentioned before, I am using the checkout.session.completed webhook, so I have the checkoutSession on the payload
oh, there is a checkoutsession.subscription
What? No invoice has nothing to do with this. There's a subscription field on the Checkout Session object
That'll only be set in mode: 'subscription' sessions, and you can expand it to get default_payment_method which Checkout will always set
yes, that is part of the mode check, thank you. this is quite simple now