#Mike.7189-quantity-producst
1 messages ยท Page 1 of 1 (latest)
Hi there ๐ for question 1, can you elaborate on what you mean? Where in your process would you like to reduce the quantity?
when the customer was charged
I'm sorry, but I'm still not following. Why would you be reducing the quantity of items after a customer has been charged?
Because customer has paid for the item. And therefore Iโd like to reduce the stock
Oh, you're trying to decrease the quantity in your inventory management?
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
Yes
Btw are you a real meeseeks? I heard they might be really helpful ๐
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?
Checkout sessions with redirect to stripe checkout
Awesome, I think checkout.session.completed is going to be the best event to listen to then:
https://stripe.com/docs/api/events/types#event_types-checkout.session.completed
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
https://fns-accessories.web.app/en/catalog
Hit โbuy nowโ
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?
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.
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 ๐
Yes, cs stands for Checkout Session. You don't need to retrieve the session explicitly, it should be contained in event.data.object.
seems like it is there, but it has no line_objects therefore no quantity
and I don't know how to extend it
case "checkout.session.completed":
const sessionId = await event.data.object.id;
const session = await stripe.checkout.sessions.retrieve(sessionId, {
expand: ["line_items.data"],
});
const { data: items } = await session.line_items;
console.log(items);
break;
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?
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.
@near linden Expansion isn't supported in webhook events -- you must retrieve explicitly
see this archieved badge?
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
You can update to set active=false to prevent a price being used in future:
https://stripe.com/docs/api/prices/update#update_price-active
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and it'll put the product into archived?
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
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
price.active === true means the product is in Available;
price.active === false means the product is in Archived ?
Price and Product are two different things, which do you mean?
oh yes
Product has it's own active setting: https://stripe.com/docs/api/products/update#update_product-active
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
well the way I do:
I create a product and price for it. So in my case product kinda equals price
You may consider them that way, but they are separate entities
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
Yep, i'd say so! Give it a try and make sure it does what you need
will do, thanks ๐