nexylan / paybox-direct
PayBox Direct and Direct Plus API wrapper
Installs: 28 187
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 9
Open Issues: 10
Requires
- php: ^7.4 || ^8.0
- doctrine/annotations: ^1.2
- doctrine/cache: ^1.0
- greg0ire/enum: ^2.1 || ^3.0 || ^4.0
- guzzlehttp/guzzle: ^6.5
- paragonie/random_compat: ^2.0
- symfony/options-resolver: ^4.0
- symfony/validator: ^4.0 || ^5.0
Requires (Dev)
- matthiasnoback/symfony-config-test: ^4.2.1
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1
- phpunit/phpunit: ^9
- symfony/dependency-injection: ^4.0 || ^5.0
- symfony/http-kernel: ^4.0 || ^5.0
Suggests
- symfony/dependency-injection: For Symfony integration as a bundle
- symfony/http-kernel: For Symfony integration as a bundle
Conflicts
- symfony/dependency-injection: <4.0|>=6.0
- symfony/http-kernel: <4.0|>=6.0
README
Paybox Direct and Paybox Direct Plus PHP SDK.
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: