nkaurelien / momopay
Paiement mobile avec mtn cameroun
dev-master
2024-04-03 11:44 UTC
Requires
- php: ^7.0
- illuminate/console: ^5.8.15|^6.0|^7.0|^8.0
- illuminate/contracts: ^5.8.15|^6.0|^7.0|^8.0
- illuminate/events: ^5.8.15|^6.0|^7.0|^8.0
- illuminate/filesystem: ^5.8.15|^6.0|^7.0|^8.0
- illuminate/notifications: ^5.8.15|^6.0|^7.0|^8.0
- illuminate/support: ^5.8.15|^6.0|^7.0|^8.0
- nategood/httpful: ^0.3.2
This package is auto-updated.
Last update: 2024-05-03 11:51:17 UTC
README
Description
A package for mobile money payments in Cameroun.
Only Mtn Cameroon is supported
Installation
composer require nkaurelien/momopay
(optional) Add the service provider in config\app.php
providers' => [ #... \Nkaurelien\Momopay\Providers\MomopayServiceProvider::class, ]
(optional) Add the service facade in config\app.php
aliases' => [ #... 'MomoPay' => \Nkaurelien\Momopay\Facades\MomoPay::class ]
Run publish
php artisan vendor:publish
Run database migration
php artisan migrate
Configuration
Add config to config/services.php
'mtn' => [
'currency' => env('MTN_MOMO_CURRENCY', 'XAF'),
'go_live' => env('MTN_MOMO_GO_LIVE',false),
'api_key' => env('MTN_MOMO_USER_API_KEY'),
'reference_id' => env('MTN_MOMO_ID'),
'subscription_key' => env('MTN_MOMO_KEY'),
'payment_callback_route' => env('MTN_MOMO_CALLBACK_URL','payment.momo.callback'),
'payment_callback_host' => env('MTN_MOMO_CALLBACK_HOST'),
'notification_email' => env('MTN_MOMO_NOTIFICATION_EMAIL'),
],
Configuration description
reference_id
: is the user idsubscription_key
: is the Ocp-Apim-Subscription-Keytarget_environment
: can be sanbox or mtncameroon (when you go live)
Don't forget to cache the configurations again with the command php artisan config:cache
Add routes
Route::any('/payment/momo/callback', 'PaymentMomoController@callback')->name('payment.momo.callback'); Route::get('/payment/momo/transaction/{id}', 'PaymentMomoController@getPayment')->name('payment.momo.gettransaction');
Use in controller
First inject the repository class
private $paymentMomoRepository; public function __construct(PaymentMomoRepository $paymentMomoRepository){ #...
Then consume repository instance to implement your payment logic
$momoRequestToPayDto = new \Nkaurelien\Momopay\Fluent\MomoRequestToPayDto; $momoRequestToPayDto->amount = 100; $momoRequestToPayDto->payeeNote = ''; $momoRequestToPayDto->payerMessage = ''; $momoRequestToPayDto->externalId = 'my_product_id'; $momoRequestToPayDto->payer->telephone = '2376XXXXXXXX'; # optional $momoRequestToPayDto->currency = 'XAF'; // Use EUR when you are in sandbox mode $refId = \Ramsey\Uuid\Uuid::uuid4()->toString(); $requestToPayResult = $this->paymentMomoRepository->requestToPay($momoRequestToPayDto, $refId);
If you prefer the facade instead of injection then do:
#... $requestToPayResult = \Nkaurelien\Momopay\Facades\MomoPay::requestToPay($momoRequestToPayDto, $refId);
Capture events
You can listen to :
- Nkaurelien\Momopay\Events\PaymentFailed is fired after a new verification
- Nkaurelien\Momopay\Events\PaymentSuccessful is fired after a new verification
- Nkaurelien\Momopay\Events\PaymentAccepted (pending) is fired after the success of request to pay or a new verification
Use commands
To verify transactions do
php artisan momopay:verify-transactions # to verify all transactions php artisan momopay:verify-transactions [referenceId] # to verify a specific transaction
Todo
- Create payment events
- Create payment exceptions class
- Create commands for scheduler and cron jobs
- Create transaction table for re-vefication
- Email notification on payment success
- Add orange money payment method