braspag-rest 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af51da75eacd0111305201619309a0526ef5947c
4
- data.tar.gz: c0542dd1d64a09fbb86792b091467f2df2d96888
3
+ metadata.gz: 3360e6c175e92d74d09f77af1f4b7fc8be1c44cb
4
+ data.tar.gz: 814fafb264d9ff52d46c9063ce6a5ad29bec8152
5
5
  SHA512:
6
- metadata.gz: 2bbc186e05f37800f9ee185f668da8b24897ab4a8a16ca1ba5b12eebe0411fba7b59ec17aff7e5c953284696088071751a70c6cf0ab02af84403a17c235bf20f
7
- data.tar.gz: 6dc039cb0af98ef161d49ce8e691cceeb8e075ec4e5b81ba307ae32de88799817f2564076a3b788826d2ac2a9f28cd73494ecacf72e5b7cf580df345909a06c1
6
+ metadata.gz: ca38860114ae15583eae64cde61b80ff1b950dd3f30fa2cae38d7197352d25ff2a55feb7b9473fe160593dcf64cb413297f66eecbe55e43cf5e3238b9b0c128a
7
+ data.tar.gz: efc6ffb424460d2ad8a26101e9453f69f6c015b93b7671ea0ef7a32a54acc14abf55915f52e763d319770e825066ca23d8af5354ee2d0fd6901d3a07f2155c32
data/README.md CHANGED
@@ -34,6 +34,7 @@ development:
34
34
  query_url: 'https://apiquerysandbox.braspag.com.br'
35
35
  merchant_id: 'Your MerchantId here'
36
36
  merchant_key: 'Your MerchantKey here'
37
+ request_timeout: 60
37
38
  ```
38
39
 
39
40
  If you want to use a different file or manually set which environment should be
@@ -59,11 +60,13 @@ development:
59
60
  query_url: 'https://apiquerysandbox.braspag.com.br'
60
61
  merchant_id: 'Your MerchantId here'
61
62
  merchant_key: 'Your MerchantKey here'
63
+ request_timeout: 60
62
64
  production:
63
65
  url: <%= ENV['BRASPAG_URL'] %>
64
66
  query_url: <%= ENV['BRASPAG_QUERY_URL'] %>
65
67
  merchant_id: <%= ENV['BRASPAG_MERCHANT_ID'] %>
66
68
  merchant_key: <%= ENV['BRASPAG_MERCHANT_KEY'] %>
69
+ request_timeout: <%= ENV['BRASPAG_REQUEST_TIMEOUT'] %>
67
70
  ```
68
71
 
69
72
  ### Authorize an order
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "rest-client", "~> 1.8"
20
+ spec.add_dependency "rest-client", "~> 2.0"
21
21
  spec.add_dependency "hashie", "~> 3.4"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rspec", "~> 3"
26
26
  spec.add_development_dependency "pry"
27
27
  spec.add_development_dependency "pry-nav"
28
+ spec.add_development_dependency "pry-byebug"
28
29
  end
@@ -33,6 +33,10 @@ module BraspagRest
33
33
  config['merchant_key']
34
34
  end
35
35
 
36
+ def request_timeout
37
+ config.fetch('request_timeout', 60)
38
+ end
39
+
36
40
  private
37
41
 
38
42
  def config
@@ -9,7 +9,13 @@ module BraspagRest
9
9
  config.logger.info("[BraspagRest][Authorize] endpoint: #{sale_url}, params: #{params.to_json}") if config.log_enabled?
10
10
 
11
11
  execute_braspag_request do
12
- RestClient.post(sale_url, params.to_json, default_headers.merge('RequestId' => request_id))
12
+ RestClient::Request.execute(
13
+ method: :post,
14
+ url: sale_url,
15
+ payload: params.to_json,
16
+ headers: default_headers.merge('RequestId' => request_id),
17
+ timeout: config.request_timeout
18
+ )
13
19
  end
14
20
  end
15
21
 
@@ -17,7 +23,12 @@ module BraspagRest
17
23
  config.logger.info("[BraspagRest][Void] endpoint: #{void_url(payment_id, amount)}") if config.log_enabled?
18
24
 
19
25
  execute_braspag_request do
20
- RestClient.put(void_url(payment_id, amount), nil, default_headers.merge('RequestId' => request_id))
26
+ RestClient::Request.execute(
27
+ method: :put,
28
+ url: void_url(payment_id, amount),
29
+ headers: default_headers.merge('RequestId' => request_id),
30
+ timeout: config.request_timeout
31
+ )
21
32
  end
22
33
  end
23
34
 
@@ -25,7 +36,25 @@ module BraspagRest
25
36
  config.logger.info("[BraspagRest][GetSale] endpoint: #{search_sale_url(payment_id)}") if config.log_enabled?
26
37
 
27
38
  execute_braspag_request do
28
- RestClient.get(search_sale_url(payment_id), default_headers.merge('RequestId' => request_id))
39
+ RestClient::Request.execute(
40
+ method: :get,
41
+ url: search_sale_url(payment_id),
42
+ headers: default_headers.merge('RequestId' => request_id),
43
+ timeout: config.request_timeout
44
+ )
45
+ end
46
+ end
47
+
48
+ def get_sales_for_merchant_order_id(request_id, merchant_order_id)
49
+ config.logger.info("[BraspagRest][GetSale] endpoint: #{search_sales_for_merchant_order_id_url(merchant_order_id)}") if config.log_enabled?
50
+
51
+ execute_braspag_request do
52
+ RestClient::Request.execute(
53
+ method: :get,
54
+ url: search_sales_for_merchant_order_id_url(merchant_order_id),
55
+ headers: default_headers.merge('RequestId' => request_id),
56
+ timeout: config.request_timeout
57
+ )
29
58
  end
30
59
  end
31
60
 
@@ -33,7 +62,13 @@ module BraspagRest
33
62
  config.logger.info("[BraspagRest][Capture] endpoint: #{capture_url(payment_id)}, amount: #{amount}") if config.log_enabled?
34
63
 
35
64
  execute_braspag_request do
36
- RestClient.put(capture_url(payment_id), { Amount: amount }.to_json, default_headers.merge('RequestId' => request_id))
65
+ RestClient::Request.execute(
66
+ method: :put,
67
+ url: capture_url(payment_id),
68
+ payload: { Amount: amount }.to_json,
69
+ headers: default_headers.merge('RequestId' => request_id),
70
+ timeout: config.request_timeout
71
+ )
37
72
  end
38
73
  end
39
74
 
@@ -46,7 +81,12 @@ module BraspagRest
46
81
 
47
82
  BraspagRest::Response.new(gateway_response)
48
83
  rescue RestClient::ResourceNotFound => e
49
- config.logger.error("[BraspagRest][Error] message: #{e.message}, status: #{e.http_code}, body: #{e.http_body.inspect}") if config.log_enabled?
84
+ # Explicitly message due to Rest Client RestClient::NotFound normalization:
85
+ # https://github.com/rest-client/rest-client/blob/v2.0.0/lib/restclient/exceptions.rb#L90
86
+ config.logger.error("[BraspagRest][Error] message: Resource Not Found, status: #{e.http_code}, body: #{e.http_body.inspect}") if config.log_enabled?
87
+ raise
88
+ rescue RestClient::RequestTimeout => e
89
+ config.logger.error("[BraspagRest][Timeout] message: #{e.message}") if config.log_enabled?
50
90
  raise
51
91
  rescue RestClient::ExceptionWithResponse => e
52
92
  config.logger.warn("[BraspagRest][Error] message: #{e.message}, status: #{e.http_code}, body: #{e.http_body.inspect}") if config.log_enabled?
@@ -72,6 +112,13 @@ module BraspagRest
72
112
  sale_url + payment_id.to_s + CAPTURE_ENDPOINT
73
113
  end
74
114
 
115
+ def search_sales_for_merchant_order_id_url(merchant_order_id)
116
+ url = URI.parse(config.query_url)
117
+ url.path = SALE_ENDPOINT
118
+ url.query = "merchantOrderId=#{merchant_order_id}"
119
+ url.to_s
120
+ end
121
+
75
122
  def default_headers
76
123
  {
77
124
  'Accept' => 'application/json',
@@ -18,6 +18,13 @@ module BraspagRest
18
18
  new(response.parsed_body.merge('RequestId' => request_id))
19
19
  end
20
20
 
21
+ def self.find_by_order_id(request_id, order_id)
22
+ response = BraspagRest::Request.get_sales_for_merchant_order_id(request_id, order_id)
23
+ payments = response.parsed_body['Payments']
24
+
25
+ payments.map { |payment| BraspagRest::Sale.find(request_id, payment['PaymentId']) }
26
+ end
27
+
21
28
  def save
22
29
  response = BraspagRest::Request.authorize(request_id, inverse_attributes)
23
30
 
@@ -1,3 +1,3 @@
1
1
  module BraspagRest
2
- VERSION = "0.5.0"
2
+ VERSION = '0.5.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braspag-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinda Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-04 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hashie
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Gem to use Braspag gateway in his REST version
112
126
  email:
113
127
  - dev@dinda.com.br
@@ -170,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
184
  version: '0'
171
185
  requirements: []
172
186
  rubyforge_project:
173
- rubygems_version: 2.5.1
187
+ rubygems_version: 2.6.4
174
188
  signing_key:
175
189
  specification_version: 4
176
190
  summary: Gem to use Braspag gateway in his REST version