Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified bin/epayco
100644 → 100755
Empty file.
22 changes: 14 additions & 8 deletions lib/epayco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Error < StandardError
include Enumerable
attr_accessor :errors

DEFAULT_TIMEOUT = 60

# 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -132,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)
Expand All @@ -144,5 +151,4 @@ def self.lang_key key
data_hash = JSON.parse(file)
data_hash[key]
end

end