#stitch_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1267992052256215041
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there
Hello! thank you for reaching out so quick
for item in items:
line_items.append({
'price_data': {
'currency': item['currency'],
'product': productdb.get_real_product_id(item['product_id']), # get stripe product ID from obfuscated
},
'quantity': item['quantity']
})
checkout_session = stripe.checkout.Session.create(
line_items=line_items,
mode='payment',
success_url=CHECKOUT_SUCCESS_URL + order_id,
shipping_address_collection={
'allowed_countries': ['US', 'CA', 'GB', 'AU', "GB", "DE", "FR", "IT", "ES", "NL", "SE", "DK", "NO", "FI", "BE", "CH", "AT", "IE", "PT", "LU", "PL", "CZ", "SK", "HU", "GR", "BG", "RO", "HR", "SI", "LT", "LV", "EE", "MT", "CY"]
},
shipping_options=[
{
"shipping_rate_data": {
'display_name': 'UPS Ground',
'type': 'fixed_amount',
'fixed_amount': {
'amount': 1000, # $10.00
'currency': 'usd',
'currency_options': {
"eur": {
'amount': 900,
},
"cad": {
'amount': 1300,
},
'aud': {
'amount': 1500,
}
}
}
}
}
],
metadata=metadata,
)
return JSONResponse(
content={
"message": "ok",
"url": checkout_session.url
}, status_code=200)
here is some code for context on my python backend
Okay, so you're creating an inline Price in aud and also creating an inline shipping_rate but in usd
Yes that is right
why not create an inline shipping_rate in aud?
I thought it would automatically choose a rate for the provided currency, using the item's currency as reference
wait, i think i see what you mean
do i add another dict to shipping_options
for each currency supported?
Well hmm. If you use shipping_options.shipping_rate_data.fixed_amount.currency: 'aud' and define a USD price under shipping_options.shipping_rate_data.fixed_amount.currency_options, do you still get the same error?
one moment...
I get this error:
stripe._error.InvalidRequestError: Request req_L3sL5UcA4A2NGX: You are specifying a currency option that matches the top-level currency for this shipping rate. Please remove this currency option and it will be added automatically on creation.
oh, I see, you should remove
aud: {
amount: "1500",
},```
ah
lets see
stripe._error.InvalidRequestError: Request req_4COyD6YEyHtvYo: The default currency of your line items (`usd`) must match the default currency of your shipping rate (`aud`).
this is the data for line items btw
note: "price" has "price_" truncated but dont worry abt that
and "product_id" is obfuscated with my cached db
Okay, I think you're changing things up a bit. The previous two requests you shared created an inline Price in aud. req_4COyD6YEyHtvYo uses an existing Price ID that has a default price in usd
you're right. i changed this code by mistake, let me run the request again
stripe._error.InvalidRequestError: Request req_1sBcI4cN7lbNX7: Prices require an `unit_amount` or `unit_amount_decimal` parameter to be set.
I believe it's saying this because of the way i defined my inline price data. i want it to automatically fetch the prices from the product object
How can i get the currency options for a price object? I don't see it in the reference
hello! taking over from roadrunner, gimme a while to catch up and get back to you
If you want to get the full list of currencies for a multiple currency Price, when you retrieve the Price, you will need to expand [0] currency_options https://docs.stripe.com/api/prices/object#price_object-currency_options
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
req_1sBcI4cN7lbNX7 - where the error mentioned Prices require an unit_amount or unit_amount_decimal parameter to be set. You need to set either unit_amount or unit_amount_decimal, you didn't define either one
Okay, i updated the code to this
it's saying the same error, maybe i defined it wrong?
```stripe._error.InvalidRequestError: Request req_Cw8YPTmISKXZDu: Prices require an unit_amount or unit_amount_decimal parameter to be set.
Oh, its saying 'unit_amount': product_default_price.currency_options[item['currency']].unit_amount, is None
i still don't see you defining it in req_Cw8YPTmISKXZDu, it should be either https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-price_data-unit_amount or https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-price_data-unit_amount_decimal
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
๐
ty @north latch and @plucky slate โค๏ธ