braspag-rest 0.5.2 → 0.6.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: 3545cac5bbde8fc3eae100c26a013c8312cca135
4
- data.tar.gz: 48b639fb741faa148b994e66c6635d0d8cab2397
3
+ metadata.gz: c6c0cb58e4c3410f84a3656bd16112c302020180
4
+ data.tar.gz: 0fdd64300cfdbd2429494744559e25f876609c00
5
5
  SHA512:
6
- metadata.gz: dd3b62b883b30dc213025071a9bd0dbdabdf4f2b54bc61daffc2f3a3e4f19472df90b1d3eef80495f402be3d7ec77eb7f9f137a0e9cdddb5d94cb4434ed37cd6
7
- data.tar.gz: 4909da953ebc2f66b1a3259c1ef526c8eb8215e2d850e4cbafa0d5c3670f3187ab1e388b0323bff6e11849d1a538a329fb79417feb2ff3aeddbaeef9802a9003
6
+ metadata.gz: dbea53957bdc35de7f16e1c437b0eab08b7f23869b9233def76cd08dcbce6205b9cf9520de6d3db93beac5b864f0243d1b5d1982a928d4b36b86cff184dd0794
7
+ data.tar.gz: c7a7d2d0d45eb1f4d69357df539b30e7282dd2ce9a2c8e1d1b9774b7aaecc2cf18bf53f483bb5c2f12c54f37fc98c28942b82fa531851942f757892231f1d2e5
data/README.md CHANGED
@@ -210,6 +210,15 @@ sales.map { |sale| sale.customer.name }
210
210
  ```rb
211
211
  sale = BraspagRest::Sale.find('REQUEST_ID', 'PAYMENT_ID')
212
212
  sale.cancel
213
+
214
+ sale.voided_amount
215
+ => 30017
216
+
217
+ sale.voided_date
218
+ => "2017-09-11 16:53:03"
219
+
220
+ sale.payment.refunds
221
+ => [{:amount=>30017, :status=>3, :received_date=>"2017-09-11T16:53:03.407"}]
213
222
  ```
214
223
 
215
224
  ### Capture a sale
@@ -17,5 +17,7 @@ require 'braspag-rest/customer'
17
17
  require 'braspag-rest/credit_card'
18
18
  require 'braspag-rest/fraud_analyses'
19
19
  require 'braspag-rest/fraud_analysis'
20
+ require 'braspag-rest/refund'
20
21
  require 'braspag-rest/payment'
21
22
  require 'braspag-rest/sale'
23
+ require 'braspag-rest/address'
@@ -0,0 +1,12 @@
1
+ module BraspagRest
2
+ class Address < Hashie::IUTrash
3
+ property :street, from: 'Street'
4
+ property :number, from: 'Number'
5
+ property :complement, from: 'Complement'
6
+ property :zip_code, from: 'ZipCode'
7
+ property :city, from: 'City'
8
+ property :state, from: 'State'
9
+ property :country, from: 'Country'
10
+ property :district, from: 'District'
11
+ end
12
+ end
@@ -2,5 +2,7 @@ module BraspagRest
2
2
  class Customer < Hashie::IUTrash
3
3
  property :name, from: 'Name'
4
4
  property :identity, from: 'Identity'
5
+ property :identity_type, from: 'IdentityType'
6
+ property :address, from: 'Address', with: ->(values) { BraspagRest::Address.new(values) }
5
7
  end
6
8
  end
@@ -5,10 +5,12 @@ module BraspagRest
5
5
  STATUS_AUTHORIZED = 1
6
6
  STATUS_CONFIRMED = 2
7
7
  STATUS_VOIDED = 10
8
+ STATUS_REFUNDED = 11
8
9
 
9
10
  property :id, from: 'PaymentId'
10
11
  property :type, from: 'Type'
11
12
  property :amount, from: 'Amount'
13
+ property :boleto_number, from: 'BoletoNumber'
12
14
  property :captured_amount, from: 'CapturedAmount'
13
15
  property :status, from: 'Status'
14
16
  property :provider, from: 'Provider'
@@ -20,12 +22,16 @@ module BraspagRest
20
22
  property :reason_code, from: 'ReasonCode'
21
23
  property :reason_message, from: 'ReasonMessage'
22
24
  property :voided_amount, from: 'VoidedAmount'
25
+ property :voided_date, from: 'VoidedDate'
26
+
27
+ property :refunds, from: 'Refunds'
23
28
 
24
29
  property :digitable_line, from: 'DigitableLine'
25
30
  property :barcode_number, from: 'BarCodeNumber'
26
31
  property :expiration_date, from: 'ExpirationDate'
27
32
  property :instructions, from: 'Instructions'
28
33
  property :printable_page_url, from: 'Url'
34
+ property :boleto_number, from: 'BoletoNumber'
29
35
 
30
36
  property :currency, from: 'Currency'
31
37
  property :country, from: 'Country'
@@ -44,6 +50,7 @@ module BraspagRest
44
50
 
45
51
  coerce_key :fraud_analysis, BraspagRest::FraudAnalysis
46
52
  coerce_key :credit_card, BraspagRest::CreditCard
53
+ coerce_key :refunds, Array[BraspagRest::Refund]
47
54
 
48
55
  def authorized?
49
56
  status.to_i.eql?(STATUS_AUTHORIZED)
@@ -56,5 +63,9 @@ module BraspagRest
56
63
  def cancelled?
57
64
  status.to_i.eql?(STATUS_VOIDED)
58
65
  end
66
+
67
+ def refunded?
68
+ status.to_i.eql?(STATUS_REFUNDED)
69
+ end
59
70
  end
60
71
  end
@@ -0,0 +1,15 @@
1
+ module BraspagRest
2
+ class Refund < Hashie::IUTrash
3
+ include Hashie::Extensions::Coercion
4
+
5
+ STATUS_REFUNDED = 11
6
+
7
+ property :status, from: 'Status'
8
+ property :amount, from: 'Amount'
9
+ property :received_date, from: 'ReceivedDate'
10
+
11
+ def success?
12
+ status.to_i.eql?(STATUS_REFUNDED)
13
+ end
14
+ end
15
+ end
@@ -77,9 +77,9 @@ module BraspagRest
77
77
  def execute_braspag_request(&block)
78
78
  gateway_response = block.call
79
79
 
80
- config.logger.info("[BraspagRest][Response] gateway_response: #{gateway_response.inspect}") if config.log_enabled?
81
-
82
- BraspagRest::Response.new(gateway_response)
80
+ BraspagRest::Response.new(gateway_response).tap do |response|
81
+ config.logger.info("[BraspagRest][Response] gateway_response: #{response.parsed_body}") if config.log_enabled?
82
+ end
83
83
  rescue RestClient::ResourceNotFound => e
84
84
  # Explicitly message due to Rest Client RestClient::NotFound normalization:
85
85
  # https://github.com/rest-client/rest-client/blob/v2.0.0/lib/restclient/exceptions.rb#L90
@@ -41,8 +41,7 @@ module BraspagRest
41
41
  response = BraspagRest::Request.void(request_id, payment.id, amount)
42
42
 
43
43
  if response.success?
44
- voided_amount = amount ? payment.voided_amount.to_i + amount : payment.amount
45
- self.payment.initialize_attributes(voided_amount: voided_amount)
44
+ reload
46
45
  else
47
46
  initialize_errors(response.parsed_body)
48
47
  end
@@ -64,10 +63,11 @@ module BraspagRest
64
63
 
65
64
  def reload
66
65
  if !request_id.nil? && payment && !payment.id.nil?
67
- self.class.find(request_id, payment.id)
68
- else
69
- self
66
+ reloaded_reference = self.class.find(request_id, payment.id)
67
+ self.initialize_attributes(reloaded_reference.inverse_attributes)
70
68
  end
69
+
70
+ self
71
71
  end
72
72
 
73
73
  private
@@ -1,3 +1,3 @@
1
1
  module BraspagRest
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.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.2
4
+ version: 0.6.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: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -142,6 +142,7 @@ files:
142
142
  - bin/setup
143
143
  - braspag-rest.gemspec
144
144
  - lib/braspag-rest.rb
145
+ - lib/braspag-rest/address.rb
145
146
  - lib/braspag-rest/configuration.rb
146
147
  - lib/braspag-rest/credit_card.rb
147
148
  - lib/braspag-rest/customer.rb
@@ -160,6 +161,7 @@ files:
160
161
  - lib/braspag-rest/hashie/iudash.rb
161
162
  - lib/braspag-rest/hashie/iutrash.rb
162
163
  - lib/braspag-rest/payment.rb
164
+ - lib/braspag-rest/refund.rb
163
165
  - lib/braspag-rest/request.rb
164
166
  - lib/braspag-rest/response.rb
165
167
  - lib/braspag-rest/sale.rb
@@ -184,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  version: '0'
185
187
  requirements: []
186
188
  rubyforge_project:
187
- rubygems_version: 2.6.4
189
+ rubygems_version: 2.5.2
188
190
  signing_key:
189
191
  specification_version: 4
190
192
  summary: Gem to use Braspag gateway in his REST version