Secure Fields (iframes)
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 other related payment data such as cardholder name, expiry date, etc. directly by yourself.
Using Secure Fields qualifies you for SAQ A.
Browser compatibility for Secure Fields:
Text
Text
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 payment form

In order for Secure Fields to insert 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 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 GET Token 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.
get
https://api.sandbox.datatrans.com/upp/services
/v1/inline/token
Token

Token API calls examples

Request
Response Card
Response IBAN
Response Account number & Branch code
1
$ curl "https://api.sandbox.datatrans.com/upp/services/v1/inline/token?transactionId=170419151426624571" \
2
-u 'merchantId:password'
Copied!
1
{
2
"aliasCC": "AAABeM8yJsbssdexyrAAAXnn_sIdAKe0",
3
"fingerprint": "F-dV5V8dE0SZLoTurWbq2HZp",
4
"aliasCVV": "mVHJkLRrRX-vb9uUzEM40RUN",
5
"maskedCard": "424242xxxxxx4242"
6
}
Copied!
1
{
2
"aliasIban": "AAABeKaD2UbssdexyrAAAUN24QvOZg3n",
3
"maskedIban": "DE85xxxxxxxxxxxxxx2345"
4
}
Copied!
1
{
2
"aliasAccountNumber": "AAABeKahwGDssdexyrAAAV8w_R0dlq9b",
3
"maskedAccountNumber": "xxxx0604",
4
"aliasBranchCode": "AAABeKahwGDssdexyrAAAadGCQEwl6MZ"
5
}
Copied!
Example: returnPaymentMethod=true returning paymentMethod
Response
1
$ curl "https://api.sandbox.datatrans.com/upp/services/v1/inline/token?transactionId=170419151426624571&returnPaymentMethod=true" \
2
-u 'merchantId:password'
Copied!
1
{
2
"aliasCC": "AAABcHxr-sDssdexyrAAAfyXWIgaAF40",
3
"aliasCVV": "mVHJkLRrRX-vb9uUzEM40RUN",
4
"paymentMethod": "VIS",
5
"maskedCard": "424242xxxxxx4242"
6
}
Copied!
Example: mandatoryAliasCVV=true w/ transactionId that has no CVV token
Response
1
$ curl "https://api.sandbox.datatrans.com/upp/services/v1/inline/token?transactionId=170822090245534063&mandatoryAliasCVV=true" \
2
-u 'merchantId:password'
Copied!
1
400 Bad Request
2
Tokenization with CVV not found
Copied!
Example: returnCardInfo=true returning CardInfo
Response
1
curl -L -X GET 'https://api.sandbox.datatrans.com/upp/services/v1/inline/token?transactionId=210202095141262032&returnCardInfo=true' \
2
-H 'merchantId:password'
Copied!
1
{
2
"aliasCC": "AAABeM8yJsbssdexyrAAAXnn_sIdAKe0",
3
"fingerprint": "F-dV5V8dE0SZLoTurWbq2HZp",
4
"aliasCVV": "ScRuEmNjRJ682mIGKHA9xx_R",
5
"maskedCard": "424242xxxxxx4242",
6
"cardInfo": {
7
"brand": "VISA CREDIT",
8
"type": "credit",
9
"usage": "consumer",
10
"country": "GB",
11
"issuer": "DATATRANS"
12
}
13
}
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.

Next up

Last modified 4d ago