catarse_pagarme 2.4.9 → 2.4.10

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: 102545aaa90e556cf8be86f2a9029f85568d7a3e
4
- data.tar.gz: 8f8c037dc1e3d78e79cce1e4e2caadfd590abb4b
3
+ metadata.gz: 167056c394c65f4907196b570a631367b03fe471
4
+ data.tar.gz: 6dedfa0adf8a6b398e5967d320851adcc21eb637
5
5
  SHA512:
6
- metadata.gz: ef493484bbd2dc0372895c6e2c5f06586c3ebf621bce44bdc638d8bf1ee94e3f3b4f184ed4e823234594eacbde5e8b5accf3190008c204843b4a881c0b1ccc9b
7
- data.tar.gz: 711bdd179df176ef971a82e052695cc0935c7835ab508f34f93d18d074bfe2e58055352f7d653626d67fe53695aa6010bc3d12d00aafac105c99e5ed160da0a0
6
+ metadata.gz: 0230b0a36302dace3afd5bdbeb2cc5e27a021260e096950b062353d5ec50479ae80eae3f74308b5e993e1ea00d8444dfa53df690d492a9f9d866ccc1965ccd58
7
+ data.tar.gz: f59f6667a1237763d93fc3dfec731562eb355a89f666777e677a4f1a82a1ea4735ffdc96593169f69fca1631d6645d6f29290e5d28680939ebecc5736b0f7322
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catarse_pagarme (2.4.9)
4
+ catarse_pagarme (2.4.10)
5
5
  pagarme (~> 1.9.8)
6
6
  rails (~> 4.0)
7
7
 
@@ -52,7 +52,7 @@ GEM
52
52
  mime-types (1.25.1)
53
53
  minitest (5.4.0)
54
54
  multi_json (1.10.1)
55
- netrc (0.10.2)
55
+ netrc (0.10.3)
56
56
  pagarme (1.9.9)
57
57
  multi_json
58
58
  rest-client
@@ -13,7 +13,7 @@ module CatarsePagarme
13
13
  contribution.try(:invalid_refund)
14
14
  else
15
15
  delegator.change_status_by_transaction(params[:current_status])
16
- delegator.fill_acquirer_data
16
+ delegator.update_fee
17
17
  end
18
18
 
19
19
  return render nothing: true, status: 200
@@ -21,11 +21,19 @@ module CatarsePagarme
21
21
  end
22
22
  end
23
23
 
24
+ def update_fee
25
+ fill_acquirer_data
26
+ contribution.update_attributes({
27
+ payment_service_fee: get_fee,
28
+ })
29
+ end
30
+
24
31
  def fill_acquirer_data
25
32
  if !contribution.acquirer_name.present? || !contribution.acquirer_tid.present?
26
33
  contribution.update_attributes({
27
34
  acquirer_name: transaction.acquirer_name,
28
- acquirer_tid: transaction.tid
35
+ acquirer_tid: transaction.tid,
36
+ card_brand: transaction.try(:card_brand)
29
37
  })
30
38
  end
31
39
  end
@@ -6,24 +6,47 @@ module CatarsePagarme::FeeCalculatorConcern
6
6
  def get_fee
7
7
  return nil if self.contribution.payment_choice.blank? # We always depend on the payment_choice
8
8
  if self.contribution.payment_choice == ::CatarsePagarme::PaymentType::SLIP
9
- CatarsePagarme.configuration.slip_tax.to_f
9
+ get_slip_fee
10
10
  else
11
- return nil if self.contribution.acquirer_name.blank? # Here we depend on the acquirer name
12
- if self.contribution.acquirer_name == 'stone'
13
- self.contribution.installments > 1 ? tax_calc_for_installment(stone_tax) : tax_calc(stone_tax)
14
- else
15
- return nil if self.contribution.card_brand.blank? # Here we depend on the card_brand
16
- if self.contribution.card_brand == 'amex'
17
- self.contribution.installments > 1 ? tax_calc_for_installment(cielo_installment_amex_tax) : tax_calc(cielo_installment_not_amex_tax)
18
- else
19
- current_tax = self.contribution.card_brand == 'diners' ? installment_diners_tax : installment_not_diners_tax
20
- self.contribution.installments > 1 ? tax_calc_for_installment(current_tax) : tax_calc(cielo_tax)
21
- end
22
- end
11
+ get_card_fee
23
12
  end
24
13
  end
25
14
 
26
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.contribution.acquirer_name.blank? # Here we depend on the acquirer name
22
+ if self.contribution.acquirer_name == 'stone'
23
+ get_stone_fee
24
+ else
25
+ get_cielo_fee
26
+ end
27
+ end
28
+
29
+ def get_stone_fee
30
+ self.contribution.installments > 1 ? tax_calc_for_installment(stone_tax) : tax_calc(stone_tax)
31
+ end
32
+
33
+ def get_cielo_fee
34
+ return nil if self.contribution.card_brand.blank? # Here we depend on the card_brand
35
+ if self.contribution.card_brand == 'amex'
36
+ get_cielo_fee_for_amex
37
+ else
38
+ get_cielo_fee_for_non_amex
39
+ end
40
+ end
41
+
42
+ def get_cielo_fee_for_amex
43
+ self.contribution.installments > 1 ? tax_calc_for_installment(cielo_installment_amex_tax) : tax_calc(cielo_installment_not_amex_tax)
44
+ end
45
+
46
+ def get_cielo_fee_for_non_amex
47
+ current_tax = self.contribution.card_brand == 'diners' ? installment_diners_tax : installment_not_diners_tax
48
+ self.contribution.installments > 1 ? tax_calc_for_installment(current_tax) : tax_calc(cielo_tax)
49
+ end
27
50
 
28
51
  def tax_calc acquirer_tax
29
52
  ((self.contribution.value * pagarme_tax) + cents_fee).round(2) + (self.contribution.value * acquirer_tax).round(2)
@@ -11,7 +11,7 @@ module CatarsePagarme
11
11
 
12
12
  def change_contribution_state
13
13
  self.contribution.update_attributes(attributes_to_contribution)
14
- update_fee
14
+ delegator.update_fee
15
15
  self.contribution.payment_notifications.create(extra_data: self.transaction.to_json)
16
16
  delegator.change_status_by_transaction(self.transaction.status)
17
17
  end
@@ -27,10 +27,7 @@ module CatarsePagarme
27
27
  payment_method: 'Pagarme',
28
28
  slip_url: self.transaction.boleto_url,
29
29
  installments: (self.transaction.installments || 1),
30
- installment_value: (delegator.value_for_installment(self.transaction.installments || 0) / 100.0).to_f,
31
- acquirer_name: self.transaction.acquirer_name,
32
- acquirer_tid: self.transaction.tid,
33
- card_brand: self.transaction.try(:card_brand)
30
+ installment_value: (delegator.value_for_installment(self.transaction.installments || 0) / 100.0).to_f
34
31
  }
35
32
  end
36
33
 
@@ -38,11 +35,5 @@ module CatarsePagarme
38
35
  self.contribution.pagarme_delegator
39
36
  end
40
37
 
41
- private
42
- def update_fee
43
- self.contribution.update_attributes({
44
- payment_service_fee: delegator.get_fee,
45
- })
46
- end
47
38
  end
48
39
  end
@@ -1,3 +1,3 @@
1
1
  module CatarsePagarme
2
- VERSION = "2.4.9"
2
+ VERSION = "2.4.10"
3
3
  end
@@ -42,6 +42,7 @@ describe CatarsePagarme::CreditCardTransaction do
42
42
  describe 'with valid attributes' do
43
43
  before do
44
44
  contribution.should_receive(:update_attributes).at_least(1).and_call_original
45
+ PagarMe::Transaction.should_receive(:find_by_id).with(pagarme_transaction.id).and_return(pagarme_transaction)
45
46
  CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
46
47
 
47
48
  card_transaction.charge!
@@ -74,6 +74,7 @@ describe CatarsePagarme::SlipTransaction do
74
74
  slip_transaction.should_receive(:update_user_bank_account).and_call_original
75
75
  slip_transaction.user.should_receive(:update_attributes).and_return(true)
76
76
  contribution.should_receive(:update_attributes).at_least(1).and_call_original
77
+ PagarMe::Transaction.should_receive(:find_by_id).with(pagarme_transaction.id).and_return(pagarme_transaction)
77
78
  CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
78
79
 
79
80
  slip_transaction.charge!
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.4.9
4
+ version: 2.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva