コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要すべての商品を確認する
構築を開始する
開発の開始
    開発環境を設定
    最初の API リクエストを送信
    決済を受け付ける
    新機能の構築とテスト
    本番環境開始のチェックリスト
サンプルプロジェクト
API について
Build with LLMs
ノーコードで Stripe を使用する
Stripe を設定する
アカウントを作成する
ウェブダッシュボード
モバイルダッシュボード
Stripe に移行
不正利用のリスク管理
不正利用について
Radar の不正防止
不審請求の申請の管理
本人確認
ホーム始めるStart developing

注

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

支払いを受け付ける

オンライン支払いを安全に受け付けます。

ページをコピー

支払いフォームを作成するか、構築済みの決済ページを使用して、オンライン決済の受け付けを開始します。

税金、割引、配送料などを管理する Stripe Elements と Checkout セッションを実装して、お客様のウェブサイトに決済ページを構築します。

顧客の場所
サイズ
テーマ
レイアウト
Google Pay または Apple Pay ウォレットのいずれかが関連付けられた有効カードがある場合、このデモでは対応するウォレットのみが表示されます。

サーバを設定する
サーバー側

はじめに、Stripe アカウントを登録する必要があります。

アプリケーションから API にアクセスするには、公式の Stripe ライブラリを使用します。

Command Line
Node
npm install stripe@18.0.0 --save

Set the SDK to use at least the 2025-03-31.basil API version.

TypeScript
// Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys import Stripe from 'stripe'; const stripe = new Stripe(
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
, { apiVersion: '2025-03-31.basil' as any, });

Checkout セッションを作成する
サーバー側

Checkout セッションを作成してその Client Secret をフロントエンドに返すエンドポイントを、サーバーに追加します。Checkout セッションは、顧客が 1 回限りの購入またはサブスクリプションの支払いを行う際のセッションを表します。Checkout セッションは作成後 24 時間で期限切れとなります。

server.ts
TypeScript
import express, {Express} from 'express'; const app: Express = express(); app.post('/create-checkout-session', async (req: Express.Request, res: Express.Response) => { const session = await stripe.checkout.sessions.create({ line_items: [ { price_data: { currency: 'usd', product_data: { name: 'T-shirt', }, unit_amount: 2000, }, quantity: 1, }, ], mode: 'payment', ui_mode: 'custom', // The URL of your payment completion page return_url: 'https://example.com/return?session_id={CHECKOUT_SESSION_ID}' }); res.json({checkoutSessionClientSecret: session.client_secret}); }); app.listen(3000, () => { console.log('Running on port 3000'); });

フロントエンドを設定する
クライアント側

Stripe.js スクリプトをチェックアウトページに含めるには、このスクリプトを HTML ファイルの head に追加します。常に js.stripe.com から Stripe.js を直接読み込むことにより、PCI への準拠が維持されます。スクリプトをバンドルに含めたり、そのコピーを自身でホストしたりしないでください。

You’ll need to update Stripe.js to basil from v3 by including the following script tag <script src="https://js.stripe.com/basil/stripe.js"></script>. Learn more about Stripe.js versioning.

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></script> </head>

注

Stripe provides an npm package that you can use to load Stripe.js as a module. See the project on GitHub. Version 7.0.0 or later is required.

Initialize stripe.js.

checkout.js
// 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(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
, );

Checkout を初期化する
クライアント側

Create a fetchClientSecret function. This function retrieves the client secret from your server and returns a promise that resolves with the client secret. Call initCheckout, passing in fetchClientSecret. initCheckout returns a promise resolving to a checkout instance.

The checkout object acts as the foundation of your checkout page, containing data from the Checkout Session and methods to update the Session.

The object returned by checkout.session() contains your pricing information. We recommend reading and displaying the total, and lineItems from the session in your UI.

This lets you turn on new features with minimal code changes. For example, adding manual currency prices requires no UI changes if you display the total.

checkout.js
const fetchClientSecret = () => { return fetch('/create-checkout-session', {method: 'POST'}) .then((response) => response.json()) .then((json) => json.checkoutSessionClientSecret); }; stripe.initCheckout({fetchClientSecret}) .then((checkout) => { const checkoutContainer = document.getElementById('checkout-container'); checkoutContainer.append(JSON.stringify(checkout.lineItems, null, 2)); checkoutContainer.append(document.createElement('br')); checkoutContainer.append(`Total: ${checkout.session().total.total.amount}`); });
index.html
<div id="checkout-container"></div>

顧客のメールアドレスを収集する
クライアント側

If you already pass in an existing customer_email or Customer with a valid email set when creating the Checkout Session, you can skip this step.

If you implement your own email validation, you can pass in the validated email on checkout.confirm and skip this step.

顧客のメールアドレスを収集するためのメールアドレス入力を作成します。顧客が入力を完了してメールアドレスを検証し、保存したら、updateEmail を呼び出します。

決済フォームのデザインに応じて、次の方法で updateEmail を呼び出すことができます。

  • 支払いの送信の直前。また、updateEmail を呼び出して、早い段階 (ぼかしの入力時など) で検証することもできます。
  • 次のステップに進む前 (フォームが複数のステップからなる場合の保存ボタンのクリック時など)。
index.html
<input type="text" id="email" /> <div id="email-errors"></div>
checkout.js
stripe.initCheckout({fetchClientSecret}).then((checkout) => { const emailInput = document.getElementById('email'); const emailErrors = document.getElementById('email-errors'); emailInput.addEventListener('input', () => { // Clear any validation errors emailErrors.textContent = ''; }); emailInput.addEventListener('blur', () => { const newEmail = emailInput.value; checkout.updateEmail(newEmail).then((result) => { if (result.error) { emailErrors.textContent = result.error.message; } }); }); });

支払い情報を収集する
クライアント側

Payment Element を使用して、クライアントで支払い情報を収集します。Payment Element は、さまざまな決済手段で支払い情報の収集を簡略化する事前構築済みの UI コンポーネントです。

まず、コンテナーの DOM 要素を作成して、Payment Element をマウントします。次に、checkout.createPaymentElement を使用して Payment Element のインスタンスを作成し、element.mount を呼び出してマウントし、CSS セレクターまたはコンテナーの DOM 要素を指定します。

index.html
<div id="payment-element"></div>
checkout.js
const paymentElement = checkout.createPaymentElement(); paymentElement.mount('#payment-element');

See the Stripe.js docs to view what options are supported.

フロントエンドで Checkout を初期化するときに elementsOptions.appearance を渡すことで、すべての Elements のデザインをカスタマイズできるようになります。

支払いを送信する
クライアント側

checkout インスタンスから confirm を呼び出して支払いを送信する「支払う」ボタンをレンダリングします。

index.html
<button id="pay-button">Pay</button> <div id="confirm-errors"></div>
checkout.js
stripe.initCheckout({fetchClientSecret}).then((checkout) => { const button = document.getElementById('pay-button'); const errors = document.getElementById('confirm-errors'); button.addEventListener('click', () => { // Clear any validation errors errors.textContent = ''; checkout.confirm().then((result) => { if (result.type === 'error') { errors.textContent = result.error.message; } }); }); });

構築したシステムをテストする

  1. 決済ページに移動します。
  2. 次の表の決済手段を使用して、支払いの詳細を入力します。カード支払いの場合:
    • カードの有効期限として任意の将来の日付を入力します。
    • 任意の 3 桁のセキュリティコードを入力します。
    • 請求先の任意の郵便番号を入力します。
  3. Stripe に支払いを送信します。
  4. ダッシュボードに移動し、取引ページで支払いを探します。支払いが成功していると、そのリストに表示されます。
  5. 支払いをクリックすると、請求先情報や購入したアイテムのリストなどの詳細が表示されます。この情報を使用して注文のフルフィルメントを実行できます。
カード番号シナリオテスト方法
カード支払いは成功し、認証は必要とされません。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
カード支払いには認証が必要です。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
カードは、insufficient_funds などの拒否コードで拒否されます。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。
UnionPay カードは、13 ~ 19 桁の可変長です。クレジットカード番号と、任意の有効期限、セキュリティコード、郵便番号を使用してクレジットカードフォームに入力します。

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

オプション製品および価格の作成

オプション顧客データを事前入力する
サーバー側

オプション支払い方法の詳細を保存する

オプションCollect billing and shipping addresses

オプションオーソリとキャプチャーを分離する
サーバー側

オプション顧客のアカウントの管理
コーディング不要

オプション注文のフルフィルメント

参照情報

  • 1 回限りの支払いに割引を追加する
  • 税金を徴収する
  • 項目の数を調整可能にする
  • ワンクリックボタンの追加
このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc
Code quickstart
関連ガイド
Elements Appearance API
その他の決済シナリオ
カードの仕組み
使用製品
Payments
Elements
Checkout