#127-checkout-pricing
1 messages · Page 1 of 1 (latest)
What I'm looking at at that link is this:
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
line_items: [
{price: 'price_H5ggYwtDq4fbrJ', quantity: 2},
],
mode: 'payment',
});
It still seems like the price has to be pre-entered manually by me in the console. Is this correct?
Can I just specify a decimal amount instead?
the price parameter is the id of an existing Price object price_123 that you would have created in your account yes.
If you want to pass a custom price amount each time, you have to use price_data which I just linked you to above
So something like this:
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
line_items: [
price_data : {
currency : "usd",
product : "test_product",
tax_behavior: "inclusive"
}
],
mode: 'payment',
});
well it's an array of hashes so const session = await stripe.checkout.sessions.create({ success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price_data : { ... } } ], mode: 'payment', }); but yes
And should this endpoint be a POST or GET?
what do you think?
Trying GET seems to give me a better result
that's really up to you. I think it should be a POST since your code is explicitly creating a resource (A Checkout Session). But that's up to you
That does make sense. I tested it out and it seems to work fully which is beautiful. That was super helpful!