Overview
The JavaScript SDK is designed to allow integrators to seamlessly integrate payments into their website. Clearent's JavaScript SDK uses iframes to incorporate the best practices for PCI security compliance for e-commerce sites: PCI Security Standard Council - Best Practices for Securing E-commerce
The worst part about payment iframes is that they are not responsive and the host page cannot style the contents.
The best part about Clearent JavaScript SDK payment iframe is that it is responsive and the host page can style the contents.
The Clearent JavaScript SDK allows integrators to add a payment form to their website by simply copying and pasting a few lines of code into their existing website.
<div id="payment-form"></div>
<script src="https://gateway-sb.clearent.net/js-sdk/js/clearent-host.js"></script>
<script type="text/javascript">
// When you get a successful token response and
// use this to make a sale/auth on your backend
function ClearentTokenSuccess(raw, json) {
console.log("ClearentTokenSuccess");
console.log(raw);
console.log(json);
// now you can send the token to your server
// to complete the transaction via mobile-gateway
}
function ClearentTokenError(raw, json) {
console.log("ClearentTokenError");
console.log(raw);
console.log(json);
}
</script>
<script type="text/javascript">
ClearentSDK.init({
"baseUrl": "https://gateway-sb.clearent.net",
"pk": "YOUR PUBLIC KEY GOES HERE"
});
</script>
ClearentSDK.getPaymentToken();
When the getPaymentToken() method is called in this manner, the success or error message will be handled by the success and error callbacks
(callback function example above).
Using Promises: Alternatively you may wish to uses promises for the response from the ClearentSDK.getPaymentToken() method.
Below is an example of the getPaymentToken() called using promises.
ClearentSDK.getPaymentToken().then(
(result) => {
// this function is called if getting a payment token was successful
console.log("ClearentTokenSuccess");
console.log(result);
},
(error) => {
// this function is called if getting a payment token failed
console.log("ClearentTokenError");
console.log(error);
}
);
{
"code":"200",
"status":"success",
"exchange-id":"ID-clearent-mobile-jwt-1-c32bfe39-d454-4e34-8b4f-94d850643e48",
"payload":{
"mobile-jwt":{
"jwt":"eyJhbGciOi23UzIh4iJ9.eyJsYXN0LWZvdXIiOiIxMrkP8iwid
HlwZSI6Ik1BTlVBTCIsImV4cCI6MTU0NzY0NjU2MSwidG9rZW4iOiIxMTAwMDAw
MDAwMDEzNTkyIn0.eT8c_5yUzxCxL2MEtmbG444eTFRW7OxzRF7x4uRIo-U",
"last-four":"1111"
},
"payloadType":"mobile-jwt"
}
}
You can find more details in our Mobile Payment Transactions documentation.
POST /rest/v2/mobile/transactions/sale
Accept:application/json
Content-Type:application/json
api-key:YOUR_API_KEY_GOES_HERE
mobilejwt:eyJhbGciOi23UzIh4iJ9.eyJsYXN0LWZvdXIiOiIxMrkP8iwid
HlwZSI6Ik1BTlVBTCIsImV4cCI6MTU0NzY0NjU2MSwidG9rZW4iOiIxMTAw
MDAwMDAwMDEzNTkyIn0.eT8c_5yUzxCxL2MEtmbG444eTFRW7OxzRF7x4uRIo-U
Body
{
"type": "SALE",
"amount": "15.55",
"software-type": "AwesomePOSSoftware",
"software-type-version":"1"
}
{
"code": "200",
"status": "success",
"exchange-id": "ID-clearent-mobile-gateway-1-2a6b56d3-c660-4810-95ea-9fb9a21c6634",
"payload": {
"transaction": {
"amount": "15.55",
"id": "2586119",
"type": "SALE",
"result": "APPROVED",
"card": "XXXXXXXXXXXX1111",
"csc": "999",
"authorization-code": "TAS022",
"batch-string-id": "938",
"display-message": "Transaction approved",
"result-code": "000",
"exp-date": "1220",
"software-type": "AwesomePOSSoftware",
"card-type": "VISA",
"last-four": "1111"
},
"payloadType": "transaction"
}
}