nps/php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nps/php-sdk

Composer 安装命令:

composer require nps/php-sdk

包简介

A Php SDK for Ingenico ePayments - NPS LatAm Services

README 文档

README

Availability

Supports PHP 5.3 and above

How to install

Pre Requesites

You will have to install the following packages for your PHP:

· SimpleXML

· Curl

· Soap

Composer installation

the SDK can be installed with Composer by updating your composer.json file

{
    "require": 
        {
            "nps/php-sdk": "1.3.0"
        }
}

or by executing this command

$ composer require nps/php-sdk

Manual installation

You can download or clone the SDK from our Github Page. and then include the init.php file.

require_once __DIR__ . '/vendor/autoload.php';

Configuration

It's a basic configuration of the SDK

require_once __DIR__ . '/vendor/autoload.php';
use NpsSDK\Configuration;
use NpsSDK\Constants;
Configuration::environment(Constants::STAGING_ENV);
Configuration::secretKey(“yourSecretKeyHere”);

Here is an simple example request:

require_once __DIR__ . '/vendor/autoload.php';

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'     => 'john.doe@example.com',
    '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';
}

Environments

require_once __DIR__ . '/vendor/autoload.php';

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

Error handling

ApiException: This exception is raised when a ReadTimeout or a ConnectTimeout occurs.

Note: The rest of the exceptions that can occur will be detailed inside of the response provided by NPS or will be provided by the php SoapClient class.

require_once __DIR__ . '/vendor/autoload.php';

use NpsSDK\ApiException;

//Code
try{
    //code or sdk call
}catch(ApiException $e){
    //Code to handle error
}

Advanced configurations

Logging

Nps SDK allows you to log what’s happening with you request inside of our SDK, it logs by default to stout. The SDK uses the custom logger that you use for your project.

An example for monolog Logger.

use Monolog\Logger;
$logger = new Logger(“NpsSdk”);

use NpsSDK\Configuration;

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

LogLevel

Note: The logger needs to be PSR-3 compliant to work properly inside of the SDK, some examples are (Monolog, Analog).

The "INFO" level will write concise information of the request and will mask sensitive data of the request. The "DEBUG" level will write information about the request to let developers debug it in a more detailed way.

use NpsSDK\Configuration;

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

Sanitize

Sanitize allows the SDK to truncate to a fixed size some fields that could make request fail, like extremely long name.

use NpsSDK\Configuration;

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

Timeout

You can change the timeout of the request.

ExecutionTimeout(Default=60 seconds): you can change the execution timeout of the request.

ConnectionTimeout(Default=10 seconds): you can change the connection timeout of the request.

use NpsSDK\Configuration;

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

Proxy configuration

use NpsSDK\Configuration;

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

Cache

use NpsSDK\Configuration;

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

统计信息

  • 总下载量: 52.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固