Checkout in a popup, your page stays open

Add one script and call window.Paymentnp.open with a checkout URL from your server. The customer pays in a centred window over your site, and your page hears the result without losing the cart.

  • No dependencies
  • Falls back to a redirect
  • Never in an iframe

Three pieces. Two on your server, one in the browser.

  1. Create the session on your server

    The same POST /v1/checkout/sessions call as hosted checkout, with your API key kept on the server. Hand the checkout_url to the browser.

  2. Open it with checkout.js

    Call window.Paymentnp.open with the URL and three callbacks: onSuccess, onCancel and onClose. The customer pays in a 520 by 760 window centred over your page.

  3. Confirm on your server

    onSuccess tells your page to move on. Fulfil the order when the signed payment.succeeded webhook arrives, or after fetching the session from your server.

The whole browser side. One script tag and one call.

The script is served from https://paymentsnp.com/checkout.js and has no dependencies, so it works on a plain HTML page, in WordPress or inside a React app.

The name is window.Paymentnp, without the s. It is a technical identifier that existing integrations rely on, so it stays as it is.

Callbacks receive { session_id, status }. A manually_confirmed status also calls onSuccess, so check result.status if you need to tell them apart.

checkout.js
<script src="https://paymentsnp.com/checkout.js"></script>
<script>
  document.querySelector("#pay").addEventListener("click", async () => {
    // Your server creates the session and returns its checkout_url.
    const { checkoutUrl } = await fetch("/orders/1001/checkout", {
      method: "POST",
    }).then((r) => r.json());

    window.Paymentnp.open({
      checkoutUrl,
      onSuccess(result) {
        // A UI hint only. result = { session_id, status }
        location.href = "/orders/1001?check=" + result.session_id;
      },
      onCancel() { showMessage("Payment cancelled"); },
      onClose() { enablePayButton(); },
    });
  });
</script>
// What the checkout posts back to your page (window.opener):
{
  type: "paymentnp:checkout",
  session_id: "c1a94d07-...",
  status: "paid" // or "manually_confirmed", "cancelled", "expired"
}
// checkout.js checks the origin and the source window before it
// calls onSuccess (paid, manually_confirmed) or onCancel.

Built for the browsers people use. Including the ones that block popups.

A redirect when the window cannot open

Some browsers and in-app browsers block popups. checkout.js then sends the same tab to checkout, and the customer comes back through your return URLs. Your server logic does not change, because it already waits for the webhook.

The popup remembers where it came from

The popup carries your page's origin in its address fragment and keeps it across the trip to eSewa, Khalti or Fonepay, so the result still reaches your page after the provider sends the customer back.

What happens in each case
Popup opensCheckout runs in the window; your page gets the result message
Popup blockedThe same tab goes to checkout, then returns to your success or cancel URL
Customer closes the windowonClose runs; check the session on your server and re-enable the Pay button
Customer cancelsonCancel runs with the session id
Session expiresonCancel runs with status expired

Who gets the result. Only pages you approved.

The result message is checked for origin and source before any callback runs. You control which sites may receive it.

  • No dependencies

    One small script. Nothing else to install or bundle.

  • Approved embed domains

    Up to 20 per environment, set in Settings by owners and administrators. With a list, results go only to an approved opener.

  • Without a list

    The result goes to the origin of the session's success_url, or its cancel_url if there is no success_url.

  • Server confirms

    The popup result is a hint for your page. The webhook or a session fetch decides whether you ship.

Questions merchants ask. About the popup.

Can I embed checkout in an iframe instead?

No. Checkout refuses to load in a frame on any site, including yours. Use the popup or a full-page redirect. Both keep the address bar visible to the customer.

Does the popup work on phones?

checkout.js asks the browser for a popup window. Where a browser blocks it, the same tab goes to checkout and returns to your URLs, so the payment still completes.

Is onSuccess enough to ship the order?

No. It runs in the customer's browser, which you cannot trust. Ship on the signed payment.succeeded webhook or after fetching the session from your server.

Where do I add my site as an embed domain?

In the dashboard under Settings, for the current environment. Owners and administrators can add up to 20 domains each for Test and for Live.