コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要すべての商品を確認する
構築を開始する
開発の開始
サンプルプロジェクト
API について
    API ツアー
    Payment Intents API
    Setup Intents API
    決済手段
    商品と価格
    以前の API
      支払い
        新しい API への移行
        カード支払いを受け付ける
        カードを保存する
        カードの売上を保留する
        Connect を利用した支払い
      Sources
    リリースフェーズ
Build with LLMs
ノーコードで Stripe を使用する
Stripe を設定する
アカウントを作成する
ウェブダッシュボード
モバイルダッシュボード
Stripe に移行
不正利用のリスク管理
不正利用について
Radar の不正防止
不審請求の申請の管理
本人確認
ホーム始めるAbout the APIsOlder APIsCharges

注

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

Stripe Elements と Charges API を使用して決済を受け付けるCharges API

アメリカ合衆国およびカナダの顧客からのオンライン決済を受け付けます。

ページをコピー

レガシーの API

The content of this section refers to a Legacy feature. Use the Payment Intents API instead.

Charges API は、以下の機能をサポートしていません。これらの多くはクレジットカードのコンプライアンスのために必要となります。

  • インドの加盟店
  • カード認証に関する銀行のリクエスト
  • 強力な顧客認証 (SCA)

Stripe の事前構築された UI コンポーネントを使用して支払いフォームを作成すると、機密データを処理することなく、顧客のカード詳細を安全に収集することができます。カード詳細は、それを示す Token に変換され、安全にサーバーに送信することができます。お客様のサーバーはそのトークンを使用して支払いを作成できます。

注

このガイドの手順は、GitHub に完全な実装があります。リポジトリのクローンを作成し、手順に従ってデモ用のアプリを実行します。

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 Android SDK はオープンソースであり、詳細なドキュメントが提供されています。

To install the SDK, add stripe-android to the dependencies block of your app/build.gradle file:

build.gradle.kts
Kotlin
plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Android SDK implementation("com.stripe:stripe-android:21.13.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:21.13.0") }

注

SDK の最新リリースおよび過去バージョンの詳細については、GitHub の Releases ページをご覧ください。新しいリリースの公開時に通知を受け取るには、リポジトリのリリースを確認してください。

Stripe の公開可能キーを使用して SDK を設定し、 Application サブクラスなどで、Stripe API へのリクエストを実行できるようにします。

Kotlin
import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext,
"pk_test_TYooMQauvdEDq54NiTphI7jx"
) } }

注

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

独自の支払いフォームの作成
クライアント側

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

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

以下を決済ページのレイアウトに追加し、カードコンポーネントのインスタンスを作成し、支払い ボタンを作成します。

content_checkout.xml
サンプル全体を表示
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_checkout" tools:context=".CheckoutActivity"> <!-- ... --> <com.stripe.android.view.CardInputWidget android:id="@+id/cardInputWidget" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp"/> <Button android:text="Pay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/payButton" android:layout_marginTop="20dp" app:layout_constraintTop_toBottomOf="@+id/cardInputWidget" app:layout_constraintStart_toStartOf="@+id/cardInputWidget" app:layout_constraintEnd_toEndOf="@+id/cardInputWidget"/> <!-- ... --> </androidx.constraintlayout.widget.ConstraintLayout>

アプリを実行し、決済ページにカードコンポーネントと支払いボタンが表示されることを確認します。

トークンの作成
クライアント側

ユーザーが支払いボタンをタップしたら、CardInputWidget で収集されたカード情報を Stripe トークンに変換します。トークン化により、機密情報であるカードデータはお客様のサーバーを介することがなくなるため、お客様のシステムは PCI 準拠を維持できます。

以下のコードは、Stripe#createToken() の使用方法を示したものです。このメソッドは Card インスタンスを最初のパラメータとして使用します。2 番目のパラメータは ApiResultCallback<Token> インスタンスで、成功または失敗時にクライアントによって呼び出されます。トークン化が成功したら、返されたトークン ID をサーバに送信します。

CheckoutActivityKotlin.kt
Kotlin
サンプル全体を表示
// Hook up the pay button to the card widget and Stripe instance val payButton: Button = findViewById(R.id.payButton) val weakActivity = WeakReference<Activity>(this@CheckoutActivityKotlin) payButton.setOnClickListener { // Get the card details from the card widget val cardInputWidget = findViewById<CardInputWidget>(R.id.cardInputWidget) cardInputWidget.card?.let { card -> // Create a Stripe token from the card details stripe = Stripe(applicationContext, PaymentConfiguration.getInstance(applicationContext).publishableKey) stripe.createToken(card, object: ApiResultCallback<Token> { override fun onSuccess(result: Token) { val tokenID = result.id // Send the Token identifier to the server... } override fun onError(e: java.lang.Exception) { // Handle error } }) } }

クライアントから、Token id をサーバーに送信します。

トークンでの支払いの作成
サーバ側

Command Line
curl
curl https://api.stripe.com/v1/charges \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -d "amount"=999 \ -d "currency"="usd" \ -d "description"="Example charge" \ -d "source"="tok_visa"

支払いの作成の応答は、Charge (支払い) またはエラーコードを含む Error (エラー) のいずれかになります。応答が成功の場合は、顧客の注文のフルフィルメントを行い、成功ページを表示できます。それ以外の場合は、エラーを表示できます。

組み込みのテスト

カード Element にテストカードを入力したら、それをサーバに送信し、サーバが支払いを作成したかどうか確認します。これで組み込みは終了です。

カード決済の受け付けをすぐに開始できる Charges API 実装が作成されました。この API は、アメリカとカナダ以外の企業や顧客の規模拡大には対応していません。より堅牢でグローバルな決済ついては、Payment Intents API を使用した決済の受け付けをご確認ください。

参照情報

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