PHPackages                             payfast/payfast-php-sdk - 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. payfast/payfast-php-sdk

ActiveLibrary[API Development](/categories/api)

payfast/payfast-php-sdk
=======================

Payfast PHP Library

v1.1.6(2y ago)32320.5k↑20.6%22[1 PRs](https://github.com/PayFast/payfast-php-sdk/pulls)5MITPHPPHP &gt;=8.1

Since Nov 23Pushed 2y ago3 watchersCompare

[ Source](https://github.com/PayFast/payfast-php-sdk)[ Packagist](https://packagist.org/packages/payfast/payfast-php-sdk)[ RSS](/packages/payfast-payfast-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (10)Used By (5)

payfast-php-sdk
===============

[](#payfast-php-sdk)

The Payfast PHP SDK provides an easy-to-use library for integrating Payfast payments into your project. This includes Custom Integration, Onsite Integration and all APIs.

Requirements
------------

[](#requirements)

PHP 8.1 and later.

Documentation
-------------

[](#documentation)

See the [Developer Docs](https://developers.payfast.co.za/docs)

Composer
--------

[](#composer)

You can install the library via [Composer](http://getcomposer.org/). Run the following command:

```
composer require payfast/payfast-php-sdk
```

To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):

```
require_once('vendor/autoload.php');
```

Getting Started
---------------

[](#getting-started)

### Custom Integration

[](#custom-integration)

Build a checkout form and receive payments securely from the Payfast payment platform.

**NB!** The default value of 'testMode' is true.

See the [Developer Docs](https://developers.payfast.co.za/docs#quickstart)

```
try {
    $payfast = new PayFastPayment(
        [
            'merchantId' => '10000100',
            'merchantKey' => '46f0cd694581a',
            'passPhrase' => 'jt7NOE43FZPn',
            'testMode' => true
        ]
    );

    $data = [
        'amount' => '100.00',
        'item_name' => 'Order#123'
    ];

    echo $payfast->custom->createFormFields($data, ['value' => 'PAY NOW', 'class' => 'btn']);
} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

### Onsite Payments

[](#onsite-payments)

Integrate Payfast’s secure payment engine directly into your checkout page.

**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: " ***There was an exception: Sorry but Onsite is not available in Sandbox mode***"

See the [Developer Docs](https://developers.payfast.co.za/docs#onsite_payments)

```
// Include:

try {
    $payfast = new PayFastPayment(
        [
            'merchantId' => '10000100',
            'merchantKey' => '46f0cd694581a',
            'passPhrase' => 'jt7NOE43FZPn',
            'testMode' => false
        ]
    );

    $data = [
        'amount' => '100.00',
        'item_name' => 'Order#123'
    ];

    // Generate payment identifier
    $identifier = $payfast->onsite->generatePaymentIdentifier($data);

    if($identifier!== null){
        echo 'window.payfast_do_onsite_payment({"uuid":"'.$identifier.'"});';
    }
} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

### API

[](#api)

#### Recurring Billing

[](#recurring-billing)

The Subscription Payments API gives Merchants the ability to interact with subscriptions on their accounts.

**NB!** The default value of 'testMode' is true.

See the [Developer Docs](https://developers.payfast.co.za/api#recurring-billing)

```
try {
    $api = new PayFastApi(
        [
            'merchantId' => '10018867',
            'passPhrase' => '2uU_k5q_vRS_',
            'testMode' => true
        ]
    );

    $fetchArray = $api->subscriptions->fetch('2afa4575-5628-051a-d0ed-4e071b56a7b0');

    $pauseArray = $api->subscriptions->pause('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);

    $unpauseArray = $api->subscriptions->unpause('2afa4575-5628-051a-d0ed-4e071b56a7b0');

    $cancelArray = $api->subscriptions->cancel('2afa4575-5628-051a-d0ed-4e071b56a7b0');

    $updateArray = $api->subscriptions->update('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);

    $adhocArray = $api->subscriptions->adhoc('290ac9a6-25f1-cce4-5801-67a644068818', ['amount' => 500, 'item_name' => 'Test adhoc']);

} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

#### Update card

[](#update-card)

The update card endpoint allows you to provide buyers with a link to update their card details on a Recurring Billing subscription or Tokenization charges.

**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: " ***There was an exception: Sorry but Onsite is not available in Sandbox mode***"

See the [Developer Docs](https://developers.payfast.co.za/docs#recurring_card_update)

```
try {
    $payfast = new PayFastPayment(
            [
                'merchantId' => '10000100',
                'merchantKey' => '46f0cd694581a',
                'passPhrase' => 'jt7NOE43FZPn',
                'testMode' => false
            ]
        );

    echo $payfast->custom->createCardUpdateLink('2afa4575-5628-051a-d0ed-4e071b56a7b0', 'https://www.example.com/return', 'Update your card', ['target' => '_blank']);

} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

#### Transaction History

[](#transaction-history)

The transaction history API gives Merchants the ability to interact with their Payfast account.

**NB!** The default value of 'testMode' is true.

See the [Developer Docs](https://developers.payfast.co.za/api#transaction-history)

```
try {
    $api = new PayFastApi(
        [
            'merchantId' => '10018867',
            'passPhrase' => '2uU_k5q_vRS_',
            'testMode' => true
        ]
    );

    $rangeArray = $api->transactionHistory->range(['from' => '2020-08-01', 'to' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);

    $dailyArray = $api->transactionHistory->daily(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);

    $weeklyArray = $api->transactionHistory->weekly(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]);

    $monthlyArray = $api->transactionHistory->monthly(['date' => '2020-08', 'offset' => 0, 'limit' => 1000]);

} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

#### Credit card transaction query

[](#credit-card-transaction-query)

The credit card transaction query API gives Merchants the ability to query credit card transactions.

**NB!** The default value of 'testMode' is true.

See the [Developer Docs](https://developers.payfast.co.za/api#credit-card-transactions)

```
try {
    $api = new PayFastApi(
        [
            'merchantId' => '10018867',
            'passPhrase' => '2uU_k5q_vRS_',
            'testMode' => true
        ]
    );

    $creditCardArray = $api->creditCardTransactions->fetch('1124148');

} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

#### Refunds

[](#refunds)

The Refunds API Providing gives Merchants the ability to perform refunds on their account.

**NB!** The default value of 'testMode' is false. Otherwise we get the Exception: " ***There was an exception: Sorry but Onsite is not available in Sandbox mode***"

See the [Developer Docs](https://developers.payfast.co.za/api#refunds)

```
try {
    $api = new PayFastApi(
        [
            'merchantId' => '10018867',
            'passPhrase' => '2uU_k5q_vRS_',
            'testMode' => false
        ]
    );

    $refundFetchArray = $api->refunds->fetch('dc0521d3-55fe-269b-fa00-b647310d760f');

    $refundCreateArray = $api->refunds->create('dc0521d3-55fe-269b-fa00-b647310d760f', ['amount' => 50, 'reason' => 'Product returned', 'acc_type' => 'savings']);

} catch(Exception $e) {
    echo 'There was an exception: '.$e->getMessage();
}
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~269 days

Total

9

Last Release

811d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.2.5

v1.1.5PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/280865ff1a1a09dd8e24c51f8aed516057bc797668a305ebe1203f7d664e84e1?d=identicon)[appinlet](/maintainers/appinlet)

---

Top Contributors

[![clairepf](https://avatars.githubusercontent.com/u/68599211?v=4)](https://github.com/clairepf "clairepf (11 commits)")[![bruce-atkinson](https://avatars.githubusercontent.com/u/13369065?v=4)](https://github.com/bruce-atkinson "bruce-atkinson (8 commits)")[![PieterE-PF](https://avatars.githubusercontent.com/u/109581616?v=4)](https://github.com/PieterE-PF "PieterE-PF (7 commits)")[![DarronEngelbrecht](https://avatars.githubusercontent.com/u/55560979?v=4)](https://github.com/DarronEngelbrecht "DarronEngelbrecht (4 commits)")[![lefu007](https://avatars.githubusercontent.com/u/10028848?v=4)](https://github.com/lefu007 "lefu007 (2 commits)")

---

Tags

phpapipayfastonsite

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[resend/resend-php

Resend PHP library.

574.7M21](/packages/resend-resend-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

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