Skip to main content

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
    expiryjsonCard Expiry Details
    monthintegerNumber representing the card’s expiration month
    yearintegerFour-digit number representing the card’s expiration year.
    last4stringThe last 4 digits of the card
    first6stringThe first 6 digits of the card
    schemeenumCard scheme - visa, mastercard, american_express

Handling a card embed change event

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

Handler event object

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: "" }
}