I’m trying to create a subscription with stripe where you have an initial 10.99$ a month for a 100 units, then once you exceed the 100 included units, it charges you 10 cents per extra units. Eveything seems fine in the code I wrote, but when I execute it, I get the following error from stripe: You may only specify one of these parameters: unit_amount, unit_amount_decimal.
# Regular flat fee of $10.99 per month price
flat_price = stripe.Price.create(
unit_amount_decimal=1099,
product=product.id,
currency="usd",
recurring={"interval": "month"},
billing_scheme="per_unit",
)
# Set meter for calculating data usage
meter = stripe.billing.Meter.create(
display_name="GB Usage",
event_name="gb_usage",
default_aggregation={"formula": "sum"},
customer_mapping={"event_payload_key": "stripe_customer_id", "type": "by_id"},
value_settings={"event_payload_key": "value"}
)
# Calculated extra subsequent usage price
metered_price = stripe.Price.create(
product=product.id,
currency="usd",
billing_scheme="tiered",
recurring={
"usage_type": "metered",
"interval": "month",
"meter": meter.id
},
tiers_mode="graduated",
tiers=[
{"up_to": 100, "unit_amount_decimal": "0"}, # First 100GB included
{"up_to": "inf", "unit_amount_decimal": "10"} # $0.10 per additional 1GB
]
)
# Create plan B
planB = stripe.Plan.create(
currency="usd",
interval="month",
product=product.id,
nickname="Plan B",
billing_scheme="tiered",
tiers_mode="graduated",
tiers=[
flat_price,
metered_price
],
)
In the developer console of stripe, I noticed that the python library of stripe duplicates the value to unit_amount
. I tried to fix it by setting it to None
but it just overrides my value and adds back the duplicate.
{
"billing_scheme": "tiered",
"currency": "usd",
"nickname": "Plan B",
"interval": "month",
"tiers": {
"0": {
"billing_scheme": "per_unit",
"recurring": {
"interval": "month",
"usage_type": "licensed",
"interval_count": "1"
},
"type": "recurring",
"active": "True",
"id": "price_1PFHK1BYQqea3LZFgSDSejxa",
"object": "price",
"currency": "usd",
"unit_amount_decimal": "1099",
"tax_behavior": "unspecified",
"livemode": "False",
"unit_amount": "1099",
"created": "1715439289",
"product": "prod_Q5SEIDkl4LD525"
},
{
...
}
}
I use the stripe library 9.6.0
under python 3.11.6
I’m trying to figure out if the problem is the combination of both price configuration onto my plan which clashes, or is it the python library that’s broken?