#stitch_api

1 messages ยท Page 1 of 1 (latest)

carmine surgeBOT
#

๐Ÿ‘‹ 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.

plucky slate
#

Hi there

acoustic ice
#

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

plucky slate
#

Okay, so you're creating an inline Price in aud and also creating an inline shipping_rate but in usd

acoustic ice
#

Yes that is right

plucky slate
#

why not create an inline shipping_rate in aud?

acoustic ice
#

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?

plucky slate
#

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?

acoustic ice
#

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.
plucky slate
#

oh, I see, you should remove

  aud: {
   amount: "1500",
  },```
acoustic ice
#

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

plucky slate
#

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

acoustic ice
#

you're right. i changed this code by mistake, let me run the request again

carmine surgeBOT
acoustic ice
#
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

north latch
#

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

[0] https://docs.stripe.com/api/expanding_objects

#

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

acoustic ice
#

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

north latch
#
acoustic ice
#

holy cow i got it working mostly

#

just a math error but it shows the currency

north latch
#

๐Ÿ‘

acoustic ice
#

ty @north latch and @plucky slate โค๏ธ