Use the secureFields.on(...)
callback function to subscribe to one or more of the ready
, change
, error
or validate
events.
The ready event will be emitted once the iframes are loaded.
secureFields.on("ready", function() {// setting a placholder for the cardNumber fieldsecureFields.setPlaceholder("cardNumber", "Card number");​// setting a placeholder for the CVV fieldsecureFields.setPlaceholder("cvv", "CVV");});
The validate event will be emitted once the form was submitted with secureFields.submit();
secureFields.on("validate", function(event) {// put a red border around the fields if they are not validsecureFields.setStyle("cardNumber.invalid","border: 1px solid #f00");secureFields.setStyle("cvv.invalid","border: 1px solid #f00");});
Where the event
callback object has the following structure:
{"fields": {"cardNumber": {"length": 0,"valid": false},"cvv": {"length": 3,"valid": true}},"hasErrors": true // indicates if one of the fields has valid=false}
The change
event will be emitted whenever one of the following events are getting triggered:
focus
blur
keyUp
keyDown
touchstart
touchmovetouchend
touchcancel
touchforcechange
secureFields.on("change", function(event) {// some fancy stuff});
Where the event
callback object has the following structure:
{"fields": {"cardNumber": {"length": 0,"valid": false},"cvv": {"length": 0,"valid": false}},"hasErrors": true,"event": {"field": "cardNumber", // the affected input field"type": "blur" // the original event}}
The cardInfo
event will be emitted whensecureFields.getCardInfo()
is called.
secureFields.on("cardInfo", function(event) {// call backend, decide stuff ;)});
{"event": "cardInfo","data": {"cardInfo": {"brand": "VISA CREDIT","type": "credit","usage": "consumer","country": "GB","issuer": "DATATRANS"},"maskedCard": "424242xxxxxx4242","paymentMethod": "VIS"}}
Calling secureFields.getCardInfo(callback)
is the alternative way to obtain the information about the entered card by having the given callback function receive it rather than waiting for an event.
The success event will be emitted if the tokenization was successful.
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:
{"result": "success","transactionId": "180403204621339015","cardInfo":{"brand": "VISA DEBIT","issuer": "Some Bank","type": "debit", // debit or credit"usage": "unknown", // consumer, corporate or unknown"country": "US" // 2 letter ISO 3166-1 alpha-2 country code}}
The error event will be emitted if there was an error after calling secureFields.initTokenize(...)
.
Possible scenarios are:
Wrong merchantId configured in secureFields.initTokenize(...);
Wrong name of card number, CVV fields
Wrong merchantId configuration on Datatrans side
Those errors should only occur during development/testing.
secureFields.on("error", function(data) {// something bad happened});
​