Stack Pay™ - Payments SDK for PHP
, (*1)
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., (*2)
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., (*3)
Requirements
PHP 5.4.0 (or higher), (*4)
Dependencies
PHP Curl Class 7.2.0 (or higher)
This library also requires 'ext-curl': '*'
., (*5)
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., (*6)
To install via Composer, run the following command:, (*7)
composer require stack-pay/payments-sdk-php
You can also manually add this dependency to your composer.json
file:, (*8)
{
"require": {
"stack-pay/payments-sdk-php": "~1.0.0"
}
}
To use the bindings, use Composer's
autoload:, (*9)
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., (*10)
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., (*11)
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., (*12)
To enable development/testing mode, you should then use:, (*13)
$stackpay->enableTestMode();
To change currency:, (*14)
$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., (*15)
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., (*16)
$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., (*17)
$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:, (*18)
composer install
Tests
Install dependencies as mentioned above (which will resolve
PHPUnit), then you can run the
test suite:, (*19)
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., (*20)
Support
Contributing Guidelines
Please refer to CONTRIBUTING.md (coming soon), (*21)