Supports Ruby 2.3 and above
$ gem install nps_sdk
It's a basic configuration of the SDK
require 'nps_sdk'
conf = Nps::Configuration.new
conf.environment =Nps::Environments::SANDBOX_ENV
conf.key = "Secret key"
Here is an simple example request:
require 'nps_sdk'
conf = Nps::Configuration.new
conf.environment =Nps::Environments::SANDBOX_ENV
conf.key = "Secret key"
npssdk = Nps::Sdk.new(conf)
params = {
'psp_Version' => '2.2',
'psp_MerchantId' => 'psp_test',
'psp_TxSource' => 'WEB',
'psp_MerchTxRef' => 'ORDER5rf666-3',
'psp_MerchOrderId' => 'ORDER5rf666',
'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'
}
begin
resp = npssdk.authorize_2p(params)
rescue => e
#Code to handle the error
end
require 'nps_sdk'
conf = Nps::Configuration.new
conf.environment = Nps::Environments::SANDBOX_ENV
conf.environment = Nps::Environments::STAGING_ENV
conf.environment = Nps::Environments::PRODUCTION_ENV
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 savon2.
npssdk = Nps::Sdk.new(conf)
#Code
begin
#Code or sdk call
rescue => e
puts e.message
end
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.
require 'nps_sdk'
require 'logger'
conf = Nps::Configuration.new
conf.logger = Logger.new(STDOUT)
conf.key = "Secret key"
The logging.INFO level will write concise information of the request and will mask sensitive data of the request. The logging.DEBUG level will write information about the request to let developers debug it in a more detailed way.
require 'nps_sdk'
require 'logger'
conf = Nps::Configuration.new
conf.key = "Secret key"
conf.logger = Logger.new(STDOUT)
conf.log_level = Logger::DEBUG
Sanitize allows the SDK to truncate to a fixed size some fields that could make request fail, like extremely long name.
require 'nps_sdk'
conf = Nps::Configuration.new
conf.key = "Secret key"
conf.sanitize = true
You can change the timeout of the request where o_timeout is ConnectionTimeout and r_timeout is ExecutionTimeout.
require 'nps_sdk'
conf = Nps::Configuration.new
conf.key = "Secret key"
conf.o_timeout = 10
conf.r_timeout = 60
require 'nps_sdk'
conf = Nps::Configuration.new
conf.key = "Secret key"
conf.proxy_url = "YOUR/PROXY/URL"
conf.proxy_username = "USERNAME"
conf.proxy_password = "YOUR_PASSWORD"
Optional configuration which allow you to specify different urls to use as the environment for the SDK.
You need to configure SDKs environment to CustomEnv and create a URLs list which will be used as CustomEnv. The SDK will use the first URL specified in customEnvUrls parameter and try to connect. If the connection cannot be established after several retries, the SDK will proceed with the next url.
require 'nps_sdk'
conf.key = "Secret key"
conf = Nps::Configuration.new
conf.environment = Nps::Environments::CUSTOM_ENV
conf.custom_env_urls = ["https://first_url.com.ar", "https://second_url.com.ar"]