【问题标题】:Stripe Disable Proration条纹禁用按比例分配
【发布时间】:2021-03-14 06:15:02
【问题描述】:

我的 Stripe 订阅中有两个计划。 第一个计划是每月 10 欧元的计划,直到特定日期,例如它从 2021 年 10 月 2 日开始,我希望它在 2021 年 7 月 15 日结束。而且我希望订阅者即使在上个月也总是每月支付 10 欧元。所以我不想要任何按比例分配的行为。 为了尝试做到这一点,我对 customer.susbcription.created 事件 [我想更新新创建的订阅] 执行了以下操作:

$sub->cancel_at = strtotime($my_selected_timestamp);
$sub->save();

第二个是38欧元/月的计划,2个月后取消我在customer.susbcription.created事件中写的:

$sub->cancel_at = strtotime("+2 month",  $sub->start_date);    
$sub->save();  

因此,订阅于 2021 年 12 月 3 日下午 4:36 开始,我的仪表板中的结束日期实际上是 2021 年 12 月 5 日下午 4:36,但是我的下一张发票将在 4 月 12 日,5 日创建:下午 36 点,金额为 37.95 欧元,而不是 38 欧元!为什么 ?我阅读了有关 proration_behavior 并尝试通过将此行为设置为 none 来更新我已经存在的订阅,但这不起作用。

我在订阅对象中找不到任何按比例分配的字段以便将其更新为无,所以为了解决这个问题,我尝试了这个并且它成功了(现在我的下一张发票有 38 欧元):

$expiry_date =   strtotime("+2 month", $sub->start_date); 
$sub->cancel_at =  strtotime("+1 hour",  $expiry_date); 
$sub->save();

我想问你我所做的是否正确或有任何影响? 在之前的许多帖子中,许多人都说有一种方法可以使用订阅计划来做到这一点。但是在我的情况下,我无法设置一些准确的间隔数,因为我希望两个计划的代码相同,并且第二个计划在特定日期被取消。

编辑: 尝试了这段代码,但也没有用:

  $final = strtotime("+2 month", $subscription_obj->start_date); 
      \Stripe\Subscription::update($subscription_obj->id, [
        'cancel_at' => $final,
        'proration_behavior' => 'none',
      ]
    );
     $subscription_obj->save();  

这是我每月 12 欧元计划的订阅对象:

[id] => sub_J75FZOObndggWX
    [object] => subscription
    [application_fee_percent] => 
    [billing_cycle_anchor] => 1615717329
    [billing_thresholds] => 
    [cancel_at] => 1620984129
    [cancel_at_period_end] => 
    [canceled_at] => 1615717335
    [collection_method] => charge_automatically
    [created] => 1615717329
    [current_period_end] => 1618395729
    [current_period_start] => 1615717329
    [customer] => cus_J75Fs7RnQtMBTX
    [days_until_due] => 
    [default_payment_method] => pm_1IUr5IHEWYmoXN4GjeSdn3aK
    [default_source] => 
    [default_tax_rates] => Array
        (
        )

    [discount] => 
    [ended_at] => 
    [items] => Stripe\Collection Object
        (
            [object] => list
            [data] => Array
                (
                    [0] => Stripe\SubscriptionItem Object
                        (
                            [id] => si_J75F5QEL5Gnzqf
                            [object] => subscription_item
                            [billing_thresholds] => 
                            [created] => 1615717329
                            [metadata] => Stripe\StripeObject Object
                                (
                                )

                            [plan] => Stripe\Plan Object
                                (
                                    [id] => price_1IJes9HEWYmoXN4GiFeNywqa
                                    [object] => plan
                                    [active] => 1
                                    [aggregate_usage] => 
                                    [amount] => 1200
                                    [amount_decimal] => 1200
                                    [billing_scheme] => per_unit
                                    [created] => 1613048777
                                    [currency] => eur
                                    [interval] => month
                                    [interval_count] => 1
                                    [livemode] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_IvVt5EemrpxKcf
                                    [tiers_mode] => 
                                    [transform_usage] => 
                                    [trial_period_days] => 
                                    [usage_type] => licensed
                                )

                            [price] => Stripe\Price Object
                                (
                                    [id] => price_1IJes9HEWYmoXN4GiFeNywqa
                                    [object] => price
                                    [active] => 1
                                    [billing_scheme] => per_unit
                                    [created] => 1613048777
                                    [currency] => eur
                                    [livemode] => 
                                    [lookup_key] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_IvVt5EemrpxKcf
                                    [recurring] => Stripe\StripeObject Object
                                        (
                                            [aggregate_usage] => 
                                            [interval] => month
                                            [interval_count] => 1
                                            [trial_period_days] => 
                                            [usage_type] => licensed
                                        )

                                    [tiers_mode] => 
                                    [transform_quantity] => 
                                    [type] => recurring
                                    [unit_amount] => 1200
                                    [unit_amount_decimal] => 1200
                                )

                            [quantity] => 1
                            [subscription] => sub_J75FZOObndggWX
                            [tax_rates] => Array
                                (
                                )

                        )

                )

            [has_more] => 
            [total_count] => 1
            [url] => /v1/subscription_items?subscription=sub_J75FZOObndggWX
        )

    [latest_invoice] => in_1IUr5JHEWYmoXN4GTmJ3pJUZ
    [livemode] => 
    [metadata] => Stripe\StripeObject Object
        (
            [myID] => 1
        )

    [next_pending_invoice_item_invoice] => 
    [pause_collection] => 
    [pending_invoice_item_interval] => 
    [pending_setup_intent] => 
    [pending_update] => 
    [plan] => Stripe\Plan Object
        (
            [id] => price_1IJes9HEWYmoXN4GiFeNywqa
            [object] => plan
            [active] => 1
            [aggregate_usage] => 
            [amount] => 1200
            [amount_decimal] => 1200
            [billing_scheme] => per_unit
            [created] => 1613048777
            [currency] => eur
            [interval] => month
            [interval_count] => 1
            [livemode] => 
            [metadata] => Stripe\StripeObject Object
                (
                )

            [nickname] => 
            [product] => prod_IvVt5EemrpxKcf
            [tiers_mode] => 
            [transform_usage] => 
            [trial_period_days] => 
            [usage_type] => licensed
        )

    [quantity] => 1
    [schedule] => 
    [start_date] => 1615717329
    [status] => active
    [transfer_data] => 
    [trial_end] => 
    [trial_start] => 
)
```

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    您是否禁用了proration?您必须专门禁用它: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration

    proration_behavior(可选)

    确定如何处理由 billing_cycle_anchor 产生的按比例分配。有效值为 create_prorations 或 none。

    传递 create_prorations 将导致在适用时创建按比例分配的发票项目。可以通过传递 none 来禁用 Prorations。如果没有传递任何值,则默认为 create_prorations。

    至于为什么下一张发票是 37.95 美元而不是 38 美元,可能是因为按比例分配到秒:https://stripe.com/docs/billing/subscriptions/prorations#preview-proration

    在修改订阅之前,您可以使用此信息与客户确认更改。因为 Stripe 按比例分配到秒,所以按比例分配的数量可能会在预览时间和更新时间之间发生变化。为避免这种情况,请在预览更改时将 subscription_proration_date 传递给发票。更新订阅时,您可以使用订阅的 proration_date 参数传递相同的日期,以便同时计算按比例分配。

    【讨论】:

    • 一如既往的好答案!不,我没有禁用禁用按比例分配。你能告诉我如何添加到我的代码中以查看我的代码行将如何变化吗?
    • 对于按比例分配的日期和秒数,你能告诉我在我的情况下我应该设置我的日期以及如何设置吗?对不起,但我是 php 和条带新手,不知道按比例分配日期。
    • 因此,根据我的理解,为了解决我的问题,我要么在取消时取消按比例分配,要么保持按比例分配更新的按比例分配日期?
    • 在相应的Subscription webhook 事件中,例如customer.subscription.created,您可以将proration_behavior 更新为none,参见stripe.com/docs/api/subscriptions/…。试试这个方法,看看你下一张发票的金额是否正确。
    • 非常感谢您的旅游回答.. 我与 Stripe 进行了实时聊天,他们告诉我在设置特定取消日期时没有任何方法可以禁用按比例分配。仅当我们立即取消或在当前期间结束时取消时,才能禁用此按比例分配。
    猜你喜欢
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 2019-09-08
    • 2023-03-11
    • 1970-01-01
    • 2015-01-09
    相关资源
    最近更新 更多