Change event

The change event is triggered when the value of the embed changes. The payload of this event contains keys specific to the embed you are using

Method Parameters

  1. event - mandatory
    The name of the event, in this case change

  2. handler - mandatory
    handler(event) => void is a callback function that a merchant will provide that will be called when the event is fired. When called it will be passed an event object with the following properties:

    FieldSub-fieldTypeDescription
    embedTypestringThe type of embed that emitted this event. In this case card
    emptybooleantrue if the embed is empty
    completebooleantrue if the embed is well-formed and potentially complete. That is the merchant can use this to enable their pay button
    errorjsonAny error that we surface to the customer while they are typing
    valuejson
    cardholder_namestringCardholder name entered by the customer on the embed
    schemeenumCard scheme - visa, mastercard, american_express

Handling a card embed change event

cardEmbed.on('change', function(event) {
  if (event.complete) {
    // enable payment button
  } else if (event.error) {
    // show validation to customer
  }
});

Handler event object

{
  complete: false,
  brand: 'visa',
  embedType: 'card',
  empty: false,
  error: {
    cardNumber: "Enter the card number",
    expiry: "Enter valid expiry date",
    cvv: "",
    name: "",
  },,
  value: { cardholder_name: "" },
}