asdh/imepay

IME Pay payment validation package

Fund package maintenance!
asdh

1.0.0 2021-03-11 18:26 UTC

This package is auto-updated.

Last update: 2024-04-12 13:52:44 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A very small package to inetgrate IME Pay in your laravel project.

Support me

Buy me a coffee. ✌️

eSewa ID: 9840594104

Installation

You can install the package via composer:

composer require asdh/imepay

You can publish the config file with:

php artisan vendor:publish --provider="Asdh\ImePay\ImePayServiceProvider" --tag="imepay-config"

This is the contents of the published config file:

return [
    'merchant_number' => env('IME_PAY_MERCHANT_NUMBER'),
    'merchant_name' => env('IME_PAY_MERCHANT_NAME'),
    'merchant_code' => env('IME_PAY_MERCHANT_CODE'),
    'merchant_module' => env('IME_PAY_MERCHANT_MODULE'),
    'username' => env('IME_PAY_USERNAME'),
    'password' => env('IME_PAY_PASSWORD'),
    /**
     * The payment url
     *
     * E.g. https://stg.imepay.com.np:1234
     */
    'base_url' => env('IME_PAY_BASE_URL'),
];

Usage

I have also made a laravel project where I have shown how to use this package with routes, controllers and views. Click here to go to that repo.

Getting token for payment

To get the token before initiating the payment:

use Asdh\ImePay\ImePay;

$imepay = new ImePay();

// refId can be any unique id or the order id through which you can get all the details of the order/product that the user is buying
$refId = Str::uuid();
$amount = 100;

$response = $imepay->getToken($refId, $amount);

$token = $response->tokenId();

There are also other methods in the above $response instance. All these methods represent the response from the IME Pay itself.

$response->responseCode();
$response->responseDescription();
$response->refId();
$response->tokenId();
$response->amount();

To get the raw response from IME Pay:

$response->raw();

Also, if the credentials you provided was not correct, it will throw ImePayException. You can catch this exception and perform your action.

Verifying the payment

When a user pays using IME Pay in your website, IME Pay will redirect to a success url that you have to provide. In that url they will send a post request with some parameters.

Don't forget to add this route to the $except array of App\Http\Middleware\VerifyCsrfToken class. Also, this url should not be under authentication. Otherwise, the request sent from IME pay will not reach your website.

You can verify if it is valid like shown in the below code.

First of all in your controller do this:

use Asdh\ImePay\ImePay;

$imepay = new ImePay();

$response = $imepay->verify($request->all());

if ($response->isVerified()) {
    // do your stuffs...
}

There is also $response->isNotVerified() method which could be useful. If the response is not verified, you can get the message using $response->responseDescription().

There are also other methods in the above $response instance. All these methods represent the response from the IME Pay itself.

$response->responseCode();
$response->responseDescription();
$response->refId();
$response->msisdn(); // phone number of paying user
$response->tokenId();
$response->transactionId();

To get the raw response from IME Pay:

$response->raw();

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.