#chronogen
1 messages ยท Page 1 of 1 (latest)
Hi there!
Hi
We automatically close inactive threads.
Can you summarize your quesiton here in this new thread?
I want to get a list of products (through the API) that the user has purchased. When a user buys a subscription, there is an invoice in the payment_intent object and I can find out which products were sold. But if the user buys a "one time product", then I cannot determine what the person bought, since there is no invoice in the payment_intent object. How can I understand which object the user bought?
Thank you.
When you create the PaymentIntent, you could store additional information in the metadata field.
You can learn more about metadata here: https://stripe.com/docs/api/metadata
I am not creating PyamentIntent via API. I create a product through a website. Then I set the price for the product. Then I create a link. And I publish the link. After that, I listen to webhooks to see who and what bought.
I am not creating PyamentIntent via API.
Are you a software developer?
Yes
When I receive webhooks, if it is a "one time purchase" then I don't know how to get information about which product was purchased.
Yes I already answerd that question. If the amount is not enough for you, you need to store additional information in the metadata property. There's no other way.
Apparently we are talking about different things. Now I will describe the whole problem in more detail. This is definitely not the answer to my question.
Yes feel free to share more information.
But a PaymentIntent for one time purchase will only contain an amount, and no information about the product being bought.
To solve this: when you create the PaymentIntent, set some metadata to store additional information (like the product and/or quantity being bought). Then in your webhook endpoint you can read that metadata to get more information.
I'm creating a new product in the Stripe dashboard. Then I set a price for this product and create a link to this product. I am sending this link to my client so that they can make a purchase. I do all this through the website and not through the API.
I have set up a webhook. It is possible to create two types of payment on Stripe - one time purchase and recurring.
Recurring. When a person buys a product that has the recurring option set, then I get the payment_intent.succeeded webhook. This webhook has an invoice field. Through this invoice, I can then understand what exactly my user bought. I make a request via API and receive an invoice object where there are IDs of purchased products. So I have no problems here.
One time puruchase. But when the user makes a one-time purchase, I again receive the payment_intent.succeeded webhook. But in this case there is no invoice. And I can't find out what product my user bought.
Question. How can I find out what product my user bought?
and create a link to this product
Can you clarify what you mean by this? A Payment Link? Or something else?
If it's a PaymentLink, then you should listen to checkout.session.completed webhook event. And then retrieve the line_items property that will contain the information you need https://stripe.com/docs/api/checkout/sessions/object?lang=node#checkout_session_object-line_items
Note that line_items is not included by default, you will need to Expand it https://stripe.com/docs/expand
This doesn't work for me. Here is my code.
Oh sorry, this is output
This doesn't work for me.
Which part doesn't work? Did you useexpand: ["line_items"]as I explained above
Here is my code
$s = \Stripe\Checkout\Session::retrieve(
'my key',
['expand' => ['line_items']]
);
echo json_encode($s);
Can you share the request ID (req_xxx)? You can find it here https://dashboard.stripe.com/test/logs
req_dK3Mc13ivr41lX
You can see here no expand parameter were set, so there's an issue in your code: https://dashboard.stripe.com/test/logs/req_dK3Mc13ivr41lX
I think it should be:
$s = \Stripe\Checkout\Session::retrieve(
['id' => 'xxx', 'expand' => ['line_items']]
);
Damn, I guess I understand. I have Stripe SDK in my project. But it is very old. Maybe that's the problem. I'm currently trying to make a request via curl.
You can see exampls of expand with curl in the link I shared earlier: https://stripe.com/docs/expand
Happy to help ๐
Can I rate this chat somewhere? ๐
No need, but thanks ๐
Thank you ๐