
JavaScript Inline
Embed a secure, branded Moolre checkout directly in a browser application or website.
- NPM or CDN install
- Modal checkout
- Custom branding
- Success and error events
- Custom fields and validation
- Webhook and redirect URLs
Simple Integration
Load the SDK with one script tag from https://js.moolre.com, or install the npm package in a bundled application.
<!-- 1. Add the Moolre SDK to your website --><script src="https://js.moolre.com"></script><!-- 2. Add a button to trigger payment --><button id="pay-btn">Pay Now</button><script> const popup = new MoolrePay(); document.getElementById("pay-btn").addEventListener("click", () => { popup.checkout({ username: "YOUR_MOOLRE_USERNAME", publicKey: "YOUR_PUBLIC_KEY", accountNumber: "YOUR_ACCOUNT_NUMBER", amount: 50, email: "customer@example.com", currency: "GHS", externalRef: "ref_" + Date.now(), metadata: { order_id: "12345" }, onLoad: () => console.log("💡 Checkout loaded"), onSuccess: (res) => console.log("✅ Payment success:", res), onCancel: () => console.log("❌ Cancelled"), onError: (err) => console.error("💥 Error:", err), }); });</script>Customize Your Checkout
Tailor the data, colors, and text to match your brand and payment flow. Use the configuration panel below to see a live preview.
Checkout Customizer
Embed Your Custom Checkout
Copy the generated code below and paste it into your application. Use "Embed Snippet" for existing pages or "Full Page" for a standalone checkout page.
<!-- Styles --><style> .payment-form { width: 100%; max-width: 350px; background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); } /* Header Styles */ .form-header { text-align: center; margin-bottom: 1rem; border-bottom: 1px solid #f1f5f9; padding-bottom: 1.5rem; } .form-logo { height: 48px; width: auto; margin-bottom: 0.75rem; display: inline-block; } .form-title { font-size: 1.25rem; font-weight: 700; color: #1e293b; margin: 0; } /* Description Styles */ .form-description { text-align: center; color: #64748b; font-size: 0.95rem; margin-bottom: 1.5rem; line-height: 1.5; white-space: pre-line; } /* Amount Display Styles */ .amount-display { text-align: center; margin-bottom: 2rem; } .amount-display p { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; margin: 0 0 0.25rem 0; font-weight: 600; } .currency { font-size: 1.5rem; font-weight: 700; color: #1e293b; margin-right: 0.25rem; vertical-align: top; } .amount { font-size: 2.5rem; font-weight: 800; color: #1e293b; line-height: 1; } .form-group { margin-bottom: 1.25rem; } label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: #475569; font-size: 0.9rem; } input, select, textarea { width: 100%; padding: 0.75rem 0.7rem; border: 1px solid #e2e8f0; border-radius: 6px; box-sizing: border-box; /* font-size: 1rem; */ transition: border-color 0.2s; background-color: #fff; } textarea { resize: vertical; min-height: 80px; font-family: inherit; } input:focus, select:focus, textarea:focus { border-color: #ffbc38; outline: 0; box-shadow: 0 0 0 3px #ffbc3820; } .pay-button { width: 100%; font-size: .9rem; font-weight: 700; border-radius: 4px; background: #ffbc38; border: 1px solid #000000; text-shadow: 1px 1px 1px rgba(0, 0, 0, .1); outline: none; color: #fff; transition: all .3s; height: 42px; cursor: pointer; position: relative; margin-top: 1rem; } .pay-button:hover { opacity: 0.9; } .error-message { color: #ef4444; font-size: 0.8rem; margin-top: 0.35rem; font-weight: 500; } .powered-by { text-align: center; margin-top: 1.5rem; font-size: 0.75rem; color: #94a3b8; font-weight: 500; } .powered-by strong { color: rgb(255, 188, 56) !important; font-weight: 700; }</style><!-- Payment Form --><div class="payment-form"> <div class="form-header"> <img src="https://pos.moolre.com/assets/logo.png" alt="Logo" class="form-logo" /> <h2 class="form-title">Moolre Checkout</h2> </div> <div class="amount-display"> <p>Amount to Pay</p> <span class="currency">GHS</span> <span class="amount">50.00</span> </div> <div class="form-group"> <label for="customer-name">Full Name</label> <input type="text" id="customer-name" value="John Doe" placeholder="John Doe" required /> <p id="name-error" class="error-message"></p> </div> <div class="form-group"> <label for="email">Email Address</label> <input type="email" id="email" value="customer@example.com" placeholder="john.doe@example.com" required /> <p id="email-error" class="error-message"></p> </div> <div class="form-group"> <label for="phone-number">Phone Number</label> <input type="tel" id="phone-number" value="" placeholder="+233..." /> <p id="phone-error" class="error-message"></p> </div> <button id="pay-button" class="pay-button">Pay Now</button> <p class="powered-by">Powered by <strong>Moolre</strong></p></div><!-- Integration Script --><script src="https://js.moolre.com"></script><script> // Mock MoolrePay if not loaded (for offline/testing purposes) if (typeof MoolrePay === 'undefined') { window.MoolrePay = class { checkout(config) { console.log('Checkout initiated with:', config); if (config.onLoad) config.onLoad(); // Simulate user interaction setTimeout(() => { alert('Validation Passed! In a production environment, the Moolre payment popup would open here.'); // Simulate user closing popup or success if(Math.random() > 0.3) { if(config.onCancel) config.onCancel(); } else { if(config.onSuccess) config.onSuccess({ status: "success", transaction_id: "mock_tx_id" }); } }, 1000); } }; } const popup = new MoolrePay(); document.getElementById("pay-button").addEventListener("click", (e) => { e.preventDefault(); const customerName = document.getElementById('customer-name').value; const email = document.getElementById('email').value; const phoneNumber = document.getElementById('phone-number').value; const amount = 50; // --- Advanced Validation --- let isValid = true; document.getElementById('name-error').textContent = ''; document.getElementById('email-error').textContent = ''; document.getElementById('phone-error').textContent = ''; if (document.getElementById('amount-error')) { document.getElementById('amount-error').textContent = ''; } if (!customerName) { document.getElementById('name-error').textContent = 'Full Name is required.'; isValid = false; } if (!email) { document.getElementById('email-error').textContent = 'Email Address is required.'; isValid = false; } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { document.getElementById('email-error').textContent = 'Please enter a valid email address.'; isValid = false; } if (!isValid) return; popup.checkout({ username: "YOUR_MOOLRE_USERNAME", publicKey: "YOUR_PUBLIC_KEY", accountNumber: "YOUR_ACCOUNT_NUMBER", amount: parseFloat(amount), currency: "GHS", email: email, customer: { name: customerName, phone_number: phoneNumber, }, externalRef: "trx_" + Date.now(), // Auto-generated reference onLoad: () => { console.log("💡 Checkout loaded"); }, onSuccess: (res) => { console.log("✅ Payment success:", res); alert("Payment Successful!"); // Optional: Redirect to a success page // window.location.href = "/success.html"; }, onCancel: () => { console.log("❌ Cancelled"); }, onError: (err) => { console.error("💥 Error:", err); alert("An error occurred. Please check the console."); } }); });</script>SDK Reference
Complete documentation for the Moolre Inline JavaScript SDK.
Script tag
Add it before the closing </body> tag. https://js.moolre.com always serves the current release; older URLs such as /moolre.js, /moolre-min.js and /v1/inline.js redirect to it.
<script src="https://js.moolre.com"></script>npm package
Install the package via npm for modern JavaScript frameworks (React, Vue, Angular, etc.).
npm install @moolre/moolrejsThen import it in your project:
import MoolrePay from "@moolre/moolrejs";The MoolrePay class provides three main methods for handling payments.
1. popup.checkout(options)
Starts a new asynchronous transaction and opens the payment modal immediately.
const popup = new MoolrePay();popup.checkout({ username: "YOUR_MOOLRE_USERNAME", publicKey: "YOUR_PUBLIC_KEY", accountNumber: "YOUR_ACCOUNT_NUMBER", amount: 50, email: "customer@example.com", currency: "GHS", // ... other options});2. popup.setup(options)
Optional. Sets global default configuration values so you don't have to repeat them in every call.
popup.setup({ username: "YOUR_MOOLRE_USERNAME", publicKey: "YOUR_PUBLIC_KEY", accountNumber: "YOUR_ACCOUNT_NUMBER", currency: "GHS"});3. popup.preloadTransaction(options)
Advanced. Creates a transaction ahead of time (e.g. on page load) and returns a function to open the modal instantly when the user clicks pay. This reduces perceived latency.
// 1. Preload on page loadconst openPayment = await popup.preloadTransaction({ amount: 100, email: "customer@example.com", // ...});// 2. Bind the returned function to your buttondocument.getElementById('pay-btn').onclick = openPayment;| Option | Type | Required | Description |
|---|---|---|---|
| username | string | Yes | Your Moolre username, sent as X-API-USER. |
| publicKey | string | Yes | Your Moolre public API key. |
| accountNumber | string | Yes | Merchant account number to credit. |
| amount | number | Yes | Payment amount (e.g. 50.00). |
| currency | string | No | Currency code. Defaults to GHS. |
| string | Yes | Customer email for the payment receipt. | |
| externalRef | string | Yes | Your unique transaction reference ID. |
| metadata | object | No | Object containing extra data (e.g. { order_id: "123" }). |
| callbackUrl | string | No | URL to receive the callback on completion. |
| redirectUrl | string | No | URL to redirect the user to after payment. |
| Event | Description |
|---|---|
| onLoad | Triggered when the payment modal has successfully loaded and is visible to the user. |
| onSuccess | Triggered when the payment is completed successfully. Receives a response object containing the transaction status. |
| onCancel | Triggered when the user closes the modal without completing the payment. |
| onError | Triggered if an error occurs during initialization or processing (e.g. network failure, invalid keys). |
Security is our top priority. The Inline SDK is designed to be secure by default.
- TLS Encryption: All data transmission occurs over secure TLS 1.2+ channels.
- Public Key Only: This SDK is designed for client-side use. Never expose your Secret API Key in the frontend code. The `publicKey` is safe to be visible in the source code.
- PCI-DSS: The payment form is hosted in a secure iframe environment, ensuring your application handles sensitive payment data compliantly.
