From efdcb4ddf7f87ccddff98f23a22168745c0dd8fa Mon Sep 17 00:00:00 2001 From: Johan Tique Date: Mon, 3 Jun 2019 11:23:35 -0500 Subject: [PATCH 1/3] add timeout config for rest client request --- bin/epayco | 0 lib/epayco.rb | 16 +++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) mode change 100644 => 100755 bin/epayco diff --git a/bin/epayco b/bin/epayco old mode 100644 new mode 100755 diff --git a/lib/epayco.rb b/lib/epayco.rb index a6b71cb..81c4758 100644 --- a/lib/epayco.rb +++ b/lib/epayco.rb @@ -13,6 +13,8 @@ class Error < StandardError include Enumerable attr_accessor :errors + DEFAULT_TIMEOUT = 15 + # Get code, lang and show custom error def initialize code, lang file = open("https://s3-us-west-2.amazonaws.com/epayco/message_api/errors.json").read @@ -32,7 +34,7 @@ def each # Init sdk parameters class << self - attr_accessor :apiKey, :privateKey, :lang, :test + attr_accessor :apiKey, :privateKey, :lang, :test, :timeout end # Eject request and show response or error @@ -70,11 +72,12 @@ def self.request(method, url, extra=nil, params={}, headers={}, switch) }.merge(headers) headers.delete :params unless method == :get options = { - :headers => headers, - :user => apiKey, - :method => method, - :url => url, - :payload => payload + headers: headers, + user: apiKey, + method: method, + url: url, + payload: payload, + timeout: timeout.presence || DEFAULT_TIMEOUT } # Open library rest client @@ -144,5 +147,4 @@ def self.lang_key key data_hash = JSON.parse(file) data_hash[key] end - end From 8251305a67b3e402ee87ddf6ac0427c30f3d743c Mon Sep 17 00:00:00 2001 From: Johan Tique Date: Tue, 4 Jun 2019 01:36:47 -0500 Subject: [PATCH 2/3] fix error issue #7 ArgumentError: key must be 16 bytes when key is assigned to cipher --- lib/epayco.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/epayco.rb b/lib/epayco.rb index 81c4758..5b97656 100644 --- a/lib/epayco.rb +++ b/lib/epayco.rb @@ -135,7 +135,11 @@ def self.encrypt(str, key) cipher.encrypt iv = "0000000000000000" cipher.iv = iv - cipher.key = key + # For now we must slice the 16 bits manually, hopefully in the near future + # Epayco will support 32 bits encryption using another cipher, this encryption + # is used by both bank and cash payments + # cipher.key = key + cipher.key = key.byteslice(0, cipher.key_len) str = iv + str data = cipher.update(str) + cipher.final Base64.urlsafe_encode64(data) From f161eb9e1a4d7698dc7fae2f2e9041cf00d82f56 Mon Sep 17 00:00:00 2001 From: Johan Tique Date: Sat, 8 Jun 2019 15:44:37 -0500 Subject: [PATCH 3/3] update default timeout --- lib/epayco.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/epayco.rb b/lib/epayco.rb index 5b97656..c90abff 100644 --- a/lib/epayco.rb +++ b/lib/epayco.rb @@ -13,7 +13,7 @@ class Error < StandardError include Enumerable attr_accessor :errors - DEFAULT_TIMEOUT = 15 + DEFAULT_TIMEOUT = 60 # Get code, lang and show custom error def initialize code, lang