nexylan/paybox-direct

PayBox Direct and Direct Plus API wrapper

v0.4.0 2020-12-10 19:49 UTC

This package is auto-updated.

Last update: 2024-10-28 18:45:18 UTC


README

Paybox Direct and Paybox Direct Plus PHP SDK.

Latest Stable Version Latest Unstable Version License Dependency Status Reference Status

Total Downloads Monthly Downloads Daily Downloads

Build Status Scrutinizer Code Quality Code Climate Coverage Status SensioLabsInsight

Documentation

All the installation and usage instructions are located in this README. Check it for a specific versions:

  • 0.x with support for Symfony ^2.7 || ^3.0

Prerequisites

This version of the project requires:

  • PHP 7.4+
  • Symfony 2.7+ for bundle integration

Installation

First of all, you need to require this library through Composer:

composer require nexylan/paybox-direct

After this, you can use it as is.

If you are using it on a Symfony project, you should read the following instructions for a better integration.

As a Symfony bundle

If your project is not using Symfony Full Stack, you must add the following dependencies:

composer require symfony/dependency-injection symfony/http-kernel

Register the bundle in the kernel of your application:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Nexy\PayboxDirect\Bridge\Symfony\Bundle\NexyPayboxDirectBundle(),
    );

    // ...

    return $bundles;
}

Some configuration is required. Here is the default one:

nexy_paybox_direct:
    client:               null
    options:
        timeout:              ~
        production:           ~
    paybox:               # Required
        version:              ~ # Required
        site:                 ~ # Required
        rank:                 ~ # Required
        identifier:           ~ # Required
        key:                  ~ # Required
        default_currency:     ~
        default_activity:     ~

Usage

Get the client instance

To communicate with the Paybox Direct (Plus) API, you have to instantiate the Paybox class:

use Nexy\PayboxDirect\Enum\Version;
use Nexy\PayboxDirect\Paybox;

$paybox = new Paybox([
    // Optional parameters:
    'timeout' => 30,        // Change the request timeout.
    'production' => true,   // Set to true to use the production API URL.
    // Required parameters:
    'paybox_version' => Version::DIRECT_PLUS,
    'paybox_site' => '1999888',
    'paybox_rank' => '32',
    'paybox_identifier' => '107904482',
    'paybox_key' => '1999888I',
]);

If you are using the Symfony bundle bridge, all the parameters are already defined on the configuration side.

All you have to do is call the paybox service:

/** @var \Nexy\PayboxDirect\Paybox $paybox */
$paybox = $this->container->get('nexy_paybox_direct.sdk');

Make a request

Here is a commented example of how to make a Paybox Direct request with the SDK:

use Nexy\PayboxDirect\Exception\PayboxException;
use Nexy\PayboxDirect\Request\AuthorizeAndCaptureRequest;

$request = new AuthorizeAndCaptureRequest('CMD-42', 1000, '1111222233334444', '1224');
$request->setCardVerificationValue('123');
try {
    /** @var \Nexy\PayboxDirect\Response\DirectResponse $response */
    $response = $paybox->sendDirectRequest($request);
} catch (PayboxException $e) {
    echo $e->getMessage(); // Prints the Paybox error message.
    /** @var \Nexy\PayboxDirect\Response\DirectResponse $response */
    $response = $e->getResponse(); // Returns the response object if you want to manipulate it.
}
// Do stuff with the response!

If you want to do the same via the Direct Plus protocol with a subscriber reference:

$request = new AuthorizeAndCaptureRequest('CMD-42', 1000, 'subscriberCardRef', '1224', 'subscriberRef');
try {
    /** @var \Nexy\PayboxDirect\Response\DirectPlusResponse $response */
    $response = $paybox->sendDirectPlusRequest($request);
} catch (PayboxException $e) {
    echo $e->getMessage(); // Prints the Paybox error message.
    /** @var \Nexy\PayboxDirect\Response\DirectPlusResponse $response */
    $response = $e->getResponse(); // Returns the response object if you want to manipulate it.
}
// Do stuff with the response!

Note that you have to use Paybox::sendDirectPlusRequest method that returns a DirectPlusResponse object.

Requests reference

Here is a table listing all the available requests: