Module: Epayco
- Defined in:
- lib/epayco.rb,
lib/epayco/resources.rb,
lib/epayco/operations.rb
Defined Under Namespace
Modules: Operations Classes: Bank, Cash, Charge, Customers, Daviplata, Error, Plan, Resource, Safetypay, Subscriptions, Token
Class Attribute Summary collapse
-
.apiKey ⇒ Object
Returns the value of attribute apiKey.
-
.lang ⇒ Object
Returns the value of attribute lang.
-
.privateKey ⇒ Object
Returns the value of attribute privateKey.
-
.test ⇒ Object
Returns the value of attribute test.
Class Method Summary collapse
-
.request(method, url, extra = nil, params = {}, headers = {}, switch, cashdata, dt, apify) ⇒ Object
Eject request and show response or error.
Class Attribute Details
.apiKey ⇒ Object
Returns the value of attribute apiKey.
45 46 47 |
# File 'lib/epayco.rb', line 45 def apiKey @apiKey end |
.lang ⇒ Object
Returns the value of attribute lang.
45 46 47 |
# File 'lib/epayco.rb', line 45 def lang @lang end |
.privateKey ⇒ Object
Returns the value of attribute privateKey.
45 46 47 |
# File 'lib/epayco.rb', line 45 def privateKey @privateKey end |
.test ⇒ Object
Returns the value of attribute test.
45 46 47 |
# File 'lib/epayco.rb', line 45 def test @test end |
Class Method Details
.request(method, url, extra = nil, params = {}, headers = {}, switch, cashdata, dt, apify) ⇒ Object
Eject request and show response or error
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/epayco.rb', line 49 def self.request(method, url, extra=nil, params={}, headers={}, switch, cashdata, dt, apify) method = method.to_sym auth = authent(apiKey, privateKey, apify, lang) bearer_token = 'Bearer '+ (auth[:bearer_token] || auth[:token]) if !apiKey || !privateKey || !lang raise Error.new('100', lang) end params["extras_epayco"] = {extra5:"P45"} payload = JSON.generate(params) if method == :post || method == :patch params = nil unless method == :get # Switch secure or api or apify if apify if method == :post @tags = JSON.parse(payload) seted = {} file = File.read(File.dirname(__FILE__) + '/keylang_apify.json') data_hash = JSON.parse(file) @tags.each { |key, value| if data_hash[key] seted[data_hash[key]] = value else seted[key] = value end } payload = seted.to_json end url = @api_base_apify + url elsif switch if method == :post || method == :patch if cashdata enc = encrypt_aes(payload, true) payload = enc.to_json else enc = encrypt_aes(payload, false) payload = enc.to_json end end url = @api_base_secure + @api_entorno + url else if method == :post || method == :patch rb_hash = JSON.parse(payload) if dt payload = rb_hash.to_json else rb_hash["test"] = test ? "TRUE" : "FALSE" rb_hash["ip"] = local_ip payload = rb_hash.to_json end end url = @api_base + url end headers = { :params => params, :content_type => 'application/json', :type => 'sdk-jwt', :lang => 'RUBY', :Authorization => bearer_token, }.merge(headers) = { :headers => headers, :user => apiKey, :method => method, :url => url, :payload => payload } # Open library rest client begin response = execute_request() return {} if response.code == 204 and method == :delete JSON.parse(response.body, :symbolize_names => true) rescue RestClient::Exception => e handle_errors e end end |