首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >预览即将到来的发票与分段计算问题与条带[Java]

预览即将到来的发票与分段计算问题与条带[Java]
EN

Stack Overflow用户
提问于 2021-01-09 12:30:27
回答 3查看 543关注 0票数 1

我试图预览一个即将到来的发票,按比例收费。

客户在第一天将从30欧元/年计划改为65欧元/年计划(对分段计算日期很重要)。

根据文档这里,客户应该被收费:

  • -30欧元用于旧计划的剩余时间
  • 65欧元用于新计划的剩余时间

总计35欧元。下一张发票应为35欧元。使用Java库进行以下调用以获取下一张发票:

代码语言:javascript
运行
AI代码解释
复制
InvoiceUpcomingParams params = InvoiceUpcomingParams.builder()
        .setCustomer(userId)
        .setSubscription(subscriptionId)
        .addSubscriptionItem(
                InvoiceUpcomingParams.SubscriptionItem.builder()
                .setId(subscription.getItems().getData().get(0).getId())
                .setPrice(priceId)
                .build()
        ).setSubscriptionProrationDate(prorationDate)
        .build();

由此产生的发票具有以下属性:

  • amountPaid: 0
  • amountDue: 9999
  • amountRemaining: 9999
  • subTotal: 9999

...and以下发票行(ids已被混淆):

代码语言:javascript
运行
AI代码解释
复制
{
    "data": [
        {
            "amount": -3000,
            "currency": "eur",
            "description": "Unused time on xxxxx after 09 Jan 2021",
            "discount_amounts": [],
            "discountable": false,
            "discounts": [],
            "id": "---",
            "invoice_item": "---",
            "livemode": false,
            "metadata": {},
            "object": "line_item",
            "period": {
                "end": 1641756061,
                "start": 1610222989
            },
            "plan": {
                "active": true,
                "aggregate_usage": null,
                "amount": 3000,
                "amount_decimal": 3000,
                "billing_scheme": "per_unit",
                "created": 1598220277,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "interval": "year",
                "interval_count": 1,
                "livemode": false,
                "metadata": {},
                "nickname": null,
                "object": "plan",
                "product": "---",
                "tiers": null,
                "tiers_mode": null,
                "transform_usage": null,
                "trial_period_days": null,
                "usage_type": "licensed"
            },
            "price": {
                "active": true,
                "billing_scheme": "per_unit",
                "created": 1598220277,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "livemode": false,
                "lookup_key": null,
                "metadata": {},
                "nickname": null,
                "object": "price",
                "product": "---",
                "recurring": {
                    "aggregate_usage": null,
                    "interval": "year",
                    "interval_count": 1,
                    "trial_period_days": null,
                    "usage_type": "licensed"
                },
                "tiers": null,
                "tiers_mode": null,
                "transform_quantity": null,
                "type": "recurring",
                "unit_amount": 3000,
                "unit_amount_decimal": 3000
            },
            "proration": true,
            "quantity": 1,
            "subscription": "---",
            "subscription_item": "---",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "invoiceitem",
            "unified_proration": null
        },
        {
            "amount": 6499,
            "currency": "eur",
            "description": "Remaining time on xxxx after 09 Jan 2021",
            "discount_amounts": [],
            "discountable": false,
            "discounts": [],
            "id": "---",
            "invoice_item": "---",
            "livemode": false,
            "metadata": {},
            "object": "line_item",
            "period": {
                "end": 1641756061,
                "start": 1610222989
            },
            "plan": {
                "active": true,
                "aggregate_usage": null,
                "amount": 6500,
                "amount_decimal": 6500,
                "billing_scheme": "per_unit",
                "created": 1598220248,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "interval": "year",
                "interval_count": 1,
                "livemode": false,
                "metadata": {},
                "nickname": null,
                "object": "plan",
                "product": "---",
                "tiers": null,
                "tiers_mode": null,
                "transform_usage": null,
                "trial_period_days": null,
                "usage_type": "licensed"
            },
            "price": {
                "active": true,
                "billing_scheme": "per_unit",
                "created": 1598220248,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "livemode": false,
                "lookup_key": null,
                "metadata": {},
                "nickname": null,
                "object": "price",
                "product": "---",
                "recurring": {
                    "aggregate_usage": null,
                    "interval": "year",
                    "interval_count": 1,
                    "trial_period_days": null,
                    "usage_type": "licensed"
                },
                "tiers": null,
                "tiers_mode": null,
                "transform_quantity": null,
                "type": "recurring",
                "unit_amount": 6500,
                "unit_amount_decimal": 6500
            },
            "proration": true,
            "quantity": 1,
            "subscription": "---",
            "subscription_item": "---",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "invoiceitem",
            "unified_proration": null
        },
        {
            "amount": 6500,
            "currency": "eur",
            "description": "1 × xxxx (at €65.00 / year)",
            "discount_amounts": [],
            "discountable": true,
            "discounts": [],
            "id": "---",
            "invoice_item": null,
            "livemode": false,
            "metadata": {},
            "object": "line_item",
            "period": {
                "end": 1673292061,
                "start": 1641756061
            },
            "plan": {
                "active": true,
                "aggregate_usage": null,
                "amount": 6500,
                "amount_decimal": 6500,
                "billing_scheme": "per_unit",
                "created": 1598220248,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "interval": "year",
                "interval_count": 1,
                "livemode": false,
                "metadata": {},
                "nickname": null,
                "object": "plan",
                "product": "---",
                "tiers": null,
                "tiers_mode": null,
                "transform_usage": null,
                "trial_period_days": null,
                "usage_type": "licensed"
            },
            "price": {
                "active": true,
                "billing_scheme": "per_unit",
                "created": 1598220248,
                "currency": "eur",
                "deleted": null,
                "id": "---",
                "livemode": false,
                "lookup_key": null,
                "metadata": {},
                "nickname": null,
                "object": "price",
                "product": "---",
                "recurring": {
                    "aggregate_usage": null,
                    "interval": "year",
                    "interval_count": 1,
                    "trial_period_days": null,
                    "usage_type": "licensed"
                },
                "tiers": null,
                "tiers_mode": null,
                "transform_quantity": null,
                "type": "recurring",
                "unit_amount": 6500,
                "unit_amount_decimal": 6500
            },
            "proration": false,
            "quantity": 1,
            "subscription": "---",
            "subscription_item": "---",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "subscription",
            "unified_proration": null
        }
    ],
    "has_more": false,
    "object": "list",
    "request_options": null,
    "request_params": null,
    "url": "---"
}

简言之,发票行包括以下内容:

  • 2021年1月09日后xxxxx的未用时间:-3000
  • 2021年01月09 : 6499之后xxxxx的剩余时间
  • 1×xxxxx (按65.00欧元/年计算):6500

问题1

,我认为这是错误的,。根据文档这里,收费应该是:64.99-30= 34.99欧元

现在,如果我通过进行实际的订阅更新,那么Stripe生成的发票实际上是34.99欧元。因此,无论我如何调用即将到来的或它返回的内容,似乎都有问题。

我遗漏了什么?我应该自己从amountDue中扣除订阅的价格吗?

EN

回答 3

Stack Overflow用户

发布于 2021-01-09 16:34:28

我可以看到,文档示例确实遵循相同的模式。它包含3行。2用于按比例分摊的费用,1用于实际项目。

因此,这方面的要点是,即将到来的发票(在订阅续订日期)将包括按比例的费用和新的分期付款。

因此,如果我想向我的客户展示即将到来的发票,如果他们升级/降级的话,现在我必须手动从响应中减去项目价格。

发票所产生的是34.99,因为我发出的发票大致同时即将到来的发票预览修改订阅项目的价格。

票数 1
EN

Stack Overflow用户

发布于 2021-01-09 15:17:55

这是即将到来的发票端点的预期行为。请看一下预览分段计算的文档。,它显示了您在示例结果中看到的相同内容:

您可以展开下面的示例响应以查看:

  • 在第36-38行中,以先前价格计算的未使用时间的贷方.
  • 以新价格在107-109线上花费时间的成本。
  • 第276-279行发票的新小计和总额。

您正在预览即将开具的发票,这意味着它将为当前期间的变化和下一期间的正常金额开具发票。当前期间的更改有两个行项,下一个期间有一个行项。

现在,如果我进行实际的订阅更新,Stripe生成的发票实际上是34.99欧元。

听起来,您正在进行此更改,然后立即生成发票,而不是等待通常由于订阅而生成的发票。

票数 0
EN

Stack Overflow用户

发布于 2021-09-16 03:02:02

同样的问题。通过将proration_behavior设置为"always_invoice“,我设法得到了正确的即将到来的发票(即2行回扣和1行新收费)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65647310

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文