条纹禁用比例 [英] Stripe Disable Proration

查看:22
本文介绍了条纹禁用比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two plans in my Stripe subscriptions. The first plan is a plan of 10 euros/month until a specific date say for example it started in 10/2/2021 and I want it to end in 15/7/2021. And I want the subsriber to always pay 10 euros/month even for the last month. So I don't want any proration behaviour. In an attempt to do this I did the following on customer.susbcription.created event [I want to update the newly created subscription] :

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

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

The second is a plan of 38 euros/month , to cancel it in 2 months I wrote in the customer.susbcription.created event :

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

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

So the subscription started in 12/3/2021 at 4:36 PM and the end date in my dashboard was effectively 12/5/2021 at 4:36 PM however my next invoice will be created in Apr 12, 5:36 PM with an amount of €37.95 instead of 38 ! why ? I read about proration_behavior and tried to update my already existing subscription by setting this behavior to none but that didn't work.

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

I couldn't find any proration field in the subscription object in order to update it to none, so in an attempt to solve this issue I tried this and It worked (now I have 38 euros for my next invoice):

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

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

I would like to ask you If what I did is correct or does it have any implications ?? In many previous posts, many have said that there is a way to do this using Subscription Schedules. However in my case I cannot set some accurate number of intervals because I want the same code for both plans and the second plan is cancelled at a specific date.

试过这段代码,但也没有用:

EDIT : Tried this code but also didn't work:

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

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

Here's my subscription object for a plan of 12 euros/month:

[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] => 
)
```

推荐答案

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

Have you disabled proration? You have to specifically disable it: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration

proration_behavior(可选)

proration_behavior (optional)

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

Determines how to handle prorations resulting from the billing_cycle_anchor. Valid values are create_prorations or none.

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

Passing create_prorations will cause proration invoice items to be created when applicable. Prorations can be disabled by passing none. If no value is passed, the default is create_prorations.

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

As to why the next invoice is $37.95 instead of $38, likely due to proration being prorated to seconds: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration

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

You can use this information to confirm the changes with the customer before modifying the subscription. Because Stripe prorates to the second, prorated amounts can change between the time they’re previewed and the time the update is made. To avoid this, pass in a subscription_proration_date to the invoice when you preview a change. When you update the subscription, you can pass the same date using the proration_date parameter on a subscription so that the proration is calculated at the same time.

这篇关于条纹禁用比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆