> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moflay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Express payment examples

> Create M-Pesa Express payments with the Moflay SDK using phone numbers, customer IDs, metadata, and error handling.

Use these examples after you have installed the SDK and created an API key with the `express.pay` permission. Add `transactions.read` when your app also reads payment or transaction status.

## Basic payment

```typescript theme={null}
import { Moflay } from "@moflay/sdk";

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

const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  amount: 1000,
  description: "Order 1001",
  accountReference: "ORDER1001",
});

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

## Payment with customer details

```typescript theme={null}
const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  customerName: "Jane Doe",
  amount: 250000,
  description: "Plan",
  accountReference: "SUB202604",
  metadata: {
    orderId: "SUB-2026-04",
    plan: "premium",
  },
});
```

## Payment for an existing customer

When you send `customerId`, do not include extra customer fields in the same request.

```typescript theme={null}
const payment = await moflay.express.pay({
  customerId: "cus_GqfKXLmg61LURZhB",
  amount: 5000,
  description: "Invoice",
  accountReference: "INV1001",
});
```

## Handle payment creation errors

```typescript theme={null}
try {
  const payment = await moflay.express.pay({
    phoneNumber: "254712345678",
    amount: 1000,
    description: "Order 1001",
    accountReference: "ORDER1001",
  });

  console.log(payment.paymentId);
} catch (error) {
  console.error("Payment request failed", error);
}
```

## Request limits

| Field              | Limit                                                |
| ------------------ | ---------------------------------------------------- |
| `amount`           | Integer in minor currency units from `1` to `250000` |
| `description`      | Up to `13` characters                                |
| `accountReference` | Up to `12` alphanumeric characters                   |

For example, `amount: 1000` means `KES 10.00`.

## Related pages

* [Make your first payment](/first-payment)
* [Make your first payment with HTTP](/first-payment-http)
* [Payment statuses & outcomes](/payments/transaction-statuses)
* [Webhook events](/webhooks/events)
