gemfourmedia / omnipay-momo
MoMo payment gateway driver for Omnipay library
v1.0.0
2023-02-05 14:08 UTC
Requires
- php: ^7.1|^8.0
- omnipay/common: ^3.0
Requires (Dev)
- omnipay/tests: ^3.0
- phpunit/phpunit: 6
- scrutinizer/ocular: ^1.5
This package is auto-updated.
Last update: 2025-05-05 19:42:19 UTC
README
Momo payment driver for Omnipay League.
Introduce about Omnipay gateways, read here for reference
Installation
Via Composer:
composer require gemfourmedia/omnipay-momo
Usage
Initialize
Please read MoMo documentation here
use Omnipay\Omnipay; $gateway = Omnipay::create('MoMo'); $gateway->initialize([ 'accessKey' => 'Provided by MoMo', 'partnerCode' => 'Provided by MoMo', 'secretKey' => 'Provided by MoMo', ]);
Purchase Request:
$response = $gateway->purchase([ 'amount' => 20000, 'redirectUrl' => 'https://yourdomain.com/payment-success', 'ipnUrl' => 'https://yourdomain.com/ipn', 'orderId' => 'unique id', // eg: 9 'requestType' => 'captureWallet', // captureWallet|payWithATM|payWithCC 'lang' => 'vi', // vi|en 'orderInfo' => '', 'requestId' => (string) \Str::uuid(), // eg: da584fe0-0fe3-47c6-ad20-19ad3e050140 'extraData' => base64_encode(json_encode([])), ])->send(); if ($response->isRedirect()) { $redirectUrl = $response->getRedirectUrl(); // TODO: Redirect to MoMo Payment page }
For more parameters, read here.
Complete Purchase (handle respone data when MoMo redirect back to your site):
$response = $gateway->completePurchase()->send(); if ($response->isSuccessful()) { print $response->amount; print $response->orderId; var_dump($response->getData()); } else { print $response->getMessage(); }
For more parameters, read here.
MoMo IPN (Instant Payment Notification) handler:
$response = $gateway->notification()->send(); if ($response->isSuccessful()) { print $response->amount; print $response->orderId; // Get all MoMo respone data. var_dump($response->getData()); } else { print $response->getMessage(); }
For more respone parameters, read here.
Query Transaction (Check Transaction Status):
$response = $gateway->queryTransaction([ 'orderId' => '9', 'requestId' => 'da584fe0-0fe3-47c6-ad20-19ad3e050140', 'lang' => 'vi', ])->send(); if ($response->isSuccessful()) { // TODO: handle result. print $response->amount; print $response->orderId; var_dump($response->getData()); // All momo response data } else { print $response->getMessage(); }
For more parameters, read here.
Refund:
$response = $gateway->refund([ 'orderId' => 'refund-10', //Note: orderId (new) of the refund transaction which must be different from orderId of the original purchase transaction 'requestId' => '1f60e60a-a78c-45c0-b6da-94d1855157ae', 'amount' => 2100, 'transId' => 2842402931, 'lang' => 'vi', 'description' => 'Example refund 10', ])->send(); if ($response->isSuccessful()) { var_dump($response->getData()); } else { print $response->getMessage(); }
For more respone parameters, read here.
Query Refund Status:
$response = $gateway->queryRefund([ 'orderId' => 'refund-10', 'requestId' => '1f60e60a-a78c-45c0-b6da-94d1855157ae', 'lang' => 'vi', ])->send(); if ($response->isSuccessful()) { var_dump($response->getData()); } else { print $response->getMessage(); }
For more respone parameters, read here.
Debug:
print $response->getCode(); // Get result code from MoMo. print $response->getMessage(); // Get message .
Result code reference getCode()
read here.