#jackisnotreal
1 messages ยท Page 1 of 1 (latest)
https://i.imgur.com/v91owL9.png I've just been sent the following from live chat, ouch.
I think that answers my own question then, so here's a new one:
Is there an efficient way to use Stripe Checkout, and use custom prices on the fly?
My whole business is based around custom prices and invoices on-the-fly so constantly creating new prices in the dashboard would be a pain.
I essentially need to be able to specify a checkout session with 2 items:
- The product cost (decided per-ticket)
- The handling fees (10% of product cost, worked out by using Math and Float)
You can use inline prices, yes: https://stripe.com/docs/products-prices/pricing-models#variable-pricing
The example there is for Subscriptions, but works for Checkout too: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Oh sound, I was just about to ask. Thanks boss.
Can you give me an example of starting a checkout session using the 2 things above, just an example of $25 and $2.50
๐ stepping in here as ynnoj needs to step away
No worries, cheers.
Yes, for stripe checkout.
Gotcha then you basically just replace the price parameter with price_data.currency and the other required parameters that we show here: https://stripe.com/docs/api/checkout/sessions/create?lang=curl#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So like: curl https://api.stripe.com/v1/checkout/sessions \ -u sk_test_123: \ --data-urlencode success_url="https://example.com/success" \ -d "line_items[0][price_data][currency]"="usd" \ -d "line_items[0][quantity]"=2 \ -d mode=payment
And then you would need more than just currency there
Imo the best thing to do is to just test this out yourself
const session = await stripe.checkout.sessions.create({
success_url: `https://pixelprojects.xyz/`,
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Stubborn Attachments',
},
unit_amount: 2000,
},
quantity: 1,
},
{ price_data: {
currency: 'usd',
product_data: {
name: '10% of this',
},
unit_amount: 200,
},
quantity: 1,
},
]
});```
Would this work in a node runtime?
Yep that looks good at a glance
Think you missing mode
But overall you got the right idea
Where would mode go? On each line item?
Oh, at the bottom I see - where can I find the different ones to use, because I can't see the success_url one either at https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I could just be being super blind tho
ohhhhhhhhhhh yep i didnt scroll down enough, my bad ๐
๐