# PayPal による支払いを受け付ける ヨーロッパの企業に広く普及しているデジタルウォレットである PayPal の決済を受け付ける方法をご紹介します。 # Checkout > This is a Checkout for when payment-ui is checkout. View the full page at https://docs.stripe.com/payments/paypal/accept-a-payment?payment-ui=checkout. > Stripe は、通貨、支払い方法の制限、その他のパラメーターを評価することで、適切な支払い方法を顧客に自動的に提示できます。 > > - [決済の受け付け](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=checkout&ui=stripe-hosted)ガイドに従って、[動的な決済手段](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md)を使用するチェックアウトの統合機能を構築します。 - 動的な決済手段を使用しない場合は、チェックアウトの導入で、決済方法を手動で設定するために以下のステップに従ってください。 Stripe Checkout では、どちらのオプションがコンバージョン率を向上する可能性が高いかに応じて、PayPal を標準の支払い方法または独立したボタンとして表示します。 ## 互換性を判断する **サポート対象のビジネスの所在地**: Europe, GB, EEA **対応可能な通貨**: `eur, gbp, usd, chf, czk, dkk, nok, pln, sek, aud, cad, hkd, nzd, sgd` **取引通貨**: `eur, gbp, usd, chf, czk, dkk, nok, pln, sek, aud, cad, hkd, nzd, sgd` **支払いモード**: Yes **セットアップモード**: Yes **サブスクリプションモード**: Yes PayPal の支払いに対応するには、Checkout セッションが次の条件をすべて満たしている必要があります。 - すべてのラインアイテムの*価格* (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)が、同じ通貨である必要があります。異なる通貨のラインアイテムが存在する場合は、通貨ごとに別の Checkout セッションを作成します。 ## 支払いを受け付ける > このガイドを使用する前に、まず Checkout で[決済を受け付ける](https://docs.stripe.com/payments/accept-a-payment.md?integration=checkout)ための実装を構築します。 このガイドでは Paypal を有効にする方法をご案内しています。また動的な決済方法を使用した支払いの受け付けと手動で設定する決済方法との違いをご確認ください。 ### 支払い方法として PayPal を有効にする 新しい [Checkout セッション](https://docs.stripe.com/api/checkout/sessions.md)を作成する際は、次のようにします。 1. `paypal` を `payment_method_types` のリストに追加します。 1. すべての `line_items` が同じ通貨を使用していることを確認します。 #### Stripe ホスト型ページ ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=paypal" \ --data-urlencode "success_url=https://example.com/success" ``` #### 組み込みフォーム ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=paypal" \ --data-urlencode "return_url=https://example.com/return" \ -d ui_mode=embedded_page ``` ### 注文のフルフィルメント 決済受け付け後に、[注文のフルフィルメントを実行](https://docs.stripe.com/checkout/fulfillment.md)する方法を説明します。 ## 組み込みをテストする 実装内容をテストするために PayPal ビジネスアカウントを関連付ける必要はありません。ただし、[本番環境での決済を有効にする](https://docs.stripe.com/payments/paypal/activate.md)準備が整ったときには、必ず PayPal アカウントと Stripe アカウントを関連付けてください。 Checkout に **PayPal** ボタンが表示されたら、テスト支払いを完了するには [個人の PayPal サンドボックスアカウント](https://developer.paypal.com/tools/sandbox/accounts/) が必要です。代わりに Checkout で支払い方法として PayPal が表示された場合は、 **PayPal** を選択して **Pay** をクリックします (PayPal Sandbox アカウントは必要ありません)。 PayPal 支払いで最も一般的な導入と失敗のシナリオをシミュレーションするには、[テストシナリオ](https://docs.stripe.com/payments/paypal/accept-a-payment.md?platform=web&ui=stripe-hosted#test-scenarios)で説明されているパターンと一致する `email` 値を渡します。 ### テストシナリオ | メールアドレスのパターン | シナリオ | 説明 | | ------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `.*payee_account_restricted@.*` | 制限対象の加盟店アカウント | 加盟店アカウントが PayPal によって制限されている場合、支払いのキャプチャーまたはオーソリは、`payment_method_unexpected_state` エラーで失敗します。オーソリ時にこのパターンに一致するメールアドレスを指定して、オーソリを失敗させます。 | | `.*transaction_refused@.*` | 拒否された取引 | 取引が PayPal によって拒否された場合、支払いのキャプチャーは、`payment_method_provider_decline` エラーで失敗します。 | | `.*instrument_declined@.*` | 拒否された支払い方法 | 指定された支払い方法が代行業者または銀行によって拒否されたか、この支払いには使用できない場合、支払いのキャプチャーは、`payment_method_provider_decline` エラーで失敗します。 | | `.*authorization_expired@.*` | オーソリ済みの支払いを手動でキャプチャーする | オーソリがすでに期限切れになっている場合、オーソリ済みの支払いのキャプチャーは、`capture_charge_authorization_expired` エラーで失敗します。 | ## 返金および不審請求の申請を処理する PayPal の[不審請求の申請](https://docs.stripe.com/payments/paypal.md#disputed-payments)と[返金](https://docs.stripe.com/payments/paypal.md#refunds)の詳細をご確認ください。 # ダイレクト API > This is a ダイレクト API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/paypal/accept-a-payment?payment-ui=direct-api. ## 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' ``` ## PaymentIntent を作成する [サーバー側] Stripe では、[PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents/object.md) と呼ばれる支払いオブジェクトを使用して、支払いの完了まですべてのステータスを追跡および処理します。サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。すでに [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用したシステムがある場合は、`paypal` を PaymentIntent の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)リストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" ``` 返される 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 を送り返します。 #### カスタムの説明を含める デフォルトでは、PayPal ユーザの購入アクティビティページの注文詳細には、注文金額が表示されます。`description` プロパティでカスタムの説明を指定することで、これを変更することができます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "description=A sample description" \ -d "payment_method_types[]=paypal" ``` #### 利用するロケールをカスタマイズする デフォルトでは、PayPal のオーソリページは加盟店の国などの変数に基づいて各地域に適応されます。これを顧客の希望するロケールに設定するには、`preferred_locale` プロパティを使用します。この値は、2文字の小文字の言語コードの後にハイフン (`-`) を続け、その後に 2 文字の大文字の国コードを続ける必要があります。例えば、ベルギーのフランス語ユーザーに対する値は、`fr-BE` となります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_options[paypal][preferred_locale]=fr-BE" ``` [preferred_locale](https://docs.stripe.com/payments/paypal/accept-a-payment.md#customize-the-preferred-locale) プロパティを使用して、顧客の希望するロケールにPayPalオーソリページを設定できます。対応するロケールについては、次の表を参照してください: | 値 | ロケール | 国 | | ----- | ------- | ------- | | cs-CZ | チェコ語 | チェコ共和国 | | da-DK | デンマーク語 | デンマーク | | de-AT | ドイツ語 | オーストリア | | de-DE | ドイツ語 | ドイツ | | de-LU | ドイツ語 | ルクセンブルク | | el-GR | ギリシャ語 | ギリシャ | | en-GB | 英語 | イギリス | | en-US | 英語 | アメリカ合衆国 | | es-ES | スペイン語 | スペイン | | fi-FI | フィンランド語 | フィンランド | | fr-BE | フランス語 | ベルギー | | fr-FR | フランス語 | フランス | | fr-LU | フランス語 | ルクセンブルク | | hu-HU | ハンガリー語 | ハンガリー | | it-IT | イタリア語 | イタリア | | nl-BE | オランダ語 | ベルギー | | nl-NL | オランダ語 | オランダ | | pl-PL | ポーランド語 | ポーランド | | pt-PT | ポルトガル語 | ポルトガル | | sk-SK | スロバキア語 | スロバキア | | sv-SE | スウェーデン語 | スウェーデン | #### PayPal での明細書表記 買い手の銀行明細書に表示される表記は PayPal によって設定され、デフォルトでは `PAYPAL *YOUR_BUSINESS_NAME` になります。`PaymentIntent` の作成時に `statement_descriptor` を設定した場合、合計 22 文字を上限として、その値が PayPal によって設定された値に付加されます。 たとえば、PayPal のビジネス名が `BUSINESS` であり、`statement_descriptor` に `order_id_1234` を設定する場合、買い手の銀行口座明細書には `PAYPAL *BUSINESS order` と表示されます。 ## Stripe に支払いを送信する [クライアント側] 顧客が PayPal での支払いをクリックしたときに、Stripe.js を使用してその支払いを Stripe に送信します。[Stripe.js](https://docs.stripe.com/payments/elements.md) は、決済フローを構築するための基本的な JavaScript ライブラリです。このライブラリにより、以下で説明するリダイレクトなどの複雑な処理が自動的に行われ、他の決済手段にも対応できるように実装を拡張できます。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('<>'); ``` クライアント側で支払いを作成するには、[ステップ 2](https://docs.stripe.com/payments/paypal/accept-a-payment.md#create-payment-intent) で作成した `PaymentIntent` オブジェクトの [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を渡します。client secret は、 Stripe API リクエストを認証する API キーとは異なります。client secret は支払いを完了できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。 ### PayPal 支払いを確定する [stripe.confirmPayPalPayment](https://docs.stripe.com/js/payment_intents/confirm_paypal_payment) を呼び出し、顧客を PayPal にリダイレクトして支払いを完了します。`return_url` を追加して、支払い完了後に Stripe が顧客をリダイレクトする場所を指定する必要があります。新しい PayPal の決済手段に `return_url` を追加することもできますが、SetupIntent で以前に設定された PayPal の決済手段、または `setup_future_usage` を含む PaymentIntent を使用する場合、追加は必須ではありません。 ```javascript // Redirects away from the client const {error} = await stripe.confirmPayPalPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { return_url: 'https://example.com/checkout/complete', } ); if (error) { // Inform the customer that there was an error. } ``` PayPal の売上を PayPal で処理する場合、支払いに関連付けられた[取引残高](https://docs.stripe.com/api.md#balance_transaction_object)の金額は、支払い額に関係なくゼロになります。取引は Stripe 残高における入出金を表すものですが、PayPal では、売上が PayPal 残高で処理され、Stripe 残高に資金が移動しません。この場合の取引残高には、取引に伴う手数料も含まれます。売上処理の設定に関するその他の重要事項については、[こちら](https://docs.stripe.com/payments/paypal/choose-settlement-preference.md)で詳細をご覧ください。 ### リダイレクトを処理する Stripe が顧客を `return_url` にリダイレクトする際に、以下の URL クエリパラメータが提供されます。 | パラメータ | 説明 | | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent` | `PaymentIntent` の一意の識別子。 | | `payment_intent_client_secret` | `PaymentIntent` オブジェクトの [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret)。 | `return_url` を指定する際に、独自のクエリパラメータを追加することもできます。このクエリパラメータは、リダイレクトプロセスの始めから終わりまで存続します。`return_url` は、決済のステータスを提供するウェブサイトのページと一致している必要があります。戻りページをレンダリングするときに、`PaymentIntent` のステータスを確認してください。確認するには、Stripe.js の `retrievePaymentIntent` 関数を使用し、`payment_intent_client_secret` を渡します。 ```javascript (async () => { const url = new URL(window.location); const clientSecret = url.searchParams.get('payment_intent_client_secret'); const {paymentIntent, error} = await stripe.retrievePaymentIntent(clientSecret); if (error) { // Handle error } else if (paymentIntent && paymentIntent.status === 'succeeded') { // Handle successful payment } })(); ``` [payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-paypal) プロパティには、支払い者の氏名、メールアドレス、支払人 ID、取引 ID が含まれています。 | フィールド | 値 | | ---------------- | ------------------------- | | `payer_email` | PayPal アカウントの支払人のメールアドレス。 | | `payer_name` | PayPal アカウントの支払人の名前。 | | `payer_id` | 支払人の PayPal アカウントの一意の ID。 | | `transaction_id` | PayPal によって生成された一意の取引 ID。 | #### Json ```json { "charges": { "data": [ {"payment_method_details": { "paypal": { "payer_id": "H54KFE9XXVVYJ", "payer_email": "jenny@example.com", "payer_name": "Jenny Rosen", "transaction_id": "89W40396MK104212M" }, "type": "paypal" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU", "created": 1445277809, "currency": "eur", "flow": "redirect", "livemode": true, "statement_descriptor": null, "status": "pending", "type": "paypal", "usage": "single_use" } ], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_1G1sgdKi6xqXeNtkldRRE6HT" }, "payment_method_options": { "paypal": {} }, "payment_method_types": [ "paypal" ], "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "client_secret": "pi_1G1sgdKi6xqXeNtkldRRE6HT_secret_h9B56ObhTN72fQiBAuzcVPb2E", "confirmation_method": "automatic", "created": 1579259303, "currency": "eur", "livemode": true, "next_action": null } ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 ### イベントを受信し、ビジネスアクションを実行する ビジネスアクションを受信して実行するためのいくつかのオプションがあります。 #### 手動 Stripe ダッシュボードは、すべての Stripe での支払いの確認、メール領収書の送信、入金処理、または失敗した支払いの再試行に使用できます。 - [ダッシュボードでテスト支払いを確認する](https://dashboard.stripe.com/test/payments) #### カスタムコード Webhook ハンドラを作成してイベントをリッスンし、非同期型のカスタムの支払いフローを作成します。Stripe CLI を使用して、ローカルで Webhook 組み込みのテストとデバッグを行います。 - [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### 事前構築のアプリ [オートメーション](https://stripe.partners/?f_category=automation)や[マーケティングとセールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを、パートナーアプリケーションとの連携によって処理します。 ## Optional: PayPal リダイレクトを手動で処理する Stripe.js を使用すると、実装を他の支払い方法に拡張することができます。ただし、お客様のサーバーに顧客を手動でリダイレクトすることもできます。 1. タイプが `paypal` の 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=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_data[type]=paypal" \ --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)を設定することをお勧めします。 ## Optional: 支払いをオーソリし、後でキャプチャ PayPal は、[オーソリとキャプチャーの分離](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md)に対応しています。[Stripe での売上処理](https://docs.stripe.com/payments/paypal/choose-settlement-preference.md)を選択した場合オーソリは 10 日間有効です。Stripe は自動的に支払いを再度オーソリして、オーソリ期間をさらに 10 日間延長します。これにより有効期限は合計 20 日間になります。再オーソリが機能しない場合、Stripe は支払いを 10 日後すぐに期限切れにします。オーソリ期間の終了を把握するには、[charge.expired](https://docs.stripe.com/api/events/types.md#event_types-charge.expired) Webhook をリッスンします。 [PayPal での売上処理](https://docs.stripe.com/payments/paypal/choose-settlement-preference.md)を選択した場合、オーソリは 3 日間有効なままになります。Stripe はオーソリ期間をさらに 3 日間延長します。最大 10 日間の延長されたオーソリの保証期間 (PayPal では「引受期間」と呼ばれます) については、[PayPal サポート](https://www.paypal.com/nu/cshelp/business)にお問い合わせください。 ### オーソリのみ行うように Stripe に指示する オーソリとキャプチャーの分離を指定するには、PaymentIntent の作成時に [capture_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を `manual` に設定します。このパラメーターは、顧客の PayPal アカウントの金額のみをオーソリするように Stripe に指示します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual \ -d "payment_method_types[]=paypal" \ -d "payment_method_data[type]=paypal" \ -d confirm=true \ --data-urlencode "return_url=http://example.com" ``` オーソリが成功すると、Stripe は [payment_intent.amount_capturable_updated](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.amount_capturable_updated) イベントを送信します。詳細については、[イベントガイド](https://docs.stripe.com/api/events.md)をご確認ください。 ### 売上をキャプチャする オーソリが完了すると、PaymentIntent の[ステータス](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status) は `requires_capture` に移行します。オーソリ済みの売上をキャプチャーするには、PaymentIntent の[キャプチャー](https://docs.stripe.com/api/payment_intents/capture.md)リクエストを作成します。デフォルトではオーソリ済みの総額がキャプチャーされます。これを超える金額をキャプチャーすることはできませんが、これより少ない金額をキャプチャーすることは可能です。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}}/capture \ -u "<>:" \ -d amount_to_capture=750 ``` ### (任意)オーソリをキャンセルする オーソリをキャンセルする必要がある場合は、[PaymentIntent をキャンセル](https://docs.stripe.com/refunds.md#cancel-payment)してください。 ## Optional: PayPal で非同期の支払い方法の使用を有効にする デフォルトでは、Stripe は PayPal を使用した同期型の決済手段のみ許可します。これにより、各支払いの成功または失敗に関する[即時通知](https://docs.stripe.com/payments/payment-methods.md#payment-notification)を確実に受け取ることができます。非同期型の決済手段を許可すると、一部の支払いで[通知の遅延](https://docs.stripe.com/payments/payment-methods.md#payment-notification)が発生することがあります。このような支払いの成功または失敗に関する通知を受け取るには、[Webhook エンドポイント](https://docs.stripe.com/payments/payment-methods.md#webhooks)を使用します。 PayPal で非同期型の支払いを有効にするには、[Stripe サポート](https://support.stripe.com/contact)にお問い合わせください。 ## Optional: エラーコード これらは、PayPal を導入する際の一般的なエラーコードと対応する詳細です。PayPal API リクエストがエラーを返す場合、エラーにはリクエストの PayPal 問題コードとデバッグ ID が含まれます。サポートが必要な場合は、デバッグ ID を使用して [PayPal サポート](https://www.paypal-support.com/)にお問い合わせいただけます。 | エラーコード | 詳細 | | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `country_code_invalid` | 配送先住所で指定された国コードが無効です。 | | `incorrect_address` | 指定した配送先住所が無効です。このエラーは、指定された国が追加で市区町村または郵便番号を必要とする場合にも発生します。詳細については、エラーメッセージを確認し、`Debug ID` と `PayPal issue` を使用して [PayPal サポート](https://www.paypal-support.com/)にお問い合わせください。 | | `payment_method_not_available` | `paypal` 支払い方法は、現在利用できません。このエラーは、PayPal API に接続する際のタイムアウトまたはサーバーの問題によって引き起こされる場合があります。 | | `payment_method_provider_decline` | 取引が PayPal によって拒否されています。これは一般的に、加盟店の PayPal における不正利用対策設定、法令遵守違反、または支払人が選択された資金供給手段での決済を実行できないことが原因で発生します。詳細については、エラーメッセージを確認し、`Debug ID` と `PayPal issue` を使用して [PayPal サポート](https://www.paypal-support.com/)にお問い合わせください。 | | `payment_method_provider_timeout` | PayPal でリクエストがタイムアウトしました。多くの場合、これは一時的なエラーなので、しばらく経ってからリクエストを再試行できます。 | | `payment_method_unactivated` | Stripe アカウントで `paypal` の支払い方法が有効になっていません。 | | `payment_method_unexpected_state` | PayPal でのリクエストが失敗しました。これは、加盟店のビジネス用口座が PayPal によってロック、制限、閉鎖されているとき、または支払人の PayPal アカウントが制限されているときに発生する可能性があります。詳細については、エラーメッセージを確認し、`Debug ID` と `PayPal issue` を使用して [PayPal サポート](https://www.paypal-support.com/)にお問い合わせください。 | ## Optional: PayPal の組み込みをテストする PayPal の導入で支払いの成功をテストするには、[テスト API キー](https://docs.stripe.com/keys.md#test-live-modes)を使用して、リダイレクトページを表示します。このページには、テストシナリオとしてユーザー認証の**オーソリ**または**失敗**のオプションが表示されます。**Authorize test payment (テスト支払いをオーソリする)** を選択すると、PaymentIntent は `requires_action` から `succeeded` に移行します。 ユーザーが認証に失敗するケースをテストするには、テスト API キーを使用してリダイレクトページを表示します。リダイレクトページで **Fail test payment (テスト支払い失敗)** をクリックします。PaymentIntent が、`requires_action` から `requires_payment_method` に変化します。 PayPal 支払いで最も一般的な導入と失敗シナリオをシミュレーションするには、PaymentIntent の作成時に、[請求詳細](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_data-billing_details)の一部として、[テストシナリオ](https://docs.stripe.com/payments/paypal/accept-a-payment.md?platform=web#test-scenarios)で説明されているパターンと一致する `email` 値を渡します。たとえば、サーバー側で PaymentIntent を確定する際に、PayPal によって拒否される取引をシミュレーションするリクエストは以下のようになります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_data[type]=paypal" \ --data-urlencode "payment_method_data[billing_details][email]=transaction_refused@example.com" ``` ### テストシナリオ | メールアドレスのパターン | シナリオ | 説明 | | ------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `.*payee_account_restricted@.*` | 制限対象の加盟店アカウント | 加盟店アカウントが PayPal によって制限されている場合、支払いのキャプチャーまたはオーソリは、`payment_method_unexpected_state` エラーで失敗します。オーソリ時にこのパターンに一致するメールアドレスを指定して、オーソリを失敗させます。 | | `.*transaction_refused@.*` | 拒否された取引 | 取引が PayPal によって拒否された場合、支払いのキャプチャーは、`payment_method_provider_decline` エラーで失敗します。 | | `.*instrument_declined@.*` | 拒否された支払い方法 | 指定された支払い方法が代行業者または銀行によって拒否されたか、この支払いには使用できない場合、支払いのキャプチャーは、`payment_method_provider_decline` エラーで失敗します。 | | `.*authorization_expired@.*` | オーソリ済みの支払いを手動でキャプチャーする | オーソリがすでに期限切れになっている場合、オーソリ済みの支払いのキャプチャーは、`capture_charge_authorization_expired` エラーで失敗します。 | # 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/paypal/accept-a-payment?payment-ui=mobile&platform=ios. ## 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)キーを使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] ### サーバー側 Stripe では、[PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents/object.md) と呼ばれる支払いオブジェクトを使用して、支払いの完了まですべてのステータスを追跡および処理します。サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。すでに [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用したシステムがある場合は、`paypal` を PaymentIntent の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)リストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" ``` 返される 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 を送り返します。 #### カスタムの説明を含める デフォルトでは、PayPal ユーザの購入アクティビティページの注文詳細には、注文金額が表示されます。`description` プロパティでカスタムの説明を指定することで、これを変更することができます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "description=A sample description" \ -d "payment_method_types[]=paypal" ``` #### 利用するロケールをカスタマイズする デフォルトでは、PayPal のオーソリページは加盟店の国などの変数に基づいて各地域に適応されます。これを顧客の希望するロケールに設定するには、`preferred_locale` プロパティを使用します。この値は、2文字の小文字の言語コードの後にハイフン (`-`) を続け、その後に 2 文字の大文字の国コードを続ける必要があります。例えば、ベルギーのフランス語ユーザーに対する値は、`fr-BE` となります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_options[paypal][preferred_locale]=fr-BE" ``` [preferred_locale](https://docs.stripe.com/payments/paypal/accept-a-payment.md#customize-the-preferred-locale) プロパティを使用して、顧客の希望するロケールにPayPalオーソリページを設定できます。対応するロケールについては、次の表を参照してください: | 値 | ロケール | 国 | | ----- | ------- | ------- | | cs-CZ | チェコ語 | チェコ共和国 | | da-DK | デンマーク語 | デンマーク | | de-AT | ドイツ語 | オーストリア | | de-DE | ドイツ語 | ドイツ | | de-LU | ドイツ語 | ルクセンブルク | | el-GR | ギリシャ語 | ギリシャ | | en-GB | 英語 | イギリス | | en-US | 英語 | アメリカ合衆国 | | es-ES | スペイン語 | スペイン | | fi-FI | フィンランド語 | フィンランド | | fr-BE | フランス語 | ベルギー | | fr-FR | フランス語 | フランス | | fr-LU | フランス語 | ルクセンブルク | | hu-HU | ハンガリー語 | ハンガリー | | it-IT | イタリア語 | イタリア | | nl-BE | オランダ語 | ベルギー | | nl-NL | オランダ語 | オランダ | | pl-PL | ポーランド語 | ポーランド | | pt-PT | ポルトガル語 | ポルトガル | | sk-SK | スロバキア語 | スロバキア | | sv-SE | スウェーデン語 | スウェーデン | #### PayPal での明細書表記 買い手の銀行明細書に表示される表記は PayPal によって設定され、デフォルトでは `PAYPAL *YOUR_BUSINESS_NAME` になります。`PaymentIntent` の作成時に `statement_descriptor` を設定した場合、合計 22 文字を上限として、その値が PayPal によって設定された値に付加されます。 たとえば、PayPal のビジネス名が `BUSINESS` であり、`statement_descriptor` に `order_id_1234` を設定する場合、買い手の銀行口座明細書には `PAYPAL *BUSINESS order` と表示されます。 ### クライアント側 クライアント側で、サーバーの 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)) を保存します。 #### Swift ```swift class CheckoutViewController: UIViewController { var paymentIntentClientSecret: String? // ...continued from previous step override func viewDidLoad() { // ...continued from previous step startCheckout() } func startCheckout() { // Request a PaymentIntent from your server and store its client secret // Click View full sample to see a complete implementation } } ``` ## Stripe に支払いを送信する [クライアント側] 顧客が支払いのために PayPal をタップしたら、`PaymentIntent` を確定して支払いを完了します。`PaymentIntent` [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を使用して `STPPaymentIntentParams` オブジェクトを構成します。 client secret は、Stripe API リクエストを認証する API キーとは異なります。これは支払いを完了できるため、慎重に扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩したりすることがないようにしてください。 ### 戻り先 URL を設定する iOS SDK では、PayPal 支払いを完了するための WebView がアプリに表示されます。認証が終了すると、顧客が閉じなくても、自動的に WebView が閉じられるようにすることができます。この動作を有効にするには、カスタム URL スキームまたはユニバーサルリンクを構成して、URL を SDK に転送するようにアプリのデリゲートを設定します。 #### Swift ```swift // This method handles opening custom URL schemes (for example, "your-app://stripe-redirect") func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { let stripeHandled = StripeAPI.handleURLCallback(with: url) if (stripeHandled) { return true } else { // This was not a Stripe url – handle the URL normally as you would } return false } // This method handles opening universal link URLs (for example, "https://example.com/stripe_ios_callback") func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { if userActivity.activityType == NSUserActivityTypeBrowsingWeb { if let url = userActivity.webpageURL { let stripeHandled = StripeAPI.handleURLCallback(with: url) if (stripeHandled) { return true } else { // This was not a Stripe url – handle the URL normally as you would } } } return false } ``` PaymentIntent を確定する際に、`return_url` としてその URL を渡します。WebView での認証が終わると、Stripe はユーザをその `return_url` にリダイレクトします。 ### PayPal 支払いを確定する `STPPaymentHandler confirmPayment` を呼び出して支払いを完了します。これにより WebView が表示され、顧客はそこで PayPal で支払いを完了できます。完了後、支払いの結果とともに、完了ブロックが呼び出されます。 #### Swift ```swift let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) // PayPal doesn't require additional parameters so we only need to pass the initialized // STPPaymentMethodPayPalParams instance to STPPaymentMethodParams let payPal = STPPaymentMethodPayPalParams() let paymentMethodParams = STPPaymentMethodParams(payPal: payPal, billingDetails: nil, metadata: nil) paymentIntentParams.paymentMethodParams = paymentMethodParams STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self) { (handlerStatus, paymentIntent, error) in switch handlerStatus { case .succeeded: // Payment succeeded // ... case .canceled: // Payment canceled // ... case .failed: // Payment failed // ... @unknown default: fatalError() } } ``` [payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-paypal) プロパティには、支払い者の氏名、メールアドレス、支払人 ID、取引 ID が含まれています。 | フィールド | 値 | | ---------------- | ------------------------- | | `payer_email` | PayPal アカウントの支払人のメールアドレス。 | | `payer_name` | PayPal アカウントの支払人の名前。 | | `payer_id` | 支払人の PayPal アカウントの一意の ID。 | | `transaction_id` | PayPal によって生成された一意の取引 ID。 | #### Json ```json { "charges": { "data": [ {"payment_method_details": { "paypal": { "payer_id": "H54KFE9XXVVYJ", "payer_email": "jenny@example.com", "payer_name": "Jenny Rosen", "transaction_id": "89W40396MK104212M" }, "type": "paypal" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU", "created": 1445277809, "currency": "eur", "flow": "redirect", "livemode": true, "statement_descriptor": null, "status": "pending", "type": "paypal", "usage": "single_use" } ], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_1G1sgdKi6xqXeNtkldRRE6HT" }, "payment_method_options": { "paypal": {} }, "payment_method_types": [ "paypal" ], "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "client_secret": "pi_1G1sgdKi6xqXeNtkldRRE6HT_secret_h9B56ObhTN72fQiBAuzcVPb2E", "confirmation_method": "automatic", "created": 1579259303, "currency": "eur", "livemode": true, "next_action": null } ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 ### イベントを受信し、ビジネスアクションを実行する ビジネスアクションを受信して実行するためのいくつかのオプションがあります。 #### 手動 Stripe ダッシュボードは、すべての Stripe での支払いの確認、メール領収書の送信、入金処理、または失敗した支払いの再試行に使用できます。 - [ダッシュボードでテスト支払いを確認する](https://dashboard.stripe.com/test/payments) #### カスタムコード Webhook ハンドラを作成してイベントをリッスンし、非同期型のカスタムの支払いフローを作成します。Stripe CLI を使用して、ローカルで Webhook 組み込みのテストとデバッグを行います。 - [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### 事前構築のアプリ [オートメーション](https://stripe.partners/?f_category=automation)や[マーケティングとセールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを、パートナーアプリケーションとの連携によって処理します。 # 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/paypal/accept-a-payment?payment-ui=mobile&platform=android. ## 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.2.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:23.2.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) も使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] ### サーバー側 Stripe では、[PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents/object.md) と呼ばれる支払いオブジェクトを使用して、支払いの完了まですべてのステータスを追跡および処理します。サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。すでに [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用したシステムがある場合は、`paypal` を PaymentIntent の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)リストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" ``` 返される 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 を送り返します。 #### カスタムの説明を含める デフォルトでは、PayPal ユーザの購入アクティビティページの注文詳細には、注文金額が表示されます。`description` プロパティでカスタムの説明を指定することで、これを変更することができます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "description=A sample description" \ -d "payment_method_types[]=paypal" ``` #### 利用するロケールをカスタマイズする デフォルトでは、PayPal のオーソリページは加盟店の国などの変数に基づいて各地域に適応されます。これを顧客の希望するロケールに設定するには、`preferred_locale` プロパティを使用します。この値は、2文字の小文字の言語コードの後にハイフン (`-`) を続け、その後に 2 文字の大文字の国コードを続ける必要があります。例えば、ベルギーのフランス語ユーザーに対する値は、`fr-BE` となります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_options[paypal][preferred_locale]=fr-BE" ``` [preferred_locale](https://docs.stripe.com/payments/paypal/accept-a-payment.md#customize-the-preferred-locale) プロパティを使用して、顧客の希望するロケールにPayPalオーソリページを設定できます。対応するロケールについては、次の表を参照してください: | 値 | ロケール | 国 | | ----- | ------- | ------- | | cs-CZ | チェコ語 | チェコ共和国 | | da-DK | デンマーク語 | デンマーク | | de-AT | ドイツ語 | オーストリア | | de-DE | ドイツ語 | ドイツ | | de-LU | ドイツ語 | ルクセンブルク | | el-GR | ギリシャ語 | ギリシャ | | en-GB | 英語 | イギリス | | en-US | 英語 | アメリカ合衆国 | | es-ES | スペイン語 | スペイン | | fi-FI | フィンランド語 | フィンランド | | fr-BE | フランス語 | ベルギー | | fr-FR | フランス語 | フランス | | fr-LU | フランス語 | ルクセンブルク | | hu-HU | ハンガリー語 | ハンガリー | | it-IT | イタリア語 | イタリア | | nl-BE | オランダ語 | ベルギー | | nl-NL | オランダ語 | オランダ | | pl-PL | ポーランド語 | ポーランド | | pt-PT | ポルトガル語 | ポルトガル | | sk-SK | スロバキア語 | スロバキア | | sv-SE | スウェーデン語 | スウェーデン | #### PayPal での明細書表記 買い手の銀行明細書に表示される表記は PayPal によって設定され、デフォルトでは `PAYPAL *YOUR_BUSINESS_NAME` になります。`PaymentIntent` の作成時に `statement_descriptor` を設定した場合、合計 22 文字を上限として、その値が PayPal によって設定された値に付加されます。 たとえば、PayPal のビジネス名が `BUSINESS` であり、`statement_descriptor` に `order_id_1234` を設定する場合、買い手の銀行口座明細書には `PAYPAL *BUSINESS order` と表示されます。 ### クライアント側 クライアント側で、サーバーの 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)) を保存します。 #### Kotlin ```kotlin class CheckoutActivity : AppCompatActivity() { private lateinit var paymentIntentClientSecret: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ... startCheckout() } private fun startCheckout() { // Request a PaymentIntent from your server and store its client secret in paymentIntentClientSecret // Click View full sample to see a complete implementation } } ``` ## Stripe に支払いを送信する [クライアント側] 作成した SetupIntent から client secret を取得し、[PaymentLauncher confirm](https://stripe.dev/stripe-android/payments-core/com.stripe.android.payments.paymentlauncher/-payment-launcher/index.html#74063765%2FFunctions%2F-1622557690) を呼び出します。これにより、Webview が表示され、顧客は銀行のウェブサイトまたはアプリで設定を完了できます。完了後、支払い結果とともに、`onPaymentResult` が呼び出されます。 #### Kotlin ```kotlin class CheckoutActivity : AppCompatActivity() { // ... private lateinit var paymentIntentClientSecret: String private val paymentLauncher: PaymentLauncher by lazy { PaymentLauncher.Companion.create( this, PaymentConfiguration.getInstance(applicationContext).publishableKey, PaymentConfiguration.getInstance(applicationContext).stripeAccountId, ::onPaymentResult ) } private fun startCheckout() { // ... val confirmParams = ConfirmPaymentIntentParams .createWithPaymentMethodCreateParams( paymentMethodCreateParams = PaymentMethodCreateParams.createPayPal(), clientSecret = paymentIntentClientSecret ) paymentLauncher.confirm(confirmParams) } private fun onPaymentResult(paymentResult: PaymentResult) { val message = when (paymentResult) { is PaymentResult.Completed -> { "Completed!" } is PaymentResult.Canceled -> { "Canceled!" } is PaymentResult.Failed -> { // This string comes from the PaymentIntent's error message. // See here: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-last_payment_error-message "Failed: " + paymentResult.throwable.message } } } } ``` [payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-paypal) プロパティには、支払い者の氏名、メールアドレス、支払人 ID、取引 ID が含まれています。 | フィールド | 値 | | ---------------- | ------------------------- | | `payer_email` | PayPal アカウントの支払人のメールアドレス。 | | `payer_name` | PayPal アカウントの支払人の名前。 | | `payer_id` | 支払人の PayPal アカウントの一意の ID。 | | `transaction_id` | PayPal によって生成された一意の取引 ID。 | #### Json ```json { "charges": { "data": [ {"payment_method_details": { "paypal": { "payer_id": "H54KFE9XXVVYJ", "payer_email": "jenny@example.com", "payer_name": "Jenny Rosen", "transaction_id": "89W40396MK104212M" }, "type": "paypal" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU", "created": 1445277809, "currency": "eur", "flow": "redirect", "livemode": true, "statement_descriptor": null, "status": "pending", "type": "paypal", "usage": "single_use" } ], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_1G1sgdKi6xqXeNtkldRRE6HT" }, "payment_method_options": { "paypal": {} }, "payment_method_types": [ "paypal" ], "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "client_secret": "pi_1G1sgdKi6xqXeNtkldRRE6HT_secret_h9B56ObhTN72fQiBAuzcVPb2E", "confirmation_method": "automatic", "created": 1579259303, "currency": "eur", "livemode": true, "next_action": null } ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 ### イベントを受信し、ビジネスアクションを実行する ビジネスアクションを受信して実行するためのいくつかのオプションがあります。 #### 手動 Stripe ダッシュボードは、すべての Stripe での支払いの確認、メール領収書の送信、入金処理、または失敗した支払いの再試行に使用できます。 - [ダッシュボードでテスト支払いを確認する](https://dashboard.stripe.com/test/payments) #### カスタムコード Webhook ハンドラを作成してイベントをリッスンし、非同期型のカスタムの支払いフローを作成します。Stripe CLI を使用して、ローカルで Webhook 組み込みのテストとデバッグを行います。 - [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### 事前構築のアプリ [オートメーション](https://stripe.partners/?f_category=automation)や[マーケティングとセールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを、パートナーアプリケーションとの連携によって処理します。 # React Native > This is a React Native for when payment-ui is mobile and platform is react-native. View the full page at https://docs.stripe.com/payments/paypal/accept-a-payment?payment-ui=mobile&platform=react-native. ## Stripe を設定する [サーバ側] [クライアント側] ### サーバ側 この組み込みには、Stripe API と通信するエンドポイントがサーバ上に必要です。Stripe の公式ライブラリを使用して、サーバから Stripe API にアクセスします。 #### 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' ``` ### クライアント側 [React Native SDK](https://github.com/stripe/stripe-react-native) はオープンソースであり、詳細なドキュメントが提供されています。内部では、[ネイティブの iOS](https://github.com/stripe/stripe-ios) および [Android](https://github.com/stripe/stripe-android) の SDK を使用します。Stripe の React Native SDK をインストールするには、プロジェクトのディレクトリーで (使用するパッケージマネージャーによって異なる) 次のいずれかのコマンドを実行します。 #### yarn ```bash yarn add @stripe/stripe-react-native ``` #### npm ```bash npm install @stripe/stripe-react-native ``` 次に、その他の必要な依存関係をインストールします。 - iOS の場合は、**ios** ディレクトリに移動して `pod install` を実行し、必要なネイティブ依存関係もインストールします。 - Android の場合は、依存関係をインストールする必要はありません。 > [公式の TypeScript ガイド](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project)に従って TypeScript のサポートを追加することをお勧めします。 ### Stripe の初期化 React Native アプリで Stripe を初期化するには、決済画面を `StripeProvider` コンポーネントでラップするか、`initStripe` 初期化メソッドを使用します。`publishableKey` の API [公開可能キー](https://docs.stripe.com/keys.md#obtain-api-keys)のみが必要です。次の例は、`StripeProvider` コンポーネントを使用して Stripe を初期化する方法を示しています。 ```jsx import { useState, useEffect } from 'react'; import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( {/* Your app code here */} ); } ``` > テストおよび開発時には API の[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] ### サーバー側 Stripe では、[PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents/object.md) と呼ばれる支払いオブジェクトを使用して、支払いの完了まですべてのステータスを追跡および処理します。サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。すでに [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用したシステムがある場合は、`paypal` を PaymentIntent の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)リストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" ``` 返される 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 を送り返します。 #### カスタムの説明を含める デフォルトでは、PayPal ユーザの購入アクティビティページの注文詳細には、注文金額が表示されます。`description` プロパティでカスタムの説明を指定することで、これを変更することができます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "description=A sample description" \ -d "payment_method_types[]=paypal" ``` #### 利用するロケールをカスタマイズする デフォルトでは、PayPal のオーソリページは加盟店の国などの変数に基づいて各地域に適応されます。これを顧客の希望するロケールに設定するには、`preferred_locale` プロパティを使用します。この値は、2文字の小文字の言語コードの後にハイフン (`-`) を続け、その後に 2 文字の大文字の国コードを続ける必要があります。例えば、ベルギーのフランス語ユーザーに対する値は、`fr-BE` となります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "payment_method_types[]=paypal" \ -d "payment_method_options[paypal][preferred_locale]=fr-BE" ``` [preferred_locale](https://docs.stripe.com/payments/paypal/accept-a-payment.md#customize-the-preferred-locale) プロパティを使用して、顧客の希望するロケールにPayPalオーソリページを設定できます。対応するロケールについては、次の表を参照してください: | 値 | ロケール | 国 | | ----- | ------- | ------- | | cs-CZ | チェコ語 | チェコ共和国 | | da-DK | デンマーク語 | デンマーク | | de-AT | ドイツ語 | オーストリア | | de-DE | ドイツ語 | ドイツ | | de-LU | ドイツ語 | ルクセンブルク | | el-GR | ギリシャ語 | ギリシャ | | en-GB | 英語 | イギリス | | en-US | 英語 | アメリカ合衆国 | | es-ES | スペイン語 | スペイン | | fi-FI | フィンランド語 | フィンランド | | fr-BE | フランス語 | ベルギー | | fr-FR | フランス語 | フランス | | fr-LU | フランス語 | ルクセンブルク | | hu-HU | ハンガリー語 | ハンガリー | | it-IT | イタリア語 | イタリア | | nl-BE | オランダ語 | ベルギー | | nl-NL | オランダ語 | オランダ | | pl-PL | ポーランド語 | ポーランド | | pt-PT | ポルトガル語 | ポルトガル | | sk-SK | スロバキア語 | スロバキア | | sv-SE | スウェーデン語 | スウェーデン | #### PayPal での明細書表記 買い手の銀行明細書に表示される表記は PayPal によって設定され、デフォルトでは `PAYPAL *YOUR_BUSINESS_NAME` になります。`PaymentIntent` の作成時に `statement_descriptor` を設定した場合、合計 22 文字を上限として、その値が PayPal によって設定された値に付加されます。 たとえば、PayPal のビジネス名が `BUSINESS` であり、`statement_descriptor` に `order_id_1234` を設定する場合、買い手の銀行口座明細書には `PAYPAL *BUSINESS order` と表示されます。 ### クライアント側 クライアント側で、サーバーの 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)) を保存します。 ```javascript function PaymentScreen() { const fetchPaymentIntentClientSecret = async () => { const response = await fetch(`${API_URL}/create-payment-intent`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ currency: 'eur', }), }); const {clientSecret} = await response.json(); return clientSecret; }; const handlePayPress = async () => { // See below }; return (