# 将来の Cash App Pay による支払いを設定する Cash App Pay の詳細を保存し、後で顧客に請求する方法をご紹介します。 このガイドでは、Stripe 上のオンライン決済ページである [Checkout](https://docs.stripe.com/payments/checkout.md) を使用して、Cash App Pay の支払い情報を保存する方法を説明します。 Checkout で決済手段の保存後に継続支払いを作成するには、[Cash App Pay によるサブスクリプションを設定する](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md)をご覧ください。 ## 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' ``` ## 顧客を作成または取得する [サーバー側] Cash App Pay の決済手段を今後の決済で再利用するには、顧客を表すオブジェクトに関連付けます。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定済みの Account オブジェクトとしてモデル化する](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md)ことをお勧めします。 顧客がビジネスでアカウントを作成するとき、または決済手段を保存するときに、顧客設定の [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) または [Customer](https://docs.stripe.com/api/customers/create.md) を作成する。オブジェクトの ID を、顧客を表す独自の内部表現に関連付ける。 この決済に関連付ける新しい顧客を作成するか、既存の顧客を取得する。 #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## Checkout セッションを作成する [サーバー側] Stripe Checkout を使用した将来の支払いに Cash App アカウントを使用する許可を、顧客から得ることが必須です。これにより、Cash App 決済の受け付けが可能になります。サーバー側のエンドポイントを呼び出す決済ボタンをウェブサイトに追加して [Checkout セッション)](https://docs.stripe.com/api/checkout/sessions.md) を作成します。 ```html Checkout
``` `setup` モードで Checkout セッションを作成して、必要な情報を収集します。Checkout セッションを作成したら、レスポンスで返された [URL](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-url) に顧客をリダイレクトします。 #### Ruby ```ruby client.v1.checkout.sessions.create({ mode: 'setup',payment_method_types: ['card', 'cashapp'], customer: customer.id, success_url: 'https://example.com/success', }) ``` ## 実装をテストする [サーバー側] #### モバイル版ウェブアプリのテスト 実装内容をテストするには、決済手段として Cash App Pay を選択し、**支払う**をタップします。テスト時はテスト決済ページにリダイレクトされ、そこで決済を承認または拒否できます。 本番環境では、**支払う**をタップすると、Cash App モバイルアプリケーションにリダイレクトされます。Cash App 内で支払いを承認または拒否するオプションはありません。リダイレクトされた後、支払いは自動的に承認されます。 #### デスクトップ版ウェブアプリのテスト 実装をテストするには、モバイルデバイスの QR コードスキャンアプリケーションを使用して QR コードを読み取ります。テスト時は、QR コードのペイロードに URL が含まれ、テスト決済ページにリダイレクトされます。ここでテスト決済を承認または拒否できます。 本番環境では、QR コードをスキャンすると、Cash App モバイルアプリケーションにリダイレクトされます。Cash App 内で支払いを承認または拒否するオプションはありません。QR コードをスキャンすると、支払いは自動的に承認されます。 # ダイレクト API > This is a ダイレクト API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/cash-app-pay/set-up-payment?payment-ui=direct-api. [Setup Intents API](https://docs.stripe.com/payments/setup-intents.md) を使用して事前に決済手段の詳細を収集し、後から最終的な金額や支払い日を決定できます。次の場合に使用します。 - 支払い方法をウォレットに保存して、以降の購入を効率化する - サービスの提供後に追加料金を回収する - [サブスクリプションの無料トライアルを開始する](https://docs.stripe.com/billing/subscriptions/trials.md) 支払い方法の詳細を収集し、保存済みの支払い方法にすぐに請求するには、Payment Intents API を使用します。 Checkout で決済手段の保存後に継続支払いを作成するには、[Cash App Pay によるサブスクリプションを設定する](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md)をご覧ください。 ## 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' ``` ## 顧客を作成または取得する [サーバー側] Cash App Pay の決済手段を今後の決済のために保存するには、顧客を表すオブジェクトに関連付けます。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定済みの Account オブジェクトとしてモデル化する](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md)ことをお勧めします。 顧客がビジネスでアカウントを作成するとき、または決済手段を保存するときに、顧客設定の [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) または [Customer](https://docs.stripe.com/api/customers/create.md) を作成する。オブジェクトの ID を、顧客を表す独自の内部表現に関連付ける。 この決済に関連付ける新しい顧客を作成するか、既存の顧客を取得する。 #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## 決済フォームに許可に関する規約を提示する [クライアント側] 将来の*オフセッション* (A payment is described as off-session if it occurs without the direct involvement of the customer, using previously-collected payment information)の支払いに備え、顧客の Cash App Pay の認証情報 ([$Cashtag](https://cash.app/help/us/en-us/3123-cashtags)) を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 承認に関する条件は、顧客の $Cashtag を初めて保存するときにのみ表示する必要があります。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Cash App のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。これは、Cash App の設定でいつでも変更できます。 #### Setup Intents API を使用して支払い方法を保存する [Setup Intents API](https://docs.stripe.com/payments/setup-intents.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)の無料トライアルを開始する ## SetupIntent を作成して支払い方法を保存する [サーバー側] [SetupIntent](https://docs.stripe.com/api/setup_intents.md) は、将来の決済に向けて顧客の決済手段を設定するための意図を表すオブジェクトです。`SetupIntent` は、この設定プロセスの各ステップを追跡します。サーバーで `SetupIntent` を作成します。 - `cashapp` を [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) 配列に追加 - 顧客の ID を指定 - [usage](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) を `off_session` または `on_session` に設定 #### Accounts v2 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer={{CUSTOMER_ID}}" ``` ### client secret を取得する 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)) が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。 #### 1 ページのアプリケーション ブラウザーの `fetch` 関数を使用して、サーバーのエンドポイントから client secret を取得します。この方法は、クライアント側が 1 ページのアプリケーションで、特に React などの最新のフロントエンドフレームワークで構築されている場合に最適です。client secret を処理するサーバーのエンドポイントを作成します。 #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the SetupIntent {client_secret: intent.client_secret}.to_json end ``` その後、クライアント側で JavaScript を使用して client secret を取得します。 ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### サーバ側のレンダリング サーバーからクライアントに client secret を渡します。この方法は、アプリケーションがブラウザーへの送信前に静的なコンテンツをサーバーで生成する場合に最適です。 決済フォームに [client_secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret) を追加します。サーバー側のコードで、SetupIntent から client secret を取得します。 #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the SetupIntent erb :checkout end ``` 次に、[Stripe.js](https://docs.stripe.com/payments/elements.md) を使用してクライアントに Cash App Pay を保存します。 Stripe.js スクリプトを決済ページに含めるには、このスクリプトを HTML ファイルの `head` に追加します。 ```html Checkout ``` 決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。 ```javascript // Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe('<>'); ``` `stripe.confirmCashappSetup` を使用し、[return_url](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-return_url) とオプションの [mandate_data](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-mandate_data) を指定して、クライアント側で setupIntent を確定します。[return_url](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-return_url) を使用して、SetupIntent の成功後に顧客を特定のページにリダイレクトします。 ```javascript const form = document.getElementById('setup-form'); form.addEventListener('submit', function(event) { event.preventDefault(); // Set the clientSecret here stripe.confirmCashappSetup( clientSecret, { payment_method: { type: 'cashapp', }, return_url: 'https://www.example.com/checkout/done', }, ); }); ``` 顧客は、モバイルアプリまたはデスクトップアプリで Cash App Pay を認証することができます。`confirmCashappSetup` を呼び出した後、顧客が使用するクライアントは、モバイルの場合はリダイレクト、デスクトップの場合は QR コードなど、認証方法を決定します。認証のレスポンスには、次のステップで PaymentIntent を作成するために使用する必要がある支払い方法 ID も含まれています。 #### モバイルアプリケーションの認証 `confirmCashappSetup` を呼び出した後、Stripe は、顧客をオーソリのために Cash App にリダイレクトします。支払いがオーソリされた後、Stripe は顧客を Setup Intent の `return_url` に送ります。Stripe は、URL クエリパラメーターとして `setup_intent`、`setup_intent_client_secret`、`redirect_pm_type`、`redirect_status` のほか、既存のクエリパラメーターを `return_url` に追加します。 認証セッションは 10 分後に期限切れになり、SetupIntent のステータスは `require_payment_method` に戻ります。ステータスが移行すると、顧客にはオーソリエラーが表示され、プロセスをもう一度開始する必要があります。 #### デスクトップ版ウェブアプリの認証 `confirmCashappSetup` を呼び出すと、QR コードがウェブページに表示されます。顧客は、モバイルデバイスのカメラまたは Cash App モバイルアプリケーションを使用して QR コードをスキャンし、認証セッションを終了することができます。認証が成功してから数秒後に、QR コードのモーダルは自動的に閉じられます。 認証セッションは 10 分後に期限切れになります。SetupIntent のステータスが `require_payment_method` に戻る前に、最大 20 回まで QR コードを更新できます。ステータスの移行後、顧客にはオーソリエラーが表示され、顧客はプロセスをもう一度開始する必要があります。 ## Optional: リダイレクトと認証を手動で処理する `confirmCashappSetup` でリダイレクトと認証を処理するには、Stripe.js を利用することをお勧めします。ただし、自社のサーバーでリダイレクトと認証を手動で処理することもできます。 `confirmCashappSetup` コールで `handleActions: false` を指定します。 ```javascript const form = document.getElementById('payment-form'); form.addEventListener('submit', function(event) { event.preventDefault(); // Set the clientSecret here you got in Step 2 stripe.confirmCashappSetup( clientSecret, { payment_method: { type: 'cashapp', }, return_url: 'https://www.example.com/checkout/done', }, { handleActions: false }, ).then((result) => { if (result.error) { // Display error to your customer. } else if (result.paymentIntent.status === "requires_action") { const nextAction = result.setupIntent.next_action.cashapp_handle_redirect_or_display_qr_code; const expiresAt = nextAction.qr_code.expires_at; if (IS_MOBILE) { // This URL redirects the customer to Cash App to approve or decline the payment. const mobileAuthUrl = nextAction.mobile_auth_url; } else if (IS_DESKTOP) { // Render the QR code and display it to the customer using the below image source. const imageUrlSvg = nextAction.qr_code.image_url_svg; const imageUrlPng = nextAction.qr_code.image_url_png; } } }); }); ``` SetupIntent のレスポンスには、ステータス `requires_action` が含まれます。このため、ユーザーは支払い方法の保存を完了するために別のアクションを実行する必要があります。 #### モバイルアプリケーションの認証 顧客が Cash App Pay 決済をモバイルデバイスに保存している場合: 1. 顧客を、SetupIntent のレスポンスに含まれる `next_action.cashapp_handle_redirect_or_display_qr_code.mobile_auth_url` プロパティで指定された URL にリダイレクトしてください。これにより顧客は Cash App に移動し、認証セッションを完了できます。 1. `mobile_auth_url` は 30 秒後に有効期限が切れます。有効期限までに顧客が `mobile_auth_url` にリダイレクトされない場合は、[stripe.retrieveSetupIntent](https://docs.stripe.com/js/setup_intents/retrieve_setup_intent) を呼び出して新しい `mobile_auth_url` を取得します。 #### デスクトップ版ウェブアプリの認証 顧客が Cash App Pay 決済をデスクトップウェブアプリに保存している場合: 1. 顧客を、SetupIntent のレスポンスに含まれる `next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url` プロパティで指定された URL にリダイレクトしてください。 1. 顧客はモバイルデバイスのカメラまたは Cash App モバイルアプリを使用してこのページに表示される QR コードをスキャンし、認証セッションを終了します。 アプリ内認証が成功すると、Cash Appはチェックアウトを完了するために、リクエストで指定した `return_url` に顧客をリダイレクトします。同時に SetupIntent は自動的に `succeeded` ステータスに移行します。SetupIntent のレスポンスには、将来の PaymentIntent で再利用可能な支払い方法 ID も含まれています。 #### Payment Intents API を使用して支払い方法を保存する [Payment Intents API](https://docs.stripe.com/payments/payment-intents.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)の無料トライアルを開始する ## PaymentIntent を作成して支払い方法を保存する [サーバー側] [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) は、顧客に請求する意図を表すオブジェクトです。`PaymentIntent` リクエストで保存済み決済手段を指定しない場合、新しい決済手段が作成され、`PaymentIntent` の確定前に顧客に関連付けられます。 お使いのサーバーで `PaymentIntent` を作成します。 - `cashapp` を [payment_method_types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types) 配列に追加 - 顧客に設定された `Account` または `Customer` の ID を指定します - `confirm` を true に設定します - [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) を `off_session` または `on_session` に設定します - [return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) には、`PaymentIntent` が成功した後に顧客を戻すページの URL を設定します - 同意書を作成する必要がある場合は、 [mandate_data](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-mandate_data) を設定します #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=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" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d setup_future_usage=off_session \ -d amount=1000 \ -d currency=usd \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=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" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "customer={{CUSTOMER_ID}}" \ -d setup_future_usage=off_session \ -d amount=1000 \ -d currency=usd \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true ``` 返される PaymentIntent には *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)) が含まれています。これを使用することでクライアント側は、PaymentIntent オブジェクト全体を渡すことなく安全に決済プロセスを完了できます。クライアント側のアプリケーションに client secret を渡して、決済プロセスを続行します。 PaymentIntent のレスポンスには `requires_action` ステータスが含まれます。これは、ユーザーに対して、PaymentIntent を完了するために別のアクションを実行するよう要求するものです。同じ PaymentIntent レスポンスの `next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url` オブジェクトを使用して、Cash App モバイルアプリケーションを開いて認証セッションを終了するためのページに顧客をリダイレクトします。アプリ内の認証が成功した後、Cash App は、リクエストで設定された `return_url` に顧客をリダイレクトし、決済が確定され、PaymentIntent は自動的に `succeeded` 状態に移行します。PaymentIntent レスポンスには、今後の PaymentIntents で再利用できる支払い方法 ID も含まれています。 ## 保存された支払い方法を使用して PaymentIntent を作成する [サーバー側] [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) を作成した後、[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) を作成して確定することで、将来の Cash App Pay による決済を受け付けることができます。`PaymentIntent` の確定時には、作成した `PaymentMethod` の ID を使用してください。顧客がこの `PaymentIntent` の決済フローにいない場合は、`off_session` の値も true に設定する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method={{PAYMENTMETHOD_ID}}" \ -d amount=1000 \ -d currency=usd \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=usd \ -d "customer={{CUSTOMER_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の取り消しを処理する 再使用可能な決済手段を取り消すには、以下の 2 つの方法があります。 - 顧客は、Cash App モバイルアプリで再利用可能な決済手段を無効にすることができます。この場合、Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントを送信します。[Webhook](https://docs.stripe.com/webhooks.md) イベントに登録し、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化します。 - 顧客は、再利用可能な決済手段に対応している場合、UI で無効にすることもできます。この場合、サーバーは [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化することができます。 いずれのケースでも、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出した後、[payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントが送信されます。 # iOS > This is a iOS for when payment-ui is mobile and platform is ios. View the full page at https://docs.stripe.com/payments/cash-app-pay/set-up-payment?payment-ui=mobile&platform=ios. [Setup Intents API](https://docs.stripe.com/payments/setup-intents.md) を使用して事前に決済手段の詳細を収集し、後から最終的な金額や支払い日を決定できます。次の場合に使用します。 - 支払い方法をウォレットに保存して、以降の購入を効率化する - サービスの提供後に追加料金を回収する - [サブスクリプションの無料トライアルを開始する](https://docs.stripe.com/billing/subscriptions/trials.md) このガイドでは、最初に Setup Intents API を使用して支払い方法の詳細を保存し、Payment Intents API を使用して保存した支払い方法に後で請求する方法を説明します。 ## Stripe を設定する [サーバ側] [クライアント側] まず、Stripe アカウントが必要です。[今すぐ登録](https://dashboard.stripe.com/register)してください。 ### サーバ側 この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから 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' ``` ### クライアント側 [Stripe iOS SDK](https://github.com/stripe/stripe-ios) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-ios/index.html)、iOS 13 以降をサポートするアプリと互換性があります。 #### Swift Package Manager SDK をインストールするには、以下のステップに従います。 1. Xcode で、**File (ファイル)** > **Add Package Dependencies… (パッケージ依存関係を追加)** を選択し、リポジトリー URL として `https://github.com/stripe/stripe-ios-spm` を入力します。 1. [リリースページ](https://github.com/stripe/stripe-ios/releases)から最新のバージョン番号を選択します。 1. **StripePaymentsUI** 製品を[アプリのターゲット](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)に追加します。 #### CocoaPods 1. まだインストールしていない場合は、[CocoaPods](https://guides.cocoapods.org/using/getting-started.html) の最新バージョンをインストールします。 1. 既存の [Podfile](https://guides.cocoapods.org/syntax/podfile.html) がない場合は、以下のコマンドを実行して作成します。 ```bash pod init ``` 1. この行を `Podfile` に追加します。 ```podfile pod 'StripePaymentsUI' ``` 1. 以下のコマンドを実行します。 ```bash pod install ``` 1. これ以降は、Xcode でプロジェクトを開く際に、`.xcodeproj` ファイルではなく、必ず `.xcworkspace` ファイルを使用するということを忘れないでください。 1. 今後、SDK の最新バージョンに更新するには、以下を実行します。 ```bash pod update StripePaymentsUI ``` #### Carthage 1. まだインストールしていない場合は、[Carthage](https://github.com/Carthage/Carthage#installing-carthage) の最新バージョンをインストールします。 1. この行を `Cartfile` に追加します。 ```cartfile github "stripe/stripe-ios" ``` 1. [Carthage のインストール手順](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)に従います。必ず、[こちら](https://github.com/stripe/stripe-ios/tree/master/StripePaymentsUI/README.md#manual-linking)にリストされている必要なフレームワークのすべてを埋め込んでください。 1. 今後、SDK の最新バージョンに更新するには、以下のコマンドを実行します。 ```bash carthage update stripe-ios --platform ios ``` #### 手動のフレームワーク 1. Stripe の [GitHub リリースページ](https://github.com/stripe/stripe-ios/releases/latest)に移動して、**Stripe.xcframework.zip** をダウンロードして解凍します。 1. **StripePaymentsUI.xcframework** を、Xcode プロジェクトの **General (一般) ** 設定の **Embedded Binaries (埋め込みバイナリー)** セクションにドラッグします。**Copy items if needed (必要に応じてアイテムをコピーする)** を必ず選択してください。 1. [こちら](https://github.com/stripe/stripe-ios/tree/master/StripePaymentsUI/README.md#manual-linking)にリストされている必要なフレームワークのすべてに対して、ステップ 2 を繰り返します。 1. 今後、Stripe の SDK の最新バージョンに更新するには、ステップ 1 から 3 を繰り返します。 > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases (リリース)](https://github.com/stripe/stripe-ios/releases) ページをご覧ください。リポジトリの[リリースをウォッチ](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)して、新しいリリースの公開時に通知を受け取ることも可能です。 アプリの起動時に Stripe [公開可能キー](https://dashboard.stripe.com/test/apikeys)を使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。 #### Swift ```swift import UIKitimportStripePaymentsUI @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {StripeAPI.defaultPublishableKey = "<>" // do any other necessary launch configuration return true } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 ## 顧客を作成または取得する [サーバー側] Cash App Pay の決済手段を今後の決済のために保存するには、顧客を表すオブジェクトに関連付けます。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定済みの Account オブジェクトとしてモデル化する](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md)ことをお勧めします。 顧客がビジネスでアカウントを作成するとき、または決済手段を保存するときに、顧客設定の [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) または [Customer](https://docs.stripe.com/api/customers/create.md) を作成する。オブジェクトの ID を、顧客を表す独自の内部表現に関連付ける。 この決済に関連付ける新しい顧客を作成するか、既存の顧客を取得する。 #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## SetupIntent を作成する [サーバー側] [SetupIntent](https://docs.stripe.com/api/setup_intents.md) は、将来の決済に向けて顧客の決済手段を設定する意図を表すオブジェクトです。`SetupIntent` は、この設定プロセスの各ステップを追跡します。 `SetupIntent` をサーバーで作成します。 - `cashapp` を [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) 配列に追加 - 顧客の ID を指定 - [usage](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) を `off_session` または `on_session` に設定 #### Accounts v2 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer={{CUSTOMER_ID}}" ``` ## 決済フォームに承認に関する条件を提示する [クライアント側] 将来の*オフセッション* (A payment is described as off-session if it occurs without the direct involvement of the customer, using previously-collected payment information)の支払いに備え、顧客の Cash App Pay の認証情報 ([$Cashtag](https://cash.app/help/us/en-us/3123-cashtags)) を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 承認に関する条件は、顧客の $Cashtag を初めて保存するときにのみ表示する必要があります。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Cash App のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。これは、Cash App の設定でいつでも変更できます。 ## 支払い方法の詳細を収集する [クライアント側] #### Swift ```swift // Cash App Pay does not require additional parameters so we only need to pass the initialized // STPPaymentMethodCashAppParams instance to STPPaymentMethodParams let cashApp = STPPaymentMethodCashAppParams() let paymentMethodParams = STPPaymentMethodParams(cashApp: cashApp, billingDetails: nil, metadata: nil) ``` ## Stripe に支払いを送信する [クライアント側] 作成した SetupIntent から client secret を取得し、[STPPaymentHandler confirmSetupIntent](https://stripe.dev/stripe-ios/stripe-payments/Classes/STPPaymentHandler.html#/c:objc\(cs\)STPPaymentHandler\(im\)confirmSetupIntent:withAuthenticationContext:completion:) を呼び出します。これにより WebView が表示され、顧客はそこから Cash App で支払いを完了できます。その後、支払い結果とともに、完了ブロックが呼び出されます。 #### Swift ```swift let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: setupIntentClientSecret) setupIntentParams.paymentMethodParams = paymentMethodParams setupIntentParams.returnURL = "payments-example://stripe-redirect" STPPaymentHandler.shared().confirmSetupIntent(withParams: setupIntentParams, authenticationContext: self) { (handlerStatus, setupIntent, error) in switch handlerStatus { case .succeeded: // Setup succeeded case .canceled: // Setup was canceled case .failed: // Setup failed @unknown default: fatalError() } } ``` ## 保存された支払い方法を使用して PaymentIntent を作成する [サーバー側] [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) を作成した後、[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) を作成して確定することで、将来の Cash App Pay による決済を受け付けることができます。`PaymentIntent` の確定時には、作成した `PaymentMethod` の ID を使用してください。顧客がこの `PaymentIntent` の決済フローにいない場合は、`off_session` の値も true に設定する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method={{PAYMENTMETHOD_ID}}" \ -d amount=1000 \ -d currency=usd \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method={{PAYMENTMETHOD_ID}}" \ -d amount=1000 \ -d currency=usd \ -d "customer={{CUSTOMER_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の取り消しを処理する 再使用可能な決済手段を取り消すには、以下の 2 つの方法があります。 - 顧客は、Cash App モバイルアプリで再利用可能な決済手段を無効にすることができます。この場合、Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントを送信します。[Webhook](https://docs.stripe.com/webhooks.md) イベントに登録し、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化します。 - 顧客は、再利用可能な決済手段に対応している場合、UI で無効にすることもできます。この場合、サーバーは [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化することができます。 いずれのケースでも、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出した後、[payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントが送信されます。 # Android > This is a Android for when payment-ui is mobile and platform is android. View the full page at https://docs.stripe.com/payments/cash-app-pay/set-up-payment?payment-ui=mobile&platform=android. Available in: US [Setup Intents API](https://docs.stripe.com/payments/setup-intents.md) または [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用して、今後の支払いのために Cash App Pay の詳細を保存できます。 ## Stripe を設定する [サーバ側] [クライアント側] まず、Stripe アカウントが必要です。[今すぐ登録](https://dashboard.stripe.com/register)してください。 ### サーバ側 この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから 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' ``` ### クライアント側 [Stripe Android SDK](https://github.com/stripe/stripe-android) はオープンソースであり、[詳細なドキュメントが提供されています](https://stripe.dev/stripe-android/)。 SDK をインストールするには、[app/build.gradle](https://developer.android.com/studio/build/dependencies) ファイルの `dependencies` ブロックに `stripe-android` を追加します。 #### Kotlin ```kotlin plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Android SDK implementation("com.stripe:stripe-android:23.8.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:23.8.0") } ``` > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases](https://github.com/stripe/stripe-android/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリのリリースを確認](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/configuring-notifications#configuring-your-watch-settings-for-an-individual-repository)してください。 Stripe の[公開可能キー](https://dashboard.stripe.com/apikeys)を使用して SDK を設定し、 `Application` サブクラスなどで、Stripe API へのリクエストを実行できるようにします。 #### Kotlin ```kotlin import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext, "<>" ) } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 Stripe サンプルでは、サーバへの HTTP リクエストの作成に、[OkHttp](https://github.com/square/okhttp) および [GSON](https://github.com/google/gson) も使用します。 ## 顧客を作成または取得する [サーバー側] Cash App Pay の決済手段を今後の決済のために保存するには、顧客を表すオブジェクトに関連付けます。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定済みの Account オブジェクトとしてモデル化する](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md)ことをお勧めします。 顧客がビジネスでアカウントを作成するとき、または決済手段を保存するときに、顧客設定の [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) または [Customer](https://docs.stripe.com/api/customers/create.md) を作成する。オブジェクトの ID を、顧客を表す独自の内部表現に関連付ける。 この決済に関連付ける新しい顧客を作成するか、既存の顧客を取得する。 #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## SetupIntent を作成する [サーバー側] [SetupIntent](https://docs.stripe.com/api/setup_intents.md) は、将来の決済に向けて顧客の決済手段を設定するための意図を表すオブジェクトです。`SetupIntent` は、この設定プロセスの各ステップを追跡します。サーバーで `SetupIntent` を作成します。 - `cashapp` を [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) 配列に追加 - 顧客の ID を指定 - [usage](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) を `off_session` または `on_session` に設定 #### Accounts v2 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method_data[type]=cashapp" \ -d usage=off_session \ -d "customer={{CUSTOMER_ID}}" ``` ## 決済フォームに承認に関する条件を提示する [クライアント側] 将来の*オフセッション* (A payment is described as off-session if it occurs without the direct involvement of the customer, using previously-collected payment information)の支払いに備え、顧客の Cash App Pay の認証情報 ([$Cashtag](https://cash.app/help/us/en-us/3123-cashtags)) を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 承認に関する条件は、顧客の $Cashtag を初めて保存するときにのみ表示する必要があります。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Cash App のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。これは、Cash App の設定でいつでも変更することができます。 ## Stripe に支払い方法の詳細を送信する [クライアント側] 作成した SetupIntent から client secret を取得し、[PaymentLauncher confirm](https://stripe.dev/stripe-android/payments-core/com.stripe.android.payments.paymentlauncher/-payment-launcher/confirm.html) を呼び出します。これにより、WebView が表示され、顧客はここで Cash App Pay の設定を完了できます。完了すると、支払い結果とともに、指定された `PaymentResultCallback` が呼び出されます。 #### Kotlin ```kotlin class CashAppPaySetupActivity : AppCompatActivity() { // ... private val paymentLauncher: PaymentLauncher by lazy { val paymentConfiguration = PaymentConfiguration.getInstance(applicationContext) PaymentLauncher.create( activity = this, publishableKey = paymentConfiguration.publishableKey, stripeAccountId = paymentConfiguration.stripeAccountId, callback = ::onPaymentResult, ) } override fun onCreate(savedInstanceState: Bundle?) { // … startCheckout() } private fun startCheckout() { // Create a SetupIntent on your backend and return the client_secret here val setupIntentClientSecret = // … val cashAppPayParams = PaymentMethodCreateParams.createCashAppPay() val confirmParams = ConfirmSetupIntentParams.create( paymentMethodCreateParams = cashAppPayParams, clientSecret = setupIntentClientSecret, // Add a mandate ID or MandateDataParams… ) paymentLauncher.confirm(confirmParams) } private fun onPaymentResult(paymentResult: PaymentResult) { // Handle the setup result… } } ``` ## 保存された支払い方法を使用して PaymentIntent を作成する [サーバー側] [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) を作成した後、[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) を作成して確定することで、将来の Cash App Pay による決済を受け付けることができます。`PaymentIntent` の確定時には、作成した `PaymentMethod` の ID を使用してください。顧客がこの `PaymentIntent` の決済フローにいない場合は、`off_session` の値も true に設定する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d "payment_method={{PAYMENTMETHOD_ID}}" \ -d amount=1000 \ -d currency=usd \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=cashapp" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=usd \ -d "customer={{CUSTOMER_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の取り消しを処理する 再使用可能な決済手段を取り消すには、以下の 2 つの方法があります。 - 顧客は、Cash App モバイルアプリで再利用可能な決済手段を無効にすることができます。この場合、Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントを送信します。[Webhook](https://docs.stripe.com/webhooks.md) イベントに登録し、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化します。 - 顧客は、再利用可能な決済手段に対応している場合、UI で無効にすることもできます。この場合、サーバーは [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出して無効化することができます。 いずれのケースでも、[detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) を呼び出した後、[payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントが送信されます。