【发布时间】: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