catarse_pagarme 2.14.12 → 2.16.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
  SHA256:
3
- metadata.gz: c52bfe0429ba2976126325031d6c5372a549e0e054e7b210d0771be827f6322a
4
- data.tar.gz: 72f750266694d8661a6b807c9331f0ac1263679c743b0bb01b99ca9bbebf453b
3
+ metadata.gz: 280c47fbcd1f68b9b8388c7a668578c88c6256da12248c9c7094460db5a9bc46
4
+ data.tar.gz: de3c7200fd94ef8d836ebde417fb005d5da3338b84ee4519d85c180199b5fbef
5
5
  SHA512:
6
- metadata.gz: 914fcfc46b1cb2a8a78ca6875552d6ef8de296449ef36033a0312661ec3dabf60028d20e42d75dc2112d3149964e368afa26f0e2b62be2a1cb56b961a689c3f7
7
- data.tar.gz: 979286b6207d4af8d9cf93a4ee14099bc79a03361e02f8bf1825387e97c28d9a6380d7a0f0ead484b649f7676f5a147c6f36f9b714f319805bab483f0249a373
6
+ metadata.gz: 89bad0499c9b211cd2d0ca91f2a34709a75b128a98ec93e9fe6718a942fa26bd0483c78a4b1d3a5c8370089732a08d5a4fab32c40aad551a04c9cdf54a0da772
7
+ data.tar.gz: a4e5a09162bf1d373aeae3c8f3e0b3319e57521e42f78910b2a0c41a589ade9372075921e3bca2f9e6973e6bc2f64ea1b2e8c49693a01f1d16b604390515d0c1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catarse_pagarme (2.14.12)
4
+ catarse_pagarme (2.16.1)
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
 
@@ -83,11 +83,7 @@ module CatarsePagarme
83
83
  end
84
84
 
85
85
  def document_number
86
- user_document = contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
87
- card_owner_document = contribution.card_owner_document.try(:gsub, /[-.\/_\s]/, '')
88
- fallback_document = '00000000000'
89
-
90
- user_document || card_owner_document || fallback_document
86
+ contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
91
87
  end
92
88
 
93
89
  def phone_matches
@@ -137,7 +133,7 @@ module CatarsePagarme
137
133
 
138
134
  def address_hash
139
135
  {
140
- country: contribution.country.try(:name),
136
+ country_code: contribution.country.try(:code),
141
137
  state: contribution.address_state,
142
138
  city: contribution.address_city,
143
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,6 +8,8 @@ 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
@@ -33,7 +35,8 @@ module CatarsePagarme
33
35
  async: false,
34
36
  postback_url: self.attributes[:postback_url],
35
37
  installments: self.attributes[:installments],
36
- soft_descriptor: self.attributes[:soft_descriptor]
38
+ soft_descriptor: self.attributes[:soft_descriptor],
39
+ metadata: self.attributes[:metadata]
37
40
  }.merge(credit_card_identifier)
38
41
  )
39
42
 
@@ -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.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
+ payables_fee == 0 ? cost : payables_fee
43
16
  else
44
- get_cielo_fee_for_non_amex
17
+ 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.12"
2
+ VERSION = "2.16.1"
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
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.12
4
+ version: 2.16.1
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-04-08 00:00:00.000000000 Z
12
+ date: 2020-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: countries