Skip to main content
@sapiom/browser-pay intercepts the card request that carries a Sapiom placeholder and relays it through Sapiom. It needs Node.js 18 or later. For a walkthrough, see Pay in the browser.

attachInterceptor(target, options)

Connects to the browser and starts intercepting. Resolves to an InterceptorHandle once interception is active. Fill card fields only after it resolves. target is one of:
  • a CDP WebSocket URL, ws:// or wss://
  • a DevTools discovery URL, http:// or https://, such as http://localhost:9222
  • an object with wsEndpoint(), such as a Puppeteer browser
  • a Puppeteer page, through browser().wsEndpoint()
  • a custom object whose browser() or context().browser() returns an object with wsEndpoint()
Browser Pay opens its own CDP connection, so wsEndpoint() must return a CDP URL. A Puppeteer browser launched with pipe: true has none. Playwright’s Browser and Page have no wsEndpoint(), and BrowserServer returns a Playwright protocol URL. With Playwright, pass the CDP URL here and to chromium.connectOverCDP().

CDP URLs

Discovery URLs need @sapiom/browser-pay 0.4.0 or later. Browser Pay uses a ws:// or wss:// URL as is. For an http:// or https:// URL, it reads webSocketDebuggerUrl from json/version/ under the URL’s path, with its query string, and connects there.
  • webSocketDebuggerUrl must be ws:// or wss://, and wss:// if discovery used https://.
  • Redirects are not followed.
  • A path ending in /devtools/browser/<id> or /devtools/page/<id> skips discovery. Give Playwright the ws:// or wss:// form of such a URL, because connectOverCDP() treats every http(s) URL as discovery.
  • Other schemes are rejected.
Trust the discovery endpoint as much as the browser, because it decides where Browser Pay connects. See Connect your browser provider.

AttachOptions

InterceptorHandle

httpPaymentRelay(options)

Builds a relay that posts to POST /v1/transactions/{transactionId}/payment/relay. Without a profileId, the relay forwards the checkout request’s headers, including Authorization, but not cookie, host or the browser’s sec-* headers. Sapiom records header names, never values.

Events

Event URLs contain only the origin.

Retries

Timeouts, network errors, HTTP 502, 503 and 504, and relay_in_progress are retried with the same idempotency key until timeoutMs. Any other refusal fails the request. A relay that returns outcome: "unknown" is never sent again.

RefusalReason

unknown_injection, injection_expired, payment_released, key_rotated, already_relayed, relay_in_progress, relaying_under_other_key, card_removed, card_unavailable, payment_not_authorized, total_changed, destination_not_allowed, card_fields_invalid, merchant_mismatch, provider_unavailable, merchant_unavailable, payments_stopped, sapiom_error. Each reason’s meaning is in Relay refusals. The reason is unrecognized if the relay’s reason does not match ^[a-z]+(_[a-z]+)*$ or has more than 48 characters. Browser Pay shows all other reasons from the relay without change.

FailureReason

intercept_unavailable, unknown_session, unreadable_body, detached, page_origin, unknown, timeout, network, response_credential, headers_unrelayable. Each reason’s meaning is in Browser Pay failures.

Other exports

Types: AttachOptions, InterceptorEvent, InterceptorHandle, InterceptorTarget, PaymentRelay, RelayCallOptions, RelayRequest, RelayResponse, HeldPlaceholder, PayLogger, HttpRelayOptions, FailureReason, RefusalReason.