Example description: Credit Card Storage
In this demo example you have Custom Form with enabled support for verification for a Payment with Credit Card storage. Once the payment has been processed and the card is stored. Retrieve a list of Customer Cards is easily available using an e-mail address.
function onValidFormPay()
{
var form = document.querySelector('form[data-centralpay="form"]');
var urlCentralpayApi = 'https://test-api.centralpay.net/v2/rest/';
var firstname = form.querySelector('input[name="order[firstName]"]').value;
var lastname = form.querySelector('input[name="order[lastName]"]').value;
var number = form.querySelector('input[data-centralpay="card[number]"]').value;
var holderEmail = form.querySelector('input[name="card[cardholderEmail]"]').value;
var expirationMonth = form.querySelector('input[data-centralpay="card[expirationMonth]"]').value;
var expirationYear = form.querySelector('input[data-centralpay="card[expirationYear]"]').value;
var cvc = form.querySelector('input[data-centralpay="card[cvc]"]').value;
var data = {
'merchantPublicKey': document.querySelector('input[data-example="merchantPublicKey"]').value,
'card[holderEmail]': holderEmail,prettyprint lang-html
'card[holderName]': lastname + " " + firstname,
'card[number]': number,
'card[cvc]': cvc,
'card[expirationMonth]': expirationMonth,
'card[expirationYear]': expirationYear,
};
const query = new URLSearchParams(data);
var xhr = new XMLHttpRequest();
xhr.open('POST', urlCentralpayApi + 'cardToken');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if(xhr.status === 400){
console.log("400: Manage this case");
}
else if(xhr.status === 200){
console.log(JSON.parse(xhr.responseText));
//Get cardTokenId from response and send it during customer creation
}
else{
console.log("Error: Manage this case");
}
}
};
xhr.send(query.toString());
}
curl -v customer \
-u ' ' \
-d merchantCustomerId= \
-d cardTokenId= \
-d firstName= \
-d lastName= \
-d email= \
curl -v card \
-u ' ' \
-d merchantCardId= \
-d customerId= \
-d cardTokenId= \
curl -v https://test-api.centralpay.net/v2/rest/transaction \
-u ' ' \
-d merchantTransactionId= \
-d amount= \
-d currency= \
-d receiptEmail= \
-d pointOfSaleId= \
-d cardTokenId= \
-d customerId= \
-d cardId= \
-d cvcValidation= \
-d description= \
-d endUserIp= 35.172.217.40 \
-d order[firstName]= \
-d order[lastName]= \
-d order[country]= \
-d endUserLanguage= \
-d browserAcceptLanguage= \
-d browserUserAgent= \