Skip to content

MTN MoMo

PayBridge's MTN MoMo adapter uses the MTN MoMo Collection API's asynchronous Request to Pay operation. The SDK submits a request and returns a pending payment. The payer must approve the request on their mobile device. Use VerifyPaymentAsync to read the final state from MTN.

This adapter is separate from PawaPay, which provides a multi-operator API. MTN's API User, API Key, Collection subscription key, target environment and currency must all belong to the relevant MTN market and product subscription.

Configure

Create an API User and API Key for the Collection product, and obtain its subscription key from the MTN MoMo Developer Portal. For production, use the credentials issued for the target market. The target environment is market-specific, for example mtnnigeria or mtnghana. For sandbox calls, set IsSandbox to true; the adapter sends X-Target-Environment: sandbox. Sandbox calls go to sandbox.momodeveloper.mtn.com. With IsSandbox set to false, calls go to MTN's production API host, proxy.momoapi.mtn.com, and use your configured target environment.

builder.Services.AddPayBridge(configuration, options =>
{
    options.EnabledGateways = [PaymentGatewayType.MtnMomo];
    options.DefaultGateway = PaymentGatewayType.MtnMomo;
    options.MtnMomo.ApiUser = configuration["PaymentGatewayConfig:MtnMomo:ApiUser"]!;
    options.MtnMomo.ApiKey = configuration["PaymentGatewayConfig:MtnMomo:ApiKey"]!;
    options.MtnMomo.CollectionSubscriptionKey =
        configuration["PaymentGatewayConfig:MtnMomo:CollectionSubscriptionKey"]!;
    options.MtnMomo.TargetEnvironment = "sandbox";
    options.MtnMomo.IsSandbox = true;
});

Keep API credentials in user secrets or a server-side secret store. Do not put them in a browser application or commit them to source control.

Create and verify a payment

Pass the payer's MSISDN in CustomerPhone in international format, an amount and the currency supported by the selected MTN environment. MTN's sandbox example uses EUR; production currency must match the configured market. The SDK creates a UUID v4 reference, as required by MTN's X-Reference-Id, and also uses it as externalId.

Set IdempotencyKey when a payment request may be retried. The adapter maps the same key to the same UUID, so MTN recognises a retry instead of sending the payer a second prompt. If MTN answers a retried key with HTTP 409, the adapter returns Pending with the same reference; call VerifyPaymentAsync for the current status. Without a key, each call creates a new random reference.

var payment = await paymentService.CreatePaymentAsync(
    new PaymentRequest
    {
        Amount = 2500,
        Currency = "EUR",
        CustomerPhone = "2348012345678",
        Description = "Order 123"
    },
    PaymentGatewayType.MtnMomo);

// payment.Status is Pending until the payer approves or rejects the prompt.
var result = await paymentService.VerifyPaymentAsync(
    payment.TransactionReference,
    PaymentGatewayType.MtnMomo);

The adapter sends the MSISDN as digits only. It removes spaces, dashes, dots, brackets and a leading + or 00, so +234 801 234 5678 is sent as 2348012345678. It rejects other characters, and numbers outside 8 to 15 digits, before calling MTN.

Do not treat the initial HTTP 202 response as a completed payment. A successful status lookup returns Successful; pending requests remain Pending, and rejected or failed requests return Failed.

Callbacks and refunds

Set PaymentRequest.WebhookUrl to ask MTN to send a callback. MTN requires the callback host to be registered on the API User and to match that registration exactly. MTN documents that a callback is sent only once, without retry. Use the callback to trigger a server-to-server status lookup. PayBridge does not verify an MTN callback signature, so do not mark a payment successful based on the callback payload alone. The callback reference is available as externalId through GatewayExtractor when the provider route is selected explicitly. The example API's signature-verifying webhook controller will reject MTN callbacks until a signature contract is implemented. A custom callback receiver must treat the payload only as a notification and confirm the payment with MTN before updating payment state.

Refund requests are not supported by this Collection adapter. MTN documents Refund APIs under a separate product flow, and the public contract does not provide enough request details to implement a compatible refund safely.

Official documentation

Check the MTN portal for the current target environment, currency support, product subscription, account permissions and production onboarding details.