https://github.com/machour/konnect
Konnect PHP SDK
https://github.com/machour/konnect
clictopay konnect payment-gateway tunisia
Last synced: about 2 months ago
JSON representation
Konnect PHP SDK
- Host: GitHub
- URL: https://github.com/machour/konnect
- Owner: machour
- Created: 2022-12-07T19:56:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-08T08:00:04.000Z (over 2 years ago)
- Last Synced: 2025-03-14T14:38:27.795Z (3 months ago)
- Topics: clictopay, konnect, payment-gateway, tunisia
- Language: PHP
- Homepage: https://konnect.network
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Konnect PHP SDK (unofficial)
The payment solution for Tunisia.
Simple, fast, personalized, immediate and for all !## Installation
```shell
composer require machour/konnect
```This SDK follows the PSR-18 "HTTP Client" standard, to allow for more interoperability.
It's most likely your framework will handle the dependencies injection for you, if not
you can use any implementation of the spec.The below example uses this two librairies:
```shell
composer require guzzlehttp/guzzle nyholm/psr7
```## SDK Initialization
```php
setApiKey($apiKey);// By default, the SDK is in sandbox mode.
// To switch to production, use the following
$konnect->setProductionMode();
```## API
### `initPayment(array $params)`
Creates a new payment request.
See [Konnect's documentation](https://api.konnect.network/api/v2/konnect-gateway#tag/Payments/paths/~1payments~1init-payment/post) for the full description of `$params` and the returned array.
```php
/**
* @throws ApiException|\Psr\Http\Client\ClientExceptionInterface
*/
public function initPayment(array $params): array
```See usage sample and output
```php
$response = $konnect->initPayment([
"receiverWalletId" => "5f7a209aeb3f76490ac4a3d1",
"description" => "payment description",
"amount" => 100000, // millimes
"type" => "immediate",
"lifespan" => 10, // minutes
"token" => "TND",
"firstName" => "Mon prenom",
"lastName" => "Mon nom",
"phoneNumber" => "12345678",
"email" => "[email protected]",
"orderId" => "1234657",
"link" => "https://api.dev.konnect.network/WSlQUtBF8",
"silentWebhook" => true,
"checkoutForm" => true,
"webhook" => "https://merchant.tech/api/notification_payment",
"successUrl" => "https://dev.konnect.network/gateway/payment-success",
"failUrl" => "https://dev.konnect.network/gateway/payment-failure",
"acceptedPaymentMethods" => [
"bank_card",
"wallet",
"e-DINAR"
]
]);var_dump($response);
/**
array(2) {
["payUrl"]=>
string(80) "https://preprod.konnect.network/gateway/pay?payment_ref=6392d70408ac861bcea30337"
["paymentRef"]=>
string(24) "6392d70408ac861bcea30337"
}
*/
```### `getPaymentDetails(string $paymentId)`
Gets payment details for the specified id.
See [Konnect's documentation](https://api.konnect.network/api/v2/konnect-gateway#tag/Payments/paths/~1payments~1:paymentId/get) for the full description of the returned array.
```php
/**
* @throws ApiException|\Psr\Http\Client\ClientExceptionInterface
*/
public function getPaymentDetails(string $paymentId): array
```## Exceptions
This SDK throws a `\Machour\Konnect\ApiException` if there's anything wrong with your call.
The exception's `errors` property will contains the reported errors.If however, something is wrong with the Konnect server, a `PSR-18` exception will be thrown instead.
```php
try {
$response = $konnect->initPayment([/* ... */]);
} catch (ApiException $e) {
// HTTP status code
echo $e->getCode();
// HTTP status message
echo $e->getMessage();
// Konnect API usage errors
var_dump($e->errors);
} catch (\Psr\Http\Client\ClientExceptionInterface $e) {
// Transport error, something is wrong with the Konnect API, and they're
// probably already working on that
}
}
```## See also
* [Konnect web site](https://konnect.network/)
* [Konnect docs](https://api.konnect.network/api/v2/konnect-gateway)