PHP code example of wanzoou / momoapicollection

1. Go to this page and download the library: Download wanzoou/momoapicollection 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/ */

    

wanzoou / momoapicollection example snippets




use Wanzoou\Momoapicollection\MomoAPI;

$momo = new MomoAPI();

$momo->setMomoPayHost('sandbox.momodeveloper.mtn.com'); // Set MoMo API host
$momo->setPrimaryKey('your_primary_key'); // Set your primary key
$momo->setProviderCallbackHost('your_callback_host'); // Set your provider callback host
$momo->setTargetEnvironment('sandbox'); // Set the target environment (sandbox or live)

$phone = '237679465319'; // Payer's phone number
$amount = 100; // Amount to be paid
$currency = 'EUR'; // Currency

$responseCode = $momo->requestToPay($phone, $amount, $currency);

if ($responseCode == 202) {
    echo "Payment request initiated successfully.";
} else {
    echo "Failed to initiate payment request.";
}

$status = $momo->requestToPayTransactionStatus();
echo "Transaction Status: " . json_encode($status);


Wanzoou\Momoapicollection\MomoAPI;

$momo = new MomoAPI();
$momo->setMomoPayHost('sandbox.momodeveloper.mtn.com');
$momo->setPrimaryKey('your_primary_key');
$momo->setProviderCallbackHost('your_callback_host');
$momo->setTargetEnvironment('sandbox');

$phone = '237679465319';
$amount = 100;
$currency = 'EUR';

$responseCode = $momo->requestToPay($phone, $amount, $currency);

if ($responseCode == 202) {
    echo "Payment request initiated successfully.\n";
    $status = $momo->requestToPayTransactionStatus();
    echo "Transaction Status: " . json_encode($status);
} else {
    echo "Failed to initiate payment request.\n";
}