# Cash App Pay によるサブスクリプションを設定する Cash App Pay を使用したサブスクリプションの作成と請求の方法をご紹介します。 このガイドを使用して、支払い方法として [Cash App Pay](https://docs.stripe.com/payments/cash-app-pay.md) を使用する*サブスクリプション* (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)を設定します。 # Intents API を設定 > This is a Intents API を設定 for when api-integration is setupintents. View the full page at https://docs.stripe.com/billing/subscriptions/cash-app-pay?api-integration=setupintents. 2 つの API コールを使用してサブスクリプションを作成し、確定します。[1 つ目の API コール](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#create-setup-intent)は、[Setup Intents API](https://docs.stripe.com/api/setup_intents.md) を使用して Cash App Pay を支払い方法として設定します。[2 つ目の API コール](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#create-subscription)は、顧客、商品、支払い方法の情報を [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) に送信し、サブスクリプションの作成と支払いの確定を 1 回のコールで行います。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、15 USD の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**15**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 ## SetupIntent を作成する [サーバー側] 今後の支払いに備えて顧客の支払い方法を保存するために、[SetupIntent (支払い方法設定インテント)](https://docs.stripe.com/api/setup_intents.md) を作成します。`SetupIntent` はこの設定プロセスのステップを追跡します。 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d confirm=true \ --data-urlencode "return_url=https://www.stripe.com" \ -d usage=off_session \ -d "payment_method_data[type]=cashapp" \ -d "payment_method_types[]=cashapp" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" ``` 返される SetupIntent には、*client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれており、クライアント側は、SetupIntent オブジェクト全体を渡すのではなく、client secret を使用して安全にセットアップを完了します。さまざまな方法を使用して、[クライアント側に client secret を渡す](https://docs.stripe.com/payments/payment-intents.md#passing-to-client)ことができます。SetupIntent のレスポンスには、PaymentIntent を確定するために次のステップで使用する必要がある支払い方法の ID も含まれます。 SetupIntent のレスポンスには `requires_action` ステータスが含まれるため、ユーザーが SetupIntent を完了するには別のアクションを実行する必要があります。SetupIntent レスポンスの `next_action.cashapp_handle_redirect_or_display_qr_code` オブジェクトを使用して、Stripe がオンラインで提供する、QR コードのページにユーザーをリダイレクトするか、QR コードを直接表示します。 ユーザーを認証するには、[SetupIntent を確定して支払い方法を保存する](https://docs.stripe.com/payments/cash-app-pay/set-up-payment.md?platform=web&ui=direct-api#web-create-setup-intent)の手順を使用します。認証後、Cash App モバイルアプリケーションは、モバイルデバイスの `return_url` にユーザーをリダイレクトし、SetupIntent のステータスが `succeeded` に移行します。 ## サブスクリプションを作成する [サーバー側] 価格と顧客を含むサブスクリプションを作成します。`default_payment_method` パラメーターの値を SetupIntent から戻された PaymentMethod ID に設定します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "items[0][price]={{PRICE_ID}}" \ -d default_payment_method={{PAYMENT_METHOD_ID}} ``` レスポンスにはサブスクリプションの最初の [PaymentIntent](https://docs.stripe.com/payments/payment-intents.md) が含まれ、これには *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が格納されています。この client secret は、PaymentIntent オブジェクト全体を渡すことなく支払いプロセスを安全に完了するために、クライアント側で使用されます。この `client_secret` をフロントエンドに返して、支払いを完了します。 > 無料トライアル期間付きの*サブスクリプション* (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)を作成するには、[サブスクリプションのトライアル](https://docs.stripe.com/billing/subscriptions/trials.md)をご覧ください。 # Subscriptions API > This is a Subscriptions API for when api-integration is subscription. View the full page at https://docs.stripe.com/billing/subscriptions/cash-app-pay?api-integration=subscription. 2 つの API コールを使用してサブスクリプションを作成し確定します。[最初の API コール](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#pi-create-subscription)は、顧客と商品の情報を [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) に送信し、PaymentIntent を 1 回のコールで作成します。レスポンスには、PaymentIntent ID が含まれており、これを [Payment Intents API](https://docs.stripe.com/api/payment_intents.md) コールで使用して[支払いを確定](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#pi-confirm-payment)する必要があります。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、15 USD の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**15**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 ## サブスクリプションを作成する [サーバー側] [payment_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-payment_behavior) パラメーターに `default_incomplete` の値を指定して、ステータスが `incomplete` の価格と顧客の [Subscription (サブスクリプション)](https://docs.stripe.com/api/subscriptions.md) を作成します。サブスクリプションが有効になったときに支払い方法を保存するには、`payment_settings.save_default_payment_method=on_subscription` パラメーターを設定します。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d payment_behavior=default_incomplete \ -d "items[0][price]={{PRICE_ID}}" \ -d "payment_settings[save_default_payment_method]=on_subscription" \ -d "expand[0]=latest_invoice.payments" \ -d "expand[1]=latest_invoice.confirmation_secret" ``` レスポンスには、*サブスクリプション* (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)の最初の[請求書)](https://docs.stripe.com/api/invoices.md)が含まれます。これにはインボイスの支払いが含まれます。これには、Stripe がこのインボイスに対して生成したデフォルトの PaymentIntent と、PaymentIntent オブジェクト全体を渡す代わりにクライアント側で支払いプロセスを安全に完了するために使用できる Confirmation Secret が含まれます。`latest_invoice.confirmation_secret.client_secret` をフロントエンドに返して、支払いを完了します。 支払いの確定に使用する必要がある PaymentIntent ID を `latest_invoice.payments` から取得します。 > 無料トライアル期間付きの*サブスクリプション* (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)を作成するには、[サブスクリプションのトライアル](https://docs.stripe.com/billing/subscriptions/trials.md)をご覧ください。 ## 支払いを確定する [サーバー側] サブスクリプションレスポンスの PaymentIntent ID を使用し、[PaymentIntents (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) で支払いを確定します。 PaymentIntent ID を URL パスに追加し、`payment_method_types` パラメーターの値を `cashapp` に設定します。 ```curl curl https://api.stripe.com/v1/payment_intents/:id/confirm \ -u "<>:" \ -d "payment_method_data[type]=cashapp" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" \ -d "mandate_data[customer_acceptance][accepted_at]=1660000000" ``` PaymentIntent のレスポンスには `requires_action` ステータスが含まれるため、ユーザーが PaymentIntent を完了するには別のアクションを実行する必要があります。PaymentIntent レスポンスの `next_action.cashapp_handle_redirect_or_display_qr_code` オブジェクトを使用して、Stripe がオンラインで提供する、QR コードのページにユーザーをリダイレクトするか、QR コードを直接表示します。ユーザーを認証するには、[リダイレクトと取引の認証](https://docs.stripe.com/payments/cash-app-pay/accept-a-payment.md?platform=web&ui=direct-api#handle-redirect)の手順を使用します。認証後、Cash App モバイルアプリケーションは、モバイルデバイスの `return_url` にユーザーをリダイレクトし、PaymentIntent のステータスが `succeeded` に移行します。 支払いが成功すると、サブスクリプションが有効になり、使われた支払い方法がデフォルトの支払い方法として保存されます。 # Stripe がオンラインで提供するページ > This is a Stripe がオンラインで提供するページ for when api-integration is checkout. View the full page at https://docs.stripe.com/billing/subscriptions/cash-app-pay?api-integration=checkout. [Checkout API](https://docs.stripe.com/api/checkout/sessions.md) を使用すると、構築済みの決済ページでサブスクリプションを作成して確認できます。 ## 商品と価格を作成する [ダッシュボード] [Products (商品)](https://docs.stripe.com/api/products.md) は、販売しているアイテムまたはサービスを表します。[Prices (価格)](https://docs.stripe.com/api/prices.md) は、商品の価格と請求頻度を定義します。これには、商品の価格、受け付ける通貨、および 1 回限りの支払いか継続支払いかが含まれます。商品と価格が数個のみの場合は、ダッシュボードでそれらを作成および管理します。 このガイドでは、例としてストックフォトサービスを使用し、15 USD の月次サブスクリプションを顧客に請求します。これをモデル化するには、次のようにします。 1. [商品](https://dashboard.stripe.com/products?active=true)ページに移動し、**商品を作成**をクリックします。 1. 商品の**名前**を入力します。オプションで**説明**を追加して、商品の画像をアップロードできます。 1. **商品税コード**を選択します。[商品税コード](https://docs.stripe.com/tax/tax-codes.md)の詳細をご確認ください。 1. **継続**を選択します。次に、価格に**15**を入力し、通貨として**\**を選択します。 1. **価格に税金を含める**かどうかを選択します。[税金設定](https://dashboard.stripe.com/test/settings/tax)のデフォルト値を使用するか、値を手動で設定できます。この例では、**自動**を選択します。 1. **請求期間**で**月次**を選択します。 1. **その他の料金体系オプション**をクリックします。次に、この例の料金体系モデルとして**定額**を選択します。[定額料金](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate)とその他の[料金体系モデル](https://docs.stripe.com/products-prices/pricing-models.md)の詳細をご確認ください。 1. 将来的に特定の価格を整理、クエリ、更新するために、内部**価格の説明**と[検索キー](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) 追加します。 1. **次へ**をクリックします。次に、**商品を追加**をクリックします。 商品と価格を作成したら、価格 ID を記録しておき、後続のステップで使用できるようにします。ID は料金体系ページで `price_G0FvDp6vZvdwRZ` のように表示されます。 ## Checkout セッションを作成する [サーバー側] Stripe Checkout を使用した将来の支払いに Cash App アカウントを使用することを、顧客が承認する必要があります。これにより、Cash App による決済を受け付けることができます。ウェブサイトにサーバー側のエンドポイントを呼び出す決済ボタンを追加して、[Checkout Session (セッション)](https://docs.stripe.com/api/checkout/sessions.md) を作成します。 ```html Checkout
``` `subscription` モードで Checkout セッションを作成して、必要な情報を収集します。Checkout セッションを作成したら、レスポンスで返された [URL](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-url) に顧客をリダイレクトします。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ --data-urlencode "success_url=https://example.com/success" \ -d "line_items[0][price]={{RECURRING_PRICE_ID}}" \ -d "line_items[0][quantity]=1" \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=cashapp" \ -d mode=subscription ``` ## 実装をテストする [サーバー側] #### モバイル版ウェブアプリの認証 決済手段として **Cash App Pay** を選択し **サブスクリプション** をタップします。テスト中はテストページにリダイレクトされ、そこで設定を承認または拒否できます。 本番環境では、**登録する** をタップすると、Cash App にリダイレクトされます。ベストプラクティスとして、顧客にリリースする前に、実際の Cash App アカウントを使用して本番環境でテストします。本番環境では、Cash App 内で設定を承認または拒否するオプションはありません。顧客が Cash App にリダイレクトされると、設定は自動的に承認されます。 #### デスクトップ版ウェブアプリの認証 テスト中に、モバイルデバイスの QR コードスキャンアプリケーションで QR コードをスキャンします。QR コードペイロードには、テスト支払いページにリダイレクトする URL が含まれています。テストのセットアップを承認または拒否できます。 本番環境では、Cash App モバイルアプリケーションで QR コードを読み取ります。ベストプラクティスとして、顧客にリリースする前に、実際の Cash App アカウントを使用して本番環境でテストします。本番環境では、Cash App 内で設定を承認または拒否するオプションはありません。QR コードを読み取ると自動的に承認されます。