コンテンツにスキップ
アカウントを作成
または
サインイン
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 integration

注

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

銀行認証なしのカード支払い

地域的な制限があるシンプルなモバイルシステムを構築します。

ページをコピー

この実装は、アメリカとカナダのカードのみを受け付けるビジネスをサポートしています。シンプルですが、グローバルな顧客ベースをサポートするように拡張することはできません。

この組み込みはどのように機能しますか?

これはグローバルな組み込みとはどう違いますか?

成長を遂げている企業やグローバル企業には、Stripe のグローバルなシステムを使用して、銀行の 2 段階認証の要求に対応し、顧客がより広範な支払い方法を使用できるようにすることをお勧めします。

Stripe iOS SDK をインストールする
クライアント側

まず、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. StripePaymentsUI 製品をアプリのターゲットに追加します。

注

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.

アプリの起動時に Stripe 公開可能キーを使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。

AppDelegate.swift
Swift
import UIKit import StripePaymentsUI @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
// do any other necessary launch configuration return true } }

注

Use your test keys while you test and develop, and your live mode keys when you publish your app.

カード詳細を収集する
クライアント側

カード番号、有効期限、セキュリティコード、郵便番号を収集する SDK で提供されるドロップイン UI コンポーネントである STPPaymentCardTextField を使用して、クライアント側でカード情報を安全に収集します。

STPPaymentCardTextField は、その時点で検証と形式の設定を行います。

以下のコードを使用して、カードコンポーネントのインスタンスを作成し、支払う ボタンを作成します。

CheckoutViewController.swift
Swift
import UIKit import StripePaymentsUI class CheckoutViewController: UIViewController { lazy var cardTextField: STPPaymentCardTextField = { let cardTextField = STPPaymentCardTextField() return cardTextField }() lazy var payButton: UIButton = { let button = UIButton(type: .custom) button.layer.cornerRadius = 5 button.backgroundColor = .systemBlue button.titleLabel?.font = UIFont.systemFont(ofSize: 22) button.setTitle("Pay", for: .normal) button.addTarget(self, action: #selector(pay), for: .touchUpInside) return button }() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white let stackView = UIStackView(arrangedSubviews: [cardTextField, payButton]) stackView.axis = .vertical stackView.spacing = 20 stackView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(stackView) NSLayoutConstraint.activate([ stackView.leftAnchor.constraint(equalToSystemSpacingAfter: view.leftAnchor, multiplier: 2), view.rightAnchor.constraint(equalToSystemSpacingAfter: stackView.rightAnchor, multiplier: 2), stackView.topAnchor.constraint(equalToSystemSpacingBelow: view.safeAreaLayoutGuide.topAnchor, multiplier: 2), ]) } @objc func pay() { // ... } }

アプリを実行し、チェックアウトページにカードコンポーネントが表示されることを確認します。顧客が 支払う をタップしたら、createPaymentMethod を呼び出してカード詳細を収集し、PaymentMethod を作成します。その PaymentMethod の ID をサーバーに送信します。

CheckoutViewController.swift
Swift
func pay() { // Create a PaymentMethod with the card text field's card details STPAPIClient.shared.createPaymentMethod(with: cardTextField.paymentMethodParams) { (paymentMethod, error) in guard let paymentMethod = paymentMethod else { // Display the error to the customer return } let paymentMethodID = paymentMethod.stripeId // Send paymentMethodID to your server for the next step } }

支払いの作成
サーバー側

サーバー上で、クライアントからリクエストを受信するエンドポイントを設定します。サーバーから Stripe API にアクセスするには、公式ライブラリを使用します。

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 は PaymentIntent オブジェクトを使用して、顧客から支払いを回収するお客様の意図を示し、プロセス全体を通して請求の実施と支払い状態の変化を追跡します。

ステップ 2. のリクエストに応答する HTTP エンドポイントを作成します。そのエンドポイントで、顧客にいくら請求するかを決定します。支払いを作成するには、以下のパラメーターで、ステップ 2 からの PaymentMethod ID を使用して PaymentIntent を作成します。

クライアント側ではなく、信頼できる環境のサーバー側で常に支払い金額を指定してください。これにより、悪意のある顧客が独自の金額を選択できないようにします。

Command Line
curl
# Check the status of the PaymentIntent to make sure it succeeded curl https://api.stripe.com/v1/payment_intents \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
: \ -d amount=1099 \ -d currency=usd \ # A PaymentIntent can be confirmed some time after creation, # but here we want to confirm (collect payment) immediately. -d confirm=true \ -d payment_method="{{PAYMENT_METHOD_ID}}" \ # If the payment requires any follow-up actions from the # customer, like two-factor authentication, Stripe will error # and you will need to prompt them for a new payment method. -d error_on_requires_action=true

警告

支払いを確定する際に、error_on_requires_action を true に設定すると、ユーザーから 2 段階認証が必要とされる場合、Stripe はその支払いを自動的に拒否します。

Payment Intents API レスポンス

API で支払いを作成すると、そのレスポンスには PaymentIntent のステータスが含まれます。支払いが成功した場合には、ステータスは succeeded になります。

{ "id": "pi_0FdpcX589O8KAxCGR6tGNyWj", "object": "payment_intent", "amount": 1099, "charges": { "object": "list", "data": [ { "id": "ch_GA9w4aF29fYajT", "object": "charge", "amount": 1099, "refunded": false, "status": "succeeded", } ] }, "client_secret": "pi_0FdpcX589O8KAxCGR6tGNyWj_secret_e00tjcVrSv2tjjufYqPNZBKZc", "currency": "usd", "last_payment_error": null, "status": "succeeded", }

支払いが拒否されると、そのレスポンスにはエラーコードとエラーメッセージが含まれます。以下は、カードに 2 段階認証が必要とされるために支払いが拒否された例です。

{ "error": { "code": "authentication_required", "decline_code": "authentication_not_handled", "doc_url": "https://docs.stripe.com/error-codes#authentication-required", "message": "This payment required an authentication action to complete, but `error_on_requires_action` was set. When you're ready, you can upgrade your integration to handle actions at https://stripe.com/docs/payments/payment-intents/upgrade-to-handle-actions.", "payment_intent": { "id": "pi_1G8JtxDpqHItWkFAnB32FhtI", "object": "payment_intent", "amount": 1099, "status": "requires_payment_method", "last_payment_error": { "code": "authentication_required", "decline_code": "authentication_not_handled", "doc_url": "https://docs.stripe.com/error-codes#authentication-required", "message": "This payment required an authentication action to complete, but `error_on_requires_action` was set. When you're ready, you can upgrade your integration to handle actions at https://stripe.com/docs/payments/payment-intents/upgrade-to-handle-actions.", "type": "card_error" }, }, "type": "card_error" } }

組み込みをテストする

この実装の準備ができていることを確認するために、テスト環境で使用できるテストカードがいくつかあります任意のセキュリティコード、郵便番号、および今後の有効期限を指定して使用します。

数字説明
支払いが成功し、すぐに処理されます。
常に支払い拒否コード insufficient_funds で失敗します。
認証を必要とします。この組み込みでは authentication_not_handled という拒否コードで失敗します。

テストカードの全一覧をご覧ください。

カード認証を処理するために組み込みをアップグレードする

基本的なカード支払い用の支払い組み込みが完了しました。この組み込みは、支払い中に認証を必要とするカードを拒否する ことにご注意ください。

ダッシュボードで、Failed としてリストされた支払いを見かけるようになったら、組み込みをアップグレードしてください。Stripe のグローバル組み込みは、そのような支払いを自動的に拒否せずに処理します。

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