Create a checkout session on your server and present it in a modal or embedded checkout using the EDPay JavaScript SDK.
The SDK can present the session in a modal or embedded container. Use callbacks to update the interface; confirm payment status through a webhook or server-to-server lookup.

Create the parent with POST /v1/payments, then call POST /v1/payments/{id}/public-checkout with both partner-key headers and Idempotency-Key. Keep the payment ID and private key on your server. Set embed_origin to the exact HTTPS origin for modal or embedded presentation:
// Create the parent payment, then start hosted checkout for that payment.
export async function createHostedCheckout(order: Order) {
const paymentResponse = await fetch("https://api-pay.edutecka.com/v1/payments", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-EDPay-Public-Key": process.env.EDPAY_PUBLIC_KEY!,
"X-EDPay-Private-Key": process.env.EDPAY_PRIVATE_KEY!,
"Idempotency-Key": "payment-" + order.id,
},
body: JSON.stringify({
amount_minor: order.amountMinor,
currency: order.currency,
reference: order.reference,
}),
});
if (!paymentResponse.ok) throw new Error("Payment could not be created.");
const payment = await paymentResponse.json();
const checkoutResponse = await fetch(
"https://api-pay.edutecka.com/v1/payments/" + payment.data.id + "/public-checkout", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-EDPay-Public-Key": process.env.EDPAY_PUBLIC_KEY!,
"X-EDPay-Private-Key": process.env.EDPAY_PRIVATE_KEY!,
"Idempotency-Key": "public-checkout-" + order.id,
},
body: JSON.stringify({ embed_origin: "https://shop.example.com" }),
});
if (!checkoutResponse.ok) throw new Error("Hosted checkout could not be created.");
const checkout = await checkoutResponse.json();
return { token: checkout.data.token, paymentId: payment.data.id };
}Load the EDPay JavaScript bundle and pass the session token returned by your backend. The public key may be used in the browser; never expose the private key:
<!-- 1. Load official SDK on your frontend page -->
<script src="https://pay.edutecka.com/v1/edpay.js"></script>
<script>
// Initialize with the account's public key.
const edpay = new EDPay({
publicKey: "YOUR_PUBLIC_KEY<YOUR_PUBLIC_KEY>",
});
async function handlePayment() {
// Ask your own backend to create the session; never expose the private key.
const res = await fetch("/api/checkout", { method: "POST" });
if (!res.ok) throw new Error("Checkout session could not be created.");
const { token } = await res.json();
edpay.checkout({
token,
mode: "modal",
onSuccess: function(result) {
// Verify final status through your webhook or server-side lookup.
console.log("Checkout completed:", result);
},
onError: function(err) {
console.warn("Payment error or cancelled:", err);
},
onClose: function() {
console.log("Modal closed by user");
}
});
}
</script>If you prefer embedding payment directly inside a page column or div without opening a popup modal:
// Embedded mode (mounts inside a <div> container on your page)
edpay.checkout({
token: token,
mode: "embedded",
container: "payment-container", // DOM container ID
width: "100%",
height: "640px",
onSuccess: (payment) => {
// Handle approved payment
}
});| Parameter | Type | Default | Description |
|---|---|---|---|
| token | string | — | Public session token returned by POST /v1/payments. |
| mode | "modal" | "embedded" | "modal" | Visual presentation mode in browser window. |
| container | string | HTMLElement | — | DOM element ID to mount the iframe (required if mode='embedded'). |
| onSuccess | function(payment) | — | Callback invoked when payment is successfully confirmed. |
| onError | function(error) | — | Callback invoked upon customer cancellation or gateway decline. |
| onClose | function() | — | Callback invoked when customer closes the modal window. |