JS Client Side Encryption SDK

The Client Side Encryption (CSE) SDK is a JavaScript library that encrypts card data in the customer's browser. You build your own card form, the library encrypts what the customer enters, and your server sends the encrypted string to Buckaroo. The card data never reaches your server unencrypted, and only Buckaroo can decrypt it.
Building a mobile app?
Use the iOS Client Side Encryption SDK or the Android Client Side Encryption SDK. They encrypt the card data on the device in the same way.
How it works
- Show a card form.
Your checkout page asks for the card number, expiry date, security code and cardholder name. - Validate and encrypt.
The library checks the input and turns it into one encrypted string, in the browser. - Send the string to your server.
Your page posts the encrypted string to your server, not the card data. - Start the payment.
Your server sends the string to Buckaroo in aPayEncryptedorAuthorizeEncryptedrequest.
Supported payment methods
- All credit cards
- Bancontact
Add the library
Load the library from Buckaroo on the page that has your card form:
<script src="https://static.buckaroo.nl/script/ClientSideEncryption001.js"></script>All functions are available under BuckarooClientSideEncryption.V001.
The library uses the browser's Web Crypto API, which browsers only make available on pages served over HTTPS. It does not work on a page served over plain HTTP.
Validate the input
Use the validation functions to check each field before you encrypt. They return true or false.
| Function | Checks |
|---|---|
validateCardNumber(cardNumber, cardService) | Digits only, 10 to 19 long, and a valid check digit. With a card service, also the number format for that card |
validateCvc(cvc, cardService) | 3 or 4 digits, or empty. With a card service, the length for that card |
validateYear(year) | 2 or 4 digits |
validateMonth(month) | A number from 1 to 12 |
validateCardholderName(name) | Not empty |
cardService is optional. Pass the card brand, such as visa, mastercard, amex, maestro or bancontact, for a stricter check.
- Pass all values as strings
- Remove spaces from the card number first. The library accepts digits only
validateYearandvalidateMonthcheck the format, not whether the card has expired- Maestro and Bancontact cards have no security code. Pass an empty string for those
Encrypt the card data
encryptCardData takes the five card values and a callback. The callback receives the encrypted string.
BuckarooClientSideEncryption.V001.encryptCardData(
'5386860000000000', // card number
'2030', // expiry year
'12', // expiry month
'123', // security code, or '' for Maestro and Bancontact
'John Williams', // cardholder name
function (encryptedCardData) {
// send encryptedCardData to your server
}
);If the encryption fails, the library logs the error to the browser console and does not call the callback.
Encrypt a security code
encryptSecurityCode encrypts only the security code. Use it for requests that take an EncryptedSecurityCode, such as a payment with a stored card where the customer only enters the security code again.
BuckarooClientSideEncryption.V001.encryptSecurityCode(
'123', // security code
function (encryptedSecurityCode) {
// send encryptedSecurityCode to your server
}
);Start the payment on your server
Send the encrypted string to Buckaroo in the EncryptedCardData parameter of a PayEncrypted or AuthorizeEncrypted request. See Credit cards and Bancontact for the request details.
From there the payment continues as if the customer had entered the card on the Buckaroo payment page. The response is either a redirect URL for 3D Secure authentication, or the status of the transaction.
The Buckaroo SDKs have a ready-made call for this request. See the PHP SDK, Node SDK and Python SDK.
Full example
A card form that validates the input, encrypts it and posts the encrypted string to your server:
<form id="card-form">
<!-- The card fields have no name attribute, so the browser never submits them -->
<label>Card number <input id="cardNumber" autocomplete="cc-number" inputmode="numeric"></label>
<label>Expiry month <input id="expiryMonth" autocomplete="cc-exp-month" inputmode="numeric"></label>
<label>Expiry year <input id="expiryYear" autocomplete="cc-exp-year" inputmode="numeric"></label>
<label>Security code <input id="cvc" autocomplete="cc-csc" inputmode="numeric"></label>
<label>Cardholder name <input id="cardholder" autocomplete="cc-name"></label>
<button type="submit">Pay</button>
<p id="card-error" hidden>Check your card details and try again.</p>
</form>
<script src="https://static.buckaroo.nl/script/ClientSideEncryption001.js"></script>
<script>
var cse = BuckarooClientSideEncryption.V001;
document.getElementById('card-form').addEventListener('submit', function (event) {
event.preventDefault();
var cardNumber = document.getElementById('cardNumber').value.replace(/\s/g, '');
var month = document.getElementById('expiryMonth').value.trim();
var year = document.getElementById('expiryYear').value.trim();
var cvc = document.getElementById('cvc').value.trim();
var cardholder = document.getElementById('cardholder').value.trim();
var valid =
cse.validateCardNumber(cardNumber) &&
cse.validateMonth(month) &&
cse.validateYear(year) &&
cse.validateCvc(cvc) &&
cse.validateCardholderName(cardholder);
document.getElementById('card-error').hidden = valid;
if (!valid) {
return;
}
cse.encryptCardData(cardNumber, year, month, cvc, cardholder, function (encryptedCardData) {
// Post only the encrypted string to your own server
fetch('/checkout/pay', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ encryptedCardData: encryptedCardData }),
});
});
});
</script>Go live
Client Side Encryption has to be enabled for your account before you can use it for live payments.
- Test the full flow in the test environment. See Test transactions for test cards
- Complete the PCI SAQ-A self-assessment form and send it to Buckaroo
- Buckaroo enables Client Side Encryption for your live payments
Updated 6 days ago