|
8 | 8 |
|
9 | 9 | An easy to use **SDK** for **PHP** with all the best practices to kickstart your integration with the **Settle Payment Platform**. |
10 | 10 |
|
11 | | -THIS IS A DRAFT |
12 | | - |
13 | 11 | ## Installation |
14 | 12 |
|
15 | 13 | `composer require danielz/settle-sdk-php` |
16 | 14 |
|
| 15 | +## Usage |
| 16 | + |
| 17 | +The library provides a basic Client class that handles the communication with the Settel REST API: |
| 18 | + |
| 19 | +```php |
| 20 | +$settle_client = new SettleApiClient( |
| 21 | + SETTLE_MERCHANT_ID, |
| 22 | + SETTLE_USER_ID, |
| 23 | + SETTLE_PUBLIC_KEY, |
| 24 | + SETTLE_PRIVATE_KEY, |
| 25 | + SETTLE_IN_SANDBOX |
| 26 | +); |
| 27 | +``` |
| 28 | + |
| 29 | +The library then provides an entry point class for each section in the [REST API](https://api.support.settle.eu/api/reference/rest/v1/). |
| 30 | +Currently, only MerchantsApi is available as Permissions and OAuth2 are pending breaking changes and will be added soon. |
| 31 | + |
| 32 | + |
| 33 | +### Merchants API |
| 34 | +The following class serves as an entry point for all the resources in the section: |
| 35 | +```php |
| 36 | +$merchant_api = new MerchantApi($settle_client); |
| 37 | +``` |
| 38 | +Each resource (class) can be accessed via magic property on the Merchants API object: |
| 39 | + |
| 40 | +```php |
| 41 | +$merchant_api->api_keys->...; |
| 42 | +$merchant_api->balance->...; |
| 43 | +$merchant_api->dynamic_links->...; |
| 44 | +$merchant_api->payment_requests->...; |
| 45 | +$merchant_api->payment_sends->...; |
| 46 | +$merchant_api->pos->...; |
| 47 | +$merchant_api->profile->...; |
| 48 | +$merchant_api->settlements->...; |
| 49 | +$merchant_api->short_links->...; |
| 50 | +$merchant_api->status_codes->...; |
| 51 | +``` |
| 52 | + |
| 53 | +The methods that each class implements very closely matches the REST API specification: |
| 54 | + |
| 55 | +```php |
| 56 | +$merchant_api->api_keys->list(); |
| 57 | +$merchant_api->api_keys->get($api_key_id); |
| 58 | +$merchant_api->api_keys->create($api_key_data); |
| 59 | +$merchant_api->api_keys->update($api_key_id, $api_key_data); |
| 60 | +$merchant_api->api_keys->delete($api_key_id); |
| 61 | +``` |
| 62 | + |
| 63 | +Only `PaymentRequests` class has a few extra helper methods: |
| 64 | + |
| 65 | +```php |
| 66 | +$merchant_api->payment_requests->capture($payment_request_id,$currency,$amount) |
| 67 | +$merchant_api->payment_requests->refund($payment_request_id, $currency, $amount); |
| 68 | +$merchant_api->payment_requests->getPaymentLink($payment_request_id); |
| 69 | +$merchant_api->payment_requests->getMobilePaymentLink($payment_request_id); |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +### Webhooks / Callbacks |
| 79 | +In order to validate callback requests from Settle, both Apache and nginx servers require manual setup to pass the `Authorization` header to PHP. |
| 80 | + |
| 81 | +Here's an example for Apache: |
| 82 | + |
| 83 | +``` |
| 84 | +RewriteEngine On |
| 85 | +RewriteRule .* - [e=HTTP_AUTHORIZATION:%{HTTP:Authorization}] |
| 86 | +``` |
| 87 | + |
| 88 | +Here's an example for nginx: |
| 89 | +``` |
| 90 | +proxy_set_header Authorization $http_authorization; |
| 91 | +proxy_pass_header Authorization; |
| 92 | +``` |
0 commit comments