#127-checkout-pricing

1 messages · Page 1 of 1 (latest)

umbral sinewBOT
proud tide
#

127-checkout-pricing

warm flume
#

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?

proud tide
#

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

warm flume
#

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',
});
proud tide
#

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

warm flume
#

And should this endpoint be a POST or GET?

proud tide
#

what do you think?

warm flume
#

Trying GET seems to give me a better result

proud tide
#

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

warm flume
#

That does make sense. I tested it out and it seems to work fully which is beautiful. That was super helpful!