# Perl SDK ## Availability Supports Perl 5.24.1 ## How to install ``` cpan install NpsSDK::Nps ``` ## Configuration It's a basic configuration of the SDK ```perl use NpsSDK::Nps; use warnings; use strict; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_"); ``` Here is a simple example request: ```perl use NpsSDK::Nps; use warnings; use strict; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_"); my $params = { 'psp_Version' => '2.2', 'psp_MerchantId' => 'psp_test', 'psp_TxSource' => 'WEB', 'psp_MerchTxRef' => 'ORDER69461-3', 'psp_MerchOrderId' => 'ORDER69461', 'psp_Amount' => '15050', 'psp_NumPayments' => '1', 'psp_Currency' => '032', 'psp_Country' => 'ARG', 'psp_Product' => '14', 'psp_CardNumber' => '4507990000000010', 'psp_CardExpDate' => '1612', 'psp_PosDateTime' => '2016-12-01 12:00:00', 'psp_CardSecurityCode' => '123' }; my $response = NpsSDK::Nps::pay_online_2p($params); ``` ## Environments ```perl use NpsSDK::Nps; $NpsSDK::Constants::PRODUCTION_ENV $NpsSDK::Constants::STAGING_ENV $NpsSDK::Constants::SANDBOX_ENV ``` ## Error handling You can check if something went wrong checking the type of $response. There are 3 type of errors: Timeout, Connection and Unknown. Their type of object are NpsSDK::TimeoutException, NpsSDK::ConnectionException, NpsSDK::UnknownError respectively. The example below also work for Connection and Unknown errors. ```perl use NpsSDK::Nps; use warnings; use stricts; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", timeout => 60); my $response = NpsSDK::Nps::pay_online_2p($params); if (ref($response) eq "NpsSDK::TimeoutException") { #Your code to handle the error }; ``` ## Advanced configurations ### Logging Nps SDK allows you to log what’s happening with you request inside of our SDK. In order to do so you will have to create a logger with Log::Log4perl and pass it by configuration. ```perl use NpsSDK::Nps; use warnings; use strict; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", logger => $logger); ``` ### LogLevel 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. Simple debug screen logging example: ```perl use NpsSDK::Nps; use warnings; use strict; use Log::Log4perl; Log::Log4perl->init(\< $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", logger => $logger); ``` You can also save the logs in a file: ```perl use NpsSDK::Nps; use warnings; use strict; use Log::Log4perl; Log::Log4perl->init(\< $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", logger => $logger); ``` ### Sanitize Sanitize allows the SDK to truncate to a fixed size some fields that could make request fail, like extremely long name. ```perl use NpsSDK::Nps; use warnings; use strict; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", sanitize => 1); ``` ### Timeout You can change the timeout of the request. ```perl use NpsSDK::Nps; use warnings; use strict; NpsSDK::Configuration::configure(environment => $NpsSDK::Constants::SANDBOX_ENV, secret_key => "_YOUR_SECRET_KEY_", timeout => 60); ```