nkwa-pay / sdk
Requires
- php: ^8.2
- brick/date-time: ^0.7.0
- brick/math: ^0.12.1
- galbar/jsonpath: ^3.0
- guzzlehttp/guzzle: ^7.0
- phpdocumentor/type-resolver: ^1.8
- speakeasy/serializer: ^4.0.3
Requires (Dev)
- laravel/pint: ^1.21.2
- phpstan/phpstan: ^2.1.0
- phpunit/phpunit: ^10
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-04-22 06:59:25 UTC
README
Nkwa Pay SDK for PHP
Summary
Nkwa Pay API: Use this API to integrate mobile money across your payment flows, create and manage payments, collections, and disbursements.
Read the docs at https://docs.mynkwa.com/api-reference
Table of Contents
SDK Installation
The SDK relies on Composer to manage its dependencies.
To install the SDK and add it as a dependency to an existing composer.json
file:
composer require "nkwa-pay/sdk"
SDK Example Usage
Example
declare(strict_types=1); require 'vendor/autoload.php'; use Pay; $sdk = Pay\Pay::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $response = $sdk->payments->get( id: 'b888f774-3e7c-4135-a18c-6b985523c4bc' ); if ($response->payment !== null) { // handle response }
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKeyAuth |
apiKey | API key |
To authenticate with the API the apiKeyAuth
parameter must be set when initializing the SDK. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Pay; $sdk = Pay\Pay::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $response = $sdk->payments->get( id: 'b888f774-3e7c-4135-a18c-6b985523c4bc' ); if ($response->payment !== null) { // handle response }
Available Resources and Operations
Available methods
operators
operators->availability
- get - Check which operators and operations are currently available.
payments
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the get
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\HttpError | 401, 404 | application/json |
Errors\HttpError | 500 | application/json |
Errors\APIException | 4XX, 5XX | */* |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use Pay; use Pay\Models\Errors; $sdk = Pay\Pay::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); try { $response = $sdk->payments->get( id: 'b888f774-3e7c-4135-a18c-6b985523c4bc' ); if ($response->payment !== null) { // handle response } } catch (Errors\HttpErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\HttpErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\APIException $e) { // handle default exception throw $e; }
Server Selection
Override Server URL Per-Client
The default server can be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Pay; $sdk = Pay\Pay::builder() ->setServerURL('https://api.staging.nkwapay.mynkwa.com') ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $response = $sdk->payments->get( id: 'b888f774-3e7c-4135-a18c-6b985523c4bc' ); if ($response->payment !== null) { // handle response }