2017 © Pedro Peláez
 

library ibercheck-api-sdk

Ibercheck API SDK

image

ibercheck/ibercheck-api-sdk

Ibercheck API SDK

  • Wednesday, October 19, 2016
  • by Maks3w
  • Repository
  • 2 Watchers
  • 0 Stars
  • 226 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 22 % Grown

The README.md

Ibercheck API SDK for PHP

Ibercheck page | API Documentation page | API Playground page, (*1)

This SDK provides a friendly interface for performing requests and decode responses., (*2)

Installation

You can use Composer:, (*3)

composer require ibercheck/ibercheck-api-sdk

Usage

Create the sale hash

$hash = Ibercheck\Api\Sale::createSaleHash(
    's3cr3t', // Affiliate Secret
    'ABCD_123456', // Order number
    'autocheck' // Product mnemonic
);

Authenticate webhook request

if(!Ibercheck\Api\Webhook::isAuthentic(
        's3cr3t', // Affiliate Secret
        '596f6838cb5b....ae812fb62f91c6', // Value of `X-Ibercheck-Signature` header
        '{....}' // Webhook payload
    )
) {
    throw new Exception('Fraudulent webhook received');
}

API Calls

This SDK assist you for craft a well formatted API request and decode the response back to PHP., (*4)


// Exchange affiliate credentials with a private access token. $oAuthRequest = new Ibercheck\Api\ApiRequest('POST', 'http://api_dev.ibercheck.net/oauth'); $oAuthRequest = $oAuthRequest->withJsonSerializableData( [ 'grant_type' => 'client_credentials', 'client_id' => 'ACME_SL', // Affiliate Name 'client_secret' => 's3cr3t', // Affiliate Secret ] ); $oAuthResponsePayload = sendRequestToApi($oAuthRequest); // Use the new private access token for authenticate your API requests. $meRequest = new Ibercheck\Api\ApiRequest('GET', 'http://api_dev.ibercheck.net/me'); $meRequest = $meRequest->withAuthentication($oAuthResponsePayload['access_token']); $meResponsePayload = sendRequestToApi($meRequest); print_r($meResponsePayload); function sendRequestToApi(Psr\Http\Message\RequestInterface $request) { $psr18HttpClient = new Psr\Http\Client\ClientInterface(); $ibercheckApiClient = new Ibercheck\Api\Client($psr18HttpClient); try { $response = $ibercheckApiClient->sendRequest($request); $payload = $ibercheckApiClient->decodeResponseBody((string) $response->getBody()); } catch (Ibercheck\Api\ApiCommunicationException $apiCommunicationException) { // A network error has occurred while sending the request or receiving the response. // Retry } catch (Ibercheck\Api\DeserializeException $deserializationException) { // Nobody knows when this happen, may an HTTP Proxy on our side or on your side started to return HTML responses with errors. // Retry } catch (Ibercheck\Api\ApiServerException $apiServerException) { // Our server has crashed. We promise to fix it ASAP. echo 'Error code', $apiClientException->getStatus(), PHP_EOL; echo 'Error type', $apiClientException->getType(), PHP_EOL; echo 'Error message', $apiClientException->getMessage(), PHP_EOL; echo 'Error detail', var_export($apiClientException->getDetail(), true), PHP_EOL; } catch (Ibercheck\Api\ApiClientException $apiClientException) { // Your client has sent an invalid request. Please check your code. echo 'Error code', $apiClientException->getStatus(), PHP_EOL; echo 'Error type', $apiClientException->getType(), PHP_EOL; echo 'Error message', $apiClientException->getMessage(), PHP_EOL; echo 'Error detail', var_export($apiClientException->getDetail(), true), PHP_EOL; } return $payload; }

License

Distributed under the MIT license, (*5)

The Versions

19/10 2016

dev-master

9999999-dev

Ibercheck API SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

ibercheck

11/07 2016

v0.1.1

0.1.1.0

Ibercheck API SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

ibercheck

11/07 2016

v0.1.0

0.1.0.0

Ibercheck API SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

ibercheck