# 将来の Revolut Pay による支払いを設定する Revolut Pay の詳細を保存し、後で顧客に請求する方法をご紹介します。 # Checkout > This is a Checkout for when payment-ui is checkout. View the full page at https://docs.stripe.com/payments/revolut-pay/set-up-future-payments?payment-ui=checkout. このガイドでは、Stripe 上のオンライン決済ページである [Checkout](https://docs.stripe.com/payments/checkout.md) を使用して、Revolut Pay の支払い情報を保存する方法を説明します。 [Revolut Pay で支払うサブスクリプションを設定](https://docs.stripe.com/billing/subscriptions/revolut-pay.md)し、Checkout で決済手段を保存した後に継続支払いを作成する方法をご紹介します。 ## 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' ``` ## 支払い方法を保存する許可を得る [サーバー側] 将来の使用に備えて顧客の支払い方法を保存する場合は、顧客の許可を得る必要があります。あらかじめ契約 (同意書とも呼ばれます) を作成しておくことで、顧客の支払い情報を保存し、顧客がウェブサイトやアプリを能動的に使用していないときでも請求できるようになります。 顧客の支払い方法の保存をどのように計画しているかを示す規約をウェブサイトやアプリに追加し、顧客が承認できるようにします。顧客がオフラインのときに請求する予定である場合は、規約に以下の内容も含める必要があります。 - 指定された取引で顧客の代理として単独の支払いまたは一連の支払いを開始することを許可する、顧客からお客様への許可 - 予測される支払い頻度 (1 回限り、継続支払い) とタイミング - 支払い金額の決定方法 - サブスクリプションサービスに使用される支払い方法を設定する場合は、キャンセルに関するポリシー これらの条件に関する顧客の書面による同意の記録を必ず保管してください。 ## Customer を作成または取得する [サーバー側] 今後の支払いで Revolut Pay 支払い方法を再利用できるようにするには、これを *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) に関連付けます。 顧客がアカウントを作成するときに、[Customer オブジェクト](https://docs.stripe.com/api/customers.md)を作成して、この Customer オブジェクトの ID を貴社独自の内部表記と関連付けてください。あるいは、将来の支払いに備えて決済手段を保存する前に、新しい Customer を作成することもできます。 新しい Customer を作成するか、または既存の Customer を取得して、この決済に関連付けます。サーバーに以下のコードを含め、新しい Customer を作成します。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "description=My First Test Customer (created for API docs)" ``` ## Checkout セッションを作成する [サーバー側] Stripe Checkout での将来の支払いに Revolut アカウントを使用する許可を顧客から得る必要があります。これにより、Revolut 決済の受け付けが可能になります。サーバー側のエンドポイントを呼び出す決済ボタンをウェブサイトに追加して [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 Stripe::Checkout::Session.create({ mode: 'setup',payment_method_types: ['card', 'revolut_pay'], customer: customer.id, success_url: 'https://example.com/success', }) ``` ## 実装をテストする 支払い方法として Revolut Pay を選択してから、**Continue to Revolut Pay (Revolut Pay に進む)** をクリックします。リダイレクトページで SetupIntent を認証することで、設定の成功ケースをテストできます。SetupIntent のステータスが requires_action から succeeded に移行します。 # ダイレクト API > This is a ダイレクト API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/revolut-pay/set-up-future-payments?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](https://docs.stripe.com/payments/payment-intents.md) を使用します。 オンセッションの Revolut 決済では、決済フローをアクティブに実行している場合、保存された決済手段を使用している場合でも、確定のために Revolut アプリにリダイレクトされます。 [Revolut Pay で支払うサブスクリプションを設定](https://docs.stripe.com/billing/subscriptions/revolut-pay.md)し、Checkout で決済手段を保存した後に継続支払いを作成する方法をご紹介します。 ## 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' ``` ## 支払い方法を保存する許可を得る [サーバー側] 将来の使用に備えて顧客の支払い方法を保存する場合は、顧客の許可を得る必要があります。あらかじめ契約 (同意書とも呼ばれます) を作成しておくことで、顧客の支払い情報を保存し、顧客がウェブサイトやアプリを能動的に使用していないときでも請求できるようになります。 顧客の支払い方法の保存をどのように計画しているかを示す規約をウェブサイトやアプリに追加し、顧客が許可できるようにします。顧客がオフラインのときに請求する予定である場合は、規約に以下の内容も含める必要があります。 - 指定された取引で顧客の代理として単独の支払いまたは一連の支払いを開始することを許可する、顧客からお客様への許可 - 予測される支払い頻度 (1 回限り、継続支払い) とタイミング - 支払い金額の決定方法 - サブスクリプションサービスに使用される支払い方法を設定する場合は、キャンセルに関するポリシー これらの規約に関する顧客の書面による同意の記録を必ず保管してください。 ## Customer を作成または取得する [サーバー側] 今後の支払いに備えて Revolut Pay 支払い方法を保存するには、これを *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) に関連付けます。 ビジネスで顧客がアカウントを作成した後に Customer オブジェクトを作成します。Customer オブジェクトの ID を独自の内部的な顧客の表記に関連付けることにより、後から保存済みの支払い方法情報を取得して使用できます。顧客がアカウントを作成していない場合でも Customer オブジェクトを作成して、後で顧客のアカウントの内部表記に関連付けることができます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "description=My First Test Customer (created for API docs)" ``` ## 決済フォームに許可に関する規約を提示する [クライアント側] 将来の*オフセッション* (A payment is described as off-session if it occurs without the direct involvement of the customer, using previously-collected payment information)の支払いに備え、顧客の Revolut Pay の認証情報を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 許可を表示する必要があるのは、顧客の Revolut Pay の認証情報を保存した後の初めての機会のみです。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行することで、この許可が取り消されるまで、Rocket Rides の規約に従って、お客様の今回の支払いおよび今後の支払いをお客様の Revolut Pay アカウントから引き落とすことを Rocket Rides に許可したとみなされます。 #### 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 は、この設定プロセスの手順を追跡します。[payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) を `revolut_pay` に設定してサーバーで SetupIntent を作成し、Customer の ID と [usage=off_session](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) または `usage=on_session` を指定します。 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -d "payment_method_data[type]=revolut_pay" \ -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) を使用してクライアントに Revolut 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.confirmRevolutPaySetup` を使用し、[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 // Redirects away from the client const {error} = await stripe.confirmRevolutPaySetup( '{{SETUP_INTENT_CLIENT_SECRET}}', { return_url: 'https://example.com/setup/complete', mandate_data: { customer_acceptance: { type: 'online', online: { infer_from_client: true } } }, } ); if (error) { // Inform the customer that there was an error. } ``` ## Optional: Revolut Pay のリダイレクトを手動で処理する Stripe.js を使用すると、実装を他の支払い方法に拡張することができます。ただし、お客様のサーバーに顧客を手動でリダイレクトすることもできます。 1. タイプが `revolut_pay` の PaymentIntent を作成し*確定* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)します。`payment_method_data` を指定すると、PaymentMethod が作成され、PaymentIntent ですぐに使用されます。 また、顧客が支払いを完了した後にリダイレクトされる先の URL を `return_url` フィールドに指定する必要があります。独自のクエリパラメータをこの URL に指定することもできます。これらのパラメータは、リダイレクトフロー完了時の最終的な URL に含められます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1000 \ -d currency=gbp \ -d "payment_method_types[]=revolut_pay" \ -d "payment_method_data[type]=revolut_pay" \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d confirm=true ``` 1. `PaymentIntent` のステータスが `requires_action` であることと、`next_action` のタイプが `redirect_to_url` であることを確認します。 #### Json ```json {"status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", ... } ``` 1. `next_action.redirect_to_url.url` プロパティで指定された URL に顧客をリダイレクトします。ここでのコード例はおおまかなものであり、リダイレクト方法は、お客様のウェブフレームワークによって異なることがあります。 #### Ruby ```ruby if payment_intent.status == 'requires_action' && payment_intent.next_action.type == 'redirect_to_url' url = payment_intent.next_action.redirect_to_url.url redirect(url) end ``` 支払いプロセスが完了すると、顧客は `return_url` にリダイレクトされます。`payment_intent` および `payment_intent_client_secret` URL クエリパラメーターは、お客様独自のクエリパラメーターと併せて含まれています。支払いのステータスをプログラムで確認するために、[Webhook エンドポイント](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks)を設定することをお勧めします。 #### 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 リクエストで保存された決済手段を提供しない場合、Stripe は PaymentIntent を確定する前に、新しい決済手段を作成して顧客に関連付けます。サーバーで [payment_method_types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types) を `revolut_pay` に設定して PaymentIntent を作成し、Customer の ID `confirm=true`、[return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) を使用する [setup_future_usage=off_session](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage)、オプションの [mandate_data](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-mandate_data) を指定します。[return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) を使用して、PaymentIntent の成功後に顧客を特定のページにリダイレクトします。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -d "payment_method_data[type]=revolut_pay" \ -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=gbp \ -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 を作成する [サーバー側] [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) を作成した後、[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) を作成して確定すると、それ以降の Revolut Pay による決済を受け付けられるようになります。PaymentIntent を確定する際は、以前の SetupIntent オブジェクトまたは PaymentIntent オブジェクトと同じ決済手段 ID を使用します。顧客がこの PaymentIntent の決済フロー内にいない場合は、`off_session` 値も true に設定する必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=gbp \ -d customer={{CUSTOMER_ID}} \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の関連付けを解除する 再利用可能な決済手段を無効にするには、お使いのサーバーから [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) エンドポイントを呼び出します。Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントと [payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントの両方を送信します。[Webhook](https://docs.stripe.com/webhooks.md) イベントに登録して、通知を受け取ることができます。 # 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/revolut-pay/set-up-future-payments?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 を使用して保存した支払い方法に後で請求する方法を説明します。 オンセッションの Revolut 決済では、決済フローをアクティブに実行している場合、保存された決済手段を使用している場合でも、確定のために Revolut アプリにリダイレクトされます。 ## 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)キーを使用します。 ## Customer を作成または取得する [サーバー側] 今後の支払いに備えて Revolut Pay の支払い方法を保存するには、これを *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) に関連付ける必要があります。 顧客がビジネスでアカウントを作成する際に、Customer オブジェクトを作成します。この Customer オブジェクトの ID を、顧客を表す自社の内部表記と関連付けます。あるいは、将来の支払いに備えて支払い方法を保存する前に、Customer オブジェクトを作成することもできます。 新しい Customer を作成するには、サーバー側で以下のコードを含めます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "description=My First Test Customer (created for API docs)" ``` ## SetupIntent を作成する [サーバー側] [SetupIntent](https://docs.stripe.com/api/setup_intents.md) は、将来の支払いに備えて顧客の決済手段を設定する意図を示すオブジェクトです。SetupIntent は、この設定プロセスの手順を追跡します。[payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) を `revolut_pay` に設定してサーバーで SetupIntent を作成し、Customer の ID と [usage=off_session](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) または `usage=on_session` を指定します。 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -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)の支払いに備え、顧客の Revolut Pay の認証情報を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 許可を表示する必要があるのは、顧客の Revolut Pay の認証情報を初めて保存した後のみです。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Revolut Pay のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。 ## 支払い方法の詳細を収集する [クライアント側] #### Swift ```swift // Revolut Pay does not require additional parameters so we only need to pass the initialized // STPPaymentMethodRevolotPayParams instance to STPPaymentMethodParams let revolutPay = STPPaymentMethodRevolutPayParams() let paymentMethodParams = STPPaymentMethodParams(revolutPay: revolutPay, 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 が表示され、顧客はそこから Revolut Pay で支払いを完了できます。その後、支払い結果とともに、完了ブロックが呼び出されます。 #### 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) を作成して確定すると、それ以降の Revolut Pay による決済を受け付けられるようになります。PaymentIntent を確定する際は、以前の SetupIntent オブジェクトまたは PaymentIntent オブジェクトと同じ決済手段 ID を使用します。顧客がこの PaymentIntent の決済フロー内にいない場合は、`off_session` 値も true に設定する必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=gbp \ -d customer={{CUSTOMER_ID}} \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の取り消しを処理する 再利用可能な決済手段を無効にするには、お使いのサーバーから [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) エンドポイントを呼び出します。Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントと [payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントの両方を送信します。[Webhook イベント](https://docs.stripe.com/webhooks.md)に登録して、通知を受け取ることができます。 # 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/revolut-pay/set-up-future-payments?payment-ui=mobile&platform=android. [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 を使用して保存した支払い方法に後で請求する方法を説明します。 オンセッションの Revolut 決済では、決済フローをアクティブに実行している場合、保存された決済手段を使用している場合でも、確定のために Revolut アプリにリダイレクトされます。 ## 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.1.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:23.1.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) も使用します。 ## Customer を作成または取得する [サーバー側] 今後の支払いに備えて Revolut Pay の支払い方法を保存するには、これを *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) に関連付ける必要があります。 顧客がビジネスでアカウントを作成する際に、Customer オブジェクトを作成します。この Customer オブジェクトの ID を、顧客を表す自社の内部表記と関連付けます。あるいは、将来の支払いに備えて支払い方法を保存する前に、Customer オブジェクトを作成することもできます。 新しい Customer を作成するには、サーバー側で以下のコードを含めます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "description=My First Test Customer (created for API docs)" ``` ## SetupIntent を作成する [サーバー側] [SetupIntent](https://docs.stripe.com/api/setup_intents.md) は、将来の支払いに備えて顧客の決済手段を設定する意図を示すオブジェクトです。SetupIntent は、この設定プロセスの手順を追跡します。[payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) を `revolut_pay` に設定してサーバーで SetupIntent を作成し、Customer の ID と [usage=off_session](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) または `usage=on_session` を指定します。 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -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)の支払いに備え、顧客の Revolut Pay の認証情報を保存してアカウントに請求できるようにします。[PaymentIntent](https://docs.stripe.com/api/payment_intents.md) や [SetupIntent](https://docs.stripe.com/api/setup_intents.md) を確定する前に、カスタムの決済フォームに書面による承認の通知を表示する必要があります。 許可を表示する必要があるのは、顧客の Revolut Pay の認証情報を初めて保存した後のみです。 カスタムの決済フォームでは以下のテキストを使用することをお勧めします。 > 続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Revolut Pay のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。 ## Stripe に支払い方法の詳細を送信する [クライアント側] 作成した SetupIntent から client secret を取得し、[PaymentLauncher confirm](https://stripe.dev/stripe-android/payments-core/com.stripe.android.payments.paymentlauncher/-payment-launcher/confirm.html) を呼び出します。これにより WebView が表示され、顧客はそこから Revolut Pay の設定を完了できます。完了すると、支払い結果とともに、指定された `PaymentResultCallback` が呼び出されます。 #### Kotlin ```kotlin class RevolutPaySetupActivity : 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 revolutPayParams = PaymentMethodCreateParams.createRevolutPay() val confirmParams = ConfirmSetupIntentParams.create( paymentMethodCreateParams = revolutPayParams, 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) を作成して確定すると、それ以降の Revolut Pay による決済を受け付けられるようになります。PaymentIntent を確定する際は、以前の SetupIntent オブジェクトまたは PaymentIntent オブジェクトと同じ決済手段 ID を使用します。顧客がこの PaymentIntent の決済フロー内にいない場合は、`off_session` 値も true に設定する必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=revolut_pay" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=gbp \ -d customer={{CUSTOMER_ID}} \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## 再利用可能な決済手段の取り消しを処理する 再利用可能な決済手段を無効にするには、お使いのサーバーから [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) エンドポイントを呼び出します。Stripe は [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) イベントと [payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) イベントの両方を送信します。[Webhook イベント](https://docs.stripe.com/webhooks.md)に登録して、通知を受け取ることができます。