composer require prinx/payswitch-momo# .env file
PAYSWITCH_MOMO_API_ENV=test|prod
PAYSWITCH_MOMO_API_USER=
PAYSWITCH_MOMO_API_KEY=
PAYSWITCH_MOMO_API_MERCHANT_ID=
PAYSWITCH_MOMO_API_PROCESSING_CODE="000200"
PAYSWITCH_MOMO_API_DESCRIPTION="At least 10 characters"
PAYSWITCH_MOMO_LOG_ENABLED=true|false
PAYSWITCH_MOMO_LOCAL_LOG_ENABLED=true|falseMake sure the value for
PAYSWITCH_MOMO_API_PROCESSING_CODEandPAYSWITCH_MOMO_API_KEYare enclosed with double quotes.
use Prinx\Payswitch\MobileMoney;
$momo = new MobileMoney;
$amount = 1; // 1 cedi
$phone = '233...';
$network = ''; // Must be one of MTN|VODAFONE|AIRTEL
$response = $momo->pay($amount, $phone, $network);
if ($response->isSuccessful()) {
// User successfully payed
} else {
$error = $response->getError();
}Vodafone users always generate a voucher code to be able to process their mobile money transactions. After getting the voucher code from the user, you can easily pass it argument of the pay method:
// ...
$response = $momo->pay($amount, $phone, $network, $voucherCode);