---
updatedAt: 2026-11-10T09:37:07.000Z
agentTools:
  projectIndex: https://docs.pci-proxy.com/llms.txt
---

# Events

Callback functions let you configure the form logic.

The `secureFields.on(...)` callback functions let you subscribe to one or more of the events as described below.

## on ready

The `ready` event will be emitted once the iframes are loaded.

```javascript on ready
secureFields.on("ready", function() {
  // setting a placholder for the cardNumber field
  secureFields.setPlaceholder("cardNumber", "Card number");

  // setting a placeholder for the CVV field
  secureFields.setPlaceholder("cvv", "CVV");
}
```

## on validate

The `validate` event will be emitted once the form is submitted with `secureFields.submit()`

```javascript on validate
secureFields.on("validate", function(event) {
  // put a red border around the fields if they are not valid
  secureFields.setStyle("cardNumber.invalid", "border: 1px solid #f00");
  secureFields.setStyle("cvv.invalid", "border: 1px solid #f00");
});
```

where the`event` callback object has the following structure:

```javascript event
{
  "fields": {
    "cardNumber": {
      "length": 0,
      "valid": false
    },
    "cvv": {
      "length": 3,
      "valid": true
    }
  },
  "hasErrors": true
}
```

`"hasErrors": true` indicates that one of the has `"valid": false`.

## on change

The `change` event will be emitted whenever one of the following events is triggered:

* `focus`
* `blur`
* `keyUp`
* `keyDown`
* `touchstart`
* `touchmovetouchend`
* `touchcancel`
* `touchforcechange`
* `autocomplete`

For example,

```javascript on change
secureFields.on("change", function(event) {
  // your code
});
```

## on cardInfo

The `cardInfo` event will be emitted when `secureFields.getCardInfo()` is called. It is available only before `secureFields.submit()`.

```javascript on cardInfo
secureFields.on("cardInfo", function(event) {
    // e.g. call backend
});
```

`cardInfo` has the following structure

```json cardInfo
{
  "event": "cardInfo",
  "data": {
    "cardInfo": {
      "brand": "VISA CREDIT",
      "type": "credit",
      "usage": "consumer",
      "country": "GB",
      "issuer": "DATATRANS"
    },
    "maskedCard": "424242xxxxxx4242",
    "paymentMethod": "VIS"
  }
}
```

Calling `secureFields.getCardInfo(callback)` is an alternative way to obtain information about the entered card by having the given callback function receive it rather than waiting for an event.

> 📘 coBrand
>
> When enabled for your merchantID we return additionally the `coBrand` value in the cardInfo object.\
> Please contact us if you need the coBrand value for a given card brand.

## on success

The `success` event will be emitted if the tokenization was successful.

```javascript on success
secureFields.on("success", function(data) {
  if (data.transactionId) {
    // send data.transactionId and the
    // rest of the form to your server
  }
});
```

where the `event` callback object has the following structure:

```json event
{
  "result": "success",
  "transactionId": "180403204621339015",
  "cardInfo": {
    "brand": "VISA DEBIT",
    "issuer": "Some Bank",
    "type": "debit", // debit, credit or prepaid
    "usage": "unknown", // consumer, corporate or unknown
    "country": "US" // 2 letter ISO 3166-1 alpha-2 country code
  }
}
```

## on error

Errors can happen in several scenarios, for example:

* incorrect `merchantId` configured in `secureFields.initTokenize(...);`
* incorrect name of the card number or CVV fields
* incorrect `merchantId` configuration on our end.

These scenarios can be caught with

```javascript error handling
secureFields.on("error", function(data) {
  // what to do when an error occurred
}
```

## Possible error objects:

```Text the jQuery.ajax() errors are returned at secureFields.submit(), for example, if the Internet connection is down:
{"event":"error","data":{"error":"error","action":"submit"}}
```

```Text Incorrect merchantId
{"event":"error","data":"Invalid merchantId"}
```

```Text Incorrect merchantId configuration on our end
{"event":"error","data":"Invalid merchant setup. Server-to-server security must be enabled"}
```

```Text Incorrect name of the card number or CVV fields
{"event":"error","data":"Invalid field"}

{"event":"error","data":"Field " + fieldName + " not allowed for alias version " + aliasFormat"}
// example: {"event":"error","data":"Field myFieldName not allowed for alias version V20"}

{"event":"error","data":"Field " + fieldName + " not allowed for mode " + mode"}  
// example: {"event":"error","data":"Field myFieldName not allowed for mode TOKENIZE"}
```

```Text CardInfo errors:
{"event":"cardInfo","data":{"result":"error","error":"The cardNumber is not yet valid"}}
{"event":"cardInfo","data":{"result":"error","error":"error"}} //jQuery.ajax() error if the Internet connection is down
```