catarse_pagarme 2.14.10 → 2.15.0

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
  SHA256:
3
- metadata.gz: e5cf253edf3740df0178687448f76d33ac7307dfc4e0365c97cd74a8942d0c70
4
- data.tar.gz: 6102f081c3a8777089cbf4b104e555289f58f09bf87c13397fdf977685db2a5f
3
+ metadata.gz: 33de3fd1e6afdac8723405f945acc3d89d97be9420eace3c44f354e01113de6f
4
+ data.tar.gz: b25b6ad732704f9faf108861a844936ba21722b7ab41be1fb06f155510413d9e
5
5
  SHA512:
6
- metadata.gz: e570aa0e9cba1ac76665fe9b57a6af2245cf503132e47560d2a08be7abe8dbaa4cc431c34cbc908c1392fbbf7ed9a2423379ebf6b699c95e167d12a76669e79f
7
- data.tar.gz: 90b5aaa7df3bdc6620b45b67745f0493e2ad0fb0e3b55aca83653c820f8d3c064a7205fb057fce2a112a01477d9fa4d42b36844b2cbb5945ac2dcd7cd8274528
6
+ metadata.gz: 73b17f419b5ef6ab87886c5642dd83fccb1189737a3398e5698d6aaf5cb60457846816fc547185c5fbbcafd9c8092b78f55d0a3c26648e9de03643c1c9343007
7
+ data.tar.gz: 8740a9e7f9ce6296534ea70ba43d183788b850bc100dcf82a8bdf8631dcc3b53f519b27912e5ecdea0fd479e042da3534e6d1a819f4bf48042cabc8658e00d4f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catarse_pagarme (2.14.10)
4
+ catarse_pagarme (2.15.0)
5
5
  countries (= 3.0.0)
6
6
  konduto-ruby (= 2.1.0)
7
7
  pagarme (= 2.1.4)
@@ -19,20 +19,24 @@ module CatarsePagarme
19
19
  payment_method: payment.payment_method
20
20
  }
21
21
  )
22
- ::Raven.capture_exception(exception)
22
+ ::Raven.capture_exception(exception, level: 'fatal')
23
23
  ::Raven.user_context({})
24
24
  end
25
25
 
26
26
  def metadata_attributes
27
27
  {
28
28
  key: payment.generate_key,
29
- contribution_id: payment.contribution.id,
29
+ contribution_id: payment.contribution.id.to_s,
30
+ project_id: payment.project.id.to_s,
30
31
  project_name: payment.project.name,
31
32
  permalink: payment.project.permalink,
32
33
  project_online: payment.project.online_at,
33
34
  project_expires: payment.project.expires_at,
34
35
  user_total_contributions: payment.user.contributions.was_confirmed.count,
35
- user_id: payment.user.id
36
+ user_id: payment.user.id,
37
+ common_user_id: payment.user.common_id.to_s,
38
+ user_name: payment.user.name,
39
+ user_email: payment.user.email
36
40
  }
37
41
  end
38
42
 
@@ -17,6 +17,8 @@ module CatarsePagarme
17
17
  render json: { payment_status: 'failed', message: e.message }
18
18
  rescue => e
19
19
  raven_capture(e)
20
+
21
+ render json: { payment_status: 'failed', message: e.message }
20
22
  end
21
23
 
22
24
  def get_installment_json
@@ -81,11 +83,7 @@ module CatarsePagarme
81
83
  end
82
84
 
83
85
  def document_number
84
- user_document = contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
85
- card_owner_document = contribution.card_owner_document.try(:gsub, /[-.\/_\s]/, '')
86
- fallback_document = '00000000000'
87
-
88
- user_document || card_owner_document || fallback_document
86
+ contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
89
87
  end
90
88
 
91
89
  def phone_matches
@@ -135,7 +133,7 @@ module CatarsePagarme
135
133
 
136
134
  def address_hash
137
135
  {
138
- country: contribution.country.try(:name),
136
+ country_code: contribution.country.try(:code),
139
137
  state: contribution.address_state,
140
138
  city: contribution.address_city,
141
139
  zipcode: contribution.address_zip_code.try(:gsub, /[-.\/_\s]/, ''),
@@ -46,7 +46,7 @@ module CatarsePagarme
46
46
  number: document_number
47
47
  }],
48
48
  },
49
- metadata: metadata_attributes
49
+ metadata: metadata_attributes.merge({ second_slip: payment.generating_second_slip.to_s })
50
50
  }
51
51
  end
52
52
 
@@ -71,14 +71,15 @@ module CatarsePagarme
71
71
 
72
72
  def customer_attributes
73
73
  customer = self.attributes.dig(:customer)
74
+ tax_id = customer[:document_number].present? ? { tax_id: customer[:document_number] } : {}
75
+
74
76
  {
75
77
  id: customer[:id].to_s,
76
- tax_id: customer[:document_number],
77
78
  name: customer[:name],
78
79
  email: customer[:email],
79
80
  phone1: customer[:phone].to_h.values.join,
80
81
  created_at: self.attributes.dig(:antifraud_metadata, :register, :registered_at)
81
- }
82
+ }.merge(tax_id)
82
83
  end
83
84
 
84
85
  def payment_attributes
@@ -99,7 +100,8 @@ module CatarsePagarme
99
100
  city: billing_data.dig(:address, :city),
100
101
  state: billing_data.dig(:address, :state),
101
102
  zip: billing_data.dig(:address, :zipcode),
102
- }.merge(card_country_code)
103
+ country: billing_data.dig(:address, :country_code),
104
+ }
103
105
  end
104
106
 
105
107
  def shipping_address_attributes
@@ -139,10 +141,5 @@ module CatarsePagarme
139
141
  expiration_date = self.transaction.card.expiration_date
140
142
  "#{expiration_date[0..1]}20#{expiration_date[2..3]}"
141
143
  end
142
-
143
- def card_country_code
144
- country = ::ISO3166::Country.find_country_by_name(self.transaction.card.country)
145
- country.present? ? { country: country.try(:alpha2) } : {}
146
- end
147
144
  end
148
145
  end
@@ -8,10 +8,14 @@ module CatarsePagarme
8
8
  else
9
9
  antifraud_outcome = process_antifraud
10
10
 
11
+ self.payment.create_antifraud_analysis!(cost: CatarsePagarme.configuration.antifraud_tax)
12
+
11
13
  if antifraud_outcome.recommendation == :APPROVE
12
14
  self.transaction.capture
13
15
  elsif antifraud_outcome.recommendation == :DECLINE
14
16
  self.transaction.refund
17
+ elsif antifraud_outcome.recommendation == :REVIEW
18
+ self.payment.try(:notify_about_pending_review)
15
19
  end
16
20
  end
17
21
  end
@@ -31,7 +35,8 @@ module CatarsePagarme
31
35
  async: false,
32
36
  postback_url: self.attributes[:postback_url],
33
37
  installments: self.attributes[:installments],
34
- soft_descriptor: self.attributes[:soft_descriptor]
38
+ soft_descriptor: self.attributes[:soft_descriptor],
39
+ metadata: self.attributes[:metadata]
35
40
  }.merge(credit_card_identifier)
36
41
  )
37
42
 
@@ -52,7 +57,7 @@ module CatarsePagarme
52
57
  end
53
58
 
54
59
  def was_credit_card_used_before?
55
- PaymentEngines.was_credit_card_used_before?(self.transaction.card.id)
60
+ PaymentEngines.was_credit_card_used_before?(self.transaction.card.id, self.attributes.dig(:customer, :id))
56
61
  end
57
62
 
58
63
  def process_antifraud
@@ -5,102 +5,17 @@ module CatarsePagarme::FeeCalculatorConcern
5
5
 
6
6
  def get_fee
7
7
  return nil if self.payment.payment_method.blank? # We always depend on the payment_choice
8
- if self.payment.payment_method == ::CatarsePagarme::PaymentType::SLIP
9
- get_slip_fee
10
- else
11
- get_card_fee
12
- end
13
- end
14
-
15
- protected
16
- def get_slip_fee
17
- CatarsePagarme.configuration.slip_tax.to_f
18
- end
19
-
20
- def get_card_fee
21
- return nil if self.payment.gateway_data["acquirer_name"].blank? # Here we depend on the acquirer name
22
- fee = if %w(stone pagarme).include? self.payment.gateway_data["acquirer_name"]
23
- get_stone_fee
24
- else
25
- get_cielo_fee
26
- end
27
-
28
- fee + payment_cost
29
- end
30
8
 
31
- def payment_cost
32
- self.payment.gateway_data["cost"] / 100.0
33
- end
34
-
35
- def get_stone_fee
36
- self.payment.installments > 1 ? tax_calc_for_installment(stone_installment_tax) : tax_calc(stone_tax)
37
- end
9
+ transaction = PagarMe::Transaction.find(self.payment.gateway_id)
10
+ payables = transaction.payables
11
+ cost = transaction.cost.to_f / 100.00
12
+ payables_fee = payables_fee.to_a.sum(&:fee).to_f / 100.00
38
13
 
39
- def get_cielo_fee
40
- return nil if self.payment.gateway_data["card_brand"].blank? # Here we depend on the card_brand
41
- if self.payment.gateway_data["card_brand"] == 'amex'
42
- get_cielo_fee_for_amex
14
+ if self.payment.payment_method == ::CatarsePagarme::PaymentType::SLIP
15
+ cost + payables_fee
43
16
  else
44
- get_cielo_fee_for_non_amex
17
+ payables_fee == 0 ? cost : payables_fee
45
18
  end
46
19
  end
47
-
48
- def get_cielo_fee_for_amex
49
- self.payment.installments > 1 ? tax_calc_for_installment(cielo_installment_amex_tax) : tax_calc(cielo_installment_not_amex_tax)
50
- end
51
-
52
- def get_cielo_fee_for_non_amex
53
- current_tax = self.payment.gateway_data["card_brand"] == 'diners' ? installment_diners_tax : installment_not_diners_tax
54
- self.payment.installments > 1 ? tax_calc_for_installment(current_tax) : tax_calc(cielo_tax)
55
- end
56
-
57
- def tax_calc acquirer_tax
58
- ((self.payment.value * pagarme_tax) + cents_fee).round(2) + (self.payment.value * acquirer_tax).round(2)
59
- end
60
-
61
- def tax_calc_for_installment acquirer_tax
62
- (((self.payment.installment_value * self.payment.installments) * pagarme_tax) + cents_fee).round(2) + ((self.payment.installment_value * acquirer_tax).round(2) * self.payment.installments)
63
- end
64
-
65
- def antifraud_tax
66
- CatarsePagarme.configuration.antifraud_tax.to_f
67
- end
68
-
69
- def cents_fee
70
- CatarsePagarme.configuration.credit_card_cents_fee.to_f
71
- end
72
-
73
- def pagarme_tax
74
- CatarsePagarme.configuration.pagarme_tax.to_f
75
- end
76
-
77
- def cielo_tax
78
- CatarsePagarme.configuration.cielo_tax.to_f
79
- end
80
-
81
- def stone_tax
82
- CatarsePagarme.configuration.stone_tax.to_f
83
- end
84
-
85
- def stone_installment_tax
86
- CatarsePagarme.configuration.stone_installment_tax.to_f
87
- end
88
-
89
- def installment_diners_tax
90
- CatarsePagarme.configuration.cielo_installment_diners_tax.to_f
91
- end
92
-
93
- def installment_not_diners_tax
94
- CatarsePagarme.configuration.cielo_installment_not_diners_tax.to_f
95
- end
96
-
97
- def cielo_installment_amex_tax
98
- CatarsePagarme.configuration.cielo_installment_amex_tax.to_f
99
- end
100
-
101
- def cielo_installment_not_amex_tax
102
- CatarsePagarme.configuration.cielo_installment_not_amex_tax.to_f
103
- end
104
-
105
20
  end
106
21
  end
@@ -1,3 +1,3 @@
1
1
  module CatarsePagarme
2
- VERSION = "2.14.10"
2
+ VERSION = "2.15.0"
3
3
  end
@@ -245,14 +245,15 @@ describe CatarsePagarme::AntifraudOrderWrapper do
245
245
  street: 'R. A',
246
246
  city: 'New City',
247
247
  state: 'NC',
248
- zipcode: '1245'
248
+ zipcode: '1245',
249
+ country_code: 'BR'
249
250
  }
250
251
  }
251
252
  }
252
253
  }
253
254
  end
254
255
 
255
- let(:transaction) { double(card: double(country: 'BRAZIL', holder_name: 'holder name')) }
256
+ let(:transaction) { double(card: double(holder_name: 'holder name')) }
256
257
 
257
258
  before do
258
259
  subject.attributes = attributes
@@ -267,7 +268,7 @@ describe CatarsePagarme::AntifraudOrderWrapper do
267
268
  expect(billing_address_attributes[:city]).to eq 'New City'
268
269
  expect(billing_address_attributes[:state]).to eq 'NC'
269
270
  expect(billing_address_attributes[:zip]).to eq '1245'
270
- expect(billing_address_attributes[:country]).to eq 'BR'
271
+ expect(billing_address_attributes[:country_code]).to eq 'BR'
271
272
  end
272
273
  end
273
274
 
@@ -290,7 +291,7 @@ describe CatarsePagarme::AntifraudOrderWrapper do
290
291
  }
291
292
  end
292
293
 
293
- let(:transaction) { double(card: double(country: 'BRAZIL')) }
294
+ let(:transaction) { double(card: double) }
294
295
 
295
296
  before do
296
297
  subject.attributes = attributes
@@ -76,7 +76,7 @@ describe CatarsePagarme::CreditCardTransaction do
76
76
  end
77
77
  end
78
78
 
79
- context 'when antifraude recommends decline transaction' do
79
+ context 'when antifraud recommends decline transaction' do
80
80
  let(:antifraud_outcome) { double(recommendation: :DECLINE) }
81
81
 
82
82
  it 'refunds transaction' do
@@ -85,6 +85,16 @@ describe CatarsePagarme::CreditCardTransaction do
85
85
  card_transaction.process!
86
86
  end
87
87
  end
88
+
89
+ context 'when antifraud recommends review transaction' do
90
+ let(:antifraud_outcome) { double(recommendation: :REVIEW) }
91
+
92
+ it 'notifies about pending review' do
93
+ expect(card_transaction.payment).to receive(:notify_about_pending_review)
94
+
95
+ card_transaction.process!
96
+ end
97
+ end
88
98
  end
89
99
  end
90
100
 
@@ -269,7 +279,7 @@ describe CatarsePagarme::CreditCardTransaction do
269
279
  let(:antifraud_wrapper) { double }
270
280
 
271
281
  context 'when @antifraud_wrapper isn`t nil' do
272
- it 'returns @antifraude_wrapper' do
282
+ it 'returns @antifraud_wrapper' do
273
283
  card_transaction.instance_variable_set('@antifraud_wrapper', antifraud_wrapper)
274
284
  expect(card_transaction.antifraud_wrapper).to eq antifraud_wrapper
275
285
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.10
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-31 00:00:00.000000000 Z
12
+ date: 2020-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: countries