Checkouts

Once you've embedded PayNow.js in your website - you can easily open and manage checkout lifecycles.

Opening the Checkout

React

import PayNowJS from "@paynow-gg/paynow.js"

export default function CheckoutComponent() {
    function openCheckout() {
        PayNowJS.checkout.open({ token: "checkout token" })
    }

    return (
        <button onClick={() => openCheckout()>Open Checkout</button>
    )
}

JavaScript (CDN Installation)

<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.paynow.gg/paynow-js/bundle.js" defer></script>
    </head>
    <body>
        <button onclick="openCheckout">
            Open Checkout
        </button>

        <script>
            function openCheckout() {
                window.PayNow.checkout.open({
                    token: "CHECKOUT_TOKEN"
                })
            }
        </script>
    </body>
</html>

Closing the checkout

Call close() to programmatically dismiss the checkout overlay:

React:

JavaScript (CDN)

Event Listeners

PayNow.js emits three events during the checkout lifecycle:

  • ready - Fires when the checkout overlay is rendered

  • completed - Fires when the customer completes their purchase

  • closed - Fires when the checkout overlay is dismissed

You can listen to these events via the on and off functions on checkout

React Usage

JavaScript (CDN) Usage

API Reference

Methods

  • checkout.open(options: { token: string, baseURL?: string; renderTo?: { element: HTMLElement; } }): Opens the checkout with the specified token and optional base URL. You should never need to set baseURL - its used internally.

  • checkout.close(): Closes the open checkout.

  • checkout.on<K extends keyof CheckoutEvents>(event: K, handler: CheckoutEvents[K]): Registers an event listener for a specified checkout event.

  • checkout.off<K extends keyof CheckoutEvents>(event: K, handler: CheckoutEvents[K]): Unregisters an event listener for a specified checkout event.

Events

  • ready: Emitted when the checkout is ready to use.

  • completed: Emitted when an order is completed, providing an object with the orderId.

  • closed: Emitted when the checkout is closed.

Last updated

Was this helpful?