nps_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cab606c49f8e1f21269f86d9c8c7a1f81b5e2f19
4
+ data.tar.gz: 71ab58b6ed0d164a53370bbbaf3fbe159e7d2cbf
5
+ SHA512:
6
+ metadata.gz: 07dc075254a54198de6b24d45686e4b7992157fc0907d082860fce5b37e812783bebf881d27c69cfd678b2d873dbbfd89c2b487aaab4f1c060f49daab0ea455f
7
+ data.tar.gz: 4e8a12941c9c5394aee7387544e69eb76a965e85c6c1043dc8195c38c2a1432735992018a50fac5716dd019de3eabca3d6d36cd917ff9e43489a6507c408add9
@@ -0,0 +1,11 @@
1
+ class ApiException < StandardError
2
+ def message
3
+ "El tiempo de ejecución há expirado"
4
+ end
5
+ end
6
+
7
+ class LoggerException < StandardError
8
+ def message
9
+ "DEBUG level is now allowed in PRODUCTION ENVIRONMENT"
10
+ end
11
+ end
@@ -0,0 +1,66 @@
1
+ psp_Person.FirstName.max_length="128"
2
+ psp_Person.LastName.max_length="64"
3
+ psp_Person.MiddleName.max_length="64"
4
+ psp_Person.PhoneNumber1.max_length="32"
5
+ psp_Person.PhoneNumber2.max_length="32"
6
+ psp_Person.Gender.max_length="1"
7
+ psp_Person.Nationality.max_length="3"
8
+ psp_Person.IDNumber.max_length=""40""
9
+ psp_Person.IDType.max_length="5"
10
+ psp_Address.Street.max_length="128"
11
+ psp_Address.HouseNumber.max_length="32"
12
+ psp_Address.AdditionalInfo.max_length="128"
13
+ psp_Address.City.max_length="40"
14
+ psp_Address.StateProvince.max_length="40"
15
+ psp_Address.Country.max_length="3"
16
+ psp_Address.ZipCode.max_length="10"
17
+ psp_OrderItem.Description.max_length="127"
18
+ psp_OrderItem.Type.max_length="20"
19
+ psp_OrderItem.SkuCode.max_length="48"
20
+ psp_OrderItem.ManufacturerPartNumber.max_length="30"
21
+ psp_OrderItem.Risk.max_length="1"
22
+ psp_Leg.DepartureAirport.max_length="3"
23
+ psp_Leg.ArrivalAirport.max_length="3"
24
+ psp_Leg.CarrierCode.max_length="2"
25
+ psp_Leg.FlightNumber.max_length="5"
26
+ psp_Leg.FareBasisCode.max_length="15"
27
+ psp_Leg.FareClassCode.max_length="3"
28
+ psp_Leg.BaseFareCurrency.max_length="3"
29
+ psp_Passenger.FirstName.max_length="50"
30
+ psp_Passenger.LastName.max_length="30"
31
+ psp_Passenger.MiddleName.max_length="30"
32
+ psp_Passenger.Type.max_length="1"
33
+ psp_Passenger.Nationality.max_length="3"
34
+ psp_Passenger.IDNumber.max_length="40"
35
+ psp_Passenger.IDType.max_length="10"
36
+ psp_Passenger.IDCountry.max_length="3"
37
+ psp_Passenger.LoyaltyNumber.max_length="20"
38
+ psp_SellerDetails.IDNumber.max_length="40"
39
+ psp_SellerDetails.IDType.max_length="10"
40
+ psp_SellerDetails.Name.max_length="128"
41
+ psp_SellerDetails.Invoice.max_length="32"
42
+ psp_SellerDetails.PurchaseDescription.max_length="32"
43
+ psp_SellerDetails.MCC.max_length="5"
44
+ psp_SellerDetails.ChannelCode.max_length="3"
45
+ psp_SellerDetails.GeoCode.max_length="5"
46
+ psp_TaxesRequest.TypeId.max_length="5"
47
+ psp_MerchantAdditionalDetails.Type.max_length="1"
48
+ psp_MerchantAdditionalDetails.SdkInfo.max_length="3"
49
+ psp_MerchantAdditionalDetails.ShoppingCartInfo.max_length="48"
50
+ psp_MerchantAdditionalDetails.ShoppingCartPluginInfo.max_length="48"
51
+ psp_CustomerAdditionalDetails.IPAddress.max_length="45"
52
+ psp_CustomerAdditionalDetails.AccountID.max_length="128"
53
+ psp_CustomerAdditionalDetails.DeviceFingerPrint.max_length="4000"
54
+ psp_CustomerAdditionalDetails.BrowserLanguage.max_length="2"
55
+ psp_CustomerAdditionalDetails.HttpUserAgent.max_length="255"
56
+ psp_BillingDetails.Invoice.max_length="32"
57
+ psp_BillingDetails.InvoiceCurrency.max_length="3"
58
+ psp_ShippingDetails.TrackingNumber.max_length="24"
59
+ psp_ShippingDetails.Method.max_length="3"
60
+ psp_ShippingDetails.Carrier.max_length="3"
61
+ psp_ShippingDetails.GiftMessage.max_length="200"
62
+ psp_AirlineDetails.TicketNumber.max_length="14"
63
+ psp_AirlineDetails.PNR.max_length="10"
64
+ psp_VaultReference.PaymentMethodToken.max_length="64"
65
+ psp_VaultReference.PaymentMethodId.max_length="64"
66
+ psp_VaultReference.CustomerId.max_length="64"
@@ -0,0 +1,19 @@
1
+ module Nps
2
+ class Configuration
3
+ attr_accessor :logger
4
+ attr_accessor :log_level
5
+ attr_accessor :key
6
+ attr_accessor :environment
7
+ attr_accessor :log
8
+ attr_accessor :o_timeout
9
+ attr_accessor :r_timeout
10
+ attr_accessor :sanitize
11
+ attr_accessor :verify_ssl
12
+ attr_accessor :cert_file
13
+ attr_accessor :key_file
14
+ attr_accessor :proxy_url
15
+ attr_accessor :proxy_username
16
+ attr_accessor :proxy_password
17
+
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Nps
2
+ class Environments
3
+ SANDBOX_ENV = "sandbox.wsdl"
4
+ STAGING_ENV = "staging.wsdl"
5
+ PRODUCTION_ENV = "production.wsdl"
6
+ DEVELOPMENT_ENV = "development.wsdl"
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ require 'logger'
2
+
3
+ module Nps
4
+ class NpsFormatter < Logger::Formatter
5
+
6
+ def call(severity, time, progname, msg)
7
+ msg = ofuscate(msg)
8
+ "#{time} - #{severity} - NpsSDK - #{msg2str(msg)}"
9
+ end
10
+
11
+ def ofuscate_cvc(msg)
12
+ msg.gsub(/>\d{3,4}<\/psp_CardSecurityCode>/) { |x| x.gsub(/\d{3,4}/) { |x| "*" * x.length}}
13
+ end
14
+
15
+ def ofuscate_card_number(msg)
16
+ msg.gsub(/>\d{13,19}<\/psp_CardNumber>/) { |x| x.gsub(/\d{13,19}/) { |x| x.slice(0,6) + "*" * (x.length - 10) + x.slice(x.length - 4, x.length)} }
17
+ end
18
+
19
+
20
+ def ofuscate_card_exp_date(msg)
21
+ msg.gsub(/>\d{4}<\/psp_CardExpDate>/) { |x| x.gsub(/\d{4}/) { |x| "*" * x.length} }
22
+ end
23
+
24
+ def ofuscate(msg)
25
+ msg = ofuscate_card_exp_date(msg)
26
+ msg = ofuscate_card_number(msg)
27
+ msg = ofuscate_cvc(msg)
28
+ end
29
+ end
30
+ end
data/lib/nps/sdk.rb ADDED
@@ -0,0 +1,143 @@
1
+ require 'savon'
2
+ require_relative 'services'
3
+ require 'digest'
4
+ require_relative 'soap_client'
5
+
6
+ module Nps
7
+
8
+ class Sdk < SoapClient
9
+
10
+ def pay_online_2p(params)
11
+ soap_call(Services::PAY_ONLINE_2P, params)
12
+ end
13
+
14
+ def authorize_2p(params)
15
+ soap_call(Services::AUTHORIZE_2P, params)
16
+ end
17
+
18
+ def pay_online_3p(params)
19
+ soap_call(Services::PAY_ONLINE_3P, params)
20
+ end
21
+
22
+ def authorize_3p(params)
23
+ soap_call(Services::AUTHORIZE_3P, params)
24
+ end
25
+
26
+ def split_pay_online_3p(params)
27
+ soap_call(Services::SPLIT_PAY_ONLINE_3P, params)
28
+ end
29
+
30
+ def split_authorize_3p(params)
31
+ soap_call(Services::SPLIT_AUTHORIZE_3P, params)
32
+ end
33
+
34
+ def cash_payment_3p(params)
35
+ soap_call(Services::CASH_PAYMENT_3P, params)
36
+ end
37
+
38
+ def bank_payment_3p(params)
39
+ soap_call(Services::BANK_PAYMENT_3P, params)
40
+ end
41
+
42
+ def capture(params)
43
+ soap_call(Services::CAPTURE, params)
44
+ end
45
+
46
+ def refund(params)
47
+ soap_call(Services::REFUND, params)
48
+ end
49
+
50
+ def simple_query_tx(params)
51
+ soap_call(Services::SIMPLE_QUERY_TX, params)
52
+ end
53
+
54
+ def query_txs(params)
55
+ soap_call(Services::QUERY_TXS, params)
56
+ end
57
+
58
+ def change_secret_key(params)
59
+ soap_call(Services::CHANGE_SECRET_KEY, params)
60
+ end
61
+
62
+ def fraud_screening(params)
63
+ soap_call(Services::FRAUD_SCREENING, params)
64
+ end
65
+
66
+ def notify_fraud_screening_review(params)
67
+ soap_call(Services::NOTIFY_FRAUD_SCREENING_REVIEW, params)
68
+ end
69
+
70
+ def get_iin_details(params)
71
+ soap_call(Services::GET_IIN_DETAILS, params)
72
+ end
73
+
74
+ def query_card_number(params)
75
+ soap_call(Services::QUERY_CARD_NUMBER, params)
76
+ end
77
+
78
+ def create_payment_method(params)
79
+ soap_call(Services::CREATE_PAYMENT_METHOD, params)
80
+ end
81
+
82
+ def create_payment_method_from_payment(params)
83
+ soap_call(Services::CREATE_PAYMENT_METHOD_FROM_PAYMENT, params)
84
+ end
85
+
86
+ def retrieve_payment_method(params)
87
+ soap_call(Services::RETRIEVE_PAYMENT_METHOD, params)
88
+ end
89
+
90
+ def update_payment_method(params)
91
+ soap_call(Services::UPDATE_PAYMENT_METHOD, params)
92
+ end
93
+
94
+ def delete_payment_method(params)
95
+ soap_call(Services::DELETE_PAYMENT_METHOD, params)
96
+ end
97
+
98
+ def create_customer(params)
99
+ soap_call(Services::CREATE_CUSTOMER, params)
100
+ end
101
+
102
+ def retrieve_customer(params)
103
+ soap_call(Services::RETRIEVE_CUSTOMER, params)
104
+ end
105
+
106
+ def update_customer(params)
107
+ soap_call(Services::UPDATE_CUSTOMER, params)
108
+ end
109
+
110
+ def delete_customer(params)
111
+ soap_call(Services::DELETE_CUSTOMER, params)
112
+ end
113
+
114
+ def recache_payment_method_token(params)
115
+ soap_call(Services::RECACHE_PAYMENT_METHOD_TOKEN, params)
116
+ end
117
+
118
+ def create_payment_method_token(params)
119
+ soap_call(Services::CREATE_PAYMENT_METHOD_TOKEN, params)
120
+ end
121
+
122
+ def retrieve_payment_method_token(params)
123
+ soap_call(Services::RETRIEVE_PAYMENT_METHOD_TOKEN, params)
124
+ end
125
+
126
+ def create_client_session(params)
127
+ soap_call(Services::CREATE_CLIENT_SESSION, params)
128
+ end
129
+
130
+ def get_installments_options(params)
131
+ soap_call(Services::GET_INSTALLMENTS_OPTIONS, params)
132
+ end
133
+
134
+ def split_pay_online_2p(params)
135
+ soap_call(Services::SPLIT_PAY_ONLINE_2P, params)
136
+ end
137
+
138
+ def split_authorize_2p(params)
139
+ soap_call(Services::SPLIT_AUTHORIZE_2P, params)
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,35 @@
1
+ class Services
2
+
3
+ PAY_ONLINE_2P=:pay_on_line_2p
4
+ AUTHORIZE_2P=:authorize_2p
5
+ PAY_ONLINE_3P=:pay_on_line_3p
6
+ AUTHORIZE_3P=:authorize_3p
7
+ SPLIT_PAY_ONLINE_3P=:split_pay_on_line_3p
8
+ SPLIT_AUTHORIZE_3P=:split_authorize_3p
9
+ CASH_PAYMENT_3P=:cash_payment_3p
10
+ BANK_PAYMENT_3P=:bank_payment_3p
11
+ CAPTURE=:capture
12
+ REFUND=:refund
13
+ SIMPLE_QUERY_TX=:simple_query_tx
14
+ QUERY_TXS=:query_txs
15
+ CHANGE_SECRET_KEY=:change_secret_key
16
+ FRAUD_SCREENING=:fraud_screening
17
+ NOTIFY_FRAUD_SCREENING_REVIEW=:notify_fraud_screening_review
18
+ GET_IIN_DETAILS=:get_iin_details
19
+ QUERY_CARD_NUMBER=:query_card_number
20
+ CREATE_PAYMENT_METHOD = :create_payment_method
21
+ CREATE_PAYMENT_METHOD_FROM_PAYMENT =:create_payment_method_from_payment
22
+ RETRIEVE_PAYMENT_METHOD =:retrieve_payment_method
23
+ UPDATE_PAYMENT_METHOD =:update_payment_method
24
+ DELETE_PAYMENT_METHOD =:delete_payment_method
25
+ CREATE_CUSTOMER =:create_customer
26
+ RETRIEVE_CUSTOMER =:retrieve_customer
27
+ UPDATE_CUSTOMER =:update_customer
28
+ DELETE_CUSTOMER =:delete_customer
29
+ RECACHE_PAYMENT_METHOD_TOKEN=:recache_payment_method_token
30
+ CREATE_PAYMENT_METHOD_TOKEN=:create_payment_method_token
31
+ RETRIEVE_PAYMENT_METHOD_TOKEN=:retrieve_payment_method_token
32
+ CREATE_CLIENT_SESSION=:create_client_session
33
+ GET_INSTALLMENTS_OPTIONS=:get_installments_options
34
+
35
+ end
@@ -0,0 +1,114 @@
1
+ module Nps
2
+ class SoapClient
3
+
4
+ def initialize(conf)
5
+ if conf.logger.nil?
6
+ conf.logger = Logger.new(STDOUT)
7
+ end
8
+
9
+ if conf.log_level == Logger::DEBUG
10
+ conf.logger.formatter = NpsFormatter.new
11
+ end
12
+ if conf.log_level == Logger::DEBUG and conf.environment == Nps::Environments::PRODUCTION_ENV
13
+ raise LoggerException
14
+ end
15
+
16
+ @key = conf.key
17
+ @log = conf.log
18
+ @logger = conf.logger.nil? ? Logger.new(STDOUT) : conf.logger
19
+ @wsdl = conf.environment
20
+ @open_timeout = conf.o_timeout.nil? ? 5 : conf.o_timeout
21
+ @read_timeout = conf.r_timeout.nil? ? 60 : conf.r_timeout
22
+ @sanitize = conf.sanitize.nil? ? true : conf.sanitize
23
+ @verify_ssl = conf.verify_ssl
24
+ @log_level = conf.log_level ? conf.log_level : nil
25
+ @proxy = conf.proxy_url ? conf.proxy_url : nil
26
+ @proxy_username = conf.proxy_username ? @proxy_username : nil
27
+ @proxy_password = conf.proxy_password ? @proxy_password : nil
28
+
29
+ setup
30
+ end
31
+
32
+ def setup
33
+ client_config = {
34
+ ssl_verify_mode: :none,
35
+ wsdl: File.join(File.dirname(File.expand_path(__FILE__)), "/wsdl/" + @wsdl),
36
+ logger: @logger,
37
+ open_timeout: @open_timeout,
38
+ read_timeout: @read_timeout,
39
+ pretty_print_xml: true
40
+ }
41
+
42
+ if @log_level
43
+ lvl_config = {
44
+ log_level: @log_level
45
+ }
46
+ client_config.merge!(lvl_config)
47
+ end
48
+
49
+ if @verify_ssl
50
+ ssl_config = {
51
+ ssl_verify_mode: :peer,
52
+ ssl_cert_file: @cert_file,
53
+ ssl_cert_key_file: @cert_key
54
+ }
55
+ client_config.merge!(ssl_config)
56
+ end
57
+
58
+ if @proxy
59
+ proxy = {
60
+ proxy: @proxy
61
+ }
62
+ client_config.merge!(proxy)
63
+ end
64
+
65
+ if @proxy_username
66
+ proxy_auth = {
67
+ #pendiente esto para mañana
68
+ headers: { "Proxy-Authorization" => "Basic #{secret}" }
69
+ }
70
+ client_config.merge!(proxy_auth)
71
+ end
72
+
73
+
74
+ @client = Savon.client client_config
75
+
76
+ end
77
+
78
+ def add_secure_hash(params)
79
+ concatenated_data = ""
80
+ sorted_hash = params.sort_by{|x,y| x}.to_h
81
+ sorted_hash.each { |key, value|
82
+ if not value.is_a? ::Hash
83
+ concatenated_data = concatenated_data+value.to_s
84
+ end
85
+ }
86
+ concatenated_data = concatenated_data+@key
87
+ hashed_string = Digest::MD5.hexdigest(concatenated_data)
88
+ params["psp_SecureHash"] = hashed_string
89
+ return params
90
+ end
91
+
92
+ def add_extra_data(params)
93
+ info = {"SdkInfo" => Nps::Utils::SDK[:language] + ' ' + Nps::Utils::SDK[:version]}
94
+ params["psp_MerchantAdditionalDetails"] = info
95
+ return params
96
+ end
97
+
98
+ def soap_call(service, params)
99
+ params = add_extra_data(params)
100
+ if @sanitize
101
+ params = Nps::Utils::sanitize(params)
102
+ end
103
+ unless params.has_key? 'psp_ClientSession'
104
+ params = add_secure_hash(params)
105
+ end
106
+ params = {"Requerimiento" => params}
107
+ begin
108
+ @client.call(service, message: params).body
109
+ rescue TimeoutError
110
+ raise ApiException
111
+ end
112
+ end
113
+ end
114
+ end
data/lib/nps/utils.rb ADDED
@@ -0,0 +1,54 @@
1
+ module Nps
2
+ class Utils
3
+ SDK = {language: 'Ruby', version: RUBY_VERSION}
4
+ API_VERSION = {version: '1'}
5
+ CACHE_TTL = 1
6
+ TIMEOUT = 90
7
+
8
+
9
+ def self.sanitize(params)
10
+ #File.join(File.dirname(File.expand_path(__FILE__)), "/wsdl/" + @wsdl)
11
+ myini = IniFile.load(File.join(File.dirname(File.expand_path(__FILE__)), "conf/sanitize_struc.ini"))
12
+ return check_sanitize(params, true, nil, myini)
13
+ end
14
+
15
+ def self.check_sanitize(params, is_root, nodo, file)
16
+ if is_root
17
+ result_params = {}
18
+ else
19
+ result_params = params
20
+ end
21
+ params.each do |k, v|
22
+ if v.is_a?(Hash)
23
+ result_params[k] = check_sanitize(v, false, k, file)
24
+ elsif v.is_a?(Array)
25
+ result_params[k] = check_sanitize_array(v, k, file)
26
+ else
27
+ result_params[k] = validate_size(v, k, nodo, file)
28
+ end
29
+ end
30
+ return result_params
31
+ end
32
+
33
+ def self.check_sanitize_array(params, nodo, file)
34
+ result_params = []
35
+ params.each { |x| result_params.push(check_sanitize(x, false, nodo, file)) }
36
+ return result_params
37
+
38
+ end
39
+
40
+ def self.validate_size(value, k, nodo, file)
41
+ if nodo != nil
42
+ key_name = nodo.to_s + "." + k + ".max_length"
43
+ else
44
+ key_name = k + ".max_length"
45
+ end
46
+ size = file["global"][key_name]
47
+ if size.nil?
48
+ return value
49
+ end
50
+ return value.to_s.slice(0,size)
51
+ end
52
+
53
+ end
54
+ end