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()

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.

NameTypeRequiredDescription
options.clientClientRequiredA Comcarde Web SDK client instance, already created via comcarde.client.create().
options.authorizationstringRequiredMerchant 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()

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.

NameTypeRequiredDescription
amountstringRequiredDecimal amount as a string, e.g. '10.00'. Never a number, never minor units.
currencyCodestringRequiredISO 4217 currency code, e.g. 'GBP'.
localestringOptionalBCP 47 locale with an underscore separator, e.g. 'en_GB'. Defaults to the browser locale.
sessionEndpointstringOptionalOverrides 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.

statuswarning / errorMeaning
SUCCESS—Ready. getCards() and processPayment() can be called.
PARTIALwarningThe 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_FAILEDerrorA 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()

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.

NameTypeRequiredDescription
amountstringRequiredNew decimal amount, e.g. '7.99'.
currencyCodestringRequiredNew ISO 4217 currency code.
clickToPay.updateAmount({ amount: '7.99', currencyCode: 'GBP' });

Throws: VISA_CTP_NOT_INITIALIZED, VISA_CTP_INVALID_OPTIONS

Identification

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.

NameTypeRequiredDescription
identityValuestringRequiredThe email address or phone number the consumer typed.
identityType'EMAIL_ADDRESS' | 'MOBILE_PHONE_NUMBER'RequiredCase-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()

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.

NameTypeRequiredDescription
validationDatastringRequiredThe 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()'s complianceSettings — never on verifyOtp().

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()

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.

NameTypeRequiredDescription
requestedValidationChannelIdstringOptionalRequests 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()

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.

NameTypeRequiredDescription
pan.primaryAccountNumberstringRequiredThe card number.
pan.panExpirationMonthstringRequiredTwo-digit month.
pan.panExpirationYearstringRequiredFour-digit year.
pan.cardholderNamestringRequiredName as printed on the card.
pan.cardSecurityCodestringRequiredCVV / CVC.
sessionOptions.amountstringOptional*Required only if no session exists yet on this client.
sessionOptions.currencyCodestringOptional*Required only if no session exists yet on this client.
sessionOptions.localestringOptionalUsed only when a session is minted. Defaults as for initializeClickToPay().
sessionOptions.sessionEndpointstringOptionalUsed 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()

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 complianceSettings on CHECKOUT_SAVED_CARD and ENROLL_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 a PRIVACY_POLICY or TERMS_AND_CONDITIONS resource as a baseline, and add REMEMBER_ME only when the consumer ticked that box. Go to ComplianceSettings.

CHECKOUT_SAVED_CARD

Consumer picked a card already returned by getCards() / verifyOtp().

NameTypeRequiredDescription
cardIdstringRequiredThe id from the chosen card.
complianceSettingsComplianceSettingsRequired in practiceNot enforced by the type signature, but checkout fails without at least one resource. See note above.
includeAuthenticationDetailsbooleanOptionalWhen true, the result includes authenticationDetails. Defaults to false. See Authentication details.

ENROLL_AND_CHECKOUT

New card, saved for next time and paid with in the same step.

NameTypeRequiredDescription
encryptedCardstringOne of thesePreferred. Output of your card-capture component's own encrypt call.
panPanInputOne of theseLegacy path for callers holding a raw PAN — internally routed through encryptCard().
consumerConsumerOptionalIdentity/contact details forwarded with the enrolment. See Consumer.
complianceSettingsComplianceSettingsRequired in practiceNot enforced by the type signature, but checkout fails without at least one resource. See note above.
includeAuthenticationDetailsbooleanOptionalWhen true, the result includes authenticationDetails. Defaults to false. See Authentication details.

TOKENIZE

New card, pay once — nothing is saved to Click to Pay.

NameTypeRequiredDescription
hostedFieldsTokenstringRequiredToken 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 (see getInitStatus()).

const result = await clickToPay.processPayment({
  action: 'CHECKOUT_SAVED_CARD',
  cardId: selectedCard.id
});

const nonce = result.paymentInstrument.nonce;
// POST { paymentInstrument: { type: 'clickToPay', nonce } } to /v1/payments

Throws: 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:

SchemeAuthenticatedAttemptedNot performed
Visa, Amex050607
Mastercard020100

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, 06 means an exemption or network-token transaction without 3-D Secure and carries no liability shift. 07 means an authenticated merchant-initiated or recurring payment. Neither means "attempted".

SituationauthenticationDetails
includeAuthenticationDetails not set or falseKey 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 readnull. 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/payments

Session & diagnostics

getSessionJwt()

client.getSessionJwt() → string | null

Returns 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()

client.getInitStatus() → InitStatus

A cheap, synchronous snapshot of client state. Useful for guarding UI transitions and for diagnostics — never throws.

NameTypeDescription
scriptLoadedbooleanTrue 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.
sdkInitializedbooleanTrue only when startup fully succeeded (i.e. status was SUCCESS, not PARTIAL).
sessionStalebooleanTrue after a processPayment() call. Treat as "needs re-init" — the next initializeClickToPay() handles it automatically.
warning{ code, message } | nullPresent when the last init resolved as PARTIAL.

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 immediately

Throws: whatever the wallet script rejects with, passed through as-is (not a ComcardeError). Local state is left unchanged when it fails.

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

FieldTypeDescription
identityValuestringEmail address or phone number.
identityType'EMAIL_ADDRESS' | 'MOBILE_PHONE_NUMBER'Case-sensitive.

Consumer (processPayment's ENROLL_AND_CHECKOUT.consumer)

FieldTypeDescription
emailAddressstringOptional.
mobileNumber{ countryCode, phoneNumber }Optional. Split out of a single phone input, e.g. { countryCode: '44', phoneNumber: '7700900000' }.
firstName / lastNamestringOptional. Send both if your capture form collects them separately.
fullNamestringOptional. Send alongside firstName/lastName — most integrations set it to their concatenation.
consumerIdentityConsumerIdentityOptional. The identity getCards() / verifyOtp() was called with.
countryCodestringOptional. ISO country, e.g. 'GB'.
localestringOptional. ISO language, e.g. 'en'.

Card (returned by getCards / verifyOtp)

FieldTypeDescription
idstringPass this back as cardId on processPayment().
brandstringCard product descriptor for display.
lastFourstringLast four digits, for display only.
expiryMonth / expiryYearstringDisplay only.
artUristring | nullCard art image, when available.
displayTextstringReady-to-render label, e.g. "Consumer Debit ....1881".

ComplianceSettings

FieldTypeDescription
complianceResourcesArray<{ 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)

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.

FieldTypeDescription
ecistring | undefinedElectronic Commerce Indicator. Scheme-specific, see Authentication details. Treat missing as "not performed".
verificationDataArrayNetwork verification records. Passed through for reference; you don't need it to decide on 3-D Secure.

PanInput (legacy — prefer a card-capture component)

FieldType
primaryAccountNumberstring
panExpirationMonthstring
panExpirationYearstring
cardholderNamestring
cardSecurityCodestring
📘

Amounts are always decimal strings — '10.00', never 1000 or a bare number. Identity types are case-sensitive upper snake case. Both are validated at the point of call and surface as VISA_CTP_INVALID_OPTIONS when malformed.


Did this page help you?