zfhassaan/alfa
Composer 安装命令:
composer require zfhassaan/alfa
包简介
Laravel 9 package for bank alfalah
README 文档
README
This is Bank Alfalah payment gateway package to pay using Alfa Wallet, Bank Account Number or Credit Card (Credit Card not yet implemented). You can use this package with Laravel or any PHP framework via composer.
Installation
You can install the package via composer:
composer require zfhassaan/alfa
Set .env configurations
You can get these values from Bank Alfalah Merchant portal
ALFAPAY_URL= ALFAPAY_MODE=sandbox ALFAPAY_CHANNEL_ID= ALFAPAY_MERCHANT_ID= ALFAPAY_STORE_ID= ALFAPAY_RETURN_URL= ALFAPAY_MERCHANT_USERNAME= ALFAPAY_MERCHANT_PASSWORD= ALFAPAY_MERCHANT_HASH= ALFAPAY_KEY_1= ALFAPAY_KEY_2=
Configuration
Add These Files in app/config.php
/* * Package Service Providers... */ \zfhassaan\Alfapay\AlfapayServiceProvider::class,
and also add Alias in app/config.php
'aliases' => Facade::defaultAliases()->merge([ 'Alfapay' => \zfhassaan\Alfapay\AlfapayFacade::class, ])->toArray(),
Usage
First you've to get auth token by providing your unique transaction number or order number and then can post request the amount information along with some validation. Please refer to YouTube video for full understanding.
use zfhassaan\Alfapay\AlfaPay; public function get_token(){ // generate random transaction/order number $transNum = rand(0,17866120); // get AuthToken from AlfaPay API $alfa = new AlfaPay(); $response = $alfa->setTransactionReferenceNumber($transNum)->getToken(); // if( $response != null && $response->success == 'true' ) { return $response->AuthToken; } else { // log error if( $response == null ) { abort(403, 'Error: Timeout connection. Auth Token not generated.'); } else { abort(403, 'Error: '.$response->ErrorMessage.'. Auth Token does not generated.'); } } }
Snipped for Proceed Transaction
public function process(){ $alfa->setAuthToken($this->get_token()); $alfa->setCurrency('PKR'); $alfa->setTransactionReferenceNumber($request->TransctionReferenceNumber); $alfa->setTransactionType($request->TransactionTypeId); $alfa->setAmount($request->Amount); $alfa->setMobileNumber($request->MobileNumber); $alfa->setEmail($request->Email); $alfa->setCountryCode('164'); // Pakistan = 164 $alfa->sendTransactionRequest(); // return $alfa->sendTransactionRequest(); $transactionResponse = $alfa->sendTransactionRequest(); if($transactionResponse != null && $transactionResponse->success = 'true') { $TransactionReferenceNumber = $transactionResponse->TransactionReferenceNumber; $TransactionTypeId = $transactionResponse->TransactionTypeId; $HashKey = $transactionResponse->HashKey; $AuthToken = $request->AuthToken; // Can return it in a view to send next request for OTP // It depends on the developer how to utilize it. } abort(404,$transactionResponse); }
OTP Request ( Or Proceed to Payment )
public function otp(Request $request) { $this->validate($request,[ 'OTP' => 'required', 'HashKey' => 'required', 'TransactionTypeId'=>'required', 'TransactionReferenceNumber'=>'required', ]); $alfa = new AlfaPay(); $alfa->setCurrency('PKR'); $alfa->setTransactionReferenceNumber($request->TransactionReferenceNumber); $alfa->setTransactionType($request->TransactionTypeId); $alfa->setHashKey($request->HashKey); $alfa->setSMSOTP($request->OTP); $alfa->setAuthToken($request->AuthToken); $processResponse = $alfa->processTransaction(); if($processResponse != null && property_exists($processResposne, 'response_code')) { try{ $currency = $alfa->getCurrency('PKR'); $paidAmount = $processResponse->transaction_amount; $apiResponse = serialize($processResponse); session()->flash('success', 'Payment Success'); // Return with currency, paid Amount , apiResponse, ProcessResponse or // compact it in views to show Thank you ( Order Confirmation page ) } catch(\Exception $e) { abort(403, 'Error: ', $e->getMessage()); } } else { abort(403, 'Error: '.$processResponse->ErrorMessage.'. Transaction OTP not completed'); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email naeemins@gmail.com instead of using the issue tracker.
Credits
The repository is forked from codesocolock and fixed to work with PHP 8.1 and Laravel 9
License
The MIT License (MIT). Please see License File for more information.
zfhassaan/alfa 适用场景与选型建议
zfhassaan/alfa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zfhassaan/alfa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zfhassaan/alfa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 60
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-12