This guide explains how to integrate Kodaris Payments Gateway into your ecommerce checkout flow for credit card processing using the One Time Payment Flow.
The integration uses a two-step process:
Make a server-to-server call to obtain a secure credit card form URL:
None
GET /api/system/paymentProcessing/card/formUrl?companyID=123
Authorization: Bearer YOUR_API_KEY
Parameters:
Response:
JSON
{
"success": true,
"code": 200,
"messages": [],
"errors": [],
"data":"https://payments.kodaris.com/api/user/kodarispayments/cardForm?nonce=nonceToken",
"requestId": "some_string"
}
Important:
Embed the form URL in an iframe on your checkout page:
HTML
<iframe
id="kodaris-payment-iframe"
src="FORM_URL_FROM_STEP_1"
width="100%"
height="400">
</iframe>
<button id="submit-payment">Complete Payment</button>
Trigger form submission from outside the iframe:
Javascript
const kodarisPaymentIframe = document.getElementById('kodaris-payment-iframe');
const submitButton = document.getElementById('submit-payment');
submitButton.onclick = () => {
kodarisPaymentIframe.contentWindow.postMessage(
{ type: 'kpSubmit' },
'https://payments.kodaris.com'
);
};
// Handle Payment Response
// Listen for messages from the payment iframe:
window.addEventListener('message', async (ev) => {
// Security: Only trust messages from Kodaris
if (ev.origin !== 'https://payments.kodaris.com') {
console.error('Untrusted message origin');
return;
}
if (ev.data.type === 'kpSubmitSuccess') {
const paymentNonce = ev.data.nonce;
// TODO Send nonce to your server for processing
} else if (ev.data.type === 'kpSubmitError') {
alert('Payment failed. Please try again.');
// TODO Handle validation or submission errors
}
});
Once you receive the nonce token from the client, process the payment on your server:
None
POST /api/system/paymentProcessing/card/charge/byNonce?amount=1.23&invoiceNumber=1234&companyID=123
Authorization: Bearer YOUR_API_KEY
Content-Type: text/plain
noncetokenhere
Parameters: