# Bacs ダイレクトデビットによるサブスクリプションを設定する Bacs ダイレクトデビットを使用したサブスクリプションの作成と請求の方法をご紹介します。 [GitHub のサンプル](https://github.com/stripe-samples/checkout-single-subscription)を確認するか[デモ](https://checkout.stripe.dev/checkout)をご覧ください。 このガイドを参照して、決済手段に [Bacs Direct Debit](https://docs.stripe.com/payments/payment-methods/bacs-debit.md) と *Checkout* (A low-code payment integration that creates a customizable form for collecting payments. You can embed Checkout directly in your website, redirect customers to a Stripe-hosted payment page, or create a customized checkout page with Stripe Elements) を使用する*サブスクリプション* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)を設定します。 ## Stripe を設定する [サーバ側] まず、Stripe アカウントが必要です。[今すぐ登録してください](https://dashboard.stripe.com/register)。 アプリケーションから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## 継続支払いの商品と価格を作成する > Prices API は、Stripe で 1 回限りの購入およびサブスクリプションをモデル化する方法を統一します。Prices API を使用しない既存のシステムも引き続き[サポートされます](https://support.stripe.com/questions/prices-api-and-existing-checkout-integrations)が、一部の Checkout 機能では Prices のみがサポートされます。Prices API へのアップグレードについては、[移行ガイド](https://docs.stripe.com/payments/checkout/migrating-prices.md)を参照してください。 Checkout を使用するには、まず*商品* (Products represent what your business sells—whether that's a good or a service)と*価格* (Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the interval if the price is for subscriptions)を作成する必要があります。物品やサービスレベルごとに商品を作成します。各商品の料金体系は 1 つ以上の価格で示されます。 たとえば、10 USD/月、100 USD/年、9 GBP/月、90 GBP/年の、4 つの「価格」が設定されたソフトウェア「商品」を作成できます。これにより、対象商品の詳細を変更せずに価格を変更したり追加したりできます。商品と価格は、[API を通じて](https://docs.stripe.com/api/prices.md)、または [Stripe ダッシュボード](https://dashboard.stripe.com/products)を使用して作成できます。 価格が購入時に決定される場合 (顧客が寄付金額を設定する場合など)、または事前に価格を作成しない選択をした場合は、Checkout セッションの作成時に[価格をインライン](https://docs.stripe.com/billing/subscriptions/bacs-debit.md#creating-prices-inline)で作成することができます。 #### ダッシュボード 商品の設定を開始する前に、サンドボックスを使用していることを確認してください。次に、販売する予定の商品とサービスを定義します。新しい商品と価格を作成するには、以下を実行します。 - ダッシュボードで [商品](https://dashboard.stripe.com/products) セクションに移動します - **商品を追加**をクリックします - 価格を設定する際に「継続」を選択します - 料金プランを設定する 継続支払いの商品ごとに異なるパラメータを設定して、複数の料金プランを定義できます。各料金には ID が生成され、これを決済プロセス中に参照できます。 > サンドボックスで作成された商品は本番環境にコピーできるため、再度作成する必要はありません。ダッシュボードの商品詳細表示で、右上隅にある **本番環境にコピー** をクリックします。この操作はサンドボックスで作成された各商品に対して 1 回のみ実行できます。テスト環境の商品に対する以降の更新は、本番環境の商品には反映されません。 #### API API を使用して基本的な [Product (商品)](https://docs.stripe.com/api/products.md) を作成するには、`name` フィールドのみが必要です。指定した商品の `name`、`description`、および `images` が Checkout で顧客に表示されます。 ```curl curl https://api.stripe.com/v1/products \ -u "<>:" \ -d "name=Blue banana" ``` 次に、[Price (価格)](https://docs.stripe.com/api/prices.md) を作成して、商品の請求額と請求頻度を定義します。これには商品のコスト、使用通貨および請求期間も含まれます。 #### curl ```bash curl https://api.stripe.com/v1/prices \ -u <>: \ -d "product"="{{ PRODUCT_ID }}" \ -d "unit_amount"=1000 \ -d "currency"="gbp" \ -d "recurring[interval]=month" ``` この料金 ID は、Checkout を使用して支払いプロセスを開始するときに、商品を参照する手段になります。 ## Checkout セッションを作成する [クライアント側] [サーバ側] ウェブサイトに決済ボタンを追加し、サーバー側のエンドポイントを呼び出して Checkout セッションを作成します。 ```html Checkout
``` ### Checkout セッションのパラメーター 使用できるパラメーターの完全なリストについては、[Checkout セッションの作成](https://docs.stripe.com/api/checkout/sessions/create.md)を参照してください。 既存の [Price](https://docs.stripe.com/api/prices.md) の ID を使用して Checkout セッションを作成します。モードが `subscription` に設定されており、1 つ以上の継続価格を渡すことを確認してください。継続価格に加えて、1 回限りの価格を追加できます。Checkout セッションを作成したら、レスポンスで返された [URL](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-url) に顧客をリダイレクトします。 #### cURL ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ ``` 顧客が支払いを正常に完了すると、`success_url` (支払いが成功したことを顧客に通知するウェブページ) にリダイレクトされます。上記の例のように、`success_url` に `{CHECKOUT_SESSION_ID}` テンプレート変数を含めることで、成功ページでセッション ID が使用できるようになります。 デフォルトでは、Checkout セッションは作成後 24 時間で期限が切れます。 [ダッシュボード](https://dashboard.stripe.com/settings/payment_methods)で、顧客が使用できる支払い方法を有効にします。Checkout は、[複数の支払い方法](https://docs.stripe.com/payments/payment-methods/payment-method-support.md#product-support)に対応しています。 > 決済開始の検出にあたっては、`success_url` へのリダイレクトのみに依存しないでください。その理由は次のとおりです。 > > - 悪意を持つユーザが、支払いをせずに `success_url` に直接アクセスし、商品やサービスにアクセスできるようになる可能性があります。 - 決済が成功した後で、顧客が `success_url` にリダイレクトされる前にブラウザタブを閉じる可能性あります。 ## 支払いが成功したことを確認する 顧客は支払いを完了すると、`success_url` パラメータで指定された URL にリダイレクトされます。通常、これはお客様の Web サイト上のページであり、支払いが成功したことを顧客に知らせます。 ただし、Bacs Direct Debit は通知遅延型の支払い方法であるため、資金はすぐに利用可能になりません。このため、資金が利用可能になるまで、注文の *フルフィルメント* (Fulfillment is the process of providing the goods or services purchased by a customer, typically after payment is collected) を保留にします。支払いが成功すると、基盤となる *PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) のステータスが `processing` から `succeeded` に変わります。 次のように、複数の方法で支払いが成功したことを確認できます。 #### ダッシュボード 成功した決済は、ダッシュボードの [決済の一覧](https://dashboard.stripe.com/payments) に表示されます。決済をクリックすると、その決済の詳細ページに移動します。**決済サマリー** セクションには、Billing 情報と購入された項目の一覧が含まれ、これを使用して手動で注文のフルフィルメントを実行できます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/source.16d3029596357c80a8efdbbfe106108a.png) > Stripe は顧客が支払いに成功するたびにお客様にメール通知を送信し、今後受領する支払いの最新情報を把握できるようサポートします。ダッシュボードを使用して[メール通知を設定](https://dashboard.stripe.com/settings/user)します。 #### Webhook 決済のステータスに変化があると、以下の決済イベントが送信されます。 | イベント名 | 説明 | 次のステップ | | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ------------------------------------ | | [checkout.session.completed](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.completed) | 顧客が Checkout フォームを送信して、デビット支払いのオーソリを正常に実行しました。 | 支払いが成功するか、失敗するまで待ちます。 | | [checkout.session.async_payment_succeeded](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.async_payment_succeeded) | 遅延された支払い方法は、最終的に成功しました。 | 顧客が購入した商品またはサービスの発送を行います。 | | [checkout.session.async_payment_failed](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.async_payment_failed) | 遅延された支払い方法は、最終的に失敗しました。 | 顧客にメールをして、決済をもう一度試みるようにリクエストします。 | | [invoice.paid](https://docs.stripe.com/api/events/types.md#event_types-invoice.paid) | 顧客の支払いが成功しました。 | 顧客が購入した商品またはサービスの発送を行います。 | | [invoice.payment_failed](https://docs.stripe.com/api/events/types.md#event_types-invoice.payment_failed) | 何らかの理由により顧客の支払いが拒否されたか、失敗しました。 | メールで顧客に連絡して、支払いをもう一度お試しいただくように依頼します。 | Webhook コードでこれらの決済イベントのすべてを処理する必要があります。 各 Checkout Webhook のペイロードには [Checkout Session オブジェクト](https://docs.stripe.com/api/checkout/sessions.md) が含まれ、インボイスの Webhook には [Invoice (インボイス)](https://docs.stripe.com/api/invoices/object.md) オブジェクトが含まれます。この両方に、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) および *PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) に関する情報が含まれます。 顧客がリダイレクトされる前に、Stripe から `checkout.session.completed` Webhook がお客様のサーバーに送信されます。Webhook の確認応答 (任意の `2xx` ステータスコード) によって、`success_url` への顧客のリダイレクトが開始されます。支払いに成功してから 10 秒以内に Stripe が成功確認応答を受け取らなかった場合、顧客は自動的に `success_url` ページにリダイレクトされます。 [Webhook を使用](https://docs.stripe.com/webhooks.md)して支払いの成功を確認し、顧客が購入した商品やサービスのフルフィルメントを行うことをお勧めします。以下は、支払いの成功または失敗を処理する Webhook エンドポイントの例です。 #### 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('<>') # You can find your endpoint's secret in your webhook settings endpoint_secret = 'whsec_...' # Using Sinatra post '/webhook' do payload = request.body.read event = nil # Verify webhook signature and extract the event # See https://stripe.com/docs/webhooks#verify-events for more information. sig_header = request.env['HTTP_STRIPE_SIGNATURE'] begin event = Stripe::Webhook.construct_event( payload, sig_header, endpoint_secret ) rescue JSON::ParserError => e # Invalid payload status 400 return rescue Stripe::SignatureVerificationError => e # Invalid signature status 400 return end case event['type'] when 'checkout.session.completed' session = event['data']['object'] subscription_id = session.subscription # Find the subscription or save it to your database. # invoice.paid may have fired before this so there # could already be a subscription. find_or_create_subscription(subscription_id) when 'invoice.paid' invoice = event['data']['object'] subscription_id = invoice.parent.subscription_details.subscription # Find the subscription or save it to your database. # checkout.session.completed may not have fired yet # so we may need to create the subscription. subscription = find_or_create_subscription(subscription_id) # Fulfill the purchase fulfill_order(invoice) # Record that the subscription has been paid for # this payment period. invoice.paid will fire every # time there is a payment made for this subscription. record_as_paid_for_this_period(subscription) when 'invoice.payment_failed' invoice = event['data']['object'] # Send an email to the customer asking them to retry their payment email_customer_about_failed_payment(invoice) end status 200 end ``` 顧客、決済、またはサブスクリプションに関する情報を取得するには、Webhook のペイロードの `customer`、`payment_intent`、および `subscription` のプロパティによって参照される `Customer`、`PaymentIntent`、または `Subscription` のオブジェクトを取得します。 ### Webhook からラインアイテムを取得する デフォルトでは、Checkout Webhook は `line_items` を返しません。Checkout セッションで作成されたアイテムを取得するには、Checkout セッション ID を使用して追加のリクエストを行います。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions/{{CHECKOUT_SESSION_ID}}/line_items \ -u <>: ``` #### Stripe CLI ```bash stripe get /v1/checkout/sessions/{{CHECKOUT_SESSION_ID}}/line_items ``` ### Webhook をローカルでテストする Webhook をローカルでテストするには、[Stripe CLI](https://docs.stripe.com/stripe-cli.md) を使用できます。Stripe CLI をインストールすると、サーバーにイベントを転送できるようになります。 ```bash stripe listen --forward-to localhost:4242/webhook Ready! Your webhook signing secret is '{{WEBHOOK_SIGNING_SECRET}}' (^C to quit) ``` [Webhook の設定](https://docs.stripe.com/webhooks.md)についてもっと知る。 #### サードパーティーのプラグイン [Zapier](https://stripe.com/works-with/zapier) などのプラグインを使用すると、Stripe の決済からの情報を利用して購入のフルフィルメントシステムを自動更新できます。 プラグインで対応可能な自動化の例の一部を以下に挙げます。 - 支払いの成功に対応して、注文の追跡に使用されるスプレッドシートを更新する - 支払いの成功に対応して、在庫管理システムを更新する - メールまたはチャットアプリケーションを使用して、社内のカスタマーサービスチームへの通知をトリガーする ## 組み込みをテストする この実装の準備ができていることを確認するために、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で使用できる[テスト用銀行口座番号](https://docs.stripe.com/keys.md#test-live-modes)が複数用意されています。 | 銀行コード | 口座番号 | 説明 | | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------ | | 10-88-00 | 00012345 | 支払いが成功し、請求書が `paid` に変化します。 | | 10-88-00 | 90012345 | 支払いが 3 分後に成功し、請求書が `paid` に変化します。 | | 10-88-00 | 33333335 | 支払いが `debit_not_authorized` エラーコードによって失敗し、請求書が `open` に変化します。同意書は `inactive` になり、この PaymentMethod を再び使用することはできません。 | | 10-88-00 | 93333335 | 支払いが `debit_not_authorized` エラーコードによって 3 分後に失敗し、請求書が `open` に変化します。同意書は `inactive` になり、この PaymentMethod を再び使用することはできません。 | | 10-88-00 | 22222227 | 支払いが `insufficient_funds` エラーコードによって失敗し、請求書が `open` に変化します。この同意書は `active` のままで、PaymentMethod は再使用が可能です。 | | 10-88-00 | 92222227 | 支払いが `insufficient_funds` エラーコードによって 3 分後に失敗し、請求書が `open` に変化します。この同意書は `active` のままで、PaymentMethod は再使用が可能です。 | | 10-88-00 | 55555559 | 支払いが 3 分後に成功し、Invoice が `paid` に変わりますが、不審請求の申請が直ちに作成されます。 | | 10-88-00 | 00033333 | 支払い方法の作成は成功しますが、同意書が顧客の銀行によって拒否され、即座に inactive に変化します。 | | 10-88-00 | 00044444 | Bacs ダイレクトデビットの設定を求めるリクエストが、口座番号が無効なため即座に失敗し、顧客は送信前に情報を更新するように求められます。支払いの詳細は回収されません。 | テストの実行には前述の任意の口座番号を使用できます。ただし、Bacs ダイレクトデビットによる支払いは処理に数日かかるため、3 分の遅延で動作するテスト用口座番号を使用して、本番環境の支払いの動作のシミュレーションをしやすくします。 > デフォルトでは、Stripe は決済情報が初めて収集されたときと、顧客の口座から引き落としが行われるたびに、顧客に[メール](https://docs.stripe.com/payments/payment-methods/bacs-debit.md#debit-notifications)を送信します。これらの通知は、サンドボックスでは送信されません。 ## Optional: 1 回限りの設定手数料を追加する [サーバ側] `subscription` モードには継続支払いの料金を渡すだけでなく、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 回限りの手数料の追加に便利です。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"="bacs_debit" \ -d "line_items[0][price]"="{{RECURRING_PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "line_items[1][price]"="{{ONE_TIME_PRICE_ID}}" \ -d "line_items[1][quantity]"=1 \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" ``` ## Optional: 価格と商品をインラインで作成する [サーバ側] 既存の料金 ID に渡すだけではなく、Checkout セッションの作成でアイテムの料金を定義することもできます。まず、[Product (商品)](https://docs.stripe.com/api/products.md) を定義します。次に、商品 ID を使用し、それを `unit_amount`、`currency`、`recurring` の詳細とともに [price_data](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-price_data) に渡して、Checkout セッションを作成します。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"=bacs_debit \-d line_items[0][price_data][unit_amount]=5000 \ -d line_items[0][price_data][currency]=gbp\ -d line_items[0][price_data][product]="{{PRODUCT_ID}}" \ -d line_items[0][price_data][recurring][interval]=month \ -d line_items[0][quantity]=1 \ -d mode=subscription \ -d success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ ``` また、商品もインラインで作成する必要がある場合は、[product_data](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-price_data-product_data) を使用して作成できます。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"=bacs_debit \-d "line_items[][price_data][currency]"=gbp\ -d "line_items[][price_data][product_data][name]"=T-shirt \ -d "line_items[][price_data][unit_amount]"=2000 \ -d "line_items[][quantity]"=1 \ -d "mode"="subscription" \ -d success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ ``` ## Optional: 既存の顧客 [サーバ側] 顧客を表す *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) オブジェクトを以前に作成している場合、Checkout Session を作成する際に [customer](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer) 引数を使用してその顧客 ID を渡します。こうすることで、そのセッション中に作成されたすべてのオブジェクトが正しい Customer オブジェクトに関連付けられます。 顧客 ID を渡すと、Stripe は Customer オブジェクトに保管されたメールアドレスを使用して、Checkout ページのメールフィールドに事前入力します。顧客が Checkout ページでメールアドレスを変更すると、支払いの成功後に Customer オブジェクトの該当項目が更新されます。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "customer"="{{CUSTOMER_ID}}" \ -d "payment_method_types[]"="bacs_debit" \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success" ``` ## Optional: 顧客データの事前入力 [サーバ側] すでに顧客のメールを収集していて、それを Checkout セッションで事前に入力するには、Checkout セッションの作成時に [customer_email](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer_email) を渡します。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \-d customer_email="customer@example.com" \ -d "payment_method_types[]"=bacs_debit \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \ -d mode=subscription \ -d success_url="https://example.com/success" \ ``` ## Optional: トライアルの処理 [サーバ側] Checkout セッションで [trial_end](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-trial_end) または [trial_period_days](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-trial_period_days) を使用して、トライアル期間の日数を指定できます。この例では、`trial_period_days` を使用して 30 日間のトライアルを含むサブスクリプションの Checkout セッションを作成します。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"=bacs_debit \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \-d "subscription_data[trial_period_days]"=30 \ -d mode=subscription \ -d success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ ``` Checkout では、トライアルを含むサブスクリプションに対して以下の情報が自動的に表示されます。 - トライアル期間 - トライアル期限満了後の支払いの頻度と金額 法令遵守要件の詳細については、[法令遵守要件の管理](https://docs.stripe.com/billing/subscriptions/trials/manage-trial-compliance.md)または[サポート](https://support.stripe.com/questions/2020-visa-trial-subscription-requirement-changes-guide)ガイドを参照してください。 ## Optional: 税率 [サーバ側] Checkout セッションで[税率](https://docs.stripe.com/billing/taxes/tax-rates.md) (消費税、VAT、GST、その他) を指定し、*サブスクリプション* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)に税金を適用できます。 - 顧客が決済フロープロセスを開始する前に、顧客に請求する正確な税率を把握している場合は、固定税率を使用します (イギリスの顧客にのみ販売し、常に 20% の VAT を課税する場合など)。 - *Prices* (Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the interval if the price is for subscriptions) API では、請求する税率を決定する前に顧客の詳細情報 (請求先住所、配送先住所など) が必要な場合に、動的税率を使用できます。動的税率では、地域ごとに異なる複数の税率 (イギリスの顧客には 20% の VAT、アメリカ・カリフォルニア州の顧客には 7.25% の売上税など) を作成でき、Stripe は顧客の居住地を、これらの税率のいずれかとマッチングします。 #### 固定税率 Checkout で開始したサブスクリプションにデフォルトの税率を適用するには、[subscription_data.default_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-default_tax_rates) を設定します。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"=bacs_debit \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \-d "subscription_data[default_tax_rates][]"="{{TAX_RATE_ID}}" \ -d mode=subscription \ -d success_url="https://example.com/success" \ ``` また、[line_items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-tax_rates) あるいは [subscription_data.items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-items-tax_rates) を指定して、特定のプランまたはインボイスのラインアイテムに税率を適用することもできます。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"="bacs_debit" \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \-d "line_items[][tax_rates][0]"="{{TAX_RATE_ID}}" \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success" \ ``` #### 動的税率 [Tax Rate (税率)](https://docs.stripe.com/api/tax_rates/object.md) の配列を [line_items.dynamic_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates) に渡します。各 Tax Rate には[サポート対象の](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates) `country` が設定されている必要があり、アメリカの場合は `state` も必要です。 このリストでは、税率を顧客の[配送先住所](https://docs.stripe.com/payments/collect-addresses.md)または請求先住所と突き合わせます。請求する税率を決定する際は、請求先住所よりも配送先住所が優先されます。 配送先住所や請求先住所を収集していない場合は、税率の決定に顧客の国 (および該当する場合には郵便番号) が使用されます。顧客の配送先住所、請求先住所、または国に一致する税率を渡していない場合、税率は適用されません。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"="bacs_debit" \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \-d "line_items[][dynamic_tax_rates][]"="{{FIRST_TAX_RATE_ID}}" \ -d "line_items[][dynamic_tax_rates][]"="{{SECOND_TAX_RATE_ID}}" \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success" \ ``` > [subscription_data.default_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-default_tax_rates) および [line_items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-tax_rates) を [line_items.dynamic_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates) と組み合わせて使用することはできません。 Stripe のデータエクスポート機能を使用して、送金に必要となる定期的な申告書に入力することができます。詳細については、[納税申告および送金](https://docs.stripe.com/billing/taxes/tax-rates.md#remittance)を参照してください。 ## Optional: クーポンの追加 [サーバ側] Checkout セッションでは、[discounts (割引)](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-discounts) を設定することで、サブスクリプションに[クーポン](https://docs.stripe.com/billing/subscriptions/coupons.md)を適用できます。このクーポンは、顧客の他のクーポンよりも優先されます。[既存の顧客](https://docs.stripe.com/billing/subscriptions/bacs-debit.md#handling-existing-customers)でサブスクリプションを作成している場合、その顧客に関連付けられたクーポンがサブスクリプションの*インボイス* (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)に適用されます。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"=bacs_debit \ -d "line_items[][price]"="{{PRICE_ID}}" \ -d "line_items[][quantity]"=1 \-d "discounts[][coupon]"="{{COUPON_ID}}" \ -d "mode"="subscription" \ -d success_url="https://example.com/success" \ ``` ### 顧客に表示されるプロモーションコードを追加する また、ユーザーが引き換え可能な[プロモーションコード](https://docs.stripe.com/billing/subscriptions/coupons.md#promotion-codes)は、Checkout セッションで [allow_promotion_codes](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-allow_promotion_codes) パラメーターを使用して有効にできます。Checkout セッションで `allow_promotion_codes` が有効になっている場合、Checkout には顧客が利用するためのプロモーションコードの入力欄が表示されます。[クーポン](https://docs.stripe.com/billing/subscriptions/coupons.md)およびプロモーションコードは、顧客が Checkout で引き換えられるようにダッシュボードまたは API で作成します。 #### curl ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"="bacs_debit" \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][price_data][currency]"="gbp" \ -d "line_items[0][price_data][product]={{PRODUCT_ID}}" \ -d "line_items[0][price_data][recurring][interval]=month" \ -d "line_items[0][quantity]"=1 \-d "allow_promotion_codes"="true" \ -d "mode"="subscription" \ -d "success_url"="https://example.com/success" \ ``` ## See also - [自社のシステムを構築する](https://docs.stripe.com/payments/checkout/customization.md) - [カスタマーポータルでサブスクリプションを管理する](https://docs.stripe.com/billing/subscriptions/build-subscriptions.md?payment-ui=checkout&ui=stripe-hosted)