PHPackages                             io-digital/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. io-digital/payfast

AbandonedArchivedLibrary

io-digital/payfast
==================

Process online payments in Laravel with Payfast

v0.1.25(9y ago)53603MITPHP

Since Feb 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/io-digital/payfast)[ Packagist](https://packagist.org/packages/io-digital/payfast)[ RSS](/packages/io-digital-payfast/feed)WikiDiscussions laravel5.1 Synced 2mo ago

READMEChangelog (10)Dependencies (6)Versions (27)Used By (0)

Laravel 5 Payfast
=================

[](#laravel-5-payfast)

A dead simple Laravel 5 payment processing class for payments through payfast.co.za. This package only supports ITN transactions.

Forked from [billowapp/payfast](https://github.com/billowapp/payfast).

**This repo adds missing verification steps that are required.**

**Still in development.**

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

[](#installation)

Add Laravel 5 Payfast to your composer.json

```
composer require io-digital/payfast

```

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

```
'providers' => [
    //

    IoDigital\Payfast\PayfastServiceProvider::class,
];

```

In your `.env` add the following keys:

```
PAYFAST_MERCHANT_ID=your-id
PAYFAST_MERCHANT_KEY=your-key

```

IMPORTANT: In order to work with the ITN callback reliably, it's suggested to make use of [ngrok](https://ngrok.com/). That would make your `config/payfast.php` file url's look like:

```
'return_url' => 'https://xxxxxxxx.ngrok.io/success',

```

### 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 $except array. Validation is done via the ITN response.

```
protected $except = [
        '/itn'
    ];

```

```

/*
|--------------------------------------------------------------------------
| 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.

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

    'merchant' => [
        'merchant_id' => '10000100', // TEST Credentials. Replace with your merchant ID from Payfast.
        'merchant_key' => '46f0cd694581a', // TEST Credentials. Replace with your merchant key from Payfast.
        'return_url' => 'http://your-domain.co.za/success', // The URL the customer should be redirected to after a successful payment.
        'cancel_url' => 'http://your-domain.co.za/cancelled', // The URL the customer should be redirected to after a payment is cancelled.
        'notify_url' => 'http://your-domain.co.za/itn', // The URL to which Payfast will post return variables.
    ]

];

```

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

```

use IoDigital\Payfast\Contracts\PaymentProcessor;

Class PaymentController extends Controller
{

    public function confirmPayment(PaymentProcessor $payfast)
    {
        // Eloquent 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');

        //PS ADD DIVISION BY 100 FOR CENTS AS THE NEW DEPENDENCY "mathiasverraes/money": "^1.3" DOESN'T DO CONVERSION
        payfast->setAmount($purchase->amount / 100);

        $payfast->setItem('item-title', 'item-description');
        $payfast->setMerchantReference($order->m_payment_id);

        // 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 IoDigital\Payfast\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

        try {
            $verification = $payfast->verify($request, $order->amount);
            $status = $payfast->status();
        } catch (\Exception $e) {
            Log::error('PAYFAST ERROR: ' . $e->getMessage());
            $status = false;
        }

        // Verify the payment status.
        $status = (int) $payfast->verify($request, $order->amount, /*$order->m_payment_id*/)->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)

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

```

$cartTotal = 9999;
// "mathiasverraes/money": "^1.3" doesn't convert from cents correctly yet
// That's why a manual division by 100 is necessary
$payfast->setAmount($cartTotal / 100);

```

### Payment Form

[](#payment-form)

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

```

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

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

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

```

### To Do's

[](#to-dos)

1. Unit Testing
2. Add in a Facade Class
3. Allow for custom integers/strings
4. Curl request to Payfast (validation) -&gt; needs more testing

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~5 days

Total

25

Last Release

3607d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0acb24b4d76853e47a3ad42fba61d9c623a7e0ea4d38e52ac134dd953174529b?d=identicon)[io-digital](/maintainers/io-digital)

---

Top Contributors

[![garethnic](https://avatars.githubusercontent.com/u/1523598?v=4)](https://github.com/garethnic "garethnic (21 commits)")

---

Tags

laravelpackagepayfast

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[joggapp/laravel-aws-sns

Laravel package for the SNS events by AWS

3171.8k](/packages/joggapp-laravel-aws-sns)[billowapp/payfast

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

2918.2k3](/packages/billowapp-payfast)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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