#RubyDev-price_id
1 messages ยท Page 1 of 1 (latest)
Can anyone help please?
Hi @royal cradle! I'm having a look now.
Okay
For payment links, to retrieve the price ID in a webhook, you need to:
- Listen to
checkout.session.completed - By default you won't see the price ID in the Chekout object, but you can get it by expanding the
line_items.data.priceparameter https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price
Here's our documentation on how to use expand: https://stripe.com/docs/api/expanding_objects
Okay so you mean I can get only price_id within checkout session completed right?
Yes, while expanding line_items.data.price (by default the price ID is not included in the checkout session object)
Sorry but I'm not receiving any line items, price, etc within checkout.session.completed
Can you share your code with the expand?
Okay sure can I give you event id
That works too!
When listening to the checkout.session.completed event, you won't find the price ID directly.
What you need to do in your webhook is:
- Get the Checkout Session ID
- Then retrieve the Checkout Session with that ID (https://stripe.com/docs/api/checkout/sessions/retrieve) while using
expand:["line_items.data.price"] - And now you'll have access to the price ID.
In node.js it would look something like this:
const session_id = event.data.object.id;
const session = await stripe.checkout.sessions.retrieve(session_id, { expand:["line_items.data.price"] });
console.log("price ID: ", session.line_items.data[0].price.id);
ah great super awesome , let me check
RubyDev-price_id
hmm well I retrieve it but no price object still
actually I made a payment via Stripe link, does that make any difference?
#<Stripe::Checkout::Session:0x3ffa57e4c460 id=cs_test_a1rS2BqW3g4QhSOn9Rl9EbFHuKHRB2iwebQdvzPtYC8OSWj89RDKYhXd38> JSON: {
"id": "cs_test_a1rS2BqW3g4QhSOn9Rl9EbFHuKHRB2iwebQdvzPtYC8OSWj89RDKYhXd38",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": false,
"amount_subtotal": 10000,
"amount_total": 10000,
"automatic_tax": {"enabled":false,"status":null},
"billing_address_collection": "auto",
"cancel_url": "https://stripe.com",
"client_reference_id": null,
"consent": null,
"consent_collection": null,
"currency": "usd",
"customer": "cus_Kkec718cAXOoAV",
"customer_details": {"email":"dec10test17@test.com","phone":null,"tax_exempt":"none","tax_ids":[]},
"customer_email": null,
"expires_at": 1639229874,
"livemode": false,
"locale": "auto",
"metadata": {},
"mode": "payment",
"payment_intent": "pi_3K59IMGABbZHUFxp1qZWXPKn",
"payment_method_options": {},
"payment_method_types": [
"card"
],
"payment_status": "paid",
"phone_number_collection": {"enabled":false},
"recovered_from": null,
"setup_intent": null,
"shipping": null,
"shipping_address_collection": null,
"shipping_options": [
],
"shipping_rate": null,
"status": "complete",
"submit_type": null,
"subscription": null,
"success_url": "https://stripe.com",
"total_details": {"amount_discount":0,"amount_shipping":0,"amount_tax":0},
"url": null
}
Please have a look there is no price object
Please help
Hello @static geyser u there?
Hi there ๐ I'm stepping in and getting caught up on the thread.
For the request where you retrieved the checkout session, did you use our expansion feature to expand line_items?
Okay
How to use expansion feature?
actually I'm using Stripe link to pay
not sure that I can make any modification, can I?
Apologies, I meant to link you to our expansion documentation:
https://stripe.com/docs/api/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.
I see can I pass this expand to customer as well?
You can pass it for most objects, but only certain attributes are EXPANDABLE and are flagged as such in our API reference guide. For example, line_items, on the checkout session object, are expandable as noted here:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-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.
undefined method `strip' for ["line_items.data.price"]:Array
Stripe::Checkout::Session.retrieve(checkout_session_id, {expand: ["line_items.data.price"], stripe_account: site.stripe_user_id })
Do I need to update anything on gem side?
Try that again, but instead of:
expand: ["line_items.data.price"]
try this:
expand: ["line_items"]