stack-pay/payments-sdk-php

Stack Pay API SDK for PHP

1.4.0 2019-05-13 22:29 UTC

README

Total Downloads Latest Stable Version License

The Stack Pay Payments SDK for PHP is an open source library through which your PHP application can easily interact with the Stack Pay API.

Note: This release utilizes Stack Pay API v1. There are substantial differences between this version of the client library and subsequent versions. Please be mindful of this when upgrading.

Requirements

PHP 5.4.0 (or higher)

Dependencies

PHP Curl Class 7.2.0 (or higher)

This library also requires 'ext-curl': '*'.

Installation

Composer (recommended)

It is strongly recommended that you use Composer to install this package and its dependencies. Some methods utilize GuzzleHttp. If you do not install via Composer, these methods will be difficult to use.

To install via Composer, run the following command:

composer require stack-pay/payments-sdk-php

You can also manually add this dependency to your composer.json file:

{
    "require": {
        "stack-pay/payments-sdk-php": "~1.0.0"
    }
}

To use the bindings, use Composer's autoload:

require_once('vendor/autoload.php');

Manual Installation (not recommended)

If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the payments-sdk.php file.

require_once('/path/to/stack-pay/payments-sdk-php/lib/payments-sdk.php');

You will also need to download the dependencies and manually include them, which can be extremely cumbersome. It is strongly recommended that you use Composer.

Instantiating the SDK

$stackpay = new StackPay\Payments\StackPay($yourPublicKey, $yourPrivateKey);

This will create a StackPay class instance in PRODUCTION mode with USD as the default currency.

To enable development/testing mode, you should then use:

$stackpay->enableTestMode();

To change currency:

$stackpay->setCurrency('CAD');

Documentation

Request-Focused Implementation

The examples in these docs are recommended when the SDK is installed via Composer. These methods use GuzzleHttp which is very difficult to use without a good autoloader.

You can directly interact with the response returned by these methods using the ->body() method, which is the JSON-decoded Body element of the response payload as a stdClass PHP object.

$response = $request->send();

echo $response->body()->ID;

You can check the response for success using method success(). If success() returns false, then you can use error() to access code, messages, and errors attributes.

$response = $request->send();

if (! $response->success()) {
    echo $response->error()->code."\n"; // the API response error code
    echo $response->error()->message."\n"; // the API response error message
    print_r($response->error()->errors); // populated when the request body does not pass validation
}

Development

Install dependencies:

composer install

Tests

Install dependencies as mentioned above (which will resolve PHPUnit), then you can run the test suite:

composer test

If you plan to use these tests, it is highly recommended that you familiarize yourself with PHPUnit as well as the phpunit.xml configuration file included with this package.

Support

Contributing Guidelines

Please refer to CONTRIBUTING.md (coming soon)