# 製品またはサブスクリプション数量の設定

1 人の顧客に対して、複数の製品または 1 つの製品の複数の数量のサブスクリプション登録を行います。これらはすべて 1 つの請求書で請求されます。

[複数の商品](https://docs.stripe.com/billing/subscriptions/quantities.md#multiple-product-sub)または[同じ商品の複数の数量](https://docs.stripe.com/billing/subscriptions/quantities.md#multiple-quantities-sub)のサブスクリプションを作成する必要がある場合があります。[個人顧客に複数のサブスクリプションを作成](https://docs.stripe.com/billing/subscriptions/quantities.md#multiple-subscriptions)することもできます。

## 複数の商品のサブスクリプション

複数の商品を提供している場合、または同じ商品に対して異なる金額の決済を請求する場合は、複数の商品のサブスクリプションを作成できます。これにより、請求期間ごとにすべての価格を合計した 1 つの*請求書* (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)が生成され、顧客は 1 回の決済を行うだけで済みます。

### 複数製品のサブスクリプションを作成する

[items](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-items) パラメータを使用して、顧客に複数の商品のサブスクリプションを作成します。各商品に対し、`price`、および任意で `quantity` (1 以外の値を使用する場合) を指定します。

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer={{CUSTOMER_ID}}" \
  -d "items[0][price]={{PRICE_ID}}" \
  -d "items[1][price]={{PRICE_ID}}" \
  -d "items[1][quantity]=2"
```

応答には、すべてのサブスクリプション項目、価格、数量のリストが含まれます。

```json
{
  "id": "sub_CZEpS1Zt9QLxdo",
  "object": "subscription",
  ...
  "items": {
    "object": "list",
    "data": [
      {
        "id": "si_H1yPnAVzP9vDRW",
        "object": "subscription_item",
        "billing_thresholds": null,
        "created": 1585939321,
        "metadata": {
        },
        "price": {
          "id": "price_H1c8v1liEvrfcd",
          "object": "price",
          "active": true,
          "billing_scheme": "per_unit",
          "created": 1585856460,
          "currency": "usd",
          "livemode": false,
          "lookup_key": null,
          "metadata": {
          },
          "nickname": null,
          "product": "prod_H1c7exjJHbC4sr",
          "recurring": {
            "interval": "month",
            "interval_count": 1,
            "trial_period_days": null,
            "usage_type": "licensed"
          },
          "tiers": null,
          "tiers_mode": null,
          "transform_quantity": null,
          "type": "recurring",
          "unit_amount": 1000,
          "unit_amount_decimal": "1000"
        },
        "quantity": 1,
        "subscription": "sub_H1yPRslJXa4TUt",
        "tax_rates": [
        ]
      },
      {
        "id": "si_H1yPu4fSjq3oqM",
        "object": "subscription_item",
        "billing_thresholds": null,
        "created": 1585939321,
        "metadata": {
        },
        "price": {
          "id": "price_H1yCssogQ6gtx1",
          "object": "price",
          "active": true,
          "billing_scheme": "per_unit",
          "created": 1585938535,
          "currency": "usd",
          "livemode": false,
          "lookup_key": null,
          "metadata": {
          },
          "nickname": null,
          "product": "prod_H1c7exjJHbC4sr",
          "recurring": {
            "interval": "month",
            "interval_count": 1,
            "trial_period_days": null,
            "usage_type": "licensed"
          },
          "tiers": null,
          "tiers_mode": null,
          "transform_quantity": null,
          "type": "recurring",
          "unit_amount": 2000,
          "unit_amount_decimal": "2000"
        },
        "quantity": 2,
        "subscription": "sub_H1yPRslJXa4TUt",
        "tax_rates": [
        ]
      }
    ]
  },
  ...
}
```

### 複数の価格を使用する請求期間

定期的に固定金額を請求するサブスクリプションは、各[請求期間(サイクル)](https://docs.stripe.com/billing/subscriptions/billing-cycle.md)の開始時に請求されます。請求書ごとに、顧客は実質的に次の期間のサービスに対して決済を行います。[従量課金](https://docs.stripe.com/products-prices/pricing-models.md#usage-based-pricing)では、請求期間中の使用量によって顧客の決済金額が異なるため、顧客はその使用量に対して最後に決済を行います。

サブスクリプションで固定料金と従量課金を組み合わせると、各更新の開始時に、新しい請求期間の固定料金とともに、前の請求期間の使用量に対する従量課金が行われます。従量課金と固定料金が 1 つの請求書にまとめられます。

複数の商品を 1 つのサブスクにまとめる場合、請求と支払いも 1 回で行われるため、それらの商品の料金はすべて同じ通貨を使用する必要があります。

フレキシブル請求モードのサブスクでは最大 100 個のサブスク項目に対応していますが、従来の請求モードのサブスクでは最大 20 個のサブスク項目に対応しています。

請求期間が異なる可能性のあるサブスクリプションの複数の製品を処理するには、[混合間隔サブスクリプション](https://docs.stripe.com/billing/subscriptions/mixed-interval.md)を作成します

### 割引、税金、トライアル期間

複数の商品を使用する場合でも、単一商品のサブスクと同様に、[割引](https://docs.stripe.com/billing/subscriptions/coupons.md)の作成、[税金](https://docs.stripe.com/billing/taxes/collect-taxes.md)の請求、[トライアル期間](https://docs.stripe.com/billing/subscriptions/trials/free-trials.md)の利用が可能です。

これらの引数は、サブスクリプションを[作成](https://docs.stripe.com/api/subscriptions/create.md)または[更新](https://docs.stripe.com/api/subscriptions/update.md)してサブスクリプション全体に適用するときに指定するか、項目レベルで指定して特定の項目のみを割引します。

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer={{CUSTOMER_ID}}" \
  -d "discounts[0][coupon]={{COUPON_ID}}" \
  -d "default_tax_rates[0]=txr_1EO66sClCIKljWvs98IiVfHW" \
  -d trial_end=1610403705 \
  -d "items[0][price]={{PRICE_ID}}" \
  -d "items[1][price]={{PRICE_ID}}" \
  -d "items[1][quantity]=2"
```

## サブスクリプションの複数の数量

多くの場合、サブスクリプションの数量の設定は、「ユーザー数に基づくライセンス」と説明できます。この場合、費用は直線的に増加し、たとえばユーザー数が 10 の場合の料金は、基本料金の 10 倍です。

デフォルトでは、サブスクリプションのそれぞれが 1 つの商品に対応しますが、Stripe を使用すると、顧客は 1 つのアイテムのサブスクリプションで複数の数量を設定できます。たとえば、ホスティング会社を運営し、顧客はこの会社から 1 サイトあたり月額 $9.99 の料金でサイトをオンラインでホストするとします。ほとんどの顧客はサイト 1 つのみをオンラインで運営しますが、一部の顧客は多数のサイトを運営します。1 つのサイト ($9.99)、2 つのサイト($19.98) のように価格を作成することもできますが、これよりも、$9.99 の単価で顧客に数量を登録するアプローチをお勧めします。

サブスクリプションの従量課金には、従量課金とユーザー数ベースのライセンスの 2 種類があります。料金を作成するときに `recurring[usage_type]` 属性の値を設定することで、これらの請求書モデルを有効にできます。数量は、`recurring[usage_type]` を `licensed` としてサブスクリプションを作成するときにのみ指定できます。請求書期間内で変動する使用状況に対して請求書を細かく設定する場合は、数量ではなく [usage-based billing](https://docs.stripe.com/products-prices/pricing-models.md#usage-based-pricing) を使用することを検討してください。

### 複数の数量を設定

サブスクリプションに数量を設定するには、サブスクリプションを[作成](https://docs.stripe.com/api.md#create_subscription)または[更新](https://docs.stripe.com/api.md#update_subscription)する際に `quantity` の値を指定します。

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer={{CUSTOMER_ID}}" \
  -d "items[0][price]={{PRICE_ID}}" \
  -d "items[0][quantity]=5"
```

1 つの*請求書* (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)で複数の数量を請求することもできます。また、サブスクリプションに変更があった場合は、複数の数量を[比例配分](https://docs.stripe.com/billing/subscriptions/prorations.md)します。これには、サブスクリプション数量の変更も含まれます。

### 数量に応じて異なる金額を請求する

状況によっては、サブスクリプションのユーザー数に基づいてユーザーあたりの料金を調整することもできます。たとえば、ユーザー数が特定のしきい値を超えたサブスクリプションに、ボリュームライセンス割引を提供することが可能です。この場合、[段階](https://docs.stripe.com/products-prices/pricing-models.md#tiered-pricing)を用いてユーザーごとの料金を調整できます。

### 数量の変換

顧客に請求する際に、請求とは異なる詳細度での使用量の追跡が必要な場合があります。たとえば、製品を使用する 5 ユーザー (またはその一部) ごとに 10 USD を請求する生産性向上ソフトウェアがあるとします。この場合、数量の変換がなければ、5 ユーザーごとにサブスクリプションの `quantity` を 1 だけ増加させることが必要になります。

| ユーザー数 | Stripe に報告されるサブスクリプションアイテムの数量 | 合計 |
| --- | --- | --- |
| 1 | 1 | 10 USD |
| 3 | 1 | 10 USD |
| 5 | 1 | 10 USD |
| 6 | 2 | 20 USD |
| 7 | 2 | 20 USD |

[transform_quantity](https://docs.stripe.com/api/prices/create.md#create_price-transform_quantity) パラメーターを使用すると、単価を適用する前に数量を変換するように Stripe に指示できます。以下のサブスクでは、現在のユーザー数をサブスク項目の `quantity` として自然に報告できます。Stripe の請求システムは、数量を 5 で割って切り上げてから、単価による計算を行います。

```curl
curl https://api.stripe.com/v1/prices \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "nickname=Standard Cost Per 5 Users" \
  -d "transform_quantity[divide_by]=5" \
  -d "transform_quantity[round]=up" \
  -d unit_amount=1000 \
  -d currency=usd \
  -d "recurring[interval]=month" \
  -d "recurring[usage_type]=licensed" \
  -d product={{PRODUCTIVITY_SUITE_ID}}
```

`transform_quantity` は、[billing_scheme=per_unit](https://docs.stripe.com/api/prices/create.md#create_price-billing_scheme) のみで使用できます。段階制料金体系では使用できません。

#### 切り捨て/切り上げ

前の例では、5 ユーザーごとに切り上げて請求するサブスクリプションを紹介しました。たとえば、6 を 5 で割って、切り上げると 2 になります。ブロードバンドインターネットサービスで 1 ギガバイト使用するごとに請求するような、使用量の一部について請求しない使用量のケースでは、`round` の値として `down` を渡すこともできます。

#### 使用量に基づく請求

従量課金と組み合わせて `transform_quantity` を適用することもできます。この変換は、`recurring[usage_type]=metered` の価格に適用されるのと同じ方法で、請求期間の最後に `recurring[usage_type]=licensed` の価格の `quantity` に適用されます。

1,000 通のメール送信ごとに 0.10 USD の決済を請求する従量課金のマーケティングメールサービスは以下のようになります。

```curl
curl https://api.stripe.com/v1/prices \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "nickname=Metered Emails" \
  -d "transform_quantity[divide_by]=1000" \
  -d "transform_quantity[round]=down" \
  -d unit_amount=10 \
  -d currency=usd \
  -d "recurring[interval]=month" \
  -d "recurring[usage_type]=metered" \
  -d product={{MARKETING_EMAILS_ID}}
```

このサブスクリプションでは、使用量はメールごとに報告され、顧客には 1,000 通送信するごとに 0.10 USD を請求できます。

## 複数のサブスクリプション

同一の顧客に対して、複数のサブスクを同時に作成できます。この機能は、顧客が個別のサービス期間を持つ複数の商品を購読できるようにする場合に使用します。ベースとなる価格の請求期間が同じであっても、各サブスクには個別の請求期間、請求書、課金が存在します。

> 複数のサブスクリプションを同じ料金で作成した場合でも、決済や請求期間などはサブスクリプションごとに異なります。これを避けるには、代わりに[複数の数量](https://docs.stripe.com/billing/subscriptions/quantities.md#setting-quantities)を使用するサブスクリプションを 1 件作成します。

### 1 人の顧客に対して複数のサブスクリプションを作成する

[create subscription](https://docs.stripe.com/api.md#create_subscription) API を使用して、1 人の顧客に複数のサブスクリプションを作成します。

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer={{CUSTOMER_ID}}" \
  -d "items[0][price]={{PRICE_ID}}"
```

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer={{CUSTOMER_ID}}" \
  -d "items[0][price]={{PRICE_ID}}"
```

顧客は、複数の商品に登録したり、同一の商品に何度も登録したりすることもできます。各サブスクリプションに一意の ID が設定され、その状態は顧客の他のサブスクリプションとは別に処理されます。また、各サブスクリプションは、サブスクリプションの[請求サイクルのアンカー](https://docs.stripe.com/billing/subscriptions/billing-cycle.md)に基づく独自の請求期間を持ちます。

顧客に複数のサブスクリプションが存在する場合は、`Customer` オブジェクトの `subscriptions` プロパティを指定することで、サブスクリプションのリストが提供されます。

```json
{
  "id": "cus_4fdAW5ftNQow1a",
  "object": "customer",
  "subscriptions": {
    "object": "list",
    "data": [
      {
        "id": "sub_9RRl3XywPg2P5H",
        "object": "subscription",
        ...
        "price": {
          "id": "price_CZB2krKbBDOkTS",
          "object": "price",
          "amount": 2995,
          ...
        }
      },
      {
        "id": "sub_9RRlIq2t9obFLI",
        "object": "subscription",
        ...
        "price": {
          "id": "price_CZB1AX3KOacNJw",
          "object": "price",
          "amount": 1295,
          ...
        }
      }
    ],
    ...
  },
  ...
}
```

## See also

- [サブスクリプションの変更](https://docs.stripe.com/billing/subscriptions/change.md)
- [トライアル期間を利用する](https://docs.stripe.com/billing/subscriptions/trials/free-trials.md)
- [Subscription API](https://docs.stripe.com/api.md#subscriptions)
