Python 3.x 为什么在创建发票之前要对帐户收费
在向用户注册订阅时,如果用户在我的系统中有信用,我希望收取不同的费率。但是,当用户注册订阅时,Stripe会立即向他们收费,而不是等待我在invoice创建的webhook上修改invoice对象 根据这些文档,我的理解是,向用户收费将等到发票创建后,再返回200美元。然而,我的发票创建的webhook返回500的,所以我知道这不是真的 我当前的代码如下所示:Python 3.x 为什么在创建发票之前要对帐户收费,python-3.x,stripe-payments,Python 3.x,Stripe Payments,在向用户注册订阅时,如果用户在我的系统中有信用,我希望收取不同的费率。但是,当用户注册订阅时,Stripe会立即向他们收费,而不是等待我在invoice创建的webhook上修改invoice对象 根据这些文档,我的理解是,向用户收费将等到发票创建后,再返回200美元。然而,我的发票创建的webhook返回500的,所以我知道这不是真的 我当前的代码如下所示: stripe.Subscription.create( customer=user.stripe_customer_id,
stripe.Subscription.create(
customer=user.stripe_customer_id,
plan=subscription_plan.stripe_product_id,
trial_period_days=trial_period,
idempotency_key=key)
我的webhook看起来像:
def invoice_created(request, *args, **kwargs):
user = request.user
invoice = request.data['data']['object']
stripe_customer = stripe.Customer.retrieve(user.stripe_customer_id)
if request.user.credit:
stripe_customer.add_invoice_item(
amount=-user.credit,
currency='usd',
description='Applied ${:.2f} of credit for subscription.'.format(user.credit),
invoice=invoice['id'],
)
return Response(status=200)
当我试图更新发票时,它说发票不能修改。我得到的错误是:
stripe.error.InvalidRequestError: Request "": Invalid invoice: This invoice is no longer editable
我在这里该怎么办
根据这些文档,我的理解是,向用户收费将等到发票创建后,再返回200美元
但对于通常会立即充电的蓄电池而言,情况并非如此
如果要将项目添加到第一个项目中,则需要在创建订阅之前添加项目