fergusdixon/payfast-sdk-php

PayFast SDK - Make requests to PayFast

v0.0.2-alpha 2018-09-27 08:22 UTC

This package is auto-updated.

Last update: 2024-04-27 21:22:08 UTC


README

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!