本文へ移動
rdlabo.dev

Tap to Pay

Tap to Pay は、対応するスマートフォンやタブレットだけで非接触決済を受け付けます。別のカードリーダーは不要です。設定接続トークンを準備し、TerminalConnectTypes.TapToPay を使用します。

プラットフォーム要件

プラットフォーム 対応 補足
Android 対応 NFC対応端末、位置情報権限、Stripeの利用資格。minSdkVersion 26
iOS 対応 Tap to Pay on iPhone。アカウント確認は iOS 16.4以降
Web 非対応 TapToPay の探索は利用不可

Stripe Dashboard で Terminal を設定し、Location を作成します。その locationIddiscoverReaders に渡してください。

セットアップ手順

  1. アプリケーションレベルのリスナーを登録する。
  2. RequestedConnectionTokensetConnectionToken で認証付きトークンプロバイダーを登録し、initialize を呼ぶ。
  3. iOS では isTapToPayAccountLinked を呼ぶ(結果はキャッシュしない)。
  4. Android では任意で setTapToPayUxConfiguration を呼ぶ。
  5. TapToPaylocationIddiscoverReaders を実行する。
  6. 見つかったリーダーを connectReader へ渡す。
  7. 支払いを受け付けると同様に card_present PaymentIntent を収集・確定する。

method initialize(...)

Initializes the Stripe Terminal SDK and its connection-token provider.
Call this once before discovering readers.

When tokenProviderEndpoint is provided, the plugin sends a POST request
and expects { secret: string }. When it is omitted, handle
RequestedConnectionToken and call setConnectionToken() instead.

initialize(options: StripeTerminalInitializationOptions) => Promise<void>

アカウント連携を確認する

isTapToPayAccountLinked は iOS 16.4以降専用です。事前に initialize() が完了している必要がありますが、リーダー接続やNFCの起動は不要です。結果は呼び出すたび Apple から取得されるため、isLinked をキャッシュしないでください。Stripe Connect では onBehalfOf に連結アカウントIDを渡します。

Android と Web では拒否されるため、プラットフォーム判定または .catch() で保護します。

method isTapToPayAccountLinked(...)

Check whether the merchant has accepted Apple's Tap to Pay on iPhone
Terms and Conditions.

iOS only, and requires iOS 16.4 or later. initialize() must have been
called first because the SDK needs a connection token provider, but no
reader connection is required and the call does not activate the device.

The answer is read from Apple on every call. Apple's Tap to Pay on iPhone
requirements state that acceptance state must be retrieved from Apple
rather than from a local variable, so do not cache the result.

Stripe docs reference

isTapToPayAccountLinked(options?: IsTapToPayAccountLinkedOptions | undefined) => Promise<{ isLinked: boolean; }>

interface IsTapToPayAccountLinkedOptions

Options for isTapToPayAccountLinked.

Prop Type Description Since
onBehalfOf string Connected account ID, for Stripe Connect platforms. Omit to check the account that owns the API key. 8.2.0

UX設定

setTapToPayUxConfiguration は Android 専用です。initialize() 後、connectReader() 前に呼びます。iOS は未実装、Web はログを出して終了します。

Android では colorsdarkMode を反映します。TypeScript の tapZone は宣言されていますが、v8.2.1 の Android Terminal SDK には渡されません。

method setTapToPayUxConfiguration(...)

Configure the Tap to Pay UX appearance (Android only).
Call this after initialize() but before connectReader().
Has no effect on iOS or web platforms.

setTapToPayUxConfiguration(options: TapToPayUxConfiguration) => Promise<void>

interface TapToPayUxConfiguration

Configuration for the Tap to Pay UX (Android only).

Prop Type Description Since
colors TapToPayColorScheme Color scheme for the Tap to Pay screen. 8.1.0
darkMode TapToPayDarkMode Dark-mode setting for the Tap to Pay screen. 8.1.0
tapZone TapToPayTapZone Position of the tap indicator on screen. 8.1.0

interface TapToPayColorScheme

Color scheme for the Tap to Pay screen.

Prop Type Description Since
primary TapToPayColor Primary color for the tap-zone indicator. Use a hex string or default. 8.1.0
success TapToPayColor Success-state color. Use a hex string or default. 8.1.0
error TapToPayColor Error-state color. Use a hex string or default. 8.1.0

type alias TapToPayColor

'default' | string

type alias TapToPayTapZone

{ type: 'default' } | { type: 'front'; xBias: number; yBias: number } | { type: 'behind'; xBias: number; yBias: number } | { type: 'above'; bias?: number } | { type: 'below'; bias?: number } | { type: 'left'; bias?: number } | { type: 'right'; bias?: number }

enum TapToPayDarkMode

Member Value
System 'SYSTEM'
Dark 'DARK'
Light 'LIGHT'

探索して接続する

TerminalConnectTypes.TapToPaylocationId で探索します。シミュレーションでは TerminalConnectTypes.Simulated ではなく、initializeisTest: true を使用します。

探索結果のリーダーを接続します。autoReconnectOnUnexpectedDisconnect は既定で false です。iOS の merchantDisplayNameonBehalfOf は接続設定へ渡され、Android では PaymentIntent 側に設定します。

method discoverReaders(...)

Discovers readers using the requested transport. The returned readers are
snapshots; listen for DiscoveredReaders when continuous discovery can
produce additional results.

discoverReaders(options: DiscoverReadersOptions) => Promise<{ readers: ReaderInterface[]; }>

method connectReader(...)

Connects to a reader returned by discoverReaders().

connectReader(options: ConnectReaderOptions) => Promise<void>

接続後、サーバーで作成した card_present PaymentIntent を collectPaymentMethodconfirmPaymentIntent で処理します。

制限事項

  • Web は Tap to Pay を探索・接続できません。
  • UXの色とダークモードは Android 専用です。
  • アカウント連携状態は iOS 専用で、毎回 Apple から再取得します。
  • tapZone は現在の Android SDK に接続されていません。
  • 任意のリーダー更新を決済中にインストールしないでください。
  • シークレットキーと接続トークン作成はバックエンドに保持してください。