Skip to content

fergusdixon/payfast-sdk-php

Repository files navigation

payfast-sdk-php

MIT License Travis Build Status Codacy Badge StyleCI codecov Packagist Version

A PHP handler for making requests to documented PayFast endpoints.

See their docs

Features

  • CI tools
  • Handle signature generation
  • Generate Timestamp
  • Make user defined requests
  • Support R0 verification charges
  • Error handling
  • Built in functions
    • Ping
    • Transaction History
    • Query Card Transaction
    • Subscriptions
      • Charge Subscription
      • Fetch Subscription Info
      • Pause Subscription
      • Unpause Subscription
      • Cancel Subscription

Usage

This PayFast SDK requires config variables passed to it.

merchantId and passPhrase are mandatory, if not defined other fields will default to values shown below:

$config = [
    'merchantId' => 'testId',               // Required
    'passPhrase' => 'testPhrase',           // Required
    'endpoint' => '//api.payfast.co.za',
    'port' => 443,
    'ssl' => true,
    'testing' => false,
];

$payfast = new PayFastSDK($config);

Custom Requests

You can create a request to any endpoint in PayFast using $payfast->request->customRequest($verb, $method, $options)

For example, getting Transaction History

$verb = 'GET';
$method = '/history';
$options = [
    'from' => '2018-02-01',
    'to' => '2018-03-04',
];
$response = $payfast->request->customRequest($verb, $method, $options)

Quirks

Signature Generation

Payfast requires a MD5 hash of the alphabetised submitted variables, header and body variables, as well as the passphrase to ensure the request has not been tampered with.

Testing

Payfast provides a sandbox environment to test integrations.

Test requests are sent to the normal endpoint, but append ?testing=true to the URI.

Acknowledgements

  • Add yourself here!