2017 © Pedro PelĂĄez
 

library sdk

Clearhaus PHP SDK

image

clearhaus/sdk

Clearhaus PHP SDK

  • Friday, December 1, 2017
  • by neeckeloo
  • Repository
  • 2 Watchers
  • 1 Stars
  • 51 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

Clearhaus PHP SDK

SDK for Clearhaus API written in PHP and decoupled from any HTTP messaging client using HTTPlug., (*1)

You can sign up for a Clearhaus account at https://www.clearhaus.com/., (*2)

Build Status Latest Stable Version Total Downloads GitHub license, (*3)

Requirements

Installation

Clearhaus SDK only officially supports installation through Composer. For Composer documentation, please refer to getcomposer.org., (*4)

You can install the module from command line:, (*5)

$ composer require clearhaus/sdk

Documentation

Please see http://docs.gateway.clearhaus.com for up-to-date documentation., (*6)

Authentication

For authentication, you must provide an API key that you will find in your account:, (*7)

use Clearhaus\Client;

$client = new Client($apiKey);

Signed requests

The signature is an RSA signature of the HTTP body; it is represented in Hex. The signee must be identified by the signing API-key., (*8)

use Clearhaus\Client;

$client->enableSignature();

Authorizations

To reserve money on a cardholder’s bank account you make a new authorization resource., (*9)

$authorization = $client->authorizations->authorize([
    'amount' => 2050,
    'currency' => 'EUR',
    'ip' => '1.1.1.1',
    'card' => [
        'number' => '4111111111111111',
        'expire_month' => '06',
        'expire_year' => '2018',
        'csc' => '123',
    ],
]);

You can also use a card previously tokenized., (*10)

$authorization = $client->authorizations->authorizeFromCardId($cardId, [
    'amount' => 2050,
    'currency' => 'EUR',
    'ip' => '1.1.1.1',
]);

Captures

To transfer money from a cardholder’s bank account to your merchant bank account you make a new capture resource. You can make multiple captures for an authorization transaction., (*11)

$client->captures->capture($authorization['id']);

You can withdraw a partial amount by providing an amount parameter:, (*12)

$client->captures->capture($authorization['id'], ['amount' => 1000]);

Refunds

To refund money to a cardholder’s bank account you make a new refund resource. You can make multiple refunds for an authorization transaction., (*13)

$client->refunds->refund($authorization['id']);

You can refund a partial amount by providing an amount parameter:, (*14)

$client->refunds->refund($authorization['id'], ['amount' => 500]);

Voids

To release reserved money on a cardholder’s bank account you make a new void resource. A reservation normally last for 7 days depending on issuing bank and is then automatically released., (*15)

$client->voids->void($authorization['id']);

Credits

To payout (e.g. winnings and not refunds) money to a cardholder’s bank account you make a new credit resource. You must have a card resource to make a credit transaction., (*16)

$client->credits->credit($card['id'], [
    'amount' => 2050,
    'currency' => 'EUR',
]);

Cards

A card resource (token) corresponds to a payment card and can be used to make a credit or authorization transaction without providing sensitive card data. A card resource must be used to make subsequent recurring authorization transactions., (*17)

$card = $client->cards->createCard([
    'card' => [
        'number' => '4111111111111111',
        'expire_month' => '06',
        'expire_year' => '2018',
        'csc' => '123',
    ],
]);

Accounts

The account resource holds basic merchant account information., (*18)

$account = $client->accounts->getAccount();

3-D Secure

3-D Secure is a protocol designed to improve security for online transactions. Before you continue please read more about this protocol at 3Dsecure.io., (*19)

To perform a 3-D Secure transaction you make an ordinary authorization including a pares value:, (*20)

$authorization = $client->authorizations->authorize([
    'amount' => 2050,
    'currency' => 'EUR',
    'ip' => '1.1.1.1',
    'card' => [
        'number' => '4111111111111111',
        'expire_month' => '06',
        'expire_year' => '2018',
        'csc' => '123',
    ],
    'threed_secure' => [
        'pares' => '<some-pares-value>',
    ],
]);

PSR-11 factory

You can use the predefined factory Clearhaus\Container\ClientFactory to instantiate a Clearhaus client:, (*21)

use Clearhaus\Container\ClientFactory;

$factory = new ClientFactory();
$client = $factory($psrContainer);

The client configuration must look like below:, (*22)

use Clearhaus\Client;

return [
    'clearhaus_sdk' => [
        'api_key' => null, // Allow to provide API key that you will find in your account
        'mode' => Client::MODE_TEST, // Allow to define the usage of either test or live accounts
        'use_signature' => true, // Allow to configure the usage of request signature
        'plugins' => [], // HTTPlug plugins that allow to add some processing logic
    ],
];

Testing

bash $ vendor/bin/phpspec run, (*23)

Credits

License

The MIT License (MIT). Please see License File for more information., (*24)

The Versions