PHPackages                             neolikotsi/payfast - 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. [Payment Processing](/categories/payments)
4. /
5. neolikotsi/payfast

ActiveLibrary[Payment Processing](/categories/payments)

neolikotsi/payfast
==================

Laravel 5.4+|6+|7+|8+ package for processing ITN payments through payfast.co.za

0.6.0(4y ago)0462MITPHP

Since Feb 25Pushed 4y agoCompare

[ Source](https://github.com/neolikotsi/payfast)[ Packagist](https://packagist.org/packages/neolikotsi/payfast)[ RSS](/packages/neolikotsi-payfast/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (46)Used By (0)

Laravel Payfast
===============

[](#laravel-payfast)

A dead simple Laravel payment processing class for payments through payfast.co.za. This package only supports ITN transactions. Laravel Payfast is strictly use at own risk.

Installation
------------

[](#installation)

Add Laravel Payfast to your composer.json

```
composer require neolikotsi/payfast
```

Add the PayfastServiceProvider to your providers array in config/app.php

```
'providers' => [
    //

    'NeoLikotsi\PayfastServiceProvider'
];
```

Config
------

[](#config)

publish default configuration file.

```
php artisan vendor:publish
```

IMPORTANT: You will need to edit `App\Http\Middleware\VerifyCsrfToken` by adding the route, which handles the ITN response to the $excepted array. Validation is done via the ITN response.

```
/*
|--------------------------------------------------------------------------
| Merchant Settings
|--------------------------------------------------------------------------
| All Merchant settings below are for example purposes only. for more info
| see www.payfast.co.za. The Merchant ID and Merchant Key can be obtained
| from your payfast.co.za account.
|
*/

[

    'testing' => true, // Set to false when in production.

    'passphrase' => env('PF_PASSPHRASE'), // SECURITY PASSPHRASE

    'currency' => 'ZAR', // ZAR is the only supported currency at this point.

    'merchant' => [
        'merchant_id' => env('PF_MERCHANT_ID', '10000100'), // TEST Credentials. Replace with your merchant ID from Payfast.
        'merchant_key' => env('PF_MERCHANT_KEY', '46f0cd694581a'), // TEST Credentials. Replace with your merchant key from Payfast.
        'return_url' => env('PF_RETURN_URL', 'http://your-domain.co.za/success'), // Redirect URL on Success.
        'cancel_url' => env('PF_CANCEL_URL', 'http://your-domain.co.za/cancel'), // Redirect URL on Cancellation.
        'notify_url' => env('PF_ITN_URL', 'http://your-domain.co.za/itn'), // ITN URL.
    ],

];
```

Usage
-----

[](#usage)

Creating a payment returns an html form ready to POST to payfast. When the customer submits the form they will be redirected to payfast to complete payment. Upon successful payment the customer will be returned to the specified 'return\_url' and in the case of a cancellation they will be returned to the specified 'cancel\_url'

---

**NOTE**

If you want to use subscripions, make sure to set your merchant's passphrase in the config file for this package. It is required for subscriptions.

---

```
use NeoLikotsi\Contracts\PaymentProcessor;

Class PaymentController extends Controller
{

    public function confirmPayment(PaymentProcessor $payfast)
    {
        // Eloqunet example.
        $cartTotal = 9999;
        $order = Order::create([
            'm_payment_id' => '001', // A unique reference for the order.
            'amount'       => $cartTotal
        ]);

        // Build up payment Paramaters.
        $payfast->setBuyer('first name', 'last name', 'email');
        $payfast->setAmount($order->amount);
        $payfast->setItem('item-title', 'item-description');
        $payfast->setMerchantReference($order->m_payment_id);

        // Optionally send confirmation email to seller
        $payfast->setEmailConfirmation();
        $payfast->setConfirmationAddress(config('payfast.PF_CONFIRMATION_EMAIL'));

        // Optionally make this a subscription
        $payfast->setIsSubscription();    // will default to 1
        $payfast->setFrequency();           // will default to 3 = monthly if not set
        $payfast->setCycles();              // will default to 0 = indefinite if not set

        // Return the payment form.
        return $payfast->paymentForm('Place Order');
    }

}
```

ITN Responses
-------------

[](#itn-responses)

Payfast will send a POST request to notify the merchant (You) with a status on the transaction. This will allow you to update your order status based on the appropriate status sent back from Payfast. You are not forced to use the key 'm\_payment\_id' to store your merchant reference but this is the the key that will be returned back to you from Payfast for further verification.

```
use NeoLikotsi\Contracts\PaymentProcessor;

Class PaymentController extends Controller
{

    public function itn(Request $request, PaymentProcessor $payfast)
    {
        // Retrieve the Order from persistance. Eloquent Example.
        $order = Order::where('m_payment_id', $request->get('m_payment_id'))->firstOrFail(); // Eloquent Example

        // Verify the payment status.
        $status = $payfast->verify($request, $order->amount)->status();

        // Handle the result of the transaction.
        switch( $status )
        {
            case 'COMPLETE': // Things went as planned, update your order status and notify the customer/admins.
                break;
            case 'FAILED': // We've got problems, notify admin and contact Payfast Support.
                break;
            case 'PENDING': // We've got problems, notify admin and contact Payfast Support.
                break;
            default: // We've got problems, notify admin to check logs.
                break;
        }
    }

}
```

The response variables POSTED back by payfast may be accessed as follows:

```
 return $payfast->responseVars();
```

Variables Returned by Payfast

```
[
    'm_payment_id' => '',
    'pf_payment_id' => '',
    'payment_status' => '',
    'item_name' => '',
    'item_description' => '',
    'amount_gross' => '',
    'amount_fee' => '',
    'amount_net' => '',
    'custom_str1' => '',
    'custom_str2' => '',
    'custom_str3' => '',
    'custom_str4' => '',
    'custom_str5' => '',
    'custom_int1' => '',
    'custom_int2' => '',
    'custom_int3' => '',
    'custom_int4' => '',
    'custom_int5' => '',
    'name_first' => '',
    'name_last' => '',
    'email_address' => '',
    'merchant_id' => '',
    'signature' => '',
];
```

Amounts
-------

[](#amounts)

The cart total may be set in 2 ways, as a string value:

```
    $cartTotal = '99.99';

    $payfast->setAmount($cartTotal);
```

Or as an Integer. In the case of an integer, the cart total must be passed through in cents, as follows:

```
$cartTotal = 9999; // Laravel Payfast will parse this value and format it accordingly. See sebastianbergmann/money
$payfast->setAmount($cartTotal);
```

Payment Form
------------

[](#payment-form)

By default the paymentForm() method will return a compiled HTML form including a submit button. There are 3 configurations available for the submit button.

```
$payfast->paymentForm() // Default Text: 'Pay Now'

$payfast->paymentForm(false) // No submit button, handy for submitting the form via javascript

$payfast->paymentForm('Confirm and Pay') // Override Default Submit Button Text.
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 88% 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 ~48 days

Recently: every ~134 days

Total

43

Last Release

1703d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/708a9d3fbe214c757b76c9be0785145425b946218c26b215b1d0af68d8cc4873?d=identicon)[neolikotsi](/maintainers/neolikotsi)

---

Top Contributors

[![warhsn](https://avatars.githubusercontent.com/u/11815088?v=4)](https://github.com/warhsn "warhsn (73 commits)")[![jonowat](https://avatars.githubusercontent.com/u/10924375?v=4)](https://github.com/jonowat "jonowat (8 commits)")[![mikerockett](https://avatars.githubusercontent.com/u/4586280?v=4)](https://github.com/mikerockett "mikerockett (1 commits)")[![neolikotsi](https://avatars.githubusercontent.com/u/7394627?v=4)](https://github.com/neolikotsi "neolikotsi (1 commits)")

---

Tags

laravelpayfastpayment-gatewayphplaravelpackagepayfast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/neolikotsi-payfast/health.svg)

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

###  Alternatives

[laraveldaily/laravel-invoices

Missing invoices for Laravel

1.5k1.3M4](/packages/laraveldaily-laravel-invoices)[yansongda/laravel-pay

专注 Alipay/WeChat/Unipay 的 laravel 支付扩展包

1.1k353.2k9](/packages/yansongda-laravel-pay)[billowapp/payfast

Laravel 5.4+ package for processing ITN payments through payfast.co.za

2918.2k3](/packages/billowapp-payfast)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[asciisd/knet

Knet package is provides an expressive, fluent interface to KNet's payment services.

141.1k](/packages/asciisd-knet)[threesquared/laravel-paymill

Laravel wrapper for the Paymill API

121.3k](/packages/threesquared-laravel-paymill)

PHPackages © 2026

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