Requirements
PHP 5.4 or later
Installation
Installation via Composer
composer require nuvei-international/nuvei-php
Manually
If you do not wish to use Composer, you can download the latest release. Then include the init.php
file.
require_once('/path/to/nuvei-sdk/init.php');
Dependencies
The PHP SDK requires the following extensions to work properly:
Initializing the SDK
Client
$nuvei = new \Nuvei\Api\RestClient([ 'environment' => \Nuvei\Api\Environment::INT, 'merchantId' => '<your merchantId>', 'merchantSiteId' => '<your merchantSiteId>', 'merchantSecretKey' => '<your merchantSecretKey>', ]);
Or
$nuvei = new \Nuvei\Api\RestClient(); $config = $nuvei->getConfig(); $config->setEnvironment(\Nuvei\Api\Environment::INT); $config->setMerchantId('<your merchantId>'); $config->setMerchantSiteId('<your merchantSiteId>'); $config->setMerchantSecretKey('<your merchantSecretKey>');
Logger
Logger can be configured with a PSR-3 compatible logger .
Example with Monolog
$logger = new Monolog\Logger('nuvei-php-sdk'); $logger->pushHandler(new Monolog\Handler\StreamHandler('path/to/log', Monolog\Logger::DEBUG)); $nuvei->setLogger($logger);
Example
Nuvei’s PHP SDK appends merchantId
, merchantSiteId
, timestamp
, and checksum
in the request.
<?php use Nuvei\Api\RestClient; use Nuvei\Tests\SimpleData; use Nuvei\Tests\TestCaseHelper; require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../init.php'; require __DIR__ . '/../tests/TestCaseHelper.php'; require __DIR__ . '/../tests/SimpleData.php'; $config = [ 'environment' => \Nuvei\Api\Environment::INT, 'merchantId' => '<your merchantId>', 'merchantSiteId' => '<your merchantSiteId>', 'merchantSecretKey' => '<your merchantSecretKey>', ]; $nuvei = new \Nuvei\Api\Nuvei(); $nuvei->initialize($config); $paymentResponse = $nuvei->getPaymentService()->initPayment([ 'currency' => 'EUR', 'amount' => '10', 'userTokenId' => '<user token id>', 'paymentOption' => [ 'card' => [ 'cardNumber' => '<card number>', 'cardHolderName' => 'card name', 'expirationMonth' => '<expiration month>', 'expirationYear' => '<expiration year>', 'CVV' => '<cvv>', ] ], 'billingAddress' => [ "firstName" => "<first name>", "lastName" => "<last name>", "address" => "<address>", "phone" => "<phone number>", "zip" => "<zip code>", "city" => "<city>", 'country' => "<country ISO 3166-1 alpha-2>", "state" => "<state>", "email" => "<email address>", "county" => "<county>", ] ]); print_r($paymentResponse); $openOrderRequest = $nuvei->getPaymentService()->openOrder([ 'userTokenId' => '<user token id>', 'clientUniqueId' => '', 'clientRequestId' => '', 'currency' => SimpleData::getCurrency(), 'amount' => SimpleData::getAmount(), 'amountDetails' => SimpleData::getAmountDetails(), 'items' => SimpleData::getItems(), 'deviceDetails' => SimpleData::getDeviceDetails(), 'userDetails' => SimpleData::getUserDetails(), 'shippingAddress' => SimpleData::getShippingAddress(), 'billingAddress' => SimpleData::getBillingAddress(), 'dynamicDescriptor' => SimpleData::getDynamicDescriptor(), 'merchantDetails' => SimpleData::getMerchantDetails(), 'addendums' => SimpleData::getAddEndUms(), ]); print_r($openOrderRequest);