<head>
of your page:<script src="https://token.dcap.com/v1/client"></script>
<form id="payment_form">
<input type="text" data-token="card_number" />
<input type="text" data-token="exp_month" />
<input type="text" data-token="exp_year" />
<input type="text" data-token="cvv" />
Note: The payment info input controls must not have ID or Name attributes.
<input type="hidden" id="token" />
var tokenCallback = function(response) {
if (response.Error)
{
alert("Token error: " + response.Error);
}
else
{
var token = response.Token;
document.getElementById("token").value = token;
}
}
requestToken
with your token key, payment form ID, and token callback method:DatacapWebToken.requestToken("[Token Key Goes Here]", "payment_form", tokenCallback);
{
Token: "DC4:AAAMbdJpMn6wZYlx84etCekz2HMpp6IQtqL0G3aMInirXYQMNLpr9oJMctxC76NVSGkO5XXO/naM0X1CfzX1md2caSTHKO4QjpYmzJlMOsQwer5VUEJWCZVzd0Ytr2jvRLw=",
Brand: "Visa",
ExpirationMonth: "12",
ExpirationYear: "2020",
Last4: "1111"
}
{
Error: "Failed to create token"
}
The Datacap WebToken client provides a few methods to help integrators validate their input fields, for card
number, expiration date, and CVV that return bool
values indicating input validity.
var validCard = DatacapWebToken.validateCardNumber("4242424242424242");
var validExpirationDate = DatacapWebToken.validateExpirationDate("06", "2020");
var validCVV = DatacapWebToken.validateCVV("123");
Now that you've got fresh tokens in your payment form, you can submit the form and process token payments on Datacap's payment platform!
If you encounter any bugs or issues with the latest version of WebToken, please report them to us by opening a GitHub Issue!