catarse_pagarme 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -257
- data/app/controllers/catarse_pagarme/application_controller.rb +6 -7
- data/app/controllers/catarse_pagarme/credit_cards_controller.rb +5 -5
- data/app/controllers/catarse_pagarme/notifications_controller.rb +6 -6
- data/app/controllers/catarse_pagarme/slip_controller.rb +6 -6
- data/app/helpers/catarse_pagarme/application_helper.rb +3 -3
- data/app/models/catarse_pagarme/credit_card_transaction.rb +1 -1
- data/app/models/catarse_pagarme/fee_calculator_concern.rb +12 -12
- data/app/models/catarse_pagarme/payment_concern.rb +9 -0
- data/app/models/catarse_pagarme/{contribution_delegator.rb → payment_delegator.rb} +17 -17
- data/app/models/catarse_pagarme/slip_transaction.rb +3 -2
- data/app/models/catarse_pagarme/transaction_base.rb +14 -13
- data/lib/catarse_pagarme/engine.rb +1 -1
- data/lib/catarse_pagarme/version.rb +1 -1
- data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +5 -5
- data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +11 -6
- data/spec/controllers/catarse_pagarme/slip_controller_spec.rb +6 -6
- data/spec/dummy/app/models/contribution.rb +1 -24
- data/spec/dummy/app/models/payment.rb +55 -0
- data/spec/dummy/app/models/payment_engines.rb +7 -0
- data/spec/helpers/catarse_pagarme/application_helper_spec.rb +2 -2
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +23 -23
- data/spec/models/catarse_pagarme/{contribution_delegator_spec.rb → payment_delegator_spec.rb} +28 -55
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +35 -29
- data/spec/support/factories.rb +16 -6
- metadata +8 -6
- data/app/models/catarse_pagarme/contribution_concern.rb +0 -9
data/spec/models/catarse_pagarme/{contribution_delegator_spec.rb → payment_delegator_spec.rb}
RENAMED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe CatarsePagarme::
|
3
|
+
describe CatarsePagarme::PaymentDelegator do
|
4
4
|
let(:contribution) { create(:contribution, value: 10) }
|
5
|
-
let(:
|
5
|
+
let(:payment) { contribution.payments.first }
|
6
|
+
let(:delegator) { payment.pagarme_delegator }
|
6
7
|
|
7
|
-
context "instance of CatarsePagarme::
|
8
|
-
it { expect(delegator).to be_a CatarsePagarme::
|
8
|
+
context "instance of CatarsePagarme::paymentDelegator" do
|
9
|
+
it { expect(delegator).to be_a CatarsePagarme::PaymentDelegator }
|
9
10
|
end
|
10
11
|
|
11
12
|
context "#value_for_transaction" do
|
12
13
|
subject { delegator.value_for_transaction }
|
13
14
|
|
14
|
-
it "should convert
|
15
|
+
it "should convert payment value to pagarme value format" do
|
15
16
|
expect(subject).to eq(1000)
|
16
17
|
end
|
17
18
|
end
|
@@ -24,7 +25,7 @@ describe CatarsePagarme::ContributionDelegator do
|
|
24
25
|
CatarsePagarme.configuration.stub(:interest_rate).and_return(1.8)
|
25
26
|
end
|
26
27
|
|
27
|
-
it "should return the
|
28
|
+
it "should return the payment value with installments tax" do
|
28
29
|
expect(subject).to eq(1057)
|
29
30
|
end
|
30
31
|
end
|
@@ -49,26 +50,20 @@ describe CatarsePagarme::ContributionDelegator do
|
|
49
50
|
delegator.stub(:transaction).and_return(fake_transaction)
|
50
51
|
end
|
51
52
|
|
52
|
-
context 'when choice is nil' do
|
53
|
-
let(:contribution) { create(:contribution, value: 10, payment_choice: nil) }
|
54
|
-
subject { delegator.get_fee }
|
55
|
-
it { expect(subject).to eq(nil) }
|
56
|
-
end
|
57
|
-
|
58
53
|
context 'when choice is credit card and acquirer_name is nil' do
|
59
|
-
let(:
|
54
|
+
let(:payment) { create(:payment, value: 10, payment_method: CatarsePagarme::PaymentType::CREDIT_CARD, gateway_data: {acquirer_name: nil}) }
|
60
55
|
subject { delegator.get_fee }
|
61
56
|
it { expect(subject).to eq(nil) }
|
62
57
|
end
|
63
58
|
|
64
59
|
context 'when choice is slip' do
|
65
|
-
let(:
|
60
|
+
let(:payment) { create(:payment, value: 10, payment_method: CatarsePagarme::PaymentType::SLIP, gateway_data: {acquirer_name: nil}) }
|
66
61
|
subject { delegator.get_fee }
|
67
62
|
it { expect(subject).to eq(2.00) }
|
68
63
|
end
|
69
64
|
|
70
65
|
context 'when choice is credit card' do
|
71
|
-
let(:
|
66
|
+
let(:payment) { create(:payment, value: 10, payment_method: CatarsePagarme::PaymentType::CREDIT_CARD, gateway_data: {acquirer_name: 'stone', card_brand: 'visa'}, installments: 1) }
|
72
67
|
subject { delegator.get_fee }
|
73
68
|
it { expect(subject).to eq(0.76) }
|
74
69
|
end
|
@@ -88,41 +83,19 @@ describe CatarsePagarme::ContributionDelegator do
|
|
88
83
|
|
89
84
|
%w(paid authorized).each do |status|
|
90
85
|
context "when status is #{status}" do
|
91
|
-
context "and
|
92
|
-
before do
|
93
|
-
contribution.stub(:confirmed?).and_return(true)
|
94
|
-
contribution.should_not_receive(:confirm)
|
95
|
-
end
|
96
|
-
|
97
|
-
it { delegator.change_status_by_transaction(status) }
|
98
|
-
end
|
99
|
-
|
100
|
-
context "and contribution is not confirmed" do
|
101
|
-
before do
|
102
|
-
contribution.stub(:confirmed?).and_return(false)
|
103
|
-
contribution.should_receive(:confirm)
|
104
|
-
end
|
105
|
-
|
106
|
-
it { delegator.change_status_by_transaction(status) }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
%w(waiting_payment processing).each do |status|
|
112
|
-
context "when status is #{status}" do
|
113
|
-
context "and contribution is already waiting confirmation" do
|
86
|
+
context "and payment is already paid" do
|
114
87
|
before do
|
115
|
-
|
116
|
-
|
88
|
+
payment.stub(:paid?).and_return(true)
|
89
|
+
payment.should_not_receive(:pay)
|
117
90
|
end
|
118
91
|
|
119
92
|
it { delegator.change_status_by_transaction(status) }
|
120
93
|
end
|
121
94
|
|
122
|
-
context "and
|
95
|
+
context "and payment is not paid" do
|
123
96
|
before do
|
124
|
-
|
125
|
-
|
97
|
+
payment.stub(:paid?).and_return(false)
|
98
|
+
payment.should_receive(:pay)
|
126
99
|
end
|
127
100
|
|
128
101
|
it { delegator.change_status_by_transaction(status) }
|
@@ -131,19 +104,19 @@ describe CatarsePagarme::ContributionDelegator do
|
|
131
104
|
end
|
132
105
|
|
133
106
|
context "when status is refunded" do
|
134
|
-
context "and
|
107
|
+
context "and payment is already refunded" do
|
135
108
|
before do
|
136
|
-
|
137
|
-
|
109
|
+
payment.stub(:refunded?).and_return(true)
|
110
|
+
payment.should_not_receive(:refund)
|
138
111
|
end
|
139
112
|
|
140
113
|
it { delegator.change_status_by_transaction('refunded') }
|
141
114
|
end
|
142
115
|
|
143
|
-
context "and
|
116
|
+
context "and payment is not refunded" do
|
144
117
|
before do
|
145
|
-
|
146
|
-
|
118
|
+
payment.stub(:refunded?).and_return(false)
|
119
|
+
payment.should_receive(:refund)
|
147
120
|
end
|
148
121
|
|
149
122
|
it { delegator.change_status_by_transaction('refunded') }
|
@@ -151,19 +124,19 @@ describe CatarsePagarme::ContributionDelegator do
|
|
151
124
|
end
|
152
125
|
|
153
126
|
context "when status is refused" do
|
154
|
-
context "and
|
127
|
+
context "and payment is already canceled" do
|
155
128
|
before do
|
156
|
-
|
157
|
-
|
129
|
+
payment.stub(:refused?).and_return(true)
|
130
|
+
payment.should_not_receive(:refuse)
|
158
131
|
end
|
159
132
|
|
160
133
|
it { delegator.change_status_by_transaction('refused') }
|
161
134
|
end
|
162
135
|
|
163
|
-
context "and
|
136
|
+
context "and payment is not refused" do
|
164
137
|
before do
|
165
|
-
|
166
|
-
|
138
|
+
payment.stub(:refused?).and_return(false)
|
139
|
+
payment.should_receive(:refuse)
|
167
140
|
end
|
168
141
|
|
169
142
|
it { delegator.change_status_by_transaction('refused') }
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CatarsePagarme::SlipTransaction do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
|
4
|
+
let(:payment) { create(:payment, value: 100) }
|
5
|
+
let(:pagarme_transaction_attributes) {
|
6
|
+
{
|
7
7
|
id: 'abcd',
|
8
8
|
charge: true,
|
9
9
|
status: 'paid',
|
@@ -12,13 +12,18 @@ describe CatarsePagarme::SlipTransaction do
|
|
12
12
|
acquirer_name: 'pagarme',
|
13
13
|
tid: '123123',
|
14
14
|
card_brand: nil
|
15
|
-
}
|
15
|
+
}
|
16
16
|
}
|
17
|
+
|
18
|
+
let(:pagarme_transaction) {
|
19
|
+
double(pagarme_transaction_attributes)
|
20
|
+
}
|
21
|
+
|
17
22
|
let(:valid_attributes) do
|
18
23
|
{
|
19
24
|
slip_payment: {
|
20
25
|
payment_method: 'boleto',
|
21
|
-
amount:
|
26
|
+
amount: payment.pagarme_delegator.value_for_transaction,
|
22
27
|
postback_url: 'http://test.foo'
|
23
28
|
}, user: {
|
24
29
|
bank_account_attributes: {
|
@@ -34,7 +39,7 @@ describe CatarsePagarme::SlipTransaction do
|
|
34
39
|
{
|
35
40
|
slip_payment: {
|
36
41
|
payment_method: 'boleto',
|
37
|
-
amount:
|
42
|
+
amount: payment.pagarme_delegator.value_for_transaction,
|
38
43
|
postback_url: 'http://test.foo'
|
39
44
|
}, user: {
|
40
45
|
bank_account_attributes: {
|
@@ -44,22 +49,23 @@ describe CatarsePagarme::SlipTransaction do
|
|
44
49
|
}
|
45
50
|
end
|
46
51
|
|
47
|
-
let(:slip_transaction) { CatarsePagarme::SlipTransaction.new(valid_attributes,
|
52
|
+
let(:slip_transaction) { CatarsePagarme::SlipTransaction.new(valid_attributes, payment) }
|
48
53
|
|
49
54
|
before do
|
50
55
|
PagarMe::Transaction.stub(:new).and_return(pagarme_transaction)
|
51
|
-
|
56
|
+
pagarme_transaction.stub(:to_json).and_return(pagarme_transaction_attributes.to_json)
|
57
|
+
CatarsePagarme::PaymentDelegator.any_instance.stub(:change_status_by_transaction).and_return(true)
|
52
58
|
end
|
53
59
|
|
54
60
|
context "#user" do
|
55
61
|
subject { slip_transaction.user }
|
56
|
-
it { expect(subject).to eq(
|
62
|
+
it { expect(subject).to eq(payment.user) }
|
57
63
|
end
|
58
64
|
|
59
65
|
context "#charge!" do
|
60
66
|
context "with invalid attributes" do
|
61
67
|
let(:slip_transaction) {
|
62
|
-
CatarsePagarme::SlipTransaction.new(invalid_attributes,
|
68
|
+
CatarsePagarme::SlipTransaction.new(invalid_attributes, payment)
|
63
69
|
}
|
64
70
|
|
65
71
|
it "should raises an error" do
|
@@ -73,44 +79,44 @@ describe CatarsePagarme::SlipTransaction do
|
|
73
79
|
before do
|
74
80
|
slip_transaction.should_receive(:update_user_bank_account).and_call_original
|
75
81
|
slip_transaction.user.should_receive(:update_attributes).and_return(true)
|
76
|
-
|
82
|
+
payment.should_receive(:update_attributes).at_least(1).and_call_original
|
77
83
|
PagarMe::Transaction.should_receive(:find_by_id).with(pagarme_transaction.id).and_return(pagarme_transaction)
|
78
|
-
CatarsePagarme::
|
84
|
+
CatarsePagarme::PaymentDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
79
85
|
|
80
86
|
slip_transaction.charge!
|
81
|
-
|
87
|
+
payment.reload
|
82
88
|
end
|
83
89
|
|
84
|
-
it "should update
|
85
|
-
expect(
|
90
|
+
it "should update payment payment_id" do
|
91
|
+
expect(payment.gateway_id).to eq('abcd')
|
86
92
|
end
|
87
93
|
|
88
|
-
it "should update
|
89
|
-
expect(
|
94
|
+
it "should update payment payment_service_fee" do
|
95
|
+
expect(payment.gateway_fee).to eq(0.0)
|
90
96
|
end
|
91
97
|
|
92
|
-
it "should update
|
93
|
-
expect(
|
98
|
+
it "should update payment payment_method" do
|
99
|
+
expect(payment.gateway).to eq('Pagarme')
|
94
100
|
end
|
95
101
|
|
96
|
-
it "should update
|
97
|
-
expect(
|
102
|
+
it "should update payment slip_url" do
|
103
|
+
expect(payment.gateway_data["boleto_url"]).to eq('boleto url')
|
98
104
|
end
|
99
105
|
|
100
|
-
it "should update
|
101
|
-
expect(
|
106
|
+
it "should update payment payment_choice" do
|
107
|
+
expect(payment.payment_method).to eq(CatarsePagarme::PaymentType::SLIP)
|
102
108
|
end
|
103
109
|
|
104
|
-
it "should update
|
105
|
-
expect(
|
110
|
+
it "should update payment acquirer_name" do
|
111
|
+
expect(payment.gateway_data["acquirer_name"]).to eq('pagarme')
|
106
112
|
end
|
107
113
|
|
108
|
-
it "should update
|
109
|
-
expect(
|
114
|
+
it "should update payment acquirer_tid" do
|
115
|
+
expect(payment.gateway_data["acquirer_tid"]).to eq('123123')
|
110
116
|
end
|
111
117
|
|
112
|
-
it "should update
|
113
|
-
expect(
|
118
|
+
it "should update payment installment_value" do
|
119
|
+
expect(payment.installment_value).to_not be_nil
|
114
120
|
end
|
115
121
|
end
|
116
122
|
end
|
data/spec/support/factories.rb
CHANGED
@@ -18,7 +18,6 @@ FactoryGirl.define do
|
|
18
18
|
factory :user do |f|
|
19
19
|
f.name "Foo bar"
|
20
20
|
f.email { generate(:email) }
|
21
|
-
f.bio "This is Foo bar's biography."
|
22
21
|
end
|
23
22
|
|
24
23
|
factory :credi_card do |f|
|
@@ -52,7 +51,7 @@ FactoryGirl.define do
|
|
52
51
|
f.permalink { generate(:permalink) }
|
53
52
|
f.association :user, factory: :user
|
54
53
|
f.association :category, factory: :category
|
55
|
-
f.
|
54
|
+
f.about_html "Foo bar"
|
56
55
|
f.headline "Foo bar"
|
57
56
|
f.goal 10000
|
58
57
|
f.online_date Time.now
|
@@ -64,11 +63,22 @@ FactoryGirl.define do
|
|
64
63
|
factory :contribution do |f|
|
65
64
|
f.association :project, factory: :project
|
66
65
|
f.association :user, factory: :user
|
67
|
-
f.confirmed_at Time.now
|
68
66
|
f.value 10.00
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
after :create do |contribution|
|
68
|
+
create(:payment, paid_at: Time.now, gateway_id: '1.2.3', state: 'paid', value: contribution.value, contribution: contribution)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
factory :payment do |f|
|
73
|
+
f.association :contribution
|
74
|
+
f.gateway 'pagarme'
|
75
|
+
f.value 10.00
|
76
|
+
f.state 'paid'
|
77
|
+
f.installment_value 10.00
|
78
|
+
f.payment_method "CartaoDeCredito"
|
79
|
+
after :build do |payment|
|
80
|
+
payment.gateway = 'pagarme'
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
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.6.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: 2015-
|
12
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -109,10 +109,10 @@ files:
|
|
109
109
|
- app/controllers/catarse_pagarme/slip_controller.rb
|
110
110
|
- app/helpers/catarse_pagarme/application_helper.rb
|
111
111
|
- app/models/catarse_pagarme/bank_account_concern.rb
|
112
|
-
- app/models/catarse_pagarme/contribution_concern.rb
|
113
|
-
- app/models/catarse_pagarme/contribution_delegator.rb
|
114
112
|
- app/models/catarse_pagarme/credit_card_transaction.rb
|
115
113
|
- app/models/catarse_pagarme/fee_calculator_concern.rb
|
114
|
+
- app/models/catarse_pagarme/payment_concern.rb
|
115
|
+
- app/models/catarse_pagarme/payment_delegator.rb
|
116
116
|
- app/models/catarse_pagarme/payment_type.rb
|
117
117
|
- app/models/catarse_pagarme/slip_transaction.rb
|
118
118
|
- app/models/catarse_pagarme/transaction_base.rb
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- spec/dummy/app/models/concerns/.keep
|
150
150
|
- spec/dummy/app/models/contribution.rb
|
151
151
|
- spec/dummy/app/models/credit_card.rb
|
152
|
+
- spec/dummy/app/models/payment.rb
|
152
153
|
- spec/dummy/app/models/payment_engines.rb
|
153
154
|
- spec/dummy/app/models/payment_notification.rb
|
154
155
|
- spec/dummy/app/models/project.rb
|
@@ -186,8 +187,8 @@ files:
|
|
186
187
|
- spec/dummy/public/favicon.ico
|
187
188
|
- spec/helpers/catarse_pagarme/application_helper_spec.rb
|
188
189
|
- spec/models/catarse_pagarme/bank_account_concern_spec.rb
|
189
|
-
- spec/models/catarse_pagarme/contribution_delegator_spec.rb
|
190
190
|
- spec/models/catarse_pagarme/credit_card_transaction_spec.rb
|
191
|
+
- spec/models/catarse_pagarme/payment_delegator_spec.rb
|
191
192
|
- spec/models/catarse_pagarme/slip_transaction_spec.rb
|
192
193
|
- spec/spec_helper.rb
|
193
194
|
- spec/support/factories.rb
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- spec/dummy/app/models/concerns/.keep
|
236
237
|
- spec/dummy/app/models/contribution.rb
|
237
238
|
- spec/dummy/app/models/credit_card.rb
|
239
|
+
- spec/dummy/app/models/payment.rb
|
238
240
|
- spec/dummy/app/models/payment_engines.rb
|
239
241
|
- spec/dummy/app/models/payment_notification.rb
|
240
242
|
- spec/dummy/app/models/project.rb
|
@@ -272,8 +274,8 @@ test_files:
|
|
272
274
|
- spec/dummy/public/favicon.ico
|
273
275
|
- spec/helpers/catarse_pagarme/application_helper_spec.rb
|
274
276
|
- spec/models/catarse_pagarme/bank_account_concern_spec.rb
|
275
|
-
- spec/models/catarse_pagarme/contribution_delegator_spec.rb
|
276
277
|
- spec/models/catarse_pagarme/credit_card_transaction_spec.rb
|
278
|
+
- spec/models/catarse_pagarme/payment_delegator_spec.rb
|
277
279
|
- spec/models/catarse_pagarme/slip_transaction_spec.rb
|
278
280
|
- spec/spec_helper.rb
|
279
281
|
- spec/support/factories.rb
|