定制 zfhassaan/alfa 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zfhassaan/alfa

最新稳定版本:v1.0.1

Composer 安装命令:

composer require zfhassaan/alfa

包简介

Laravel 9 package for bank alfalah

README 文档

README

Latest Version on Packagist MIT Licensed Total Downloads

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.

统计信息

  • 总下载量: 59
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-12