条纹即将到来的发票,以相同的计费周期

发布于 2025-01-23 06:04:45 字数 1440 浏览 0 评论 0 原文

我想向客户展示如果他们对订阅进行更改,则预览了他们的订阅费用。为此,我正在使用“即将发票” 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

罪歌 2025-01-30 06:04:45

您每月有10美元的订阅,15天后(半个月的半个月),您想将其更改为30美元。在即将发票的情况下,您将获得客户在下一个计费周期中应支付的发票,其中包括3个订单项目:

  • 未使用的时间: - 5美元(这是最初的价格除以两个)
  • 剩余时间: +15美元(这是新价格除以新价格二)
  • 下一张发票: + $ 30(下个月的新价格)

这里的总数是: - $ 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:

  • Unused time: -$5 (that's the initial price divided by two)
  • Remaining time: +$15 (that's the new price divided by two)
  • Next invoice: +$30 (the new price for next month)

Here the total is: -$5 + $15 + $30 = $40 to be paid in 15 days. If that's not what you want you could:

Note that changing the billing cycle of a subscription from monthly to yearly works differently, as explained here.

你的呼吸 2025-01-30 06:04:45

重置您的计费周期以获取确切的金额

添加 subscription_billing_cycle_anchor =“现在” 获得即将发票时

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,
                }
            ],

            subscription_billing_cycle_anchor = "now",  #  add 
        )
        return invoice
    except Exception as e:
        return str(e)

reset your billing cycle for get the exact amount

add subscription_billing_cycle_anchor = "now" at getting upcoming invoice

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,
                }
            ],

            subscription_billing_cycle_anchor = "now",  #  add 
        )
        return invoice
    except Exception as e:
        return str(e)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文