PHP code example of shipu / php-aamarpay-payment

1. Go to this page and download the library: Download shipu/php-aamarpay-payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shipu / php-aamarpay-payment example snippets


Shipu\Aamarpay\AamarpayServiceProvider::class,

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

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

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

use \Shipu\Aamarpay\Aamarpay;

...

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

use \Shipu\Aamarpay\Aamarpay;

...

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

use \Shipu\Aamarpay\Aamarpay;

...

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

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' => '[email protected]', // Customer email
])->transactionId()->amount(3500)->hiddenValue();

or 

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

use \Shipu\Aamarpay\Aamarpay;

...

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

use \Shipu\Aamarpay\Aamarpay;

...

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

use \Shipu\Aamarpay\Aamarpay;

...

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

{{ aamarpay_payment_url() }}

{!!
    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' => '[email protected]', // 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' => '[email protected]', // Customer email
        'cus_phone' => '01616022669' // Customer Phone
    ], 3500, 'T-shirt', 'BDT') 
!!}

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

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

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


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

protected $except = [
    ...
    'payment/*',
    ...
];
shell
composer 
shell
php artisan vendor:publish --provider="Shipu\Aamarpay\AamarpayServiceProvider"