#Rohit89
1 messages · Page 1 of 1 (latest)
The paymentIntent or charge object doesn't carry the information about item quantity, you should listen to checkout.session.completed events instead
Once you have the checkout session object, expand the line_items field (https://stripe.com/docs/api/checkout/sessions/object?lang=ruby#checkout_session_object-line_items) to get the price and quantity.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok, I have checked the checkout.session.completed webhook response too. It also wont have line_items details
As I explained before, you need expand the line_items field, it not included by default. (https://stripe.com/docs/api/expanding_objects?lang=ruby#expanding_objects)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok. Can we expand line_items in charge object after charge is succesfull or it can only be expanded for checkout.session completed?
There's not line_items in a charge object.
ok so that can be expanded in checkout.session objec
Is there any documentation where I can see what are expandable in charge object and checkout session
?
Sure you can find them in API reference
Charge -> https://stripe.com/docs/api/charges/object?lang=ruby#charge_object
Checkout Session -> https://stripe.com/docs/api/checkout/sessions/object?lang=ruby#checkout_session_object
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thank you so much! Let me check
Does the charge object include info about any promo code used? any discount?
No it doesn't, but you can find them in a checkout session object
Sure. And is there way to change the description that I can see under recent activity when I view customer.
Payment for US$316.00 was successful
Is it possible to change or customise this?
You can programmatically change the charge's description through API (https://stripe.com/docs/api/charges/update?lang=ruby#update_charge-description)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Awesome. Last thing, is there any doc where I can see the list of events that happen in order when I do payment mode can be payment or subscription.
Are you asking a list of events related to checkout session?
Yes. Mode can be payment or subscription.
https://stripe.com/docs/api/events/types you can find all events here. The events starts with checkout.session.xx are events related to checkout sessions.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
It just all have events but not in order. Which one initiated first and so on
There's no guarantee on the event sequence and your app shouldn't reply on the sequence. See this https://stripe.com/docs/webhooks/best-practices#event-ordering for the best practice
Ah ok. but checkout.session.completed will always be initiated in end after charge is successful charge.succeeded. Correct?
Not necessary.
checkout.session.completed simply means the checkout session is completed. For payment method which result can't be confirmed immediately, the payment_intent's status can be pending when checkout.session.completed happens
So you should listen to payment_intent.succeeded and payment_intent.payment_failed event to get notified about the payment result
oh, line items info can be get from payment_intent.succeeded ??
Basically our customers do one time payment. I just want to capture the quantity and amount when payment is succeeded.
No, the line_items are available in checkout session, not payment_intent.
Oh. Checkout Session will be completed with payment pending
Here's my suggestion.
You listen to payment_intent.succeeded, and pass the payment_intent ID to the List Checkout Session API to retrieve the checkout session object https://stripe.com/docs/api/checkout/sessions/list?lang=ruby#list_checkout_sessions-payment_intent
And from there you can expand the line_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.
let me check
Stripe::Checkout::Session.retrieve(
'cs_test_a1vWwiWdNK9WSAG9nXUU6n9iNvzsYVGd245R2oxyqdqHHGXOiBlg6dyKRD',
)
If this is way to reterive checkout session, how we can pass payement_intent_id
You should call the list API, not retrieve API
Stripe::Checkout::Session.list({payment_intent: 'YOUR_PI'})```
Ok. This should work? Stripe::Checkout::Session.list({payment_intent: 'pi_3MRRegLv5rdhLZWU01sMYtom', expand: ['line_items']})
expand line items
Yup, you can do this as well
I am getting
Stripe::InvalidRequestError: This property cannot be expanded (line_items).
expand: ['data.line_items']}
[25] pry(main)> Stripe::Checkout::Session.list({payment_intent: 'pi_3MRRegLv5rdhLZWU01sMYtom', expand: ['line_items']})
Stripe::InvalidRequestError: This property cannot be expanded (line_items). You may want to try expanding 'data.line_items' instead.
change to data.line_items
You are right. you can find them here https://stripe.com/docs/api/checkout/sessions/object?lang=ruby#checkout_session_object-total_details-breakdown-discounts
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thank you so much for help
Oh, remember to expand the breakdown field, it's not included by default
Yeah.
Adding a description to checkout create object will update the description here?
You mean setting a description to charge/payment_intent object?
https://stripe.com/docs/api/checkout/sessions/create?lang=ruby#create_checkout_session-payment_intent_data-description yes you can specify a description when creating a checkout session
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.