Coder Social home page Coder Social logo

nps-sdk-ruby's Introduction

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"

CustomUrls

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"]

nps-sdk-ruby's People

Contributors

jmrebull avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.