Overview
The Moment JavaScript SDK enables seamless payment integration into any web application. Whether you need a modal overlay or inline embedded checkout — the SDK handles it all with a simple, unified API. Built with vanilla JavaScript (no dependencies), the SDK works with any frontend framework or plain HTML pages.Embedded Modal :
Key Features
- Zero Dependencies – Pure vanilla JavaScript, works everywhere
- Flexible Display Options – Choose between modal overlay or inline embedded checkout
- Flexible Callbacks – Handle payment success, failure, cancellation, retry, and expiry events
- Cross-Origin Safe – Secure iframe communication via
postMessage - Environment Detection – Automatic sandbox / production switching based on client key
- PCI Compliant – All sensitive payment data handled in Moment’s secure iframe
Display Variants
How It Works
- Page loads —
Moment(clientKey)creates an SDK instance;moment.checkout()is called to create a checkout instance with yourfetchClientToken,fetchSessionStatus, and event callbacks (onSuccess,onFailure, etc.) - Customer clicks Pay —
checkout.launch()is called - SDK calls
fetchClientToken— your callback creates a session on your backend (with asuccess_url) and returns theclient_token - Checkout opens in your chosen variant (modal or inline)
- Customer submits payment — Moment takes over the full page and redirects to the authentication page
- Customer completes authentication on the external page
- Customer is redirected back to your
success_urlwith?session_id=abc123appended - Page loads again —
moment.checkout()detects thesession_idin the URL automatically and calls yourfetchSessionStatus('abc123')callback - Your callback fetches the status from your backend, which queries Moment API
- SDK routes to the right handler —
onSuccess,onFailure,onExpired, oronCancel— and removessession_idfrom the URL silently - Webhooks are delivered to your backend regardless of outcome
Installation
Script Tag (Recommended)
Self-Hosted
Downloadmoment.js and include it in your project:
Module Import (Coming Soon)
Quick Start
1. Initialize the SDK
CallMoment(clientKey) once when your page loads to create an SDK instance. Then call moment.checkout() with your fetch callbacks and event handlers — it returns a checkout instance, and the SDK calls your callbacks automatically at the right moments, so you never manage tokens or session IDs manually.
Backend endpoints:
- Node.js
- Python
- Go
- Firebase
- Supabase
- Lambda
server.js
- Fetch (Native)
- Axios
- Firebase
- Supabase
app.js
2. Open Checkout
app.js
API Reference
Moment(clientKey)
Factory function — creates an isolated SDK instance scoped to your publishable key. Returns an object with product namespaces (checkout, and more in the future).
Throws immediately if
clientKey is invalid.
moment.checkout(config)
Creates and returns a checkout instance for this SDK. Detects any?session_id= in the current URL and automatically calls fetchSessionStatus if provided. Returns a checkout object with launch, close, and submit methods.
Example:
checkout.launch(options)
Opens the payment checkout. Internally calls yourfetchClientToken function to retrieve a fresh token, then opens checkout. The display variant (modal or inline) is determined from the JWT payload variant claim, which is set when creating the session on your backend.
Returns a
Promise that resolves with { checkoutUrl, variant } once the checkout is open.
Examples:
checkout.close()
Manually closes the modal or inline checkout.checkout.submit() Coming soon
Triggers payment submission from outside the iframe — useful when you want an external “Pay” button rather than relying on the checkout UI’s built-in submit. Only available for the inline variant.
Security Best Practices
- Never expose your secret key (
sk_...) in frontend code - Always create sessions server-side using your secret key
- Validate webhooks to confirm payment status server-side
- Use HTTPS for all pages that include the SDK
- Handle token expiry by requesting a new token if needed
Next Steps
- View Sample Applications for end-to-end examples
- Create your first Payment Session
- Configure Webhooks
- Test your integration in Sandbox mode

