#Mike.7189-quantity-producst

1 messages ยท Page 1 of 1 (latest)

strong cliff
#

Hi there ๐Ÿ‘‹ for question 1, can you elaborate on what you mean? Where in your process would you like to reduce the quantity?

near linden
#

when the customer was charged

strong cliff
#

I'm sorry, but I'm still not following. Why would you be reducing the quantity of items after a customer has been charged?

near linden
#

Because customer has paid for the item. And therefore Iโ€™d like to reduce the stock

strong cliff
#

Oh, you're trying to decrease the quantity in your inventory management?

near linden
#

Currently I am handling it in a very dodgy way:
On /success I am retrieving a session, getting the quantity and sending request to the database to reduce the quantity

#

And so if user is dumb enough to share this link or reload the page Iโ€™ll have quantity reduced again

#

So what I think is that I have to do in webhooks

#

So itโ€™ll happen just once per transaction

near linden
#

Btw are you a real meeseeks? I heard they might be really helpful ๐Ÿ˜…

strong cliff
#

Haha, I strive to be, it seemed a very fitting avatar for such a forum ๐Ÿ˜„

#

Alright, so it does sound like you'll want to listen to webhook events. Earlier you mentioned that you're retrieving a session, can you confirm if you're using Payment Links or Checkout Sessions?

near linden
#

Checkout sessions with redirect to stripe checkout

strong cliff
near linden
#

I don't really understand how to extend it

#
            switch (event.type) {
                case "charge.succeeded":
                    const chargeSucceded = event.data.object;
                    console.log("Billing Details:", event.data.object.billing_details);
                    console.log("Receipt URL: ", event.data.object.receipt_url);
                    console.log("Outcome: ", event.data.object.outcome);
                    break;
                default:
                    console.log(`Unhandled event type: ${event.type}`);
                    break;
            }
#

shall it be like:

case "checkout.session.completed":
      const session = await stripe.checkout.sessions.retrieve(
        {{what here?}},
        { expand: ["line_items.data"] }
    );
#

is session_id somewhere in the event object, right?

strong cliff
#

If you listen to the checkout.session.completed event, then the event object that you receive will also contain the session object.

#

So you don't need to retrieve it again.

near linden
#
Checkout Session Completed:  {
  id: 'cs_test_a17R3XhEfIE75AMPFgYA02eRae2iRe4Nj7me7oooroZJ30v2rZiXdysOSE',

does cs stands for checkout session?

#
case "checkout.session.completed":
  console.log("Checkout Session Completed: ", event.data.object);
break;
#

so getting checkout_session_id from event, retrieve the session, find quantity in there and send the request to the database, am I getting it right?

#

alright, I think i got it.
Next question: how do I achieve product (with price)?

#

I mean via api. Ez peasy via dashboard, but I need to do it with api ๐Ÿ™‚

strong cliff
#

Yes, cs stands for Checkout Session. You don't need to retrieve the session explicitly, it should be contained in event.data.object.

near linden
#

and I don't know how to extend it

near linden
#

I know how to expand it at checkout.session.retrieve, but how can I expand it at event?

#

whatever... it's no big deal. The shop ain't that big to care about complexity and stuff.

So how do I achieve the product (with price) via api?

strong cliff
#

Sorry, I was digging into logs on my account regarding the session events. Can you elaborate what you mean by 'achieve'?

#

And apologies, you're right that line_items aren't included by default in the checkout object, so you will need to retrieve the session with that expansion option.

tiny jolt
#

@near linden Expansion isn't supported in webhook events -- you must retrieve explicitly

near linden
#

so when I click create item in my CMS: it creates stripe product and stripe price for it and saves the stripe_price to my databse.
When I click delete the item it deletes it from my database, but it remains as an active product in my stripe dashboard

#

so I want to put the product in archive via api call

tiny jolt
near linden
#

and it'll put the product into archived?

tiny jolt
#

AFAIK, yes, but that's just a dashboard representation -- the API calls this "active"

#

For help with the dashboard UI you should work with our support team: https://support.stripe.com/contact

near linden
#

price.active === true means the product is in Available;
price.active === false means the product is in Archived ?

tiny jolt
#

Price and Product are two different things, which do you mean?

near linden
#

oh yes

tiny jolt
near linden
#

well the way I do:
I create a product and price for it. So in my case product kinda equals price

tiny jolt
#

You may consider them that way, but they are separate entities

near linden
#

so I want to archive a product

#

so it can't be used again, but can be accessed if needed (in case of refunds or anything else, so it has to be there with the price what it had, but remain unavailable for the audience)

#

i think product.active = false is exactly what I need

tiny jolt
#

Yep, i'd say so! Give it a try and make sure it does what you need

near linden
#

will do, thanks ๐Ÿ˜‰