Skip to content

bioritmo/nps-sdk-ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby SDK

Availability

Supports Ruby 2.3 and above

How to install

$ gem install nps_sdk

Configuration

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'     => '[email protected]',
    '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

Environments

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

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 savon2.

npssdk = Nps::Sdk.new(conf)

#Code
begin
  #Code or sdk call
rescue => e
  puts e.message
end

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.

require 'nps_sdk'
require 'logger'

conf = Nps::Configuration.new
conf.logger = Logger.new(STDOUT)
conf.key = "Secret key"

Loglevel

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

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

Timeout

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

Proxy configuration

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"

Packages

No packages published

Languages

  • Ruby 100.0%