Events

PaygreenJS communicates with your code via the CustomEvent API.

paygreenjs.on(paygreenjs.Events.INSTRUMENT_READY, (event) => {
  console.log('INSTRUMENT_READY', event.detail);
});

The data carried by an event is exposed on the detail attribute (validation status, tokens, error codes, etc.).

📘

Auto-generated reference

The exhaustive enum of every event name is available in the auto-generated documentation.

Subscription methods

NameTypeDescription
onfuncSubscribes to an event and attaches a callback.
offfuncDetaches your callback from an event.
EventsEventsTypeConstant exposing every event name.

💳 Card field events

Fired in real time as the buyer fills the hosted PAN / EXP / CVV fields.

NameDescription
PAN_FIELD_ONCHANGETriggers when the PAN field changes. event.detail contains valid, the error code (if any), the translated error message, the detected issuer and networks.
EXP_FIELD_ONCHANGETriggers when the EXP field changes. event.detail contains valid, the error code (if any), and the translated error message.
CVV_FIELD_ONCHANGETriggers when the CVV field changes. Same payload as above.
CARD_ONCHANGETriggers when the overall card validity changes (all three fields combined). event.detail.valid is the final boolean.
paygreenjs.on(paygreenjs.Events.PAN_FIELD_ONCHANGE, (event) => {
  console.log('PAN is valid:', event?.detail?.valid);
});

🔄 Payment lifecycle events

NameDescription
PAYMENT_FLOW_ONCHANGETriggers when the current payment flow changes (method picked, instrument set, etc.).
REQUEST_SUBMIT_TOKENIZE_FORMTriggers when the hosted-fields form is submitted (manually or via submitPayment()).
ACTUAL_FLOW_PAYMENT_DONETriggers when the current flow's payment is done (successfully or not). Only fired when there is a remainder left to pay.
FULL_PAYMENT_DONETriggers when the whole Payment Order has been paid.
PAYMENT_FAILTriggers when the payment authorization has been refused.
TOKEN_READYTriggers when the token is ready. Returns the token string.
TOKEN_FAILTriggers when tokenization fails. Returns an error value describing why. See Error handling.
INSTRUMENT_READYTriggers when an instrument has been created. The authorization status is available in event.detail.authentication.

🔐 Authentication & redirect events

NameDescription
AUTHENTICATION_FLOW_STARTTriggers when an authentication flow starts (3DS, OAuth, …). event.detail.type indicates which one.
ON_OPEN_POPUPTriggers when a popup must be opened. Provides the URL. Subscribe to take control of the popup yourself (recommended to avoid pop-up blockers).
ERRORTriggers when an unexpected error occurs. Returns the Error. See Error handling.

✅ Consent events

NameDescription
REUSABLE_ALLOWED_CHANGETriggers when the buyer changes the reusable-card checkbox state, or when you call paygreenjs.updateConsent(boolean).

🗑️ Deprecated events

⚠️

Do not use these in new integrations. They are only kept for backward compatibility.

NameDescriptionUse instead
PAN_FIELD_FULFILLEDTriggered when the PAN field is filled and valid.PAN_FIELD_ONCHANGE + check event?.detail?.valid.
EXP_FIELD_FULFILLEDTriggered when the EXP field is filled and valid.EXP_FIELD_ONCHANGE + check event?.detail?.valid.
CVV_FIELD_FULFILLEDTriggered when the CVV field is filled and valid.CVV_FIELD_ONCHANGE + check event?.detail?.valid.
TOKEN_DETAILS_READYTriggered when the token was ready, with issuer and details.INSTRUMENT_READY.