2017 © Pedro Peláez
 

library php-aamarpay-payment

PHP client for Aamarpay Payment Gateway API

image

shipu/php-aamarpay-payment

PHP client for Aamarpay Payment Gateway API

  • Tuesday, November 14, 2017
  • by shipu
  • Repository
  • 2 Watchers
  • 10 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 2 Versions
  • 88 % Grown

The README.md

PHP Aamarpay Payment Gateway

php-aamarpay-payment is a PHP client for Aamarpay Payment Gateway API. This package is also support Laravel and Lumen., (*1)

Installation

Go to terminal and run this command, (*2)

composer require shipu/php-aamarpay-payment

Wait for few minutes. Composer will automatically install this package for your project., (*3)

For Laravel

Below Laravel 5.5 open config/app and add this line in providers section, (*4)

Shipu\Aamarpay\AamarpayServiceProvider::class,

For Facade support you have add this line in aliases section., (*5)

'Aamarpay'   =>  Shipu\Aamarpay\Facades\Aamarpay::class,

Then run this command, (*6)

php artisan vendor:publish --provider="Shipu\Aamarpay\AamarpayServiceProvider"

Configuration

This package is required three configurations., (*7)

  1. store_id = your store id in Aamarpay Payment Gateway.
  2. signature_key = your signature key in Aamarpay Payment Gateway
  3. sandbox = true for sandbox and false for live
  4. redirect_url = your application redirect url after success and fail.

php-aamarpay-payment is take an array as config file. Lets services, (*8)

use Shipu\Aamarpay\Aamarpay;

$config = [
    'store_id' => 'Your store id',
    'signature_key' => 'Your signature key',
    'sandbox' => true,
    'redirect_url' => [
        'success' => [
            'route' => 'payment.success'
        ],
        'cancel' => [
            'route' => 'payment.cancel' 
        ]
    ]
];

$payment = new Aamarpay($config);

For Laravel

This package is also support Laravel. For laravel you have to configure it as laravel style., (*9)

Go to config\aamarpay.php and configure it with your credentials., (*10)

return [
    'store_id' => 'Your store id',
    'signature_key' => 'Your signature key',
    'sandbox' => true,
    'redirect_url' => [
        'success' => [
            'route' => 'payment.success'
        ],
        'cancel' => [
            'route' => 'payment.cancel' 
        ]
    ]
];

Usages

  • Mandatory input field name
    • tran_id // auto generate by this package
    • cus_name
    • cus_email
    • cus_phone
    • desc
    • currency // auto generate by this package
    • amount

Getting Payment Post Url

In PHP:, (*11)

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay($config);
return $payment->paymentUrl();

In Laravel:, (*12)

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->paymentUrl();

Getting Hidden Input Field

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->customer([
    'cus_name'  => 'Shipu Ahamed', // Customer name
    'cus_email' => 'shipuahamed01@gmail.com', // Customer email
    'cus_phone' => '01616022669' // Customer Phone
])->transactionId('21005455540')->amount(3500)->hiddenValue();

Where Transaction id is random value. you can generate by yourself or follow bellow steps:, (*13)

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->customer([
    'cus_name'  => 'Shipu Ahamed', // Customer name
    'cus_phone' => '01616022669' // Customer Phone
    'cus_email' => 'shipuahamed01@gmail.com', // Customer email
])->transactionId()->amount(3500)->hiddenValue();

or 

return $payment->customer([
    'cus_name'  => 'Shipu Ahamed', // Customer name
    'cus_phone' => '01616022669' // Customer Phone
    'cus_email' => 'shipuahamed01@gmail.com', // Customer email
])->amount(3500)->hiddenValue();

Default currency is BDT . For change currency:, (*14)

return $payment->customer([
    'cus_name'  => 'Shipu Ahamed', // Customer name
    'cus_phone' => '01616022669' // Customer Phone
    'cus_email' => 'shipuahamed01@gmail.com', // Customer email
])->currency()->amount(3500)->hiddenValue();

Generate Transaction Id

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->generateTransaction();

Checking Valid Response

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->valid($request);

Checking valid response with amount:, (*15)

use \Shipu\Aamarpay\Aamarpay;

...

$payment = new Aamarpay(config('aamarpay'));
return $payment->valid($request, '3500'); 

Where $request will appear after post response., (*16)

In Blade

Getting Payment Post Url

{{ aamarpay_payment_url() }}

Getting Hidden Input Field

{!!
    aamarpay_hidden_input([
        'tran_id'   => '21005455540', // random number. if you don't set this it will be auto generate.
        'cus_name'  => 'Shipu Ahamed', // Customer name
        'cus_email' => 'shipuahamed01@gmail.com', // Customer email
        'cus_phone' => '01616022669' // Customer Phone
    ], 3500) 
!!}
or
{!!
    aamarpay_hidden_input([
        'tran_id'   => '21005455540', // random number. if you don't set this it will be auto generate.
        'cus_name'  => 'Shipu Ahamed', // Customer name
        'cus_email' => 'shipuahamed01@gmail.com', // Customer email
        'cus_phone' => '01616022669' // Customer Phone
    ], 3500, 'T-shirt', 'BDT') 
!!}

Complete Post Button View

{!! 
aamarpay_post_button([
    'cus_name'  => 'Shipu Ahamed', // Customer name
    'cus_email' => 'shipuahamed01@gmail.com', // Customer email
    'cus_phone' => '01616000000' // Customer Phone
], 2000, '<i class="fa fa-money">Payment</i>', 'btn btn-sm btn-success') 
!!}

Example

Route
Route::post('payment/success', 'YourMakePaymentsController@paymentSuccess')->name('payment.success');
Route::post('payment/failed', 'YourMakePaymentsController@paymentFailed')->name('payment.failed');
Route::post('payment/cancel', 'YourMakePaymentsController@paymentCancel')->name('payment.cancel');

or, (*17)

Route::post('payment/success', 'YourMakePaymentsController@paymentSuccessOrFailed')->name('payment.success');
Route::post('payment/failed', 'YourMakePaymentsController@paymentSuccessOrFailed')->name('payment.failed');
Route::post('payment/cancel', 'YourMakePaymentsController@paymentSuccessOrFailed')->name('payment.cancel');

Controller Method
use Shipu\Aamarpay\Facades\Aamarpay;

...

public function paymentSuccessOrFailed(Request $request)
{
    if($request->get('pay_status') == 'Failed') {
        return redirect()->back();
    }

    $amount = 3500;
    $valid  = Aamarpay::valid($request, $amount);

    if($valid) {
        // Successfully Paid.
    } else {
       // Something went wrong. 
    }

    return redirect()->back();
}

To Disable CSRF token

Open app/Http/Middleware/VerifyCsrfToken.php and adding :, (*18)

protected $except = [
    ...
    'payment/*',
    ...
];

Credits

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!, (*19)

Beerpay Beerpay, (*20)

The Versions

14/11 2017

dev-master

9999999-dev

PHP client for Aamarpay Payment Gateway API

  Sources   Download

CC(1.0)

The Requires

 

laravel api php lumen gateway aamarpay php-aamarpay

14/11 2017

v1.0

1.0.0.0

PHP client for Aamarpay Payment Gateway API

  Sources   Download

CC(1.0)

The Requires

 

laravel api php lumen gateway aamarpay php-aamarpay