Laravel Package for Processing Online Payments Through Webpay Payment Gateway
danialpanah/webpay is a Laravel package for laravel package for processing online payments through webpay payment gateway.
It currently has 3 GitHub stars and 80 downloads on Packagist (latest version 1.0.0).
Install it with composer require danialpanah/webpay.
Discover more Laravel packages by danialpanah
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package for connecting and accept payments via Webpay payment gateway in your Laravel application.
composer require danialpanah/webpay
This package supports Laravel auto-discovery feature. If you are using Laravel 5.5 or greater no need to do any further actions, otherwise follow below steps.
providers[] array in config/app.php in your laravel application:DanialPanah\Webpay\WebpayServiceProvider::class
aliases[] array in config/app.php in Laravel:'Webpay': DanialPanah\Webpay\Facades\Webpay::class
After installation, you need to add your Webpay api settings. You can update config/webpay.php published file or in you Laravel .env file.
Run the following command to publish the configuration file:
php artisan vendor:publish --provider "DanialPanah\Webpay\WebpayServiceProvider"
return [
'api_key' => env('WEBPAY_API_KEY', ''),
'callback_url' => env('WEBPAY_CALLBACK_URL', '')
];
.env.example and .env files:#Webpay API key and Settings
#your webpay api key e.g "webpay:2bbc6c62-4fe..."
WEBPAY_API_KEY=
#address of rediricting after payment e.g "/payment/test"
WEBPAY_CALLBACK_URL=
Following are some approaches which you can have for initiate a payment through Webpay package:
// Importing the class namespaces before using it
use DanialPanah\WebPay\Webpay;
$samplePayment = [
'amount' => 10000, //required
'reference_number' => '#####', //required - invoice number(unique)
'payer_mobile' => '', //optional - payer mobile number for save/load cards in gateway
'cards' => '', //optional - allowed cards for perform payment
];
$webPay = new Webpay();
$paymentUrl = $webPay->sendPayment($samplePayment);
use DanialPanah\WebPay\Facades\Webpay;
$paymentUrl = Webpay::sendPayment($samplePayment);
$paymentDetails = [
'amount' => 10000, //required
'reference_number' => '#####' //required - invoice number
];
$webPay = new Webpay();
$response = $webPay->verifyPayment($paymentDetails);
use DanialPanah\WebPay\Facades\Webpay;
$response = Webpay::verifyPayment($paymentDetails);
array: [
"ok" => true
"result" => {
"state": "paid"
"total": 10000
"wage": 1500
"gateway": "sep"
"terminal": "11423087"
"pay_ref": "KmsctypmKSs0WfEB01H3ROJPLN2ZQrauExLR90nnXk"
"pay_trace": "228945"
"pay_pan": "610422******8585"
"pay_cid": "4470D3E90AA5Z3FB7B21B3348D34EE25EC331915BCQP68BC4D0D1C0678548B8D"
"pay_time": "2020-04-02T17:47:14.391164Z"
}
]
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DanialPanah\WebPay\Facades\Webpay;
class PaymentController extends Controller
{
/**
* @return RedirectResponse|Redirector
* @throws WebpayException
*/
public function pay()
{
$userTrustedCards = ['6219196262191962', '6104046161040461'];
$samplePayment = [
'amount' => 10000,
'reference_number' => '999999',
'payer_mobile' => '09121111111',
'cards' => $userTrustedCards,
];
$paymentUrl = Webpay::sendPayment($samplePayment);
return redirect($paymentUrl);
}
/**
* @param Request $request
* @throws VerifyException
*/
public function verify(Request $request)
{
$paymentDetails = [
'amount' => 10000,
'reference_number' => '999999',
];
$response = Webpay::verifyPayment($paymentDetails);
if(!$reponse['ok'] === true) {
//Transactions was not successful
}
//Do something for successful transactoin
}
}
This package supports Laravel 5.1 or greater, 6.x and 7.x with PHP 7.2 and above.
This repository is an open-source software under the MIT license.