Skip to content

Custom Checkout Integration

Create a seamless, branded payment experience directly in your online store using Moolre APIs.

Unlike redirect methods, building a custom checkout flow allows you to keep customers on your site, reducing drop-off rates and providing a consistent brand experience.

Overview

In this guide, we will build a backend integration that accepts Mobile Money payments. This is ideal for:

  • Custom-built e-commerce platforms (React, Vue, Laravel, Django).
  • Mobile applications (React Native, Flutter).
  • Subscription services requiring automated billing initiation.

Payment flow

  1. Customer Checkout

    User clicks "Pay Now" on your checkout page.

  2. API Request

    Your server calls Moolre's Mobile Money Collection endpoint.

  3. Customer Authorization

    Customer receives a prompt on their phone to enter their PIN.

  4. Confirmation

    Moolre sends a callback to your server confirming the payment.

Implementation

To initiate a payment, send a POST request to the transact endpoint.Note: For first-time payers on some networks, an OTP might be required (Response code TP14). Your UI should handle this by asking the user for the OTP and re-submitting.

const axios = require('axios');​const initiateCheckout = async (customerData, cartTotal) => {  try {    const response = await axios.post('https://api.moolre.com/open/transact/payment', {      type: 1,      channel: '13', // MTN Mobile Money      currency: 'GHS',      amount: cartTotal, // e.g., 150.00      payer: customerData.phone,      externalref: `ORDER_${Date.now()}`,      accountnumber: 'YOUR_MERCHANT_ACCOUNT_ID',      // Optional: If using USSD session      // sessionid: '...'     }, {      headers: {        'X-API-USER': process.env.MOOLRE_USER,        'X-API-PUBKEY': process.env.MOOLRE_PUB_KEY      }    });​    if (response.data.code === 'TP14') {      return { status: 'otp_required', message: response.data.message };    } else if (response.data.code === 'TR099') {        return { status: 'pending', message: 'Payment prompt sent to user device.' };    }​    return response.data;  } catch (error) {    console.error('Payment initiation failed', error);    throw error;  }};

Handling callbacks

Since mobile payments are asynchronous (the user might take a minute to enter their PIN), you should rely on callbacks to fulfill orders.

Security tip

Always verify the X-Moolre-Signature header against the raw body with your wallet secret, to ensure the request is genuinely from Moolre.