Collect payments

Ask a customer to pay from their mobile money wallet.

Ask a customer to pay from their M-Pesa or Mixx by Yas wallet. They approve with their PIN, and the amount, less the fee, goes to your balance.

Create the payment

Call Create a payment with kind COLLECTION, the amount, the currency, the customer's phone number in payment_method_data, your merchantReference and an Idempotency-Key. You do not name the network: Flex Malipo reads it from the number. You get 201 and the payment.

{
  "kind": "COLLECTION",
  "amount": 10000,
  "currency": "TZS",
  "payment_method_data": {
    "type": "mobile_money",
    "mobile_money": { "phone": "255700000001" }
  },
  "merchantReference": "order-1042"
}

The payment answers with payment_method_details, which holds the network (mpesa or mixx_by_yas) and the customer's number with the middle hidden, such as 25574*****11. transactionCode is the code the customer sees in their messages from the network. It is empty until the network gives one.

Tell the customer to check their phone

They get a prompt to approve the payment with their PIN.

Act on the outcome

Your webhook endpoint gets payment.succeeded, payment.failed or payment.expired. Deliver on payment.succeeded, never on the create response.

Without webhooks, retrieve the payment every few seconds until its status is final.

Statuses

StatusWhat to doFinal
CREATED, PROCESSING, PENDING_CUSTOMERWait.No
SUCCEEDEDDeliver.No, you can still refund it
FAILEDfailureCode says why. Create a new payment to try again.Yes
EXPIREDThe customer did not approve within 3 minutes. Create a new payment, with a new Idempotency-Key, to ask again.Yes
REVERSING, REVERSEDThe payment was reversed and the money went back to the customer. You get payment.reversed. To give money back yourself, refund the payment.REVERSED only

Amounts and fees

  • Amounts are integers in Tanzanian shillings (TZS). 10000 is TZS 10,000. See Money. Each network has a smallest and a largest amount: see Amount limits.
  • Each payment shows its fee and its net, which is amount minus fee. Preview the fee to show the customer before you charge. A payment whose fee would leave nothing is refused with 422 and the code request_not_allowed.

Networks

The network comes from the first digits of the customer's number, so you never send it:

networkWalletNumbers start with
mpesaVodacom M-Pesa25574, 25575, 25576
mixx_by_yasMixx by Yas25565, 25567, 25571

A number that moved to another network is still judged by its first digits.

List payment methods shows, for each network, whether it is available to your account and whether you have it switched on (enabled). To stop taking payments on a network, switch it off, separately in test and live mode. A payment to a number on a network that is not available or is switched off is refused with 422 and the code payment_method_unactivated. The message names the networks you can take.

Phone numbers

Send phone as 255 followed by nine digits, with no plus sign, spaces or leading zero. A number in any other shape is refused with 400, and param is payment_method_data.mobile_money.phone.

With a live key, a number that is on no network in the table above is refused with 422 and the code payment_method_unactivated. Test mode takes any number in the right shape and treats a number on no network as mpesa.

Metadata

Tag a payment with your own data, such as an order ID or a sales channel. It comes back on the payment and in every webhook event about it.

"metadata": { "orderId": "1042", "channel": "pos" }

Use up to 20 keys. A key is 1 to 40 letters, digits, _ or -, and a value is up to 500 characters. Do not put personal data in it.

Retry safely

If the network fails before you see the answer, send the same request with the same Idempotency-Key. You get the first response back, 201 with the same payment and the header Idempotent-Replayed: true, and the customer is charged once. See Idempotency.

On this page