The NimblePayments SDK for PHP makes it easy to add payment services to your e-commerce. It connects your site to the NimblePayments API directly.
- First live release
- It includes the single payment service
- PHP 5.2 or above
- curl & json extensions must be enabled
The SDK zip from the GitHub repository contains the NimblePayments SDK for PHP tool, including all its dependencies. Follow the next steps to install it:
- Download the latest/desired release zip. You will obtain a file called "sdk-php-master.zip" which includes the SDK and several samples.
- Create a new folder inside your PHP project directory to store NimblePayments SDK files.
- Unzip "sdk-php-master.zip" and copy all files in the folder you have just created in the previous step.
The file named base/ConfigSDK.php includes some configuration parameters by default that do not need to be modified.
Once you have completed the Installation and configuration processes, you are ready to generate a payment.
In order to execute a payment, you will need to create a NimbleApi
instance with payment and client information and use the SendPaymentClient
method in the class Payments
to send the payment
A payment
term refers to an object that contains all the data needed in order to execute a payment. This object is an array that must be filled with the following parameters:
amount
: it refers to the amount that has to be paid in cents avoiding the decimal digits. The real amount has to be multiplied by 100.currency
: it refers to the payment currency. It follows the currency ISO 4217 codecustomerData
: it refers to the merchant's sale identification. Example: The Prestashop`s order id.paymentSuccessUrl
: it refers to the callback URL to be redirected when the payment finishes successfully.paymentErrorUrl
: it refers to the callback URL to be redirected when the payment finishes with an error.
require_once './nimble-sdk/lib/Nimble/base/NimbleAPI.php';
use Nimble\Base\NimbleAPI;
use Nimble\Api\Payments;
// build an array with payment information
$payment = array(
'amount' => 1010,
'currency' => 'EUR',
'customerData' => 'idSample12345',
'paymentSuccessUrl' => 'https://my-commerce.com/payments/success',
'paymentErrorUrl' => 'https://my-commerce.com/payments/error'
);
Client information refers to an array called “params” that includes client’s credentials and ‘mode’ parameters.
- Client’s credentials consist of a clientid and clientsecret. Their value is the
Api_Client_Id
and theClient_Secret
codes generated when creating a Payment gateway in the Nimble dashboard. mode
parameter defines the environment in which you want to work. It has two possible values:sandbox
. It is used in the demo environment to make tests.real
. It is used to work in the real environment.
To generate a Payment you will need to execute the following steps:
- Build an array with the payment information
- Build an array with client information (
Api_Client_Id
andClient_Secret
) and mode parameters - Create a
NimbleAPI
instance - Use the
SendPaymentClient
method in the classPayments
to send the payment
require_once './nimble-sdk/lib/Nimble/base/NimbleAPI.php';
use Nimble\Base\NimbleAPI;
use Nimble\Api\Payments;
// build an array with payment information
$payment = array(
'amount' => 1010,
'currency' => 'EUR',
'customerData' => 'idSample12345',
'paymentSuccessUrl' => 'https://my-commerce.com/payments/success',
'paymentErrorUrl' => 'https://my-commerce.com/payments/error'
);
// build an array with client API information
$params = array(
'clientId' => '729DFCD7A2B4643A0DA3D4A7E537FC6E',
'clientSecret' => 'jg26cI3O1mB0$eR&fo6a2TWPmq&gyQoUOG6tClO%VE*N$SN9xX27@R4CTqi*$4EO',
'mode' => 'Sandbox'
);
$NimbleApi = new NimbleAPI($params);
$response = Payments::SendPaymentClient($NimbleApi, $payment);
In test
folder you will find scripts implementing a basics operations that uses NimbleePayments SDK as payment platform.
Please see Apiary for up-to-date documentation.