Opens the checkout over your page, so the buyer pays into escrow without leaving your site. It’s a small launcher with no dependencies: the checkout itself is drawn by KetaPay inside a secure frame. Source on GitHub. Using React? See React.

How it works

  1. Your server creates a checkout session with your secret key and sends its url to the page.
  2. Your page calls KetaPay.open({ url }). The checkout opens as a centred window on a computer, and fills the screen on a phone.
  3. The buyer pays. You get onSuccess in the browser and escrow.funded on your server.
onSuccess can’t prove a payment. Before you ship anything, wait for the escrow.funded webhook or fetch the session (see Verify payments).
This library takes no keys. Your secret key stays on your server.

Install

The script tag adds window.KetaPay.

Open the checkout

open returns { close, result }. result resolves once, to 'success' when the buyer pays, 'error' if the checkout doesn’t load, or 'closed' if they close it first:
Call checkout.close() to close it yourself, for example straight after onSuccess if you’d rather show your own receipt. Opening a second checkout while one is showing returns the one already open.

Branding

The checkout shows your business’s logo and colour from your KetaPay settings. There are no styling options in the browser, so it looks the same as your hosted checkout.

Errors

Every error is a KetaPayCheckoutError with a code. Mistakes in the call are thrown by open before anything shows; a checkout that doesn’t load goes to onError.

Good to know

  • Server rendering: importing the package touches neither window nor document, so it’s safe in Next.js, Remix and Nuxt.
  • Content Security Policy: add frame-src https://checkout.ketapay.com, and script-src https://js.ketapay.com if you use the script tag. The overlay needs nothing in style-src.
  • Sandbox: sessions created with an sk_test_ key open the same checkout in test mode. See Testing.
  • Browsers: the last two versions of Chrome, Edge, Firefox and Safari, and Safari on iOS 15 or later.

Versions

Script tag URLs name an exact version and never change once published. When 1.0 is out, https://js.ketapay.com/v1/checkout.js will always serve the newest 1.x.