#RubyDev-price_id

1 messages ยท Page 1 of 1 (latest)

static geyser
royal cradle
#

Can anyone help please?

static geyser
#

Hi @royal cradle! I'm having a look now.

royal cradle
#

Okay

static geyser
royal cradle
#

Okay so you mean I can get only price_id within checkout session completed right?

static geyser
#

Yes, while expanding line_items.data.price (by default the price ID is not included in the checkout session object)

royal cradle
#

sure thanks let me check it

#

brb

#

Thanks again

royal cradle
#

Sorry but I'm not receiving any line items, price, etc within checkout.session.completed

static geyser
#

Can you share your code with the expand?

royal cradle
#

Okay sure can I give you event id

static geyser
#

That works too!

royal cradle
#

sorry duplicate

#

brb

static geyser
#

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:

  1. Get the Checkout Session ID
  2. Then retrieve the Checkout Session with that ID (https://stripe.com/docs/api/checkout/sessions/retrieve) while using expand:["line_items.data.price"]
  3. 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);
royal cradle
#

ah great super awesome , let me check

static geyser
#

RubyDev-price_id

royal cradle
#

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

royal cradle
#

Hello @static geyser u there?

smoky saffron
#

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?

royal cradle
#

Okay

#

How to use expansion feature?

#

actually I'm using Stripe link to pay

#

not sure that I can make any modification, can I?

smoky saffron
royal cradle
#

I see can I pass this expand to customer as well?

smoky saffron
#

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

royal cradle
#

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?

smoky saffron
#

Try that again, but instead of:
expand: ["line_items.data.price"]
try this:
expand: ["line_items"]

royal cradle
#

Worked sorry thanks

#

let me work on this