catarse_pagarme 2.3.10 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/catarse_pagarme/contribution_delegator.rb +1 -28
- data/app/models/catarse_pagarme/fee_calculator_concern.rb +54 -0
- data/app/models/catarse_pagarme/transaction_base.rb +7 -1
- data/lib/catarse_pagarme/configuration.rb +4 -1
- data/lib/catarse_pagarme/version.rb +1 -1
- data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +3 -3
- data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +8 -0
- data/spec/models/catarse_pagarme/contribution_delegator_spec.rb +10 -0
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +2 -2
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 415da7334098845435424c47e308397ebbcf1250
|
4
|
+
data.tar.gz: 0801a8de19aae2c980fd9b44407c3975120883a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56a44204b6cd1feb1edf0546859e16681a49b8dae1a8d6741e87e0093189e751fae2d4229a689348dd7899714986d9eb8f0215e45f80be2c7389f99a539ea85f
|
7
|
+
data.tar.gz: 7fe2f172eac029cc469ea9651e3b23c891b874b11fbb2c1d911117076c208b455d7f23a206132f492c227f97a3062d33464cc6bf916b43ba1c0fd20aeafc6051
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module CatarsePagarme
|
2
2
|
class ContributionDelegator
|
3
3
|
attr_accessor :contribution, :transaction
|
4
|
+
include FeeCalculatorConcern
|
4
5
|
|
5
6
|
def initialize(contribution)
|
6
7
|
configure_pagarme
|
@@ -74,34 +75,6 @@ module CatarsePagarme
|
|
74
75
|
})
|
75
76
|
end
|
76
77
|
|
77
|
-
def get_fee(payment_method, acquirer_name = nil)
|
78
|
-
value = self.contribution.value
|
79
|
-
installment_value = self.contribution.installment_value
|
80
|
-
installments = self.contribution.installments
|
81
|
-
cents_fee = CatarsePagarme.configuration.credit_card_cents_fee.to_f
|
82
|
-
pagarme_tax = CatarsePagarme.configuration.pagarme_tax.to_f
|
83
|
-
cielo_tax = CatarsePagarme.configuration.cielo_tax.to_f
|
84
|
-
stone_tax = CatarsePagarme.configuration.stone_tax.to_f
|
85
|
-
|
86
|
-
if payment_method == PaymentType::SLIP
|
87
|
-
CatarsePagarme.configuration.slip_tax.to_f
|
88
|
-
else
|
89
|
-
if acquirer_name == 'stone'
|
90
|
-
if installments > 1
|
91
|
-
(((installment_value * installments) * pagarme_tax) + cents_fee).round(2) + ((installment_value * stone_tax).round(2) * installments)
|
92
|
-
else
|
93
|
-
((value * pagarme_tax) + cents_fee).round(2) + (value * stone_tax).round(2)
|
94
|
-
end
|
95
|
-
else
|
96
|
-
if installments > 1
|
97
|
-
(((installment_value * installments) * pagarme_tax) + cents_fee).round(2) + ((installment_value * cielo_tax).round(2) * installments)
|
98
|
-
else
|
99
|
-
((value * pagarme_tax) + cents_fee).round(2) + (value * cielo_tax).round(2)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
78
|
protected
|
106
79
|
|
107
80
|
def bank_account_attributes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module CatarsePagarme::FeeCalculatorConcern
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
|
6
|
+
def get_fee(payment_method, acquirer_name = nil)
|
7
|
+
if payment_method == ::CatarsePagarme::PaymentType::SLIP
|
8
|
+
CatarsePagarme.configuration.slip_tax.to_f
|
9
|
+
else
|
10
|
+
if acquirer_name == 'stone'
|
11
|
+
self.contribution.installments > 1 ? tax_calc_for_installment(stone_tax) : tax_calc(stone_tax)
|
12
|
+
else
|
13
|
+
current_tax = self.transaction.card_brand == 'diners' ? installment_diners_tax : installment_not_diners_tax
|
14
|
+
self.contribution.installments > 1 ? tax_calc_for_installment(current_tax) : tax_calc(cielo_tax)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def tax_calc acquirer_tax
|
22
|
+
((self.contribution.value * pagarme_tax) + cents_fee).round(2) + (self.contribution.value * acquirer_tax).round(2)
|
23
|
+
end
|
24
|
+
|
25
|
+
def tax_calc_for_installment acquirer_tax
|
26
|
+
(((self.contribution.installment_value * self.contribution.installments) * pagarme_tax) + cents_fee).round(2) + ((self.contribution.installment_value * acquirer_tax).round(2) * self.contribution.installments)
|
27
|
+
end
|
28
|
+
|
29
|
+
def cents_fee
|
30
|
+
CatarsePagarme.configuration.credit_card_cents_fee.to_f
|
31
|
+
end
|
32
|
+
|
33
|
+
def pagarme_tax
|
34
|
+
CatarsePagarme.configuration.pagarme_tax.to_f
|
35
|
+
end
|
36
|
+
|
37
|
+
def cielo_tax
|
38
|
+
CatarsePagarme.configuration.cielo_tax.to_f
|
39
|
+
end
|
40
|
+
|
41
|
+
def stone_tax
|
42
|
+
CatarsePagarme.configuration.stone_tax.to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
def installment_diners_tax
|
46
|
+
CatarsePagarme.configuration.cielo_installment_diners_tax.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
def installment_not_diners_tax
|
50
|
+
CatarsePagarme.configuration.cielo_installment_not_diners_tax.to_f
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -11,6 +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
15
|
self.contribution.payment_notifications.create(extra_data: self.transaction.to_json)
|
15
16
|
delegator.change_status_by_transaction(self.transaction.status)
|
16
17
|
end
|
@@ -22,7 +23,6 @@ module CatarsePagarme
|
|
22
23
|
def attributes_to_contribution
|
23
24
|
{
|
24
25
|
payment_choice: payment_method,
|
25
|
-
payment_service_fee: delegator.get_fee(payment_method, self.transaction.acquirer_name),
|
26
26
|
payment_id: self.transaction.id,
|
27
27
|
payment_method: 'Pagarme',
|
28
28
|
slip_url: self.transaction.boleto_url,
|
@@ -33,6 +33,12 @@ module CatarsePagarme
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
+
def update_fee
|
37
|
+
self.contribution.update_attributes({
|
38
|
+
payment_service_fee: delegator.get_fee(payment_method, self.transaction.acquirer_name),
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
36
42
|
def delegator
|
37
43
|
self.contribution.pagarme_delegator
|
38
44
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module CatarsePagarme
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_key, :slip_tax, :credit_card_tax, :interest_rate, :host, :subdomain, :protocol,
|
4
|
-
:max_installments, :minimum_value_for_installment, :credit_card_cents_fee, :pagarme_tax, :stone_tax,
|
4
|
+
:max_installments, :minimum_value_for_installment, :credit_card_cents_fee, :pagarme_tax, :stone_tax,
|
5
|
+
:cielo_tax, :cielo_installment_diners_tax, :cielo_installment_not_diners_tax
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
self.api_key = ''
|
@@ -17,6 +18,8 @@ module CatarsePagarme
|
|
17
18
|
self.pagarme_tax = 0.0063
|
18
19
|
self.stone_tax = 0.0307
|
19
20
|
self.cielo_tax = 0.038
|
21
|
+
self.cielo_installment_diners_tax = 0.048
|
22
|
+
self.cielo_installment_not_diners_tax = 0.0455
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
@@ -27,12 +27,12 @@ describe CatarsePagarme::CreditCardsController do
|
|
27
27
|
before do
|
28
28
|
post :create, {
|
29
29
|
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
30
|
-
payment_card_date: '10/17', payment_card_number: '
|
31
|
-
payment_card_source: '
|
30
|
+
payment_card_date: '10/17', payment_card_number: '4012888888881881', payment_card_name: 'Foo bar',
|
31
|
+
payment_card_source: '574', payment_card_installments: '1' }
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
-
it 'payment_status should be filled
|
35
|
+
it 'payment_status should be filled' do
|
36
36
|
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to be_nil
|
37
37
|
end
|
38
38
|
|
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CatarsePagarme::NotificationsController do
|
4
|
+
let(:fake_transaction) {
|
5
|
+
t = double
|
6
|
+
t.stub(:card_brand).and_return('visa')
|
7
|
+
t.stub(:acquirer_name).and_return('stone')
|
8
|
+
t.stub(:tid).and_return('404040404')
|
9
|
+
t
|
10
|
+
}
|
4
11
|
before do
|
5
12
|
PagarMe.stub(:validate_fingerprint).and_return(true)
|
13
|
+
PagarMe::Transaction.stub(:find_by_id).and_return(fake_transaction)
|
6
14
|
end
|
7
15
|
|
8
16
|
let(:project) { create(:project, goal: 10_000, state: 'online') }
|
@@ -30,12 +30,22 @@ describe CatarsePagarme::ContributionDelegator do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context "#get_fee" do
|
33
|
+
let(:fake_transaction) {
|
34
|
+
t = double
|
35
|
+
t.stub(:card_brand).and_return('visa')
|
36
|
+
t.stub(:acquirer_name).and_return('stone')
|
37
|
+
t.stub(:acquirer_tid).and_return('404040404')
|
38
|
+
t
|
39
|
+
}
|
40
|
+
|
33
41
|
before do
|
34
42
|
CatarsePagarme.configuration.stub(:slip_tax).and_return(2.00)
|
35
43
|
CatarsePagarme.configuration.stub(:credit_card_tax).and_return(0.01)
|
36
44
|
CatarsePagarme.configuration.stub(:pagarme_tax).and_return(0.0063)
|
37
45
|
CatarsePagarme.configuration.stub(:cielo_tax).and_return(0.038)
|
38
46
|
CatarsePagarme.configuration.stub(:stone_tax).and_return(0.0307)
|
47
|
+
|
48
|
+
delegator.stub(:transaction).and_return(fake_transaction)
|
39
49
|
end
|
40
50
|
|
41
51
|
context 'when choice is slip' do
|
@@ -40,7 +40,7 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
40
40
|
describe '#charge!' do
|
41
41
|
describe 'with valid attributes' do
|
42
42
|
before do
|
43
|
-
contribution.should_receive(:update_attributes).and_call_original
|
43
|
+
contribution.should_receive(:update_attributes).at_least(1).and_call_original
|
44
44
|
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
45
45
|
|
46
46
|
card_transaction.charge!
|
@@ -52,7 +52,7 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should update contribution payment_service_fee" do
|
55
|
-
expect(contribution.payment_service_fee.to_f).to eq(
|
55
|
+
expect(contribution.payment_service_fee.to_f).to eq(4.08)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should update contribution payment_method" do
|
@@ -8,7 +8,7 @@ describe CatarsePagarme::SlipTransaction do
|
|
8
8
|
transaction.stub(:charge).and_return(true)
|
9
9
|
transaction.stub(:status).and_return('paid')
|
10
10
|
transaction.stub(:boleto_url).and_return('boleto url')
|
11
|
-
transaction.stub(:installments).and_return(
|
11
|
+
transaction.stub(:installments).and_return(1)
|
12
12
|
transaction.stub(:acquirer_name).and_return('pagarme')
|
13
13
|
transaction.stub(:tid).and_return('123123')
|
14
14
|
transaction
|
@@ -72,7 +72,7 @@ describe CatarsePagarme::SlipTransaction do
|
|
72
72
|
before do
|
73
73
|
slip_transaction.should_receive(:update_user_bank_account).and_call_original
|
74
74
|
slip_transaction.user.should_receive(:update_attributes).and_return(true)
|
75
|
-
contribution.should_receive(:update_attributes).and_call_original
|
75
|
+
contribution.should_receive(:update_attributes).at_least(1).and_call_original
|
76
76
|
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
77
77
|
|
78
78
|
slip_transaction.charge!
|
data/spec/spec_helper.rb
CHANGED
@@ -30,7 +30,7 @@ RSpec.configure do |config|
|
|
30
30
|
end
|
31
31
|
|
32
32
|
config.before(:each) do
|
33
|
-
PagarMe.stub(:api_key).and_return('
|
33
|
+
PagarMe.stub(:api_key).and_return('ak_test_XLoo19QDn9kg5JFGU70x12IA4NqbAv')
|
34
34
|
PaymentEngines.stub(:configuration).and_return({})
|
35
35
|
end
|
36
36
|
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.
|
4
|
+
version: 2.4.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: 2014-12-
|
12
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- app/models/catarse_pagarme/credit_card_concern.rb
|
117
117
|
- app/models/catarse_pagarme/credit_card_delegator.rb
|
118
118
|
- app/models/catarse_pagarme/credit_card_transaction.rb
|
119
|
+
- app/models/catarse_pagarme/fee_calculator_concern.rb
|
119
120
|
- app/models/catarse_pagarme/payment_type.rb
|
120
121
|
- app/models/catarse_pagarme/save_credit_card_transaction.rb
|
121
122
|
- app/models/catarse_pagarme/slip_transaction.rb
|