10
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Stripeで、初回の契約手数料などの「1回限りの決済」をサブスクリプションに追加する方法

Posted at

サブスクリプションビジネスでは、初期費用や契約・事務手数料などの「1回限りの請求」も行う場面が存在します。

この記事では、Stripeを利用して、「サブスクリプションの請求」と「1回限りの請求」をまとめて請求・決済する方法を紹介します。

サブスクリプション作成時に、1回限りの請求も追加する

初回費用など、サブスクリプション作成時に請求したいケースでは、サブスクリプション作成時のAPIコールで設定します。

const subscription = await stripe.subscriptions.create({
  customer: '{{CUSTOMER_ID}}',
  // 定期課金の料金
  items: [{
    price: '{{RECURRING_PRICE_ID}}',
    quantity: 1,
  }],

  // 1回限りの料金
  add_invoice_items: [{
    price: '{{PRICE_ID}}',
    quantity: 1,
  }],
});

サブスクリプションだけの場合、itemsのみを設定します。

1回限りの請求を混ぜたい場合は、add_invoice_itemsを追加しましょう。

作成と決済に成功すると、初回の請求のみadd_invoice_itemsに設定した料金が表示されます。

スクリーンショット 2022-05-16 18.52.39.png

Checkoutで、1回限りの請求も追加する

Checkoutで決済画面を用意する場合は、1回限りの請求もline_itemsに追加すればOKです。

await stripe.checkout.sessions.create({
  mode: 'subscription',
  customer: '{{CUSTOMER_ID}}',
  line_items: [{
    price: '{{RECURRING_PRICE_ID}}',
    quantity: 1,
  }, {
    price: '{{PRICE_ID}}',
    quantity: 1,
  }],
  success_url: 'https://example.com/success',
  cancel_url: 'https://example.com'
})

混ぜた状態でCheckoutのセッションを作成すると、「今回の請求」と「次回以降の請求」の2つが表示されます。

スクリーンショット 2022-05-16 19.02.31.png

注意点

請求タイミングが、サブスクリプションのサイクルで決済されます。

タイミングを調整したい場合は、別途請求書やPayment Intentsを作成する方法もご検討ください。

Documents

[PR] Stripe開発者向け情報をQiitaにて配信中!

  • [Stripe Updates]:開発者向けStripeアップデート紹介・解説
  • ユースケース別のStripe製品や実装サンプルの紹介
  • Stripeと外部サービス・OSSとの連携方法やTipsの紹介
  • 初心者向けのチュートリアル(予定)

など、Stripeを利用してオンラインビジネスを始める方法について週に2〜3本ペースで更新中です。

-> Stripe Organizationsをフォローして最新情報をQiitaで受け取る

10
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?