konnect / sdk
Konnect PHP SDK
dev-main
2022-12-20 19:21 UTC
Requires
- php: ^7.3|^7.4|^8.0|^8.1|^8.2
- ext-json: *
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-factory-implementation: *
Requires (Dev)
- guzzlehttp/guzzle: ^7.5
- nyholm/psr7: ^1.5
This package is not auto-updated.
Last update: 2024-09-28 18:00:12 UTC
README
突尼斯的支付解决方案。简单、快速、个性化、即时,适用于所有人!
安装
composer require konnect/sdk
此SDK遵循PSR-18 "HTTP客户端"标准,以实现更广泛的互操作性。
如果你的框架为你处理依赖注入,则最有可能的是,否则你可以使用任何符合规范的实现。
以下示例使用这两个库
composer require guzzlehttp/guzzle nyholm/psr7
SDK初始化
<?php include './vendor/autoload.php'; use GuzzleHttp\Client; use Konnect\SDK\Gateway; use Konnect\SDK\ApiException; use Nyholm\Psr7\Factory\Psr17Factory; // Use this or bring your own implementation $psr17Factory = new Psr17Factory(); $client = new Client(); $konnect = new Gateway($psr17Factory, $psr17Factory, $client); // Mandatory // Retrieve this from your Konnect dashboard $apiKey = "6137ad140c181c5eb44a7f88:Rp2dpHPb0mBpj3_51s86zzp3PXs5w1"; $konnect->setApiKey($apiKey); // By default, the SDK is in sandbox mode. // To switch to production, use the following $konnect->setProductionMode();
API
initPayment(array $params)
创建一个新的支付请求。
请参阅Konnect的文档,了解有关$params
和返回数组的完整说明。
/** * @throws ApiException|\Psr\Http\Client\ClientExceptionInterface */ public function initPayment(array $params): array
请参阅使用示例和输出
$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" => "mon.email@mail.com", "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)
获取指定ID的支付详情。
请参阅Konnect的文档,了解返回数组的完整说明。
/** * @throws ApiException|\Psr\Http\Client\ClientExceptionInterface */ public function getPaymentDetails(string $paymentId): array
异常
如果您的调用有任何问题,此SDK将抛出\Konnect\SDK\ApiException
。异常的errors
属性将包含报告的错误。
但是,如果Konnect服务器有问题,将抛出而不是PSR-18异常。
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 } }