1. Go to this page and download the library: Download jilenloa/tppmyone4all-php 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/ */
jilenloa / tppmyone4all-php example snippets
use MyOne4All\TppClient;
use MyOne4All\Exceptions\TppException;
use MyOne4All\Models\DataBundle;
use MyOne4All\NetworkCodes;
$tppClient = new TppClient("apikey", "apisecret", "retailer");
// send mobile money implementation
$transaction_reference = "trans03423423";
$amount = 1;
$momo_response = $tppClient->sendMobileMoney("0245667942", $amount, $transaction_reference);
if($momo_response->isSuccessful()){
echo "mobile money sent";
}else if($momo_response->isPending()){
// this is very important, do not treat as an error.
// you must check transaction status later to know if it was successful or not
echo "mobile money request is being processed.";
}else{
echo "Failed: ".$momo_response->getErrorMessage();
}
// receive mobile money implementation
$transaction_reference = "trans03423423";
$amount = 1;
$payer_number = "0245667XXX";
$momo_response = $tppClient->receiveMobileMoney($payer_number, $amount, $transaction_reference);
if($momo_response->isSuccessful()){
// check transaction status later to confirm receipt
echo "mobile money payment request initiated";
}else{
echo "Failed: ".$momo_response->getErrorMessage();
}
// receive mobile money implementation
$transaction_reference = "trans03423423";
$amount = 1;
$payer_number = "0245667XXX";
$narration = "Food Purchase";
$delay = 5;
// the last parameter represents the number of seconds to delay the payment prompt
$momo_response = $tppClient->receiveMobileMoney($payer_number, $amount, $transaction_reference, $delay, $narration);
if($momo_response->isSuccessful()){
// check transaction status later to confirm receipt
echo "mobile money payment request initiated";
}else{
echo "Failed: ".$momo_response->getErrorMessage();
}