PHPackages                             zfhassaan/alfa - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. zfhassaan/alfa

ActiveLibrary[API Development](/categories/api)

zfhassaan/alfa
==============

Laravel 9 package for bank alfalah

v1.0.1(3y ago)560MITPHPPHP ^8.0.2

Since Oct 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/zfhassaan/alfaPay)[ Packagist](https://packagist.org/packages/zfhassaan/alfa)[ RSS](/packages/zfhassaan-alfa/feed)WikiDiscussions v1.0.0 Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

AlfaPay
=======

[](#alfapay)

[![Latest Version on Packagist](https://camo.githubusercontent.com/46ed60471ae3f0274930758bdfae2be8ccc0c61b9daad718523b9d59674e59e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a666861737361616e2f616c66617061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zfhassaan/alfa)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/6511a89fa4b520e6b16506e0e4ba8a9702d881eb073643f0161d901e7e53002a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a666861737361616e2f616c66617061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zfhassaan/alfa)

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

[](#installation)

You can install the package via composer:

```
composer require zfhassaan/alfa
```

Set .env configurations
-----------------------

[](#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
-------------

[](#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
-----

[](#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

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

```
The repository is forked from codesocolock and fixed to work with PHP 8.1 and Laravel 9

```

- [codesoclock](https://github.com/codesoclock)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Total

2

Last Release

1122d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f91e22a64582fa1db957f7f189736d6cd2e6f1f69c2236a42a9ee8fcbdd0723?d=identicon)[zfhassaan](/maintainers/zfhassaan)

---

Top Contributors

[![zfhassaan](https://avatars.githubusercontent.com/u/17079656?v=4)](https://github.com/zfhassaan "zfhassaan (12 commits)")

### Embed Badge

![Health badge](/badges/zfhassaan-alfa/health.svg)

```
[![Health](https://phpackages.com/badges/zfhassaan-alfa/health.svg)](https://phpackages.com/packages/zfhassaan-alfa)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
