JavaScript
The JavaScript SDK provides a secure, client‑side library for web‑based payment processing.
Prerequisites
To integrate the JavaScript SDK into your website, ensure you have following:
✅ An HTTPS-enabled web server.
✅ A modern browser that supports JavaScript.
✅ An active Xplor Pay account.
✅ A public API key.
✅ A sandbox URL for testing the integration.
Add payment form
To add the payment form into your website:
Add a
<div>tag to your code that hosts the payment form.
<div id="payment-form"></div>Add a
<script>tag to include the SDK library hosted by Xplor Pay.
<script src="https://gateway-int.clearent.net/js-sdk/js/clearent-host.js"></script>Call the
initmethod with the base URL to host the payment form and add your public key.
<script type="text/javascript">
ClearentSDK.init({
"baseUrl": "https://gateway-int.clearent.net",
"pk": "YOUR PUBLIC KEY GOES HERE"
});
</script>The baseURL directs your customers to the hosted payment form where they can enter the payment information.
Get JSON Web Token
To get a JSON Web Token when a customer submits payment information to process:
Add the
ClearentSDK.getPaymentTokenmethod using promises to access the JWT service.
ClearentSDK.getPaymentToken().then(
(result) => {
console.log("ClearentTokenSuccess");
console.log(result);
},
(error) => {
console.log("ClearentTokenError");
console.log(error);
}
);The
ClearentTokenSuccesscallback function securely receives the response from the JWT services, which includes an encrypted JSON Web Token in thejwtfield.
{
"code":"200",
"status":"success",
"exchange-id":"ID-clearent-mobile-jwt-1-c32bfe39-d454-4e34-8b4f-94d850643e48",
"payload":{
"mobile-jwt":{
"jwt":"eyJhbGciOi23UzIh4iJ9.eyJsYXN0LWZvdXIiOiIxMrkP8iwidHlwZSI6Ik1BTlVBTCIsImV4cCI6MTU0NzY0NjU2MSwidG9rZW4iOiIxMTAwMDAwMDAwMDEzNTkyIn0.eT8c_5yUzxCxL2MEtmbG444eTFRW7OxzRF7x4uRIo-U",
"last-four":"1111"
},
"payloadType":"mobile-jwt"
}
}A JSON Web Token (mobile-jwt) is required to process payments through the Mobile Transactions endpoints.
Create card token
To create a card token when processing the card payments:
Add the
create-tokenproperty to your JSON request body of the Mobile Transactions endpoint and set its value totrue.
{
"type": "sale",
"amount": "15.55",
"service-fee": "0.46",
"software-type": "Sally's Seashell Shore Software",
"software-type-version": "1.0",
"software-version": "1.0",
"create-token": true,
"billing":
{
"zip": "85284"
}
}The successful response includes a randomly generated Card Token in the id field.
{
"rel": "token",
"href": "/rest/v2/tokens/1100003582050381111",
"id": "1100003582050381111"
}A Card Token allows you to process future card transactions using the Transactions endpoints. You must include the Card Token in the card field of the JSON request body.
Last updated
Was this helpful?

