# 比例配分 修正後のサブスクリプションの比例配分を処理します。 既存のサブスクリプションを変更する上で最も複雑なのが比例配分です。比例配分では、部分的な利用を反映し、サブスクリプション料金の一定割合を顧客に請求します。このページでは、比例配分がサブスクリプションでどのように作用するのか、また顧客の比例配分を処理する方法について説明します。 ## 比例配分の仕組み たとえば、サブスクリプションの[アップグレードやダウングレード](https://docs.stripe.com/billing/subscriptions/change-price.md)によって、比例配分による請求が発生することがあります。顧客が月額 10 USD のプランから 20 USD のオプションに変更した場合、各オプションの使用時間に対して比例配分が適用された金額が請求されます。請求期間の半ばで変更が生じた場合は、顧客は 5 USD 請求の追加を受けます (最初の料金の未使用時間分が -5 USD で、新しい料金の残り時間分が 10 USD)。 比例配分は顧客に対して正確に請求することができますが、最終的な支払い額が予想とかい離する場合があります。マイナスの比例配分は自動的に返金されず、プラスの比例配分はすぐには請求されません。ただし、どちらも手動で行うことができます。 [比例配分をプレビュー](https://docs.stripe.com/billing/subscriptions/prorations.md#preview-proration)して、変更を適用する前に金額を確認できます。[クレジットの比例配分の仕組み](https://docs.stripe.com/billing/subscriptions/prorations.md#credit-prorations)については、Stripe のガイドをご覧ください。 ### 比例配分と割引 比例配分 (`prorations=true`) のすべての[請求書アイテム](https://docs.stripe.com/api/invoiceitems/object.md#invoiceitem_object)は、`discountable=false` に設定されます。比例配分を含む請求書に適用される割引は、比例配分ではない[請求書アイテム](https://docs.stripe.com/api/invoiceitems/object.md#invoiceitem_object-discounts)と[請求書ラインアイテム](https://docs.stripe.com/api/invoice-line-item/object.md#invoice_line_item_object-discounts)にのみ適用されます。サブスクリプションに以前適用され、比例配分の金額に影響する割引は、比例配分インボイスアイテムの金額に反映されます。 非比例配分では[discount_amounts](https://docs.stripe.com/api/invoice-line-item/object.md#invoice_line_item_object-discount_amounts) の割引調整が表示されます。 #### 割引の変更と比例配分 サブスクリプションレベルのプロモーションコード、クーポン、割引をそれ自体で更新しても、比例配分の請求書項目は作成されません。現在の請求サイクルの請求可能額に影響する変更のみが、次のような比例配分請求の項目を作成します。 - サブスクリプション項目の`価格`または`数量`の変更 - サブスクリプション項目の追加や削除 - 請求サイクルの起点や比例配分動作の変更 比例配分を発生させる変更を行うと、Stripe は、比例配分が計算された時点でのサブスクリプションの現在の料金体系と割引の状態を使用して、比例配分金額を計算します。項目数量の変更と割引の変更を 1 回の更新で同じ API コールの一部として行うなど、比例配分もトリガーする同じ API コールの一部として割引を変更する場合、比例配分のデビットまたはクレジットは、変更後の割引を使用して計算されます。 例えば、以下のとおりです: - **サブスクリプション項目のメタデータのみを更新する、または割引を適用または削除する場合:** 比例配分の請求書の項目は作成されず、即時の比例配分の請求やクレジットは次回の請求書に表示されません。 - **サブスクリプション項目の数量を更新し、同じコールで割引を削除する場合:** 数量変更に対して比例配分の請求書の項目が作成され、比例配分額は割引変更後の価格を反映します。比例配分の計算には、変更後の割引が使用されます。 サブスクリプションでの割引の仕組み (`duration=once` クーポンがどのように消費され、`subscription.discounts` から削除されるかなど) の詳細については、[クーポンとプロモーションコード](https://docs.stripe.com/billing/subscriptions/coupons.md#coupon-duration)をご覧ください。 ### 比例配分が発生するシナリオ デフォルトでは、以下のシナリオで比例配分が発生します。 | 更新 | 詳細 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | | [アイテム](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items)を変更する | 新しい項目の追加または既存の項目の削除 | | [価格](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items-price)の変更 | 基本コストまたは請求期間が異なる料金への変更 | | [数量](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items-quantity)の変更 | サブスクリプション項目の数量を増減する | | [trial_end](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-trial_end) または [trial_from_plan](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-trial_from_plan) の追加 | 有効なサブスクリプションへのトライアル期間の追加 | | [billing_cycle_anchor](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-billing_cycle_anchor) を変更する | 請求期間を新しい日付にリセットする | | [cancel_at](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-cancel_at) の設定 | サブスクリプションを期間の途中でキャンセルする (期間終了時ではない) | ### 比例配分がトリガーされないもの サブスクリプションの更新の多くは請求書に影響せず、比例配分も生成されません。これにより、 *proration* invoice を作成せずに、いつでも更新できます。 | パラメーター | 詳細 | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- | | **設定と設定の更新** | | | [automatic_tax](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-automatic_tax) | 課税する税金の自動計算を有効化または無効化 | | [default_payment_method](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-default_payment_method) | デフォルトの支払い方法を変更する | | [default_source](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-default_source) | デフォルト支払い元の変更 | | [payment_behavior](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-payment_behavior) | 支払い試行の動作を制御する | | [collection_method](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-collection_method) | 支払いを自動的に変更して請求書を送信 | | [days_until_due](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-days_until_due) | 請求書送信サブスクリプションの支払い期日の更新 | | [tax_filing_currency](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-tax_filing_currency) | 課税する申請通貨を変更する | | [retry_settings](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-retry_settings) | 失敗した支払いの再試行の動作を変更する | | [trial_settings](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-trial_settings) | トライアル終了時の動作設定を更新する | | [pay_immediately](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-pay_immediately) | 即時支払い動作を制御 | | [pending_invoice_item_interval](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-pending_invoice_item_interval) | 保留中のアイテムの請求書発行頻度を変更する | | [pause_collection](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-pause_collection) | 支払いの回収の一時停止または再開 | | [proration_date](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-proration_date) | 特定の比例配分日を設定する (単独で比例配分を作成しない) | | **メタデータと説明フィールド** | | | [metadata](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-metadata) および [items.metadata](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items-metadata) | サブスクリプション/サブスクリプションアイテムのメタデータを更新する | | [cancellation_details](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-cancellation_details) | キャンセルのフィードバックとコメントを追加 | | **将来の非比例配分請求書の変更の設定として機能する更新** | | | [discounts](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-discounts) と [items.discounts](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items-discounts) | 将来の請求書に適用されるサブスクリプションレベルのクーポンまたはプロモーションコードを追加または更新できます。 | | [billin_thresholds](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-billing_thresholds) および [items.billing_thresholds](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-items-billing_thresholds) | サブスクリプション/サブスクリプションアイテムの請求しきい値を更新 | | [cancel_at_period_end](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-cancel_at_period_end) | 比例配分なしで現在の期間の終了時にキャンセル | | [add_invoice_items](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-add_invoice_items) | 1 回限りの支払いを次の請求書に追加する | > これらの更新では、`proration_behavior=create_prorations` の設定でも比例配分請求項目が生成されず、`proration_behavior=always_invoice` の設定でも比例配分請求項目を含む請求書も生成されません。これは、現在の期間の請求金額に影響を与えないためです。 ### 独自の比例配分額の作成 Stripe の外部で計算した比例配分額をサブスクリプションに追加するには、(計算された比例配分額と等しい) マイナスの `unit_amount` が指定された [add_invoice_items](https://docs.stripe.com/api/subscription_schedules/create.md#create_subscription_schedule-add_invoice_items) を次のエンドポイントに渡します。 - [CreateSubscription](https://docs.stripe.com/api/subscriptions/create.md) - [UpdateSubscription](https://docs.stripe.com/api/subscriptions/update.md) - [CreateSubscriptionSchedule](https://docs.stripe.com/api/subscription_schedules/create.md) - [UpdateSubscriptionSchedule](https://docs.stripe.com/api/subscription_schedules/update.md) ### 比例配分の適用タイミング 比例配分は請求期間より前に発生した請求にのみ適用されます。[従量課金](https://docs.stripe.com/billing/subscriptions/usage-based.md)は比例配分の対象になりません。 比例配分額は、API がサブスクリプションを更新するとすぐに算出されます。変更の前と後のサブスクリプションのコストを計算するために、現行の請求期間の開始日と終了日が使用されます。 ### 日割り計算と未払いの請求書 Stripe は更新時のサブスクリプションのステータスに基づいて日割り計算を行います。その際、そのサブスクリプションに対するそれ以前の請求書はすべて支払い済みであると仮定します。顧客が現在の利用期間に対する請求書が未払いのままサブスクリプションを変更すると、未使用の期間に対してより高額なプランの価格に応じたクレジットを受け取ることがあります。このクレジットは、その期間分の支払いをまだ行っていなくても適用されます。 未払いの期間に対するクレジットを避けるために、サブスクリプションの最新の請求書が未払いの場合は日割り計算を無効にすることができます。サブスクリプションを更新する際は、[proration_behavior](https://docs.stripe.com/api/subscriptions/update.md?update_subscription-proration_behavior=#update_subscription-proration_behavior) を `none` に設定します。次のいずれかの方法を選択します。 1. **元の請求期間を維持する:** 新しい請求に対して[1 回限りの請求書を手動で作成](https://docs.stripe.com/api/invoices/create.md)します。 1. **新しいプランの決済を即時に行い、請求期間をリセットするには:** `billing_cycle_anchor` を `now` に設定します。詳細については、[請求期間を現在時刻にリセットする](https://docs.stripe.com/billing/subscriptions/billing-cycle.md#reset-the-billing-period-to-the-current-time)をご覧ください。 いずれの方法でも、顧客が最終的に古い請求書を支払うと、二重決済につながる可能性があります。これを回避するには、[未払いの請求書を無効にします](https://docs.stripe.com/api/invoices/void.md)。 ### 税金と比例配分 比例配分を行う際の税金の処理については、[継続支払いにおける税金の徴収](https://docs.stripe.com/billing/taxes/collect-taxes.md)をご覧ください。 ## クレジットの比例配分 顧客が請求期間終了前にサブスクリプションをダウングレードするか、サブスクリプションアイテムをキャンセルすると、クレジット比例配分が発行されます。Stripe は、サブスクリプションの[billing_mode](https://docs.stripe.com/billing//subscriptions/billing-mode.md#differences-between-classic-and-flexible-billing-mode)を `classic` または `flexible` のどちらに設定しているかに応じて、クレジット比例配分の計算に 2 つの方法を提供します。 ### 比例配分のない計算ロジック 次のシナリオでは、`proration_behavior` を 10 日間 `none` に設定して、 の月次サブスクリプションを にアップグレードします。基準となる以前の引き落としはありません。後で、`proration_behavior` を `always_invoice` に設定して、サブスクリプションを月次 にダウングレードします。 このシナリオを設定するには、まず 4 月 1 日に毎月 10 USD の[サブスクリプションを作成](https://docs.stripe.com/api/subscriptions/create.md)します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "items[0][price]=price_10_monthly" ``` レスポンスには、このサブスクリプション用に作成された請求書が含まれます。 ```json { "id": "sub_123", "latest_invoice": { "id": "in_123", "total": 1000, "currency": "usd" } } ``` 次に、4 月 11 日に、日割り料金を作成せずに月額 20 USD に [サブスクリプションをアップグレード](https://docs.stripe.com/billing/subscriptions/change-price.md#changing) します。 ```curl curl https://api.stripe.com/v1/subscriptions/sub_123 \ -u "<>:" \ -d "items[0][id]=sub_item_1" \ -d "items[0][price]=price_20_monthly" \ -d proration_behavior=none ``` `proration_behavior` が `none` であるため、最新の請求書は変更されません。 ```json { "id": "sub_123", "latest_invoice": { "id": "in_123" } } ``` 最後に、4 月 21 日に [サブスクリプションをダウングレード](https://docs.stripe.com/billing/subscriptions/change-price.md#changing) して月額 10 USD に変更し、日割り料金を作成します。 ```curl curl https://api.stripe.com/v1/subscriptions/sub_123 \ -u "<>:" \ -d "items[0][id]=sub_item_1" \ -d "items[0][price]=price_10_monthly" \ -d proration_behavior=always_invoice ``` | **クラシック** | **フレキシブル** | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `billing_mode=classic` の比例配分計算ロジックは、顧客が の月額料金を支払っていなくても、現在の価格に基づいてクレジットの比例配分を作成します。最新の請求書では、顧客が `price_20_monthly` の価格を一度も支払っていない場合でも、月の 3 分の 1 に対して (-) のクレジットを行い、また月の 3 分の 1 に対して () をデビットします。 | `billing_mode=flexible` で有効化された計算ロジックは、サブスクリプションアイテムに対して最後に請求された価格に基づいてクレジット比例配分を作成します。この場合、最新の請求書は、4 月 1 日に請求された の月次価格 () の 3 分の 1 をクレジットし、 の価格 () の 3 分の 1 をデビットします。クレジットとデビットはキャンセルされるため、請求書の合計は になります。 | | ```json # billing_mode = classic { "id": "sub_123", "latest_invoice": { "id": "in_456", "total": -334, "currency": "usd" } } ``` | ```json # billing_mode = flexible { "id": "sub_123", "latest_invoice": { "id": "in_456", "total": 0, "currency": "usd" } } ``` | ### 複数のサブスクリプション項目に適用されるクーポンの計算ロジック Stripe は過剰請求を防ぐために、クレジットの日割り計算の `amount_off` クーポンに重みを付けます。 次のシナリオでは、10 USD と 20 USD の項目が含まれる 25 USD の月額サブスクリプションに、5 USD のクーポンが不均等に割り当てられます。 このシナリオを設定するには、2 月 1 日に複数のアイテムとクーポンを含むサブスクリプションを作成します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "items[0][price]=price_10_monthly" \ -d "items[1][price]=price_20_monthly" \ -d "discounts[0][coupon]=five_dollars_off" ``` これにより、次のレスポンスが返されます。 ```json { "id": "sub_123", "latest_invoice": { "id": "in_123", "total": 2500, "currency": "usd", "lines": { "data": [ { "id": "ili_1", "amount": 1000, "price": "price_10_monthly", "discount_amounts": [{ "discount": "di_a", "amount": 166 }] }, { "id": "ili_2", "amount": 2000, "price": "price_20_monthly", "discount_amounts": [{ "discount": "di_a", "amount": 334 }] } ] } } } ``` 10 USD の月額サブスクリプション項目をキャンセルする手順。 ```curl curl https://api.stripe.com/v1/subscription_items/si_10_monthly \ -u "<>:" \ -d proration_behavior=create_prorations ``` サブスクリプション項目が削除されると、そのサブスクリプションに関連付けられた`billing_mode`は、比例配分の計算方法に以下のように影響します。 | **クラシック** | **フレキシブル** | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | デフォルトの動作では、5 USD クーポンが各項目 (2.5 USD ずつ) に配布され、安い項目 (5 USD) がキャンセルされ、2.5 USD が返金されます。Stripe は合計を `-0.5 x (10 USD price - 5 USD coupon) = -2.50 USD` の式で計算します。 | 柔軟な動作により、割引額の全額が比例配分計算に適用されるのではなく、キャンセルされた項目に適用される比例割引が反映されます。Stripe は、`-0.5 x (10 USD price - 1.66 USD discount amount) = -4.17 USD` の式を使用して合計を計算します。 | | ```json # billing_mode = classic { "id": "sub_123", "latest_invoice": { "id": "in_456", "total": -250, "currency": "usd" } } ``` | ```json # billing_mode = flexible { "id": "sub_123", "latest_invoice": { "id": "in_789", "total": -417, "currency": "usd" } } ``` | ## 比例配分のプレビュー [請求書プレビューを作成](https://docs.stripe.com/api/invoices/create_preview.md)して、サブスクリプションに加えられた変更をプレビューできます。この API コールでサブスクリプションは変更されません。代わりに、渡されたパラメーターのみに基づいて次回*請求書* (Invoices are statements of amounts owed by a customer. They track the status of payments from draft through paid or otherwise finalized. Subscriptions automatically generate invoices, or you can manually create a one-off invoice)が返されます。`price` または `quantity` を変更すると、比例配分が行われます。この例では `price` を変更し、比例配分の計算日を設定しています。 #### Accounts v2 #### Ruby ```ruby # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. # Find your keys at https://dashboard.stripe.com/apikeys. client = Stripe::StripeClient.new('<>') # Set proration date to this moment: proration_date = Time.now.to_i subscription = client.v1.subscriptions.retrieve('sub_49ty4767H20z6a') # See what the next invoice would look like with a price switch # and proration set: items = [{ id: subscription.items.data[0].id, price: 'price_CBb6IXqvTLXp3f', # Switch to new price }] invoice = client.v1.invoices.create_preview({ customer_account: 'acct_4fdAW5ftNQow1a', subscription: 'sub_49ty4767H20z6a', subscription_details: { items: items, proration_date: proration_date, } }) ``` #### Customers v1 #### Ruby ```ruby # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. # Find your keys at https://dashboard.stripe.com/apikeys. client = Stripe::StripeClient.new('<>') # Set proration date to this moment: proration_date = Time.now.to_i subscription = client.v1.subscriptions.retrieve('sub_49ty4767H20z6a') # See what the next invoice would look like with a price switch # and proration set: items = [{ id: subscription.items.data[0].id, price: 'price_CBb6IXqvTLXp3f', # Switch to new price }] invoice = client.v1.invoices.create_preview({ customer: 'cus_4fdAW5ftNQow1a', subscription: 'sub_49ty4767H20z6a', subscription_details: { items: items, proration_date: proration_date, } }) ``` 次のサンプルレスポンスを展開すると、以下を確認できます。 - 36~38 行目: 以前の料金での未使用分に対するクレジット。 - 107~109 行目: 新しい料金での使用分に対するコスト。 - 276~279 行目: 請求書の新しい小計と合計。 ```json { "id": "upcoming_in_1OujwkClCIKljWvsq5v2ICAN", "account_country": "US", "account_name": "Test account", "amount_due": 3627, "amount_paid": 0, "amount_remaining": 3627, "application_fee_amount": null, "attempt_count": 0, "attempted": false, "billing_reason": "upcoming", "charge": null, "collection_method": "charge_automatically", "created": 1599427688, "currency": "usd", "custom_fields": null, "customer": "cus_DGEhAXrZWrzdYs", "customer_address": null, "customer_email": "jenny.rosen@example.com", "customer_name": null, "customer_phone": null, "customer_shipping": null, "customer_tax_exempt": "none", "customer_tax_ids": [], "default_payment_method": null, "default_source": null, "default_tax_rates": [], "description": null, "discount": null, "discounts": [], "due_date": null, "ending_balance": 0, "footer": null, "lines": { "data": [ {"amount": -166, "currency": "usd", "description": "Unused time on Silver plan after 01 Sep 2020", "discount_amounts": [], "discountable": false, "discounts": [], "id": "il_tmp1HMdV2AJVYItwOKqQi4H", "invoice_item": "ii_1HMdV2AJVYItwUH1Qi4H", "livemode": false, "metadata": {}, "object": "line_item", "period": { "end": 1599427688, "start": 1598982148 }, "plan": { "active": true, "amount": 1000, "amount_decimal": "1000", "billing_scheme": "per_unit", "created": 1585856460, "currency": "usd", "id": "price_H1c8v1lifcd", "interval": "month", "interval_count": 1, "livemode": false, "metadata": {}, "nickname": null, "object": "plan", "product": "prod_c7exjJHbC4", "tiers": null, "tiers_mode": null, "transform_usage": null, "trial_period_days": null, "usage_type": "licensed" }, "price": { "active": true, "billing_scheme": "per_unit", "created": 1585856460, "currency": "usd", "id": "price_c8v1liEvrf", "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, "object": "price", "product": "prod_c7exjJHbC4", "recurring": { "interval": "month", "interval_count": 1, "trial_period_days": null, "usage_type": "licensed" }, "tiers_mode": null, "transform_quantity": null, "type": "recurring", "unit_amount": 1000, "unit_amount_decimal": "1000" }, "proration": true, "quantity": 1, "subscription": "sub_H38lqYjDO0DSzl", "subscription_item": "si_H38lIMagWoFx0W", "tax_amounts": [], "tax_rates": [], "type": "invoiceitem" }, {"amount": 541, "currency": "usd", "description": "Remaining time on Gold plan after 01 Sep 2020", "discount_amounts": [], "discountable": false, "discounts": [], "id": "il_tmp1HMdV2AJVYItwOKqDcgkmpzz", "invoice_item": "ii_1HMdV2AJVYItwOKqDcgkmpzz", "livemode": false, "metadata": {}, "object": "line_item", "period": { "end": 1599427688, "start": 1598982148 }, "plan": { "active": true, "amount": 3252, "amount_decimal": "3252", "billing_scheme": "per_unit", "created": 1598473039, "currency": "usd", "id": "price_KV3bAJVYItwOKq16frkr", "interval": "month", "interval_count": 1, "livemode": false, "metadata": {}, "nickname": null, "object": "plan", "product": "prod_JfJiw2l6ke", "tiers": null, "tiers_mode": null, "transform_usage": null, "trial_period_days": null, "usage_type": "licensed" }, "price": { "active": true, "billing_scheme": "per_unit", "created": 1598473039, "currency": "usd", "id": "price_KV3bAJVYItwOKq16frkr", "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, "object": "price", "product": "prod_JfJiw2l6ke", "recurring": { "interval": "month", "interval_count": 1, "trial_period_days": null, "usage_type": "licensed" }, "tiers_mode": null, "transform_quantity": null, "type": "recurring", "unit_amount": 3252, "unit_amount_decimal": "3252" }, "proration": true, "quantity": 1, "subscription": "sub_H38lqYjDO0DSzl", "subscription_item": "si_H38lIMagWoFx0W", "tax_amounts": [], "tax_rates": [], "type": "invoiceitem" }, { "amount": 3252, "currency": "usd", "description": "1 \u00d7 Gold product (at $32.52 / month)", "discount_amounts": [], "discountable": true, "discounts": [], "id": "il_tmp_7fc9ba9b6aa9aa", "livemode": false, "metadata": {}, "object": "line_item", "period": { "end": 1602019688, "start": 1599427688 }, "plan": { "active": true, "amount": 3252, "amount_decimal": "3252", "billing_scheme": "per_unit", "created": 1598473039, "currency": "usd", "id": "price_KV3bAJVYItwOKq16frkr", "interval": "month", "interval_count": 1, "livemode": false, "metadata": {}, "nickname": null, "object": "plan", "product": "prod_JfJiw2l6ke", "tiers": null, "tiers_mode": null, "transform_usage": null, "trial_period_days": null, "usage_type": "licensed" }, "price": { "active": true, "billing_scheme": "per_unit", "created": 1598473039, "currency": "usd", "id": "price_KV3bAJVYItwOKq16frkr", "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, "object": "price", "product": "prod_JfJiw2l6ke", "recurring": { "interval": "month", "interval_count": 1, "trial_period_days": null, "usage_type": "licensed" }, "tiers_mode": null, "transform_quantity": null, "type": "recurring", "unit_amount": 3252, "unit_amount_decimal": "3252" }, "proration": false, "quantity": 1, "subscription": "sub_H38lqYjDO0DSzl", "subscription_item": "si_H38lIMagWoFx0W", "tax_amounts": [], "tax_rates": [], "type": "subscription" } ], "has_more": false, "object": "list", "total_count": 3, "url": "/v1/invoices/upcoming_in_1OujwkClCIKljWvsq5v2ICAN/lines" }, "livemode": false, "metadata": {}, "next_payment_attempt": 1599431288, "number": null, "object": "invoice", "paid": false, "payment_intent": null, "period_end": 1599427688, "period_start": 1596749288, "post_payment_credit_notes_amount": 0, "pre_payment_credit_notes_amount": 0, "receipt_number": null, "starting_balance": 0, "statement_descriptor": null, "status": "draft", "status_transitions": { "finalized_at": null, "marked_uncollectible_at": null, "paid_at": null, "voided_at": null }, "subscription": "sub_8lqYjDO0DS", "subscription_details": { "proration_date": 1598982148 },"subtotal": 3627, "tax": null, "tax_percent": null, "total": 3627, "total_discount_amounts": [], "total_tax_amounts": [], "transfer_data": null, "webhooks_delivered_at": null } ``` サブスクリプションを変更する前に、この情報を使用して顧客に変更を確認できます。ただし、Stripe は秒単位で比例配分するため、比例配分された金額は、プレビューされてから実際に更新が実行されるまでの間に変化する可能性があります。この問題を回避するには、プレビューを作成する際に `subscription_details.proration_date` 値を渡します。サブスクリプションを更新する際には、サブスクリプションの `proration_date` パラメーターを使用して、同じ日付を渡します。これにより、比例配分が同時に計算されます。 #### Ruby ```ruby # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. # Find your keys at https://dashboard.stripe.com/apikeys. client = Stripe::StripeClient.new('<>') subscription = client.v1.subscriptions.update( 'sub_49ty4767H20z6a', { items: [ { id: subscription.items.data[0].id, price: 'price_CBb6IXqvTLXp3f', }, ], proration_date: proration_date, } ) ``` ## 比例配分の動作を制御する 比例配分は [proration_behavior](https://docs.stripe.com/api/subscriptions/update.md#update_subscription-proration_behavior) パラメーターによって制御され、`create_prorations`、`always_invoice`、`none` のいずれかのパラメーターが指定されます。 ### デフォルトの動作 `proration_behavior` のデフォルトのパラメーターは `create_prorations` であり、該当する場合は比例配分された請求書品目が作成されます。このような比例配分の項目は、[特定の条件](https://docs.stripe.com/billing/subscriptions/change-price.md#immediate-payment)の場合に限り、直ちに請求されます。 ### 比例配分を即時に作成する 同じ請求期間のサブスクリプションの変更を顧客に即時に請求するには、サブスクリプションの変更時に `proration_behavior` を `always_invoice` に設定します。これにより比例配分が計算され、請求書が即時に生成されます。 ### 比例配分の無効化 リクエストごとに比例配分を無効にしたい場合は、`proration_behavior` パラメーターを `none` に設定します。パラメーターを指定しない場合、サブスクリプションの今後のすべての比例配分がオフになります。比例配分を無期限で無効にしたい場合は、比例配分を作成するすべてのリクエストで `proration_behavior` を `none` に設定します。 #### curl ```bash curl https://api.stripe.com/v1/subscriptions/sub_49ty4767H20z6a \ -u <>: \ -d "items[0][id]"="si_1AkFf6LlRB0eXbMtRFjYiJ0J" \ -d "items[0][price]"="price_CBb6IXqvTLXp3f" \ -d "proration_behavior"="none" ``` 比例配分を無効にすると、次の請求書が生成されたときに、顧客は新しい料金で全額を請求されます。