prinx/payswitch-momo

Payswitch mobile money api utility class

v3.1.0 2021-05-18 10:10 UTC

README

Build Status Latest Stable Version License StyleCI

Work In Progress

Installation

composer require prinx/payswitch-momo

Usage

Configuration in .env file (in the project root folder)

# .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|false

Make sure the value for PAYSWITCH_MOMO_API_PROCESSING_CODE and PAYSWITCH_MOMO_API_KEY are enclosed with double quotes.

Making a payment request

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();
}

Voucher code for Vodafone users

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);

License

MIT