Secure Fields (JS)
The only payment form you’ll ever need
Secure Fields allow you to securely collect credit, debit and virtual cards as well as bank account data by injecting iframes to your DOM. A separate iframe for all sensitive values is used. Thereby, the data never touches your server and allows you to capture all the other related payment data such as cardholder name, expiry date, etc. directly by yourself.
Using Secure Fields qualifies you for SAQ A.
Browser | Version |
---|---|
Chrome | Chrome Mobile | >=28 | >=28 |
Firefox | Firefox Mobile | >=31 | >=31 |
Internet Explorer | Internet Explorer Mobile | >=9 | >= 9 |
Safari | Safari Mobile | =6 | >=6 |
Opera | Opera Mobile | >=24 | >=22 |
Blackberry Browser | =8 |
Android Browser | >=4 |
To get started include the following script on your page.
Secure Fields Script
Minified Version
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-2.0.0.js"></script>
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-2.0.0.min.js"></script>
In order for Secure Fields to insert the card number and CVV iframes at the right place, create empty DOM elements and assign them unique IDs. In the example below those are:
card-number-placeholder
cvv-placeholder
For the bank account example they are:
iban-placeholder
account-number-placeholder
branch-number-placeholder
Card Number / CVV
IBAN
Account Number / Branch Code
<form>
<div>
<div>
<label for="card-number-placeholder">Card Number</label>
<!-- card number container -->
<div id="card-number-placeholder" style="width: 250px;"></div>
</div>
<div>
<label for="cvv-placeholder">Cvv</label>
<!-- cvv container -->
<div id="cvv-placeholder" style="width: 90px;"></div>
</div>
<button type="button" id="go">Get Token!</button>
</div>
</form>
<form>
<div>
<div>
<label for="iban-placeholder">IBAN</label>
<!-- IBAN container -->
<div id="iban-placeholder" style="width: 250px;"></div>
</div>
<button type="button" id="go">Get Token!</button>
</div>
</form>
<form>
<div>
<div>
<label for="account-number-placeholder">account number</label>
<!-- account number container -->
<div id="account-number-placeholder" style="width: 90px;"></div>
</div>
<div>
<label for="branch-code-placeholder">branch code</label>
<!-- branch code container -->
<div id="branch-code-placeholder" style="width: 90px;"></div>
</div>
<button type="button" id="go">Get Token!</button>
</div>
</form>
Start with creating a new Secure Fields instance:
var secureFields = new SecureFields();
// Multiple instances might be created and used independently:
// e.g. var secureFields2 = new SecureFields();
Initialize it with your
merchantId
and specify which DOM element containers should be used to inject the iframes:Card number / CVV
IBAN
Account number / Branch Code
secureFields.initTokenize( "1100007006", {
cardNumber: "card-number-placeholder",
cvv: "cvv-placeholder"
});
secureFields.initTokenize( "1100007006", {
iban: "iban-placeholder"
});
secureFields.initTokenize( "1100007006", {
accountNumber: "account-number-placeholder",
branchCode: "branch-code-placeholder"
});
Afterwards, add optional
expm
and expy
, submit the form and listen for the success event:$(function() {
$("#go").click( function() {
secureFields.submit({ // submit the "form"
expm: 12,
expy: 26
});
});
});
secureFields.on("success", function(data) {
if(data.transactionId) {
// transmit data.transactionId and the rest
// of the form to your server
}
});
Instances can be destroyed if no longer used:
secureFields.destroy();
Once you've transmitted the
transactionId
to your server (together with the the rest of your form) you have to execute a server to server POST
request to retrieve the tokenized card or bank account values.This service requires HTTP basic authentication. The required credentials can be found in our dashboard. Please refer to API authentication data for more information.
post
https://api.sandbox.datatrans.com/
v1/tokenizations/{transactionId}
Token
Request
Response Card
Response IBAN
Response Account number & Branch code
curl -L -X POST 'https://api.sandbox.datatrans.com/v1/tokenizations/220112095131012129' \
-H 'Authorization: Basic MTEwMDAxNzc4OTpNQUd6UUVEbkVxd001d0Vr' \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: e75d621b-0e56-4b71-b889-1acec3e9d870'
{
"paymentMethod": "VIS",
"alias": "7LHXscqwAAEAAAGCq4LyxV20zPAFABWx",
"fingerprint": "F-dV5V8dE0SZLoTurWbq2HZp",
"maskedCard": "424242xxxxxx4242",
"aliasCVV": "ISlRs6QoSOyzdFl8t-hiW_-4",
"expiryYear": "25",
"expiryMonth": "06",
"cardInfo": {
"brand": "VISA CREDIT",
"type": "credit",
"usage": "consumer",
"country": "GB",
"issuer": "DATATRANS"
}
}
{
"aliasIban": "AAABeKaD2UbssdexyrAAAUN24QvOZg3n",
"maskedIban": "DE85xxxxxxxxxxxxxx2345"
}
{
"aliasAccountNumber": "AAABeKahwGDssdexyrAAAV8w_R0dlq9b",
"maskedAccountNumber": "xxxx0604",
"aliasBranchCode": "AAABeKahwGDssdexyrAAAadGCQEwl6MZ"
}
Error message | Cause / Explanation |
---|---|
Tokenization expired | The transactionId has expired. Please note that it is valid for 30 minutes only |
Tokenization not found | The merchant id used for the transaction id creation does not match the merchant id used for the GET Token call. |
Please visit our GitHub repository for additional examples of integration versions:
Demo Basic: https://datatrans.github.io/secure-fields-sample/
Demo with horizontal fields: https://datatrans.github.io/secure-fields-sample/pciproxy-examples/inline-example.html
Demo with floating labels: https://datatrans.github.io/secure-fields-sample/pciproxy-examples/floating-label.html
Last modified 7mo ago