For integration guidance — where to listen, which events to combine, and real-world implementation patterns — see the Events Guide.
Quick Navigation
| Category | Items |
|---|---|
| Initialization Events | primer:ready, primer:methods-update |
| State Events | primer:state-change |
| Card Form Events | primer:card-network-change, primer:card-success, primer:card-error |
| Payment Events | primer:payment-start, primer:payment-success, primer:payment-failure |
| Vault Events | primer:vault:methods-update, primer:vault:selection-change, primer:show-other-payments-toggled |
| Triggerable Events | primer:card-submit, primer:vault-submit, primer:show-other-payments-toggle |
| PrimerJS Callbacks | onPaymentStart, onPaymentPrepare, onPaymentSuccess, onPaymentFailure, onVaultedMethodsUpdate |
| PrimerJS Instance Methods | refreshSession(), getPaymentMethods(), setCardholderName(), vault.* |
| Type Definitions | All TypeScript interfaces |
Callbacks vs DOM Events
Event Lifecycle
1
Initialization
SDK loads, connects to the session, and signals readiness.
SDK →
PrimerJS instanceprimer:readySDK →
available methodsprimer:methods-updateSDK →
saved methodsprimer:vault:methods-updateRegister callbacks and pre-fill fields via PrimerJS
2
User Interaction
User enters card details; SDK detects the card network in real time.
SDK →
Visa detectedprimer:card-network-changeUpdate UI with card brand logo
3
Payment Processing
User submits; SDK creates the payment and communicates with the server.
APP →
(or button click)primer:card-submitSDK →
isProcessing: trueprimer:state-changeSDK →
primer:payment-startShow spinner, disable submit button
4
Outcome
Server responds; SDK dispatches success or failure.
Success
primer:payment-success
state-change → isSuccessful: true
Failure
primer:payment-failure
state-change → paymentFailure: {...}
Redirect on success via onPaymentSuccess, or show error
DOM Events
All Primer events areCustomEvent objects dispatched with bubbles: true and composed: true, allowing them to propagate through shadow DOM boundaries.
Initialization Events
primer:ready
Dispatched once when the SDK is fully initialized. Payload:PrimerJS instance
The PrimerJS instance is the primary interface for configuring callbacks and invoking SDK methods. See PrimerJS Callbacks and PrimerJS Instance Methods for the full surface.
primer:methods-update
Dispatched when available payment methods are loaded. Also re-dispatched afterrefreshSession().
Payload: InitializedPayments instance
| Method | Returns | Description |
|---|---|---|
toArray() | InitializedPaymentMethod[] | All available payment methods |
size() | number | Count of available methods |
get(type) | InitializedPaymentMethod | undefined | Look up a method by its type string |
State Events
primer:state-change
Dispatched when SDK state changes during the payment lifecycle. Fires multiple times during a single payment flow. Payload:SdkState
| Property | Type | Description |
|---|---|---|
isLoading | boolean | SDK is loading resources |
isProcessing | boolean | Payment is in progress |
isSuccessful | boolean | Payment succeeded |
primerJsError | Error | null | SDK-level error (network, configuration) |
paymentFailure | PaymentFailure | null | Payment failure details |
Card Form Events
primer:card-network-change
Dispatched when the card network is detected from user input in the card number field. Payload:CardNetworksContextType
| Property | Type | Description |
|---|---|---|
detectedCardNetwork | CardNetwork | null | Detected network, or null if undetected |
selectableCardNetworks | CardNetwork[] | Co-branded network options (e.g. Carte Bancaire / Visa) |
isLoading | boolean | Network detection is in progress |
primer:card-success
Dispatched when card form submission succeeds. Payload:CardSubmitSuccessPayload
| Property | Type | Description |
|---|---|---|
result.success | boolean | Submission succeeded |
result.token | string | Payment token |
result.paymentId | string | Payment ID |
primer:card-error
Dispatched when card form validation fails on submission. Payload:CardSubmitErrorsPayload
| Property | Type | Description |
|---|---|---|
errors | InputValidationError[] | Validation errors for each invalid field |
Payment Events
primer:payment-start
Dispatched when payment creation begins. Payload: Noneprimer:payment-success
Dispatched when payment completes successfully. Payload:PaymentSuccessData
| Property | Type | Description |
|---|---|---|
paymentSummary | PaymentSummary | PII-filtered payment data |
paymentMethodType | string | e.g., "PAYMENT_CARD", "APPLE_PAY" |
timestamp | number | Unix timestamp (seconds) |
primer:payment-failure
Dispatched when payment fails. Payload:PaymentFailureData
| Property | Type | Description |
|---|---|---|
error | { code: string; message: string; diagnosticsId?: string | null; data?: Record<string, unknown> } | Structured error information |
paymentSummary | PaymentSummary | undefined | Payment data, if available at time of failure |
paymentMethodType | string | Payment method used |
timestamp | number | Unix timestamp (seconds) |
Vault Events
primer:vault:methods-update
Dispatched when vaulted payment methods are loaded or updated. Payload:VaultedMethodsUpdateEventDetail
| Property | Type | Description |
|---|---|---|
vaultedPayments | InitializedVaultedPayments | Vaulted methods collection |
timestamp | number | Unix timestamp (seconds) |
Need
cvvRecapture? The cvvRecapture flag is only available via the onVaultedMethodsUpdate callback, not this DOM event. Use the callback if you need to know whether CVV re-entry is required.InitializedVaultedPayments methods:
| Method | Returns | Description |
|---|---|---|
toArray() | VaultedPaymentMethodSummary[] | All vaulted methods |
size() | number | Count of vaulted methods |
get(id) | VaultedPaymentMethodSummary | undefined | Look up a vaulted method by ID |
primer:vault:selection-change
Dispatched when a vaulted payment method is selected or deselected. Payload:VaultSelectionChangeData
| Property | Type | Description |
|---|---|---|
paymentMethodId | string | null | ID of the selected method, or null if deselected |
timestamp | number | Unix timestamp (seconds) |
primer:show-other-payments-toggled
Dispatched when the “show other payments” toggle state changes. Payload:ShowOtherPaymentsToggledPayload
| Property | Type | Description |
|---|---|---|
expanded | boolean | Current toggle state |
timestamp | number | Unix timestamp (seconds) |
Triggerable Events
These events can be dispatched by your code to control the SDK. All triggerable events must be dispatched withbubbles: true and composed: true to cross shadow DOM boundaries.
primer:card-submit
Triggers card form submission programmatically.primer:vault-submit
Triggers vault payment submission programmatically.primer:show-other-payments-toggle
Toggles the “other payment methods” section.PrimerJS Callbacks
Set these callbacks on thePrimerJS instance received from the primer:ready event.
onPaymentStart
Called when payment creation begins.| Parameter | Type | Description |
|---|---|---|
| (none) | — | — |
onPaymentPrepare
Called before payment is created. Allows validation or aborting.| Parameter | Type | Description |
|---|---|---|
data | { paymentMethodType: string } | Payment method being used |
handler | PrepareHandler | Control object |
PrepareHandler methods:
| Method | Returns | Description |
|---|---|---|
continuePaymentCreation() | void | Proceed with payment creation |
abortPaymentCreation() | void | Cancel payment creation |
onPaymentSuccess
Called when payment succeeds.| Parameter | Type | Description |
|---|---|---|
data | PaymentSuccessData | Payment result data |
onPaymentFailure
Called when payment fails.| Parameter | Type | Description |
|---|---|---|
data | PaymentFailureData | Error and payment data |
onVaultedMethodsUpdate
Called when vaulted payment methods are loaded or updated.| Parameter | Type | Description |
|---|---|---|
data | VaultedMethodsUpdateData | Vaulted payments and CVV recapture flag |
PrimerJS Instance Methods
refreshSession()
Synchronizes the client-side SDK with server-side session updates. Triggers a newprimer:methods-update event.
| Parameter | Type | Description |
|---|---|---|
| (none) | — | — |
| Returns | Promise<void> | Resolves when sync is complete |
getPaymentMethods()
Returns the cached list of available payment methods.| Parameter | Type | Description |
|---|---|---|
| (none) | — | — |
| Returns | PaymentMethodInfo[] | Available payment methods |
setCardholderName()
Sets the cardholder name field programmatically. Must be called afterprimer:ready.
| Parameter | Type | Description |
|---|---|---|
name | string | Cardholder name |
| Returns | void | — |
Vault API
vault.createCvvInput()
Creates a CVV input element for CVV recapture in headless mode.| Parameter | Type | Description |
|---|---|---|
options.cardNetwork | string | Card network (e.g. 'VISA') |
options.container | string | CSS selector for the container element |
options.placeholder | string | Placeholder text |
| Returns | Promise<CvvInputInstance> | The created CVV input |
vault.startPayment()
Initiates payment with the selected vaulted method.| Parameter | Type | Description |
|---|---|---|
paymentMethodId | string | ID of the vaulted payment method |
options | object | Optional payment options |
options.cvv | string | CVV value for card payments requiring re-capture |
| Returns | Promise<void> | Resolves when payment flow is initiated |
vault.delete()
Deletes a vaulted payment method.| Parameter | Type | Description |
|---|---|---|
paymentMethodId | string | ID of the vaulted payment method |
| Returns | Promise<void> | Resolves when deletion is complete |
Deprecated Methods
| Deprecated Method | Replacement |
|---|---|
primer.createCvvInput(options) | primer.vault.createCvvInput(options) |
primer.startVaultPayment(id, options?) | primer.vault.startPayment(paymentMethodId, options?) |
Type Definitions
PaymentSuccessData
Callback vs Event payload difference: The callback (
onPaymentSuccess) uses payment, while the DOM event (primer:payment-success) uses paymentSummary. Both contain the same PaymentSummary data.PaymentFailureData
Callback vs Event payload difference: The callback (
onPaymentFailure) uses payment, while the DOM event (primer:payment-failure) uses paymentSummary. Both contain the same PaymentSummary data.PaymentSummary
A PCI-compliant payment summary with minimal PII exposure. Contains payment identifiers and filtered payment method data.PaymentFailure
SdkState
CardNetworksContextType
The entire context can be
null before card network detection initializes. Always use optional chaining when accessing properties: event.detail?.detectedCardNetwork?.network.CardNetwork
CardSubmitSuccessPayload
CardSubmitErrorsPayload
InputValidationError
VaultedMethodsUpdateData
Callback vs Event payload difference: The callback (
onVaultedMethodsUpdate) includes cvvRecapture, while the DOM event (primer:vault:methods-update) does not. Use the callback if you need the CVV recapture flag.VaultedPaymentMethodSummary
VaultSelectionChangeData
ShowOtherPaymentsToggledPayload
PrepareHandler
InitializedPayments
InitializedVaultedPayments
See Also
- Events Guide — When, why, and how to use events in your integration
- SDK Options Reference — Configuration options for
<primer-checkout> - Headless Vault Guide — Custom vault UI implementation