Skip to main content
Use @moflay/sdk when you want the fastest path to a working Moflay integration in Node.js or TypeScript.

Prerequisites

Install the SDK

npm install @moflay/sdk

Authenticate the client

import { Moflay } from "@moflay/sdk";

const moflay = new Moflay({
  token: process.env.MOFLAY_API_KEY!,
});

Send an express payment

const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  amount: 100,
  description: "Payment for Order #1001",
  accountReference: "ORDER-1001",
});

console.log(payment.transactionId, payment.status);

Add customer details when needed

const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  customerName: "Jane Doe",
  customerEmail: "jane@example.com",
  amount: 2500,
  description: "Subscription renewal",
  accountReference: "SUB-2026-04",
  metadata: {
    orderId: "SUB-2026-04",
  },
});

Read customers and transactions

const transactions = await moflay.transactions.list({ limit: 10 });

for await (const page of transactions) {
  console.log(page.data);
}
const customers = await moflay.customers.list({ limit: 10 });

for await (const page of customers) {
  console.log(page.data);
}

When to use the SDK vs raw HTTP

  • Use the SDK if you are building with Node.js or TypeScript and want a faster integration path.
  • Use the REST API if your stack is not JavaScript or you prefer direct HTTP control.