PHP code example of nps / php-sdk

1. Go to this page and download the library: Download nps/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nps / php-sdk example snippets

 
 
use NpsSDK\Configuration;
use NpsSDK\Constants;
Configuration::environment(Constants::STAGING_ENV);
Configuration::secretKey(“yourSecretKeyHere”);
 

use NpsSDK\Sdk;
use NpsSDK\ApiException;
use NpsSDK\Configuration;
use NpsSDK\Constants;

Configuration::environment(Constants::SANDBOX_ENV);
Configuration::secretKey("YourKeyhere");

$sdk = new Sdk();

$params = array(
    'psp_Version'          => '2.2',
    'psp_MerchantId'       => 'psp_test',
    'psp_TxSource'         => 'WEB',
    'psp_MerchTxRef'       => 'ORDER56666-3',
    'psp_MerchOrderId'     => 'ORDER56666',
    'psp_Amount'           => '1000',
    'psp_NumPayments'      => '1',
    'psp_Currency'         => '032', 
    'psp_Country'          => 'ARG', 
    'psp_Product'          => '14',
    'psp_CustomerMail'     => '[email protected]',
    'psp_CardNumber'       => '4507990000000010', 
    'psp_CardExpDate'      => '1903', 
    'psp_CardSecurityCode' => '306',
    'psp_SoftDescriptor'   => 'Sol Tropical E',
    'psp_PosDateTime'      => '2016-12-01 12:00:00'
    
);
try{
    $resp = $sdk->payOnline2p($params);
}catch(ApiException $e){
    echo 'Code to handle error';
}
 

use NpsSDK\Configuration;
use NpsSDK\Constants;
Configuration::environment(Constants::STAGING_ENV);
Configuration::environment(Constants::SANDBOX_ENV);
Configuration::environment(Constants::PRODUCTION_ENV);
 

use NpsSDK\ApiException;

//Code
try{
    //code or sdk call
}catch(ApiException $e){
    //Code to handle error
}
 
use Monolog\Logger;
$logger = new Logger(“NpsSdk”);

use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::logger($logger);
 
use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::loglevel(“DEBUG”);
 
use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::sanitize(true);
 
use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::executionTimeout(60);
Configuration::connectionTimeout(10);
 
use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::proxyUrl("http://yourproxy");
Configuration::proxyPort(6854);
Configuration::proxyUser("proxyUsername");
Configuration::proxyPass("proxyPassword");
 
use NpsSDK\Configuration;

Configuration::secretKey(“your key here”);
Configuration::useCache(True);
Configuration::cacheTTL(86400);
Configuration::cacheLocation("/tmp");
bash
$ composer