コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要
Stripe Payments について
構築済みのシステムをアップグレード
支払いの分析
オンライン決済
概要ユースケースを見つけるManaged Payments
Payment Links を使用する
決済ページを構築
高度なシステムを構築
アプリ内実装を構築
    概要
    Payment Sheet
      アプリ内での決済を受け付け
      カスタムの支払い方法を追加する
      デザインをカスタマイズする
      サーバーで支払いを確定する
      支払い中に支払い詳細を保存する
      将来の支払いを設定する
      カードブランドを絞り込む
    Embedded Payment Element
    アプリ内購入のリンク
    住所を収集
    アメリカとカナダのカード
決済手段
決済手段を追加
決済手段を管理
Link による購入の迅速化
支払いインターフェイス
Payment Links
Checkout
Web Elements
アプリ内 Elements
決済シナリオ
カスタムの決済フロー
柔軟なアクワイアリング
オーケストレーション
店頭支払い
端末
他の Stripe プロダクト
Financial Connections
仮想通貨
Climate
ホーム支払いBuild an in-app integrationPayment Sheet

注

このページはまだ日本語ではご利用いただけません。より多くの言語で文書が閲覧できるように現在取り組んでいます。準備が整い次第、翻訳版を提供いたしますので、もう少しお待ちください。

サーバーで決済を確定

PaymentIntent または SetupIntent を作成する前にモバイル決済要素をレンダリングする組み込みを構築し、サーバーからインテントを確認します。

ページをコピー

Payment Element を使用すると、一度の導入で複数の決済手段を受け付けることができます。この実装では、Payment Element をレンダリングし、PaymentIntent を作成して、購入者のサーバーで支払いを確定するカスタム決済フローを構築します。

Stripe を設定する
サーバー側
クライアント側

サーバー側

この組み込みは、Stripe API と通信するサーバー上にエンドポイントを必要とします。サーバーから Stripe API にアクセスするには、次のように Stripe の公式ライブラリーを使用します。

Command Line
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

クライアント側

Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 13 以降をサポートするアプリと互換性があります。

SDK をインストールするには、以下のステップに従います。

  1. In Xcode, select File > Add Package Dependencies… and enter https://github.com/stripe/stripe-ios-spm as the repository URL.
  2. リリースページから最新のバージョン番号を選択します。
  3. StripePaymentSheet 製品をアプリのターゲットに追加します。

注

For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.

You also need to set your publishable key so that the SDK can make API calls to Stripe. To get started quickly, you can hardcode this on the client while you’re integrating, but fetch the publishable key from your server in production.

// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys STPAPIClient.shared.publishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"

支払い方法を有効にする

支払い方法の設定を表示して、サポートする支払い方法を有効にします。PaymentIntent を作成するには、少なくとも 1 つは支払い方法を有効にする必要があります。

By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, but we recommend turning on additional payment methods that are relevant for your business and customers. See Payment method support for product and payment method support, and our pricing page for fees.

戻り先 URL を設定する
クライアント側

The customer might navigate away from your app to authenticate (for example, in Safari or their banking app). To allow them to automatically return to your app after authenticating, configure a custom URL scheme and set up your app delegate to forward the URL to the SDK. Stripe doesn’t support universal links.

SceneDelegate.swift
Swift
// This method handles opening custom URL schemes (for example, "your-app://stripe-redirect") func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let url = URLContexts.first?.url else { return } let stripeHandled = StripeAPI.handleURLCallback(with: url) if (!stripeHandled) { // This was not a Stripe url – handle the URL normally as you would } }

Additionally, set the returnURL on your PaymentSheet.Configuration object to the URL for your app.

var configuration = PaymentSheet.Configuration() configuration.returnURL = "your-app://stripe-redirect"

支払いの詳細を収集する
クライアント側

実装には 2 つのスタイルを利用できます。いずれかを選択して、続行してください。

PaymentSheetPaymentSheet.FlowController
PaymentSheet
PaymentSheet.FlowController
支払い情報を収集して支払いを完了する画面を表示します。画面に $X を支払うというボタンが表示され、支払いが完了します。支払い情報の収集のみを行う画面を表示します。画面に続行するというボタンが表示され、顧客はアプリに戻され、ご自身のボタンで支払いが完了されます。

PaymentSheet を初期化する

When you’re ready to accept a payment (for example, when a customer taps your checkout button), initialize the PaymentSheet with a PaymentSheet.Configuration and a PaymentSheet.IntentConfiguration. The Configuration object contains the general configuration for the PaymentSheet that typically doesn’t change between payments, like the returnURL. The IntentConfiguration object contains details about the specific payment, like the amount and currency, as well as a confirmHandler callback—for now, leave its implementation empty.

import StripePaymentSheet class MyCheckoutVC: UIViewController { func didTapCheckoutButton() { let intentConfig = PaymentSheet.IntentConfiguration( mode: .payment(amount: 1099, currency: "USD") ) { [weak self] paymentMethod, shouldSavePaymentMethod, intentCreationCallback in self?.handleConfirm(paymentMethod, shouldSavePaymentMethod, intentCreationCallback) } var configuration = PaymentSheet.Configuration() configuration.returnURL = "your-app://stripe-redirect" // Use the return url you set up in the previous step let paymentSheet = PaymentSheet(intentConfiguration: intentConfig, configuration: configuration) } func handleConfirm(_ paymentMethod: STPPaymentMethod, _ shouldSavePaymentMethod: Bool, _ intentCreationCallback: @escaping (Result<String, Error>) -> Void) { // ...explained later } }

PaymentSheet を提示する

次に、PaymentSheet を提示します。present メソッドは、顧客が支払いを完了して画面が非表示になったときに呼び出される完了ブロックを使用します。結果を処理する完了ブロックを実装します (たとえば、.completed のケースで領収書や確認画面を表示するなど)。

class MyCheckoutVC: UIViewController { func didTapCheckoutButton() { // ... paymentSheet.present(from: self) { result in switch result { case .completed: // Payment completed - show a confirmation screen. case .failed(let error): print(error) // PaymentSheet encountered an unrecoverable error. You can display the error to the user, log it, etc. case .canceled: // Customer canceled - you should probably do nothing. } } } }

支払いを確定する

When the customer taps the Pay button in the PaymentSheet, it calls the callback you passed to PaymentSheet.IntentConfiguration with an STPPaymentMethod object representing the customer’s payment details.

このコールバックを実装してサーバーにリクエストを送信し、paymentMethod.stripeId と shouldSavePaymentMethod を渡します。サーバーは、PaymentIntent を作成して、その client secret を返します。

リクエストが返されたら、サーバーレスポンスの client secret またはエラーを指定して intentCreationCallback を呼び出します。PaymentSheet は、client secret を使用して PaymentIntent を完了するために必要な次のアクションを実行するか、UI に現地の言語でエラーメッセージ (errorDescription または localizedDescription) を表示します。

class MyCheckoutVC: UIViewController { // ... func handleConfirm(_ paymentMethod: STPPaymentMethod, _ shouldSavePaymentMethod: Bool, _ intentCreationCallback: @escaping (Result<String, Error>) -> Void) { // Make a request to your own server, passing paymentMethod.stripeId and shouldSavePaymentMethod, and receive a client secret or an error.. let myServerResponse: Result<String, Error> = ... switch myServerResponse { case .success(let clientSecret): // Call the `intentCreationCallback` with the client secret intentCreationCallback(.success(clientSecret)) case .failure(let error): // Call the `intentCreationCallback` with the error intentCreationCallback(.failure(error)) } } }

決済を作成して Stripe に送信する
サーバー側

サーバー側で、金額と通貨を指定して PaymentIntent を作成し、確定します。支払い方法はダッシュボードで管理できます。Stripe は取引額、通貨、決済フローなどの要素に基づいて、適切な支払い方法が返されるように処理します。悪意のある顧客が金額を恣意的に選択できないようにするために、請求額はクライアント側ではなく、常にサーバー側 (信頼性の高い環境) で指定してください。

コールが成功した場合は、PaymentIntent client secret を返します。コールが失敗した場合は、エラーを処理して、エラーメッセージと顧客向けの簡単な説明を返します。

クライアント側の引数の処理:

  • payment_method_id: この ID を使用して PaymentMethod オブジェクトを取得し、自社で構築済みの検証やビジネスロジックを実行できます。
  • should_save_payment_method - This flag controls whether or not the customer requested to save their payment method with you in the PaymentSheet UI. If true, set setup_future_usage to “off_session”.

注

When confirming a PaymentIntent from the server, pass it the mandate_data parameter to acknowledge that you’ve shown the customer the proper terms for collecting their payment details. To make sure you display the proper terms, be sure that all IntentConfiguration properties match your PaymentIntent (for example, setup_future_usage, amount, and currency).

main.rb
Ruby
require 'stripe' Stripe.api_key =
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
post '/create-intent' do data = JSON.parse request.body.read params = { amount: 1099, currency: 'usd', # In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. automatic_payment_methods: {enabled: true}, confirm: true, payment_method: data['payment_method_id'], # the PaymentMethod ID sent by your client return_url: 'your-app://stripe-redirect', # Use the return url you set up in the previous step mandate_data: { customer_acceptance: { type: "online", online: { ip_address: request.ip, user_agent: request.user_agent }, }, }, } if data['should_save_payment_method'] params[:setup_future_usage] = "off_session" # Set setup_future_usage if should_save_payment_method is true end begin intent = Stripe::PaymentIntent.create(params) {client_secret: intent.client_secret}.to_json rescue Stripe::StripeError => e {error: e.error.message}.to_json end end

支払い後のイベントを処理する
サーバー側

支払いが完了すると、Stripe は payment_intent.succeeded イベントを送信します。ダッシュボードの Webhook ツールを使用するか Webhook のガイドに従ってこれらのイベントを受信し、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。

クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアントでは、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了する場合、また悪意を持つクライアントがレスポンスを不正操作する場合もあります。非同期型のイベントをリッスンするよう組み込みを設定すると、単一の組み込みで複数の異なるタイプの支払い方法を受け付けることができます。

Payment Element を使用して支払いを回収する場合は、payment_intent.succeeded イベントのほかにこれらのイベントを処理することをお勧めします。

イベント説明アクション
payment_intent.succeeded顧客が正常に支払いを完了したときに送信されます。顧客に注文の確定を送信し、顧客の注文のフルフィルメントを実行します。
payment_intent.processing顧客が正常に支払いを開始したが、支払いがまだ完了していない場合に送信されます。このイベントは、多くの場合、顧客が口座引き落としを開始するときに送信されます。その後、payment_intent.succeeded イベント、また、失敗の場合は payment_intent.payment_failed イベントが送信されます。顧客に注文確認メールを送信し、支払いが保留中であることを示します。デジタル商品では、支払いの完了を待たずに注文のフルフィルメントを行うことが必要になる場合があります。
payment_intent.payment_failed顧客が支払いを試みたが、支払いに失敗する場合に送信されます。支払いが processing から payment_failed に変わった場合は、顧客に再度支払いを試すように促します。

実装をテストする

カード番号シナリオテスト方法
カード支払いは成功し、認証は必要とされません。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
カード支払いには認証が必要です。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
カードは、insufficient_funds などの拒否コードで拒否されます。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
UnionPay カードは、13 ~ 19 桁の可変長です。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。

実装内容をテストするためのその他の情報については、テストをご覧ください。

オプション保存済みのカードを有効にする
サーバー側
クライアント側

オプション遅延型の支払い方法を許可する
クライアント側

オプションApple Pay を有効にする

オプションカードのスキャンを有効にする

オプション画面をカスタマイズする

このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc