Skip to main content
Use this tutorial to go from a new Moflay account to your first sandbox payment.

Prerequisites

Step 1: Install the SDK

npm install @moflay/sdk

Step 2: Store your API key

export MOFLAY_API_KEY="mof_test_your_api_key"

Step 3: Send a sandbox payment

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

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

async function main() {
  const payment = await moflay.express.pay({
    phoneNumber: "254712345678",
    amount: 100,
    description: "Sandbox test payment",
    accountReference: "ORDER-1001",
  });

  console.log(payment);
}

main().catch(console.error);

Step 4: Check the result

You should receive a response that includes fields like:
  • transactionId
  • status
  • amount
  • customerId when a customer record is created or matched
After the request succeeds:
  1. Open the Moflay dashboard.
  2. Go to the Transactions page.
  3. Confirm that the payment appears in the sandbox environment.

Verify the result

Your setup is working if all of the following are true:
  • The API call returns a valid payment response
  • The transaction appears in the dashboard
  • The environment is sandbox

Troubleshooting

  • The API returns missing_api_key: Make sure you set Authorization: Bearer YOUR_API_KEY or loaded MOFLAY_API_KEY correctly.
  • The API returns invalid_api_key: Check that the key is active and belongs to the same environment you are testing.
  • The payment does not appear in the dashboard: Confirm you are viewing the sandbox environment, not production.

Next steps