Git Product home page Git Product logo

konnect's Introduction

Konnect PHP SDK (unofficial)

Konnect

The payment solution for Tunisia. Simple, fast, personalized, immediate and for all !

Installation

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:

composer require guzzlehttp/guzzle nyholm/psr7

SDK Initialization

<?php

include './vendor/autoload.php';

use GuzzleHttp\Client;
use Machour\Konnect\Gateway;
use Machour\Konnect\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)

Creates a new payment request.

See Konnect's documentation for the full description of $params and the returned array.

/**
 * @throws ApiException|\Psr\Http\Client\ClientExceptionInterface
 */
public function initPayment(array $params): array
See usage sample and output
$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 for the full description of the returned array.

/**
 * @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.

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's People

Contributors

machour avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.