settle/settle-sdk-php

PHP SDK for connecting to the Settle Payment Platform.

v1.2.3 2022-05-20 13:39 UTC

This package is auto-updated.

Last update: 2024-04-20 18:00:07 UTC


README

License Build Status Coverage Status

PHP SDK for connecting to the Settle Payment Platform

Start accepting payments via Settle in seconds

An easy to use SDK for PHP with all the best practices to kickstart your integration with the Settle Payment Platform.

Installation

composer require settle/settle-sdk-php

Usage

The library provides a basic Client class that handles the communication with the Settel REST API:

$settle_client = new SettleApiClient(
    SETTLE_MERCHANT_ID,
    SETTLE_USER_ID,
    SETTLE_PUBLIC_KEY,
    SETTLE_PRIVATE_KEY,
    SETTLE_IN_SANDBOX
);

The library then provides an entry point class for each section in the REST API. Currently, only MerchantsApi is available as Permissions and OAuth2 are pending breaking changes and will be added soon.

Merchants API

The following class serves as an entry point for all the resources in the section:

$merchant_api = new MerchantApi($settle_client);

Each resource (class) can be accessed via magic property on the Merchants API object:

$merchant_api->api_keys->...;
$merchant_api->balance->...;
$merchant_api->payment_requests->...;
$merchant_api->payment_send->...;
$merchant_api->pos->...;
$merchant_api->profile->...;
$merchant_api->settlements->...;
$merchant_api->short_links->...;
$merchant_api->status_codes->...;

The methods that each class implements very closely matches the REST API specification:

$merchant_api->api_keys->list();
$merchant_api->api_keys->get($api_key_id);
$merchant_api->api_keys->create($api_key_data);
$merchant_api->api_keys->update($api_key_id, $api_key_data);
$merchant_api->api_keys->delete($api_key_id);

Only PaymentRequests class has a few extra helper methods:

$merchant_api->payment_requests->capture($payment_request_id,$currency,$amount)
$merchant_api->payment_requests->refund($payment_request_id, $currency, $amount);
$merchant_api->payment_requests->getLink($payment_request_id);
$merchant_api->payment_requests->getDeepLink($payment_request_id);

Webhooks / Callbacks

In order to validate callback requests from Settle, both Apache and nginx servers require manual setup to pass the Authorization header to PHP.

Here's an example for Apache:

RewriteEngine On
RewriteRule .* - [e=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Here's an example for nginx:

proxy_set_header Authorization $http_authorization;
proxy_pass_header  Authorization;

Two methods on the SettleApiClient class can be used in relation to the callbacks:

// the following will return 
$is_valid = $settle_client->isValidCallback($callbackUrl, $body, $headers, $method);

// the following method will grab the data Settle sent in the current request
$settle_data = $settle_client->getCallbackData();  

Deep links

The SettleApiClient class has a helper method for creating deep links from short links for use on mobile devices. They integrate directly with the Settle mobile app. Example:

$short_link = 'https://settle.eu/s/gSpEb/pos123/';
$deep_link = $settle_client->getDeepLink($short_link);