Afterpay または Clearpay の支払いを受け付ける
アメリカ、カナダ、イギリス、オーストラリア、ニュージーランドで、Afterpay (イギリスでは Clearpay とも呼ばれている) による支払い方法を受け付ける方法をご紹介します。
アプリで Afterpay を受け付けるには、顧客が支払いを認証するための Webview を表示します。その後、顧客はアプリに戻り、お客様は支払いが成功したか失敗したかをすぐに確認できます。
注
Before you start the integration, make sure your account is eligible for Afterpay by navigating to your Payment methods settings.
Stripe を設定するサーバ側クライアント側
まず、Stripe アカウントが必要です。今すぐ登録してください。
サーバ側
この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。
クライアント側
Stripe Android SDK はオープンソースであり、詳細なドキュメントが提供されています。
To install the SDK, add stripe-android
to the dependencies
block of your app/build.gradle file:
注
SDK の最新リリースおよび過去バージョンの詳細については、GitHub の Releases ページをご覧ください。新しいリリースの公開時に通知を受け取るには、リポジトリのリリースを確認してください。
Stripe の公開可能キーを使用して SDK を設定し、 Application
サブクラスなどで、Stripe API へのリクエストを実行できるようにします。
PaymentIntent を作成するサーバ側クライアント側
A PaymentIntent is an object that represents your intent to collect payment from a customer and tracks the lifecycle of the payment process through each stage.
サーバ側
First, create a PaymentIntent
on your server and specify the amount to collect and the currency. If you already have an integration using the Payment Intents API, add afterpay_
to the list of payment method types for your PaymentIntent
.
その他の支払い方法オプション
You can specify an optional reference
parameter in the payment method options for your PaymentIntent
that sets an internal order identifier for the payment. Although this isn’t typically visible to either the business or the consumer, Afterpay’s internal support team can access it during manual support requests. The identifier is limited to 128 characters and may contain only letters, digits, underscores, backslashes, and dashes.
クライアント側
Included in the returned PaymentIntent is a client secret, which the client side can use to securely complete the payment process instead of passing the entire PaymentIntent object. On the client, request a PaymentIntent from your server and store its client secret.
支払い方法の詳細を収集するクライアント側
Afterpay requires billing details to be present for the payment to succeed. In your app, collect the required billing details from the customer:
- Full name (first and last)
- メールアドレス
- Full billing address
これらの詳細を使用して、PaymentMethodCreateParams を作成します。
Additionally, while shipping details aren’t required they can help improve authentication rates. To collect shipping details, collect the following from the customer:
- 氏名
- Full shipping address
これらの詳細を使用して、ConfirmPaymentIntentParams.Shipping を作成します。
Stripe に支払いを送金するクライアント側
ステップ 2 で作成した PaymentIntent から client secret を取得し、PaymentLauncher confirm メソッドを呼び出します。これにより、Webview が表示され、顧客は銀行のウェブサイトまたはアプリで支払いを完了できます。完了後、支払い結果とともに、onActivityResult が呼び出されます。
失敗した支払い
Afterpay は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Afterpay を使用している期間、顧客が返済する必要のある未払い額、現在の注文の値など)。
You should always present additional payment options such as card
in your checkout flow, as Afterpay payments have a higher rate of decline than many payment methods. In these cases, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_
.
For an Afterpay PaymentIntent with a status of requires_
, customers need to complete the payment within 3 hours after you redirect them to the Afterpay site (this doesn’t apply to declined payments). If they take no action within 3 hours, the PaymentMethod detaches and the object status for the PaymentIntent automatically transitions to requires_
.
このような場合、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。
エラーコード
一般的なエラーコードと対応する推奨アクションは以下のとおりです。
エラーコード | 推奨される対応 |
---|---|
payment_ | Afterpay の決済が失敗したことを示す一般的なエラー。これは、拒否エラーコードとして表示されない拒否である可能性もあります。 |
payment_ | Afterpay が顧客の支払いを拒否しました。次のステップとして、顧客から Afterpay に詳細を問い合わせる必要があります。 |
payment_ | 顧客が Afterpay の決済ページで支払いを完了しておらず、支払いセッションの期限が切れています。Stripe は、最初の決済フローの作成から 3 時間が経過しても正常にオーソリされなかった Payment Intents を自動的に期限切れにします。 |
payment_ | Afterpay でサービス関連のエラーが発生したため、リクエストを完了できません。後で再試行してください。 |
amount_ | Enter an amount within Afterpay’s default transactions limits for the country. |
amount_ | Enter an amount within Afterpay’s default transactions limits for the country. |