Paybox Direct and Paybox Direct Plus PHP SDK.
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
This version of the project requires:
- PHP 5.6+
- Symfony 2.7+ for bundle integration
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.
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: ~
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');
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.
Here is a table listing all the available requests:
Request ID | RequestInterface |
Paybox method |
ResponseInterface |
---|---|---|---|
00001 | AuthorizeRequest |
sendDirectRequest |
DirectResponse |
00002 | DebitRequest |
sendDirectRequest |
DirectResponse |
00003 | AuthorizeAndCaptureRequest |
sendDirectRequest |
DirectResponse |
00004 | CreditRequest |
sendDirectRequest |
DirectResponse |
00005 | CancelRequest |
sendDirectRequest |
DirectResponse |
00013 | UpdateAmountRequest |
sendDirectRequest |
DirectResponse |
00014 | RefundRequest |
sendDirectRequest |
DirectResponse |
00017 | InquiryRequest |
sendInquiryRequest |
InquiryResponse |
00051 | AuthorizeRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00052 | DebitRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00053 | AuthorizeAndCaptureRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00054 | CreditRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00055 | SubscriberCancelTransactionRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00056 | SubscriberRegisterRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00057 | SubscriberUpdateRequest |
sendDirectPlusRequest |
DirectPlusResponse |
00058 | SubscriberDeleteRequest |
sendDirectPlusRequest |
DirectPlusResponse |