PHP code example of angstrom / mtn-momo

1. Go to this page and download the library: Download angstrom/mtn-momo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

angstrom / mtn-momo example snippets


return [
    'api_key' => env('MOMO_API_KEY'),
    'api_user' => env('MOMO_API_USER'),
    'api_base_url' => env('MOMO_API_BASE_URL', 'https://sandbox.momodeveloper.mtn.com'),
    'environment' => env('MOMO_ENVIRONMENT', 'sandbox'),
];

use Angstrom\MoMo\Collections;

$collections = new Collections();

// Request to pay
$result = $collections->requestToPay(
    amount: 100,
    currency: 'EUR',
    externalId: 'unique-transaction-id',
    partyId: '256772123456', // Phone number
    partyIdType: 'MSISDN',
    payerMessage: 'Payment for order #123',
    payeeNote: 'Order #123'
);

// Check transaction status
$status = $collections->getTransactionStatus($result['referenceId']);

// Get account balance
$balance = $collections->getAccountBalance();

// Check if account holder is active
$status = $collections->checkAccountHolderStatus('256772123456');

use Angstrom\MoMo\Disbursements;

$disbursements = new Disbursements();

// Transfer money
$result = $disbursements->transfer(
    amount: 100,
    currency: 'EUR',
    externalId: 'unique-transaction-id',
    payeeId: '256772123456',
    payeeIdType: 'MSISDN',
    payerMessage: 'Salary payment',
    payeeNote: 'Salary for January'
);

// Check transfer status
$status = $disbursements->getTransferStatus($result['referenceId']);

// Get account balance
$balance = $disbursements->getAccountBalance();

use Angstrom\MoMo\Remittances;

$remittances = new Remittances();

// International transfer
$result = $remittances->transfer(
    amount: 100,
    currency: 'EUR',
    externalId: 'unique-transaction-id',
    payeeId: '256772123456',
    payeeIdType: 'MSISDN',
    payerMessage: 'International transfer',
    payeeNote: 'Family support'
);

// Check transfer status
$status = $remittances->getTransferStatus($result['referenceId']);

// Get exchange rate
$rate = $remittances->getExchangeRate('EUR', 'UGX');

use Angstrom\MoMo\Facades\MoMo;

// Collections
$result = MoMo::collections()->requestToPay(...);

// Disbursements
$result = MoMo::disbursements()->transfer(...);

// Remittances
$result = MoMo::remittances()->transfer(...);
bash
php artisan vendor:publish --provider="Angstrom\MoMo\MoMoServiceProvider"