Search…
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

1. Setup Secure Fields

To get started include the following script on your page.
Secure Fields Script
Minified Version
1
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-2.0.0.js"></script>
Copied!
1
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-2.0.0.min.js"></script>
Copied!
Please make sure to always load it directly from https://pay.sandbox.datatrans.com

2. Create the Payment Form

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
1
<form>
2
<div>
3
<div>
4
<label for="card-number-placeholder">Card Number</label>
5
<!-- card number container -->
6
<div id="card-number-placeholder" style="width: 250px;"></div>
7
</div>
8
<div>
9
<label for="cvv-placeholder">Cvv</label>
10
<!-- cvv container -->
11
<div id="cvv-placeholder" style="width: 90px;"></div>
12
</div>
13
14
<button type="button" id="go">Get Token!</button>
15
</div>
16
</form>
Copied!
1
<form>
2
<div>
3
<div>
4
<label for="iban-placeholder">IBAN</label>
5
<!-- IBAN container -->
6
<div id="iban-placeholder" style="width: 250px;"></div>
7
</div>
8
9
<button type="button" id="go">Get Token!</button>
10
</div>
11
</form>
Copied!
1
<form>
2
<div>
3
<div>
4
<label for="account-number-placeholder">account number</label>
5
<!-- account number container -->
6
<div id="account-number-placeholder" style="width: 90px;"></div>
7
</div>
8
<div>
9
<label for="branch-code-placeholder">branch code</label>
10
<!-- branch code container -->
11
<div id="branch-code-placeholder" style="width: 90px;"></div>
12
</div>
13
14
<button type="button" id="go">Get Token!</button>
15
</div>
16
</form>
Copied!
In test mode, only test credentials are allowed.

3. Retrieve a Transaction ID

Start with creating a new Secure Fields instance:
1
var secureFields = new SecureFields();
2
3
// Multiple instances might be created and used independently:
4
// e.g. var secureFields2 = new SecureFields();
Copied!
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
1
secureFields.initTokenize( "1100007006", {
2
cardNumber: "card-number-placeholder",
3
cvv: "cvv-placeholder"
4
});
Copied!
1
secureFields.initTokenize( "1100007006", {
2
iban: "iban-placeholder"
3
});
Copied!
1
secureFields.initTokenize( "1100007006", {
2
accountNumber: "account-number-placeholder",
3
branchCode: "branch-code-placeholder"
4
});
Copied!
Afterwards, submit the form and listen for the success event:
1
$(function() {
2
$("#go").click( function() {
3
secureFields.submit(); // submit the "form"
4
})
5
});
6
7
secureFields.on("success", function(data) {
8
if(data.transactionId) {
9
// transmit data.transactionId and the rest
10
// of the form to your server
11
}
12
});
Copied!
Instances can be destroyed if no longer used:
1
secureFields.destroy();
Copied!

4. Obtain the tokens

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

Token API Examples

Request
Response Card
Response IBAN
Response Account number & Branch code
1
curl -L -X POST 'https://api.sandbox.datatrans.com/v1/tokenizations/220112095131012129' \
2
-H 'Authorization: Basic MTEwMDAxNzc4OTpNQUd6UUVEbkVxd001d0Vr' \
3
-H 'Content-Type: application/json' \
4
-H 'Idempotency-Key: e75d621b-0e56-4b71-b889-1acec3e9d870'
Copied!
1
{
2
"paymentMethod": "VIS",
3
"alias": "AAABfk18LlrssdexyrAAAQalUKXvAHTw",
4
"fingerprint": "F-dV5V8dE0SZLoTurWbq2HZp",
5
"maskedCard": "424242xxxxxx4242",
6
"aliasCVV": "bkhZUcl_SFSaN8iNoeZTZirR",
7
"cardInfo": {
8
"brand": "VISA CREDIT",
9
"type": "credit",
10
"usage": "consumer",
11
"country": "GB",
12
"issuer": "DATATRANS"
13
}
14
}
Copied!
1
{
2
"aliasIban": "AAABeKaD2UbssdexyrAAAUN24QvOZg3n",
3
"maskedIban": "DE85xxxxxxxxxxxxxx2345"
4
}
Copied!
1
{
2
"aliasAccountNumber": "AAABeKahwGDssdexyrAAAV8w_R0dlq9b",
3
"maskedAccountNumber": "xxxx0604",
4
"aliasBranchCode": "AAABeKahwGDssdexyrAAAadGCQEwl6MZ"
5
}
Copied!

Error table

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.

Examples

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/inline-example.html Demo with floating labels: https://github.com/datatrans/secure-fields-sample/blob/master/floating-label.html
An example of how to implement this behaviour in modern web applications can be found here
In test mode, only test credentials are allowed.
Please also have a look at Styling and Events references.