Я бы рекомендовал до прикрепления подписки извлечь объект клиента, для которого вы хотите прикрепить подписку, определить валюту клиента и, при необходимости, создать новый план (в валюте). , Однако для этого вам, вероятно, понадобится использовать API конвертации валют от стороннего производителя, поскольку Stripe этого не поддерживает.
Пример на Python:
plan_id = ... # This would have been retrieved from your form, most likely (eg. 'basic-plan')
usd_plan = stripe.Plan.retrieve(plan_id)
cus = stripe.Customer.retrieve()
if cus.currency is not 'usd': # if the currency of the customer is not "usd"
# create a new plan id for currency (eg. 'basic-plan-cad')
plan_id = plan_id + '-' + cus.currency # check if there is a
# use a 3rd party to get the currency
amount_in_currency = amount * <API_CONVERSION_RATE>
# check that the plan doesn't already exist and create it otherwise
try:
stripe.Plan.create(
amount=amount_in_currency,
interval=usd_plan.interval,
product={
"name": usd_plan.product
},
currency=cus.currency,
id=plan_id
)
except Exception as e: # this may fail if the plan already exists
break
# create the subscription
sub = stripe.Subscription.create(
customer="cus_xxx",
items=[
{
"plan": plan_id, # this will either be the `basic-plan` or `basic-plan-{currency}
},
]
)