Unified Click to Pay — Client API Reference
Reference for the Unified Click to Pay client API in the BR-DGE Web SDK, including setup, identification, payment, session methods, and data structures.
Client setup
create()
create()comcarde.visaClickToPay.create(options) → Promise<VisaCtpClient>Builds an un-initialised client. Synchronous in effect — no network or DOM side-effects — so it's safe to call on every page load, before you know whether the consumer will use Click to Pay at all.
| Name | Type | Required | Description |
|---|---|---|---|
options.client | Client | Required | A Comcarde Web SDK client instance, already created via comcarde.client.create(). |
options.authorization | string | Required | Merchant bearer token used to authenticate backend calls made by this client. |
// Runs once, on page load — before the consumer has done anything.
const client = await comcarde.client.create({ authorization: token });
const clickToPay = await comcarde.visaClickToPay.create({ client, authorization: token });Throws: INSTANTIATION_OPTION_REQUIRED (when neither client nor authorization is passed)
initializeClickToPay()
initializeClickToPay()client.initializeClickToPay(options) → Promise<InitResult>Loads the wallet script and mints a session for the given amount. Call it once, before getCards() or processPayment() — and call it again whenever the amount or currency changes.
| Name | Type | Required | Description |
|---|---|---|---|
amount | string | Required | Decimal amount as a string, e.g. '10.00'. Never a number, never minor units. |
currencyCode | string | Required | ISO 4217 currency code, e.g. 'GBP'. |
locale | string | Optional | BCP 47 locale with an underscore separator, e.g. 'en_GB'. Defaults to the browser locale. |
sessionEndpoint | string | Optional | Overrides the backend path used to mint the session. |
RETURNS
Resolves with { client, status, warning }, plus error when status is REINIT_FAILED.
Calling with the same amount and currencyCode as the current session resolves immediately with the cached result. A re-initialisation that fails restores the prior session rather than leaving the client unusable — resolved as REINIT_FAILED, not a rejection.
status | warning / error | Meaning |
|---|---|---|
SUCCESS | — | Ready. getCards() and processPayment() can be called. |
PARTIAL | warning | The session is usable, but the wallet script reported a non-fatal startup issue. warning.code / warning.message describe it; warning.code is the wallet script's own code, or VISA_CTP_SDK_INITIALIZE_FAILED when it gives none. |
REINIT_FAILED | error | A re-initialisation (amount/currency change) failed; the previous session was restored automatically. error is the error that caused the failure (for example VISA_CTP_SESSION_FAILED), or VISA_CTP_REINIT_FAILED when the cause was not a ComcardeError. |
const result = await clickToPay.initializeClickToPay({
amount: '10.00',
currencyCode: 'GBP'
});
if (result.status === 'PARTIAL') {
// still usable — log result.warning and continue
}Throws: VISA_CTP_INVALID_OPTIONS, VISA_CTP_SESSION_FAILED, VISA_CTP_SDK_LOAD_ERROR, VISA_CTP_INVALID_JWT, VISA_CTP_INITIALIZATION_FAILED
updateAmount()
updateAmount()client.updateAmount(update) → { amount, currencyCode }Updates the amount and currency held on the client, which encryptCard() and ENROLL_AND_CHECKOUT read. It does not change the active session. To change the amount on the session, call initializeClickToPay() with the new figures instead: it re-mints the session automatically. Don't call updateAmount() first, because initializeClickToPay() then sees an unchanged amount and returns the existing session. Synchronous: it returns the new values directly and throws rather than rejecting.
| Name | Type | Required | Description |
|---|---|---|---|
amount | string | Required | New decimal amount, e.g. '7.99'. |
currencyCode | string | Required | New ISO 4217 currency code. |
clickToPay.updateAmount({ amount: '7.99', currencyCode: 'GBP' });Throws: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS
Identification
getCards()
getCards()client.getCards(consumerIdentity) → Promise<GetCardsResult>Looks up saved cards for the given identity. The identity is cached on the client so verifyOtp() and resendOtp() can reuse it without being passed it again. Async.
| Name | Type | Required | Description |
|---|---|---|---|
identityValue | string | Required | The email address or phone number the consumer typed. |
identityType | 'EMAIL_ADDRESS' | 'MOBILE_PHONE_NUMBER' | Required | Case-sensitive, upper snake case. |
RETURNS
One of two shapes, depending on whether the identity needs verifying first:
{
status: 'SUCCESS',
cards: [{
id: 'c_8f2a...',
brand: 'Consumer Debit',
lastFour: '1881',
expiryMonth: '09',
expiryYear: '2027',
artUri: 'https://…/art.png',
displayText: 'Consumer Debit ....1881'
}]
}{
status: 'OTP_REQUIRED',
maskedEmail: 'jo***@example.com',
maskedPhone: null
}status: 'SUCCESS' with an empty cards array means the consumer has no cards on file, or is not recognised by Click to Pay at all. Route to your add-card screen.
const result = await clickToPay.getCards({
identityValue: '[email protected]',
identityType: 'EMAIL_ADDRESS'
});
if (result.status === 'OTP_REQUIRED') {
// show the OTP screen, then call verifyOtp()
}Throws: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS, VISA_CTP_LOOKUP_FAILED. If the wallet script itself rejects the lookup, that error is passed through as-is rather than as a ComcardeError.
verifyOtp()
verifyOtp()client.verifyOtp(options) → Promise<{ status, cards }>Confirms the one-time code the consumer typed and returns their card list. Requires a prior getCards() call in the same client instance — that's where the identity being verified comes from. Async.
| Name | Type | Required | Description |
|---|---|---|---|
validationData | string | Required | The code the consumer entered. |
{ status: 'SUCCESS', cards: [ /* same shape as getCards() */ ] }Remember this device. If your OTP screen offers a "skip verification next time" checkbox, that consent travels on
processPayment()'scomplianceSettings— never onverifyOtp().
Throws: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS, VISA_CTP_OTP_INVALID, VISA_CTP_OTP_EXPIRED, VISA_CTP_OTP_LOCKED, VISA_CTP_LOOKUP_FAILED
resendOtp()
resendOtp()client.resendOtp(options?) → Promise<{ status, maskedValidationChannel }>Requests that a new verification code be sent to the consumer's registered channel. Rate-limited — don't offer unlimited retries on your resend button. Async.
| Name | Type | Required | Description |
|---|---|---|---|
requestedValidationChannelId | string | Optional | Requests a specific delivery channel when the consumer has more than one on file. |
document.getElementById('resend').addEventListener('click', () => {
clickToPay.resendOtp().catch(showError);
});Throws: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS, VISA_CTP_OTP_RATE_LIMITED, VISA_CTP_LOOKUP_FAILED
Card handling
encryptCard()
encryptCard()client.encryptCard(pan, sessionOptions?) → Promise<{ encryptedCard, brand }>Encrypts a raw card so it can be enrolled or checked out. For most integrations, prefer letting your card-capture component call this on your behalf using getSessionJwt() — this method exists for merchants who hold the raw PAN directly. Unlike every other method here, it does not require a prior initializeClickToPay() call: it will mint its own session if you pass amount and currencyCode. Async.
| Name | Type | Required | Description |
|---|---|---|---|
pan.primaryAccountNumber | string | Required | The card number. |
pan.panExpirationMonth | string | Required | Two-digit month. |
pan.panExpirationYear | string | Required | Four-digit year. |
pan.cardholderName | string | Required | Name as printed on the card. |
pan.cardSecurityCode | string | Required | CVV / CVC. |
sessionOptions.amount | string | Optional* | Required only if no session exists yet on this client. |
sessionOptions.currencyCode | string | Optional* | Required only if no session exists yet on this client. |
sessionOptions.locale | string | Optional | Used only when a session is minted. Defaults as for initializeClickToPay(). |
sessionOptions.sessionEndpoint | string | Optional | Used only when a session is minted. Overrides the backend session path. |
* If omitted, the amount and currency last set on the client (by initializeClickToPay() or updateAmount()) are used.
RETURNS
{ encryptedCard: 'eyJhbGciOi...', brand: 'Consumer Debit' }Throws: VISA_CTP_INVALID_OPTIONS, VISA_CTP_SESSION_FAILED, VISA_CTP_INVALID_JWT, VISA_CTP_ENCRYPTION_FAILED
Payment
processPayment()
processPayment()client.processPayment(options) → Promise<{ status, paymentInstrument, authenticationDetails? }>The single entry point for taking payment, whatever card the consumer chose. Dispatches on options.action. Resolves once a single-use payment instrument has been minted — it does not itself call your /payments endpoint and does not run any 3-D Secure challenge; hand the returned nonce to your existing payment call exactly as you would for a typed-in card. To decide whether your payment call needs 3-D Secure, opt in to authenticationDetails. See Authentication details. Async.
Always send
complianceSettingsonCHECKOUT_SAVED_CARDandENROLL_AND_CHECKOUT, even when the consumer has not opted into anything. It reads as optional from the type signature, but omitting it entirely causes checkout to fail — send aPRIVACY_POLICYorTERMS_AND_CONDITIONSresource as a baseline, and addREMEMBER_MEonly when the consumer ticked that box. Go to ComplianceSettings.
CHECKOUT_SAVED_CARD
CHECKOUT_SAVED_CARDConsumer picked a card already returned by getCards() / verifyOtp().
| Name | Type | Required | Description |
|---|---|---|---|
cardId | string | Required | The id from the chosen card. |
complianceSettings | ComplianceSettings | Required in practice | Not enforced by the type signature, but checkout fails without at least one resource. See note above. |
includeAuthenticationDetails | boolean | Optional | When true, the result includes authenticationDetails. Defaults to false. See Authentication details. |
ENROLL_AND_CHECKOUT
ENROLL_AND_CHECKOUTNew card, saved for next time and paid with in the same step.
| Name | Type | Required | Description |
|---|---|---|---|
encryptedCard | string | One of these | Preferred. Output of your card-capture component's own encrypt call. |
pan | PanInput | One of these | Legacy path for callers holding a raw PAN — internally routed through encryptCard(). |
consumer | Consumer | Optional | Identity/contact details forwarded with the enrolment. See Consumer. |
complianceSettings | ComplianceSettings | Required in practice | Not enforced by the type signature, but checkout fails without at least one resource. See note above. |
includeAuthenticationDetails | boolean | Optional | When true, the result includes authenticationDetails. Defaults to false. See Authentication details. |
TOKENIZE
TOKENIZENew card, pay once — nothing is saved to Click to Pay.
| Name | Type | Required | Description |
|---|---|---|---|
hostedFieldsToken | string | Required | Token from your card-capture component's tokenize call. |
includeAuthenticationDetails is ignored for TOKENIZE. The card never passes through Click to Pay checkout, so there is no network authentication result to return.
RETURNS
CHECKOUT_SAVED_CARD / ENROLL_AND_CHECKOUT
{
status: 'SUCCESS',
paymentInstrument: {
type: 'clickToPay',
nonce: 'nonce_9f3c...'
},
// Only present when includeAuthenticationDetails: true
authenticationDetails: {
eci: '05',
verificationData: [ /* passed through from the card network */ ]
}
}TOKENIZE
{
status: 'SUCCESS',
paymentInstrument: {
type: 'tokenized',
token: 'tok_1a2b...'
}
}The active session is consumed by this call, whether it succeeds or fails. You don't need to handle this explicitly — the next
initializeClickToPay()detects it and mints a fresh session automatically (seegetInitStatus()).
const result = await clickToPay.processPayment({
action: 'CHECKOUT_SAVED_CARD',
cardId: selectedCard.id
});
const nonce = result.paymentInstrument.nonce;
// POST { paymentInstrument: { type: 'clickToPay', nonce } } to /v1/paymentsThrows: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS, VISA_CTP_CARD_NETWORK_NOT_ALLOWED, VISA_CTP_PAYMENT_FAILED, VISA_CTP_ENROLLMENT_FAILED, VISA_CTP_CHECKOUT_TIMEOUT, VISA_CTP_ENCRYPTION_FAILED, VISA_CTP_DECRYPTION_FAILED, VISA_CTP_SUT_EXCHANGE_FAILED. VISA_CTP_CARD_NETWORK_NOT_ALLOWED applies only to ENROLL_AND_CHECKOUT with pan, where the card number is checked against getAllowedNetworks(). An encryptedCard is not checked here.
Authentication details
Not every Click to Pay payment is 3-D Secure authenticated by the card network. Adding a new card through ENROLL_AND_CHECKOUT, for example, is not. Set includeAuthenticationDetails: true on CHECKOUT_SAVED_CARD or ENROLL_AND_CHECKOUT and the result includes authenticationDetails: the card network's own authentication record for this checkout, returned before you call /v1/payments. Use it to decide whether your payment request needs 3-D Secure.
authenticationDetails is passed through from the network unmodified. The field to act on is eci. Its values are scheme-specific and the SDK does not remap them, so read the row for the scheme of the card being paid with:
| Scheme | Authenticated | Attempted | Not performed |
|---|---|---|---|
| Visa, Amex | 05 | 06 | 07 |
| Mastercard | 02 | 01 | 00 |
Skip your own 3-D Secure when eci is the scheme's authenticated or attempted value. Step up for any other value or when eci is missing.
Don't apply the Visa values to Mastercard. On Mastercard,
06means an exemption or network-token transaction without 3-D Secure and carries no liability shift.07means an authenticated merchant-initiated or recurring payment. Neither means "attempted".
| Situation | authenticationDetails |
|---|---|
includeAuthenticationDetails not set or false | Key is omitted from the result. |
| Requested, and the network returned an authentication record | { eci, verificationData, ... }. eci may still be absent. |
| Requested, but the network returned no record or it could not be read | null. The payment itself is not failed. |
Treat null and a missing eci the same way as "not performed": run your own 3-D Secure.
const result = await clickToPay.processPayment({
action: 'CHECKOUT_SAVED_CARD',
cardId: selectedCard.id,
complianceSettings,
includeAuthenticationDetails: true
});
const eci = result.authenticationDetails?.eci;
// scheme: 'VISA' | 'MASTERCARD' | 'AMEX', for the card being paid with
const skip3ds = scheme === 'MASTERCARD' ? ['02', '01'] : ['05', '06'];
const body = { paymentInstrument: result.paymentInstrument };
if (!skip3ds.includes(eci)) {
body.threeDSecureRequired = true;
body.threeDSecureOptions = { automaticallyStepUp: true };
}
// POST body to /v1/paymentsSession & diagnostics
getSessionJwt()
getSessionJwt()client.getSessionJwt() → string | nullReturns the active session token, or null if none has been minted yet. Pass this into your card-capture component's own encrypt call so it can authenticate without your page ever touching raw card data. Sync.
const encrypted = await hostedFields.encryptCard({
session: clickToPay.getSessionJwt(),
cardholderName
});getInitStatus()
getInitStatus()client.getInitStatus() → InitStatusA cheap, synchronous snapshot of client state. Useful for guarding UI transitions and for diagnostics — never throws.
| Name | Type | Description |
|---|---|---|
scriptLoaded | boolean | True while the wallet script is loaded and a session is held, i.e. the client is usable. False before the first successful initializeClickToPay(), and again after unbindAppInstance() or a failed first initialisation. |
sdkInitialized | boolean | True only when startup fully succeeded (i.e. status was SUCCESS, not PARTIAL). |
sessionStale | boolean | True after a processPayment() call. Treat as "needs re-init" — the next initializeClickToPay() handles it automatically. |
warning | { code, message } | null | Present when the last init resolved as PARTIAL. |
unbindAppInstance()
unbindAppInstance()client.unbindAppInstance() → Promise<void>Forgets this device and clears cached identity and session state, so the next initializeClickToPay() starts from a clean slate. Call this when the consumer wants to switch identity or sign out of Click to Pay on this device. Async.
await clickToPay.unbindAppInstance();
// safe to call initializeClickToPay() again immediatelyThrows: whatever the wallet script rejects with, passed through as-is (not a ComcardeError). Local state is left unchanged when it fails.
getAllowedNetworks()
getAllowedNetworks()client.getAllowedNetworks() → string[]Returns the card networks the active session accepts, e.g. ['VISA', 'MASTERCARD'], or [] if no session has been minted yet. Sync, never throws.
Data structures
Shapes referenced by more than one method.
ConsumerIdentity
| Field | Type | Description |
|---|---|---|
identityValue | string | Email address or phone number. |
identityType | 'EMAIL_ADDRESS' | 'MOBILE_PHONE_NUMBER' | Case-sensitive. |
Consumer (processPayment's ENROLL_AND_CHECKOUT.consumer)
(processPayment's ENROLL_AND_CHECKOUT.consumer)| Field | Type | Description |
|---|---|---|
emailAddress | string | Optional. |
mobileNumber | { countryCode, phoneNumber } | Optional. Split out of a single phone input, e.g. { countryCode: '44', phoneNumber: '7700900000' }. |
firstName / lastName | string | Optional. Send both if your capture form collects them separately. |
fullName | string | Optional. Send alongside firstName/lastName — most integrations set it to their concatenation. |
consumerIdentity | ConsumerIdentity | Optional. The identity getCards() / verifyOtp() was called with. |
countryCode | string | Optional. ISO country, e.g. 'GB'. |
locale | string | Optional. ISO language, e.g. 'en'. |
Card (returned by getCards / verifyOtp)
(returned by getCards / verifyOtp)| Field | Type | Description |
|---|---|---|
id | string | Pass this back as cardId on processPayment(). |
brand | string | Card product descriptor for display. |
lastFour | string | Last four digits, for display only. |
expiryMonth / expiryYear | string | Display only. |
artUri | string | null | Card art image, when available. |
displayText | string | Ready-to-render label, e.g. "Consumer Debit ....1881". |
ComplianceSettings
| Field | Type | Description |
|---|---|---|
complianceResources | Array<{ complianceType, uri }> | complianceType is one of REMEMBER_ME, PRIVACY_POLICY, TERMS_AND_CONDITIONS. Send REMEMBER_ME only when the consumer opted in — but always send at least one resource on an enrolment or saved-card checkout. |
AuthenticationDetails (returned by processPayment when requested)
(returned by processPayment when requested)The card network's authentication record for the checkout, passed through unmodified. Fields other than those below may appear and are passed through as-is.
| Field | Type | Description |
|---|---|---|
eci | string | undefined | Electronic Commerce Indicator. Scheme-specific, see Authentication details. Treat missing as "not performed". |
verificationData | Array | Network verification records. Passed through for reference; you don't need it to decide on 3-D Secure. |
PanInput (legacy — prefer a card-capture component)
(legacy — prefer a card-capture component)| Field | Type |
|---|---|
primaryAccountNumber | string |
panExpirationMonth | string |
panExpirationYear | string |
cardholderName | string |
cardSecurityCode | string |
Amounts are always decimal strings —
'10.00', never1000or a bare number. Identity types are case-sensitive upper snake case. Both are validated at the point of call and surface asVISA_CTP_INVALID_OPTIONSwhen malformed.
Updated about 3 hours ago
