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 +4 -4
- data/Gemfile.lock +2 -2
- data/app/controllers/catarse_pagarme/notifications_controller.rb +1 -1
- data/app/models/catarse_pagarme/contribution_delegator.rb +9 -1
- data/app/models/catarse_pagarme/fee_calculator_concern.rb +36 -13
- data/app/models/catarse_pagarme/transaction_base.rb +2 -11
- data/lib/catarse_pagarme/version.rb +1 -1
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +1 -0
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 167056c394c65f4907196b570a631367b03fe471
|
4
|
+
data.tar.gz: 6dedfa0adf8a6b398e5967d320851adcc21eb637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
55
|
+
netrc (0.10.3)
|
56
56
|
pagarme (1.9.9)
|
57
57
|
multi_json
|
58
58
|
rest-client
|
@@ -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
|
-
|
9
|
+
get_slip_fee
|
10
10
|
else
|
11
|
-
|
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
|
@@ -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!
|