我想向客户展示如果他们对订阅进行更改,则预览了他们的订阅费用。为此,我正在使用“即将发票” API端点:
https://stripe.com /docs/api/Invoices/即将到来的
从该链接中说,“您可以预览更新订阅的效果,包括预览将要进行什么。”。
Exapmle
def retrieveUpcomingInvoice(subscriptionId,customerId,nextPriceId):
try:
# Retrieve the subscription
subscription = stripe.Subscription.retrieve(subscriptionId)
# Retrieve the invoice
invoice = stripe.Invoice.upcoming(
customer=customerId,
subscription=subscriptionId,
subscription_items=[
{
'id': subscription['items']['data'][0].id,
'deleted': True,
},
{
'price': nextPriceId,
'deleted': False,
}
],
)
return invoice
except Exception as e:
return str(e)
这是我获得了用户必须支付的UPGrad订阅金额的
,但仅适用于每月不同的帐单周期到每月订阅”或“每年订阅(相同的帐单周期):
例如,如果我每月以10美元的价格进行基本订阅,并且我将订阅的预付款升级为30美元,比发票升级,以回报,我以40美元的价格获得了金额,这是合并金额和高级的,这是错误的,因为我已经支付了10美元,所以金额应为30-10 = 20 $(已测试:如果我支付的话,则从帐户中删除20美元(并且发票显示40美元,这是错误的)
每月订阅年度订阅或反之亦然(这还可以),
如果我目前我每月进行10美元的基本订阅我升级到每年加上100美元的订阅,然后在金额中即将发票的发票显示正确的信息,该信息是90美元(而且,如果我从帐户中付出90美元),
那么如何在同一计费周期中以相同的计费周期获得coorect金额
I'd like to show a customer a preview (or a quote) of what their subscription charges will be if they make changes to their subscription. For this, I'm using the "upcoming invoice" API endpoint:
https://stripe.com/docs/api/invoices/upcoming
From that link, they state that "You can preview the effects of updating a subscription, including a preview of what proration will take place.".
here is the exapmle
def retrieveUpcomingInvoice(subscriptionId,customerId,nextPriceId):
try:
# Retrieve the subscription
subscription = stripe.Subscription.retrieve(subscriptionId)
# Retrieve the invoice
invoice = stripe.Invoice.upcoming(
customer=customerId,
subscription=subscriptionId,
subscription_items=[
{
'id': subscription['items']['data'][0].id,
'deleted': True,
},
{
'price': nextPriceId,
'deleted': False,
}
],
)
return invoice
except Exception as e:
return str(e)
i got the amount_due for upgrad subscription amount user has to pay but only for different billing cycle
Monthly to monthly subscription "or" yearly to yearly subscription(same billing cycle):
like if i am on monthly basic subscription for $10 and i upgrade the subscription for advance subscription for $30 than invoice in return i got amount_due for $40 which is merged amount of plus and advanced, which is wrong , because i had already paid for 10$, so amount pay should be 30-10 = 20$ (tested: if i pay then 20$ is cut from account) (and invoice show $40 which is wrong)
Monthly subscription to yearly subscription or Vice-versa (this is ok)
if currently i am on monthly basic subscription for 10$ and i upgrade to yearly plus subscription for 100$ then upcoming invoice in amount_due show me correct information which is 90$ (and also if i pay it cut 90$ from account)
so how to get coorect amount in same billing cycle in stripe
发布评论
评论(2)
您每月有10美元的订阅,15天后(半个月的半个月),您想将其更改为30美元。在即将发票的情况下,您将获得客户在下一个计费周期中应支付的发票,其中包括3个订单项目:
这里的总数是: - $ 5 + $ 15 + $ 30 = $ 40 = $ 40在15天内支付。如果不是您想要的话:
请注意,将订阅的计费周期从每月更改为每年的工作方式不同,如在这里。
You have a subscription for $10 per month, and after 15 days (half of the month) you want to change it to $30. With the upcoming invoice, you get the invoice the customer should pay in the next billing cycle which includes 3 line items:
Here the total is: -$5 + $15 + $30 = $40 to be paid in 15 days. If that's not what you want you could:
subscription_proration_behavior: "always_invoice"
.subscription_billing_cycle_anchor: "now"
Note that changing the billing cycle of a subscription from monthly to yearly works differently, as explained here.
重置您的计费周期以获取确切的金额
添加
subscription_billing_cycle_anchor =“现在”
获得即将发票时reset your billing cycle for get the exact amount
add
subscription_billing_cycle_anchor = "now"
at getting upcoming invoice