Several JavaScript API implementations to obtain the CreditCardToken
:
Check the examples page for more info.
Import the following script that will make available tokenizeCard_fetch()
:
<script src="https://..../tokenizeCard_fetch.js" type="text/javascript"></script>
Use tokenizeCard_fetch
promise to send the required data and handle response / error:
tokenizeCard_fetch({
apiKey: '<𝘢𝘱𝘪𝘬𝘦𝘺 𝘴𝘵𝘳𝘪𝘯𝘨>',
environment: '<𝘦𝘯𝘷𝘪𝘳𝘰𝘯𝘮𝘦𝘯𝘵 𝘴𝘵𝘳𝘪𝘯𝘨>',
cardDetails: '<𝘤𝘢𝘳𝘥𝘋𝘦𝘵𝘢𝘪𝘭𝘴 𝘰𝘣𝘫𝘦𝘤𝘵>',
})
.then(CreditCardToken => console.log(CreditCardToken))
.catch(err => console.error(err))
Parameter | Type | Possible Values | Description |
---|---|---|---|
apiKey |
string | API key previously obtained from S2P server | |
environment |
string | 'DEV' 'TEST' 'LIVE' |
select the environment
|
cardDetails |
JSON object | check sample bellow | card authentication details in JSON format |
Sample card details object:
{
"CardAuthentication": {
"Customer": {
"FirstName": "John",
"LastName": "Doe",
"Email": "[email protected]",
"SocialSecurityNumber": "00003456789"
},
"BillingAddress": {
"Country": "BR"
},
"Card": {
"HolderName": "John Doe",
"Number": "4111111111111111",
"ExpirationMonth": "02",
"ExpirationYear": "2029",
"SecurityCode": "312"
}
}
}
Import the following script that will make available tokanizeCard()
:
<script src="https://..../tokenizeCard_promise.js" type="text/javascript"></script>
Use tokanizeCard_promise
to send the required data and handle response / error:
tokenizeCard_promise({
apiKey: '<𝘢𝘱𝘪𝘬𝘦𝘺 𝘴𝘵𝘳𝘪𝘯𝘨>',
environment: '<𝘦𝘯𝘷𝘪𝘳𝘰𝘯𝘮𝘦𝘯𝘵 𝘴𝘵𝘳𝘪𝘯𝘨>',
cardDetails: '<𝘤𝘢𝘳𝘥𝘋𝘦𝘵𝘢𝘪𝘭𝘴 𝘰𝘣𝘫𝘦𝘤𝘵>',
})
.then(function (CreditCardToken) {
// use received 'CreditCardToken'
console.log(CreditCardToken);
})
.catch(function (err) {
// handle error
console.error(err.status, err.statusText);
});
Parameter | Type | Possible Values | Description |
---|---|---|---|
apiKey |
string | API key previously obtained from S2P server | |
environment |
string | 'DEV' 'TEST' 'LIVE' |
select the environment
|
cardDetails |
JSON object | check sample bellow | card authentication details in JSON format |
Sample card details object:
{
"CardAuthentication": {
"Customer": {
"FirstName": "John",
"LastName": "Doe",
"Email": "[email protected]",
"SocialSecurityNumber": "00003456789"
},
"BillingAddress": {
"Country": "BR"
},
"Card": {
"HolderName": "John Doe",
"Number": "4111111111111111",
"ExpirationMonth": "02",
"ExpirationYear": "2029",
"SecurityCode": "312"
}
}
}
Import the following script that will make available tokanizeCard()
:
<script src="https://..../tokenizeCard.js" type="text/javascript"></script>
Create a function where you handle the received CreditCardToken
:
function handleRequest(CreditCardToken) {
// use received 'CreditCardToken'
console.log(CreditCardToken);
}
Create a function to handle any received errors:
function handleError(HttpStatusCode, errorText) {
// handle error
console.error(HttpStatusCode, errorText);
}
Use tokanizeCard()
to send the required data and handlers:
tokanizeCard({
apiKey: '<𝘢𝘱𝘪𝘬𝘦𝘺 𝘴𝘵𝘳𝘪𝘯𝘨>',
environment: '<𝘦𝘯𝘷𝘪𝘳𝘰𝘯𝘮𝘦𝘯𝘵 𝘴𝘵𝘳𝘪𝘯𝘨>',
cardDetails: '<𝘤𝘢𝘳𝘥𝘋𝘦𝘵𝘢𝘪𝘭𝘴 𝘰𝘣𝘫𝘦𝘤𝘵>',
handleRequest: '<𝘩𝘢𝘯𝘥𝘭𝘦𝘙𝘦𝘲𝘶𝘦𝘴𝘵 𝘤𝘢𝘭𝘭𝘣𝘢𝘤𝘬>',
handleError: '<𝘩𝘢𝘯𝘥𝘭𝘦𝘌𝘳𝘳𝘰𝘳 𝘤𝘢𝘭𝘭𝘣𝘢𝘤𝘬>'
});
Parameter | Type | Possible Values | Description |
---|---|---|---|
apiKey |
string | API key previously obtained from S2P server | |
environment |
string | 'DEV' 'TEST' 'LIVE' |
select the environment
|
cardDetails |
JSON object | check sample bellow | card authentication details in JSON format |
handleRequest |
callback function | a Javascript function that will receive CreditCardToken as a parameter |
|
handleError |
callback function | a Javascript function that will receive an error code: HttpStatusCode and errorText parameters |
Sample card details object:
{
"CardAuthentication": {
"Customer": {
"FirstName": "John",
"LastName": "Doe",
"Email": "[email protected]",
"SocialSecurityNumber": "00003456789"
},
"BillingAddress": {
"Country": "BR"
},
"Card": {
"HolderName": "John Doe",
"Number": "4111111111111111",
"ExpirationMonth": "02",
"ExpirationYear": "2029",
"SecurityCode": "312"
}
}
}