openpay 1.0.3 → 1.0.4
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 +13 -5
- data/.gitignore +1 -0
- data/.idea/.rakeTasks +2 -2
- data/.idea/OpenPay.iml +30 -20
- data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml +1 -0
- data/.idea/runConfigurations/all_specs.xml +1 -0
- data/.idea/workspace.xml +484 -268
- data/Gemfile +0 -6
- data/README.md +111 -29
- data/lib/openpay.rb +7 -3
- data/lib/openpay/bankaccounts.rb +10 -11
- data/lib/openpay/cards.rb +12 -14
- data/lib/openpay/charges.rb +38 -14
- data/lib/openpay/customers.rb +73 -67
- data/lib/openpay/errors/openpay_exception_factory.rb +14 -26
- data/lib/openpay/fees.rb +1 -1
- data/lib/openpay/open_pay_resource.rb +77 -77
- data/lib/openpay/open_pay_resource_factory.rb +1 -1
- data/lib/openpay/openpay_api.rb +6 -16
- data/lib/openpay/payouts.rb +13 -17
- data/lib/openpay/plans.rb +1 -7
- data/lib/openpay/subscriptions.rb +21 -29
- data/lib/openpay/transfers.rb +14 -18
- data/lib/openpay/utils/search_params.rb +20 -0
- data/lib/version.rb +1 -2
- data/openpay.gemspec +0 -8
- data/test/Factories.rb +80 -126
- data/test/spec/bankaccounts_spec.rb +55 -61
- data/test/spec/cards_spec.rb +56 -76
- data/test/spec/charges_spec.rb +89 -84
- data/test/spec/customers_spec.rb +37 -47
- data/test/spec/exceptions_spec.rb +4 -21
- data/test/spec/fees_spec.rb +51 -7
- data/test/spec/payouts_spec.rb +102 -65
- data/test/spec/plans_spec.rb +27 -50
- data/test/spec/subscriptions_spec.rb +87 -24
- data/test/spec/transfers_spec.rb +42 -44
- data/test/spec/utils/search_params_spec.rb +36 -0
- data/test/spec_helper.rb +1 -5
- metadata +15 -55
- data/lib/OpenPay/Cards.rb +0 -75
- data/lib/OpenPay/Charges.rb +0 -77
- data/lib/OpenPay/Customers.rb +0 -194
- data/lib/OpenPay/Fees.rb +0 -5
- data/lib/OpenPay/Payouts.rb +0 -59
- data/lib/OpenPay/Plans.rb +0 -23
- data/lib/OpenPay/Subscriptions.rb +0 -58
- data/lib/OpenPay/Transfers.rb +0 -43
- data/lib/OpenPay/bankaccounts.rb +0 -59
- data/lib/OpenPay/errors/openpay_connection_exception.rb +0 -3
- data/lib/OpenPay/errors/openpay_exception.rb +0 -29
- data/lib/OpenPay/errors/openpay_exception_factory.rb +0 -60
- data/lib/OpenPay/errors/openpay_transaction_exception.rb +0 -5
- data/lib/OpenPay/open_pay_resource.rb +0 -242
- data/lib/OpenPay/open_pay_resource_factory.rb +0 -10
- data/lib/OpenPay/openpay_api.rb +0 -58
data/test/spec/plans_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
describe Plans do
|
4
4
|
|
5
|
-
|
6
5
|
before(:all) do
|
7
6
|
|
8
7
|
@merchant_id='mywvupjjs9xdnryxtplq'
|
@@ -13,7 +12,6 @@ describe Plans do
|
|
13
12
|
@plans=@openpay.create(:plans)
|
14
13
|
@subscriptions=@openpay.create(:subscriptions)
|
15
14
|
|
16
|
-
|
17
15
|
end
|
18
16
|
|
19
17
|
|
@@ -21,103 +19,97 @@ describe Plans do
|
|
21
19
|
@plans.delete_all
|
22
20
|
end
|
23
21
|
|
22
|
+
it 'has all required methods' do
|
23
|
+
%w(all each create get list delete).each do |meth|
|
24
|
+
expect(@plans).to respond_to(meth)
|
25
|
+
end
|
26
|
+
end
|
24
27
|
|
25
28
|
describe '.create' do
|
26
29
|
|
27
|
-
|
28
30
|
it 'creates a merchant plan' do
|
29
31
|
|
30
32
|
plan_hash= FactoryGirl.build(:plan, repeat_every: 5)
|
31
33
|
plan=@plans.create(plan_hash)
|
32
34
|
|
33
|
-
|
34
35
|
#validates
|
35
36
|
expect(@plans.get(plan['id'])['repeat_every']).to be 5
|
36
37
|
|
37
38
|
#clean
|
38
39
|
@plans.delete(plan['id'])
|
39
40
|
|
40
|
-
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
end
|
45
44
|
|
46
|
-
|
47
45
|
describe 'get' do
|
48
46
|
|
49
47
|
it 'gets a merchant plan' do
|
50
48
|
|
51
|
-
|
52
49
|
#creates a plan
|
53
50
|
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
54
51
|
plan=@plans.create(plan_hash)
|
55
52
|
|
56
|
-
|
57
53
|
#validates
|
58
54
|
expect(@plans.get(plan['id'])['repeat_every']).to be 5
|
59
55
|
expect(@plans.get(plan['id'])['amount']).to be_within(0.1).of(500)
|
60
56
|
|
61
|
-
|
62
57
|
#clean
|
63
58
|
@plans.delete(plan['id'])
|
64
59
|
|
65
60
|
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
begin
|
76
|
-
@plans.get('111111')
|
77
|
-
rescue OpenpayTransactionException => e
|
78
|
-
|
79
|
-
expect(e.description).to match 'The requested resource doesn\'t exist.'
|
62
|
+
it 'fails to get a non existing customer plan' do
|
63
|
+
#validates
|
64
|
+
expect { @plans.get('111111') }.to raise_exception OpenpayTransactionException
|
65
|
+
begin
|
66
|
+
@plans.get('111111')
|
67
|
+
rescue OpenpayTransactionException => e
|
68
|
+
expect(e.description).to match 'The requested resource doesn\'t exist'
|
69
|
+
end
|
80
70
|
|
81
71
|
end
|
82
72
|
|
83
73
|
end
|
84
74
|
|
85
|
-
|
86
75
|
describe '.all' do
|
87
|
-
|
88
76
|
it 'returns all customer plans' do
|
89
|
-
|
90
77
|
expect(@plans.all.size).to be_a Integer
|
78
|
+
end
|
79
|
+
end
|
91
80
|
|
81
|
+
describe '.list' do
|
82
|
+
it 'list all plans given the filter' do
|
83
|
+
#creates a plan
|
84
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
85
|
+
plan=@plans.create(plan_hash)
|
86
|
+
|
87
|
+
search_params = OpenpayUtils::SearchParams.new
|
88
|
+
search_params.limit = 1
|
89
|
+
expect(@plans.list(search_params).size).to eq 1
|
90
|
+
|
91
|
+
#clean
|
92
|
+
@plans.delete(plan['id'])
|
92
93
|
end
|
93
94
|
|
94
95
|
end
|
95
96
|
|
96
|
-
|
97
97
|
describe '.update' do
|
98
98
|
|
99
|
-
|
100
99
|
it 'updates an existing customer plan' do
|
101
|
-
|
102
100
|
#creates a plan
|
103
101
|
plan_hash= FactoryGirl.build(:plan, trial_days: 10)
|
104
102
|
plan=@plans.create(plan_hash)
|
105
103
|
|
106
104
|
expect(plan['trial_days']).to be 10
|
107
|
-
|
108
|
-
|
109
105
|
plan_hash= FactoryGirl.build(:plan, trial_days: 100)
|
110
|
-
|
111
106
|
plan=@plans.update(plan_hash, plan['id'])
|
112
|
-
|
113
107
|
expect(plan['trial_days']).to be 100
|
114
108
|
|
115
109
|
#cleanup
|
116
110
|
@plans.delete(plan['id'])
|
117
|
-
|
118
111
|
end
|
119
112
|
|
120
|
-
|
121
113
|
it 'fails to update an non existing customer plan' do
|
122
114
|
|
123
115
|
plan_hash= FactoryGirl.build(:plan, trial_days: 100)
|
@@ -127,18 +119,14 @@ describe Plans do
|
|
127
119
|
begin
|
128
120
|
@plans.update(plan_hash, '111111')
|
129
121
|
rescue RestClient::ResourceNotFound => e
|
130
|
-
|
131
122
|
expect(e.http_body).to be_a String
|
132
123
|
expect(e.message).to match '404 Resource Not Found'
|
133
|
-
|
134
124
|
end
|
135
125
|
|
136
126
|
end
|
137
127
|
|
138
|
-
|
139
128
|
end
|
140
129
|
|
141
|
-
|
142
130
|
describe '.each' do
|
143
131
|
|
144
132
|
it 'iterates over all customer plans' do
|
@@ -149,27 +137,16 @@ describe Plans do
|
|
149
137
|
plan1=@plans.create(plan_hash)
|
150
138
|
plan2=@plans.create(plan_hash)
|
151
139
|
|
152
|
-
|
153
140
|
expect(@plans.all.size).to be_a Integer
|
154
141
|
@plans.each do |plan|
|
155
|
-
|
156
142
|
expect(plan['name']).to match 'Curso de ingles'
|
157
143
|
@plans.delete(plan['id'])
|
158
144
|
end
|
159
145
|
|
160
146
|
expect(@plans.all.size).to be_a Integer
|
161
147
|
|
162
|
-
|
163
148
|
end
|
164
149
|
|
165
|
-
|
166
150
|
end
|
167
151
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
152
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
@@ -2,7 +2,6 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
describe Subscriptions do
|
4
4
|
|
5
|
-
|
6
5
|
before(:all) do
|
7
6
|
|
8
7
|
@merchant_id='mywvupjjs9xdnryxtplq'
|
@@ -19,59 +18,61 @@ describe Subscriptions do
|
|
19
18
|
|
20
19
|
end
|
21
20
|
|
22
|
-
|
21
|
+
it 'has all required methods' do
|
22
|
+
%w(all each create get list delete).each do |meth|
|
23
|
+
expect(@subscriptions).to respond_to(meth)
|
24
|
+
end
|
25
|
+
end
|
23
26
|
|
24
27
|
describe '.create' do
|
25
28
|
|
26
29
|
it 'creates a subscription' do
|
27
30
|
|
28
31
|
#creates a customer
|
29
|
-
customer_hash=
|
32
|
+
customer_hash=FactoryGirl.build(:customer)
|
30
33
|
customer=@customers.create(customer_hash)
|
31
34
|
|
32
|
-
#creates a customer
|
33
|
-
card_hash=
|
35
|
+
#creates a customer card
|
36
|
+
card_hash=FactoryGirl.build(:valid_card)
|
34
37
|
card=@cards.create(card_hash, customer['id'])
|
35
38
|
|
36
39
|
#creates a plan
|
37
|
-
plan_hash=
|
40
|
+
plan_hash=FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
38
41
|
plan=@plans.create(plan_hash)
|
39
42
|
|
40
43
|
#creates subscription
|
41
|
-
subscription_hash=
|
44
|
+
subscription_hash=FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
42
45
|
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
43
46
|
|
44
47
|
#performs check
|
45
48
|
saved_subscription=@subscriptions.get(subscription['id'], customer['id'])
|
46
|
-
expect(saved_subscription['plan_id']).to
|
49
|
+
expect(saved_subscription['plan_id']).to eq(plan['id'])
|
47
50
|
|
48
51
|
#cleanup
|
49
52
|
@subscriptions.delete(subscription['id'], customer['id'])
|
50
53
|
|
51
54
|
end
|
52
55
|
|
53
|
-
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
58
|
describe '.get' do
|
58
59
|
|
59
60
|
it 'gets customer subscriptions' do
|
60
61
|
|
61
62
|
#creates a customer
|
62
|
-
customer_hash=
|
63
|
+
customer_hash=FactoryGirl.build(:customer)
|
63
64
|
customer=@customers.create(customer_hash)
|
64
65
|
|
65
66
|
#creates a customer card
|
66
|
-
card_hash=
|
67
|
+
card_hash=FactoryGirl.build(:valid_card)
|
67
68
|
card=@cards.create(card_hash, customer['id'])
|
68
69
|
|
69
70
|
#creates a plan
|
70
|
-
plan_hash=
|
71
|
+
plan_hash=FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
71
72
|
plan=@plans.create(plan_hash)
|
72
73
|
|
73
74
|
#creates subscription
|
74
|
-
subscription_hash=
|
75
|
+
subscription_hash=FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
75
76
|
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
76
77
|
|
77
78
|
#get customer subscription
|
@@ -87,6 +88,43 @@ describe Subscriptions do
|
|
87
88
|
|
88
89
|
end
|
89
90
|
|
91
|
+
describe '.update' do
|
92
|
+
|
93
|
+
it 'updates customer subscription' do
|
94
|
+
|
95
|
+
#creates a customer
|
96
|
+
customer_hash=FactoryGirl.build(:customer)
|
97
|
+
customer=@customers.create(customer_hash)
|
98
|
+
|
99
|
+
#creates a customer card
|
100
|
+
card_hash=FactoryGirl.build(:valid_card)
|
101
|
+
card=@cards.create(card_hash, customer['id'])
|
102
|
+
|
103
|
+
#creates a plan
|
104
|
+
plan_hash=FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
105
|
+
plan=@plans.create(plan_hash)
|
106
|
+
|
107
|
+
#creates subscription
|
108
|
+
subscription_hash=FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
109
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
110
|
+
|
111
|
+
#get customer subscription
|
112
|
+
stored_s=@subscriptions.get(subscription['id'], customer['id'])
|
113
|
+
|
114
|
+
#performs check
|
115
|
+
expect(stored_s['status']).to match 'trial'
|
116
|
+
|
117
|
+
subscription_update_hash={ trial_end_date: "2016-01-12" }
|
118
|
+
|
119
|
+
stored_s=@subscriptions.update(subscription['id'], customer['id'], subscription_update_hash)
|
120
|
+
expect(stored_s['trial_end_date']).to eq "2016-01-12"
|
121
|
+
|
122
|
+
#cleanup
|
123
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
90
128
|
|
91
129
|
describe '.all' do
|
92
130
|
|
@@ -119,7 +157,41 @@ describe Subscriptions do
|
|
119
157
|
|
120
158
|
end
|
121
159
|
|
160
|
+
describe '.list' do
|
161
|
+
|
162
|
+
it 'list subscriptions based on given filter' do
|
163
|
+
#creates a customer
|
164
|
+
customer_hash= FactoryGirl.build(:customer)
|
165
|
+
customer=@customers.create(customer_hash)
|
166
|
+
|
167
|
+
#creates a customer card
|
168
|
+
card_hash= FactoryGirl.build(:valid_card)
|
169
|
+
card=@cards.create(card_hash, customer['id'])
|
170
|
+
|
171
|
+
#creates a plan
|
172
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
173
|
+
plan=@plans.create(plan_hash)
|
174
|
+
|
175
|
+
#creates subscription
|
176
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
177
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
178
|
+
subscription1=@subscriptions.create(subscription_hash, customer['id'])
|
179
|
+
subscription2=@subscriptions.create(subscription_hash, customer['id'])
|
180
|
+
|
181
|
+
#performs check
|
182
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
183
|
+
|
184
|
+
search_params = OpenpayUtils::SearchParams.new
|
185
|
+
search_params.limit = 1
|
186
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
187
|
+
expect(@subscriptions.list(search_params, customer['id']).size).to be 1
|
188
|
+
|
189
|
+
#cleanup
|
190
|
+
@subscriptions.delete(subscription1['id'], customer['id'])
|
191
|
+
@subscriptions.delete(subscription2['id'], customer['id'])
|
192
|
+
end
|
122
193
|
|
194
|
+
end
|
123
195
|
|
124
196
|
describe '.each' do
|
125
197
|
|
@@ -154,7 +226,6 @@ describe Subscriptions do
|
|
154
226
|
|
155
227
|
end
|
156
228
|
|
157
|
-
|
158
229
|
describe '.delete' do
|
159
230
|
|
160
231
|
it 'deletes an existing subscription for a given customer' do
|
@@ -186,7 +257,6 @@ describe Subscriptions do
|
|
186
257
|
|
187
258
|
end
|
188
259
|
|
189
|
-
|
190
260
|
describe '.delete_all' do
|
191
261
|
|
192
262
|
it 'deletes all existing subscription for a given customer' do
|
@@ -195,7 +265,7 @@ describe Subscriptions do
|
|
195
265
|
customer_hash= FactoryGirl.build(:customer)
|
196
266
|
customer=@customers.create(customer_hash)
|
197
267
|
|
198
|
-
#creates a customer
|
268
|
+
#creates a customer card
|
199
269
|
card_hash= FactoryGirl.build(:valid_card)
|
200
270
|
card=@cards.create(card_hash, customer['id'])
|
201
271
|
|
@@ -219,10 +289,3 @@ describe Subscriptions do
|
|
219
289
|
end
|
220
290
|
|
221
291
|
end
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
data/test/spec/transfers_spec.rb
CHANGED
@@ -16,15 +16,18 @@ describe Transfers do
|
|
16
16
|
@bank_accounts=@openpay.create(:bankaccounts)
|
17
17
|
@transfers=@openpay.create(:transfers)
|
18
18
|
|
19
|
+
end
|
19
20
|
|
21
|
+
it 'has all required methods' do
|
22
|
+
%w(all each create get list delete).each do |meth|
|
23
|
+
expect(@bank_accounts).to respond_to(meth)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
describe '.create' do
|
23
28
|
|
24
|
-
|
25
29
|
it 'transfers money from customer to customer' do
|
26
30
|
|
27
|
-
|
28
31
|
#create new customer
|
29
32
|
customer_hash= FactoryGirl.build(:customer)
|
30
33
|
customer=@customers.create(customer_hash)
|
@@ -37,8 +40,6 @@ describe Transfers do
|
|
37
40
|
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
38
41
|
charge=@charges.create(charge_hash,customer['id'])
|
39
42
|
|
40
|
-
|
41
|
-
|
42
43
|
#create customer 2
|
43
44
|
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
44
45
|
customer2=@customers.create(customer_hash)
|
@@ -46,34 +47,18 @@ describe Transfers do
|
|
46
47
|
#create new transfer
|
47
48
|
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
48
49
|
|
49
|
-
|
50
50
|
transfer=@transfers.create(customer_hash,customer['id'])
|
51
51
|
t=@transfers.get(transfer['id'],customer['id'])
|
52
52
|
expect(t['amount']).to be_within(0.1).of 12.5
|
53
53
|
expect(t['method']).to match 'customer'
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
55
|
#clanup
|
59
56
|
@cards.delete_all(customer['id'])
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
58
|
end
|
66
59
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
60
|
end
|
72
61
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
62
|
describe 'get' do
|
78
63
|
|
79
64
|
it 'gets a customer transfer' do
|
@@ -90,8 +75,6 @@ describe Transfers do
|
|
90
75
|
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
91
76
|
charge=@charges.create(charge_hash,customer['id'])
|
92
77
|
|
93
|
-
|
94
|
-
|
95
78
|
#create customer 2
|
96
79
|
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
97
80
|
customer2=@customers.create(customer_hash)
|
@@ -99,33 +82,25 @@ describe Transfers do
|
|
99
82
|
#create new transfer
|
100
83
|
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
101
84
|
|
102
|
-
|
103
85
|
transfer=@transfers.create(customer_hash,customer['id'])
|
104
86
|
t=@transfers.get(transfer['id'],customer['id'])
|
105
87
|
expect(t).to be_a Hash
|
106
88
|
expect(t['amount']).to be_within(0.1).of 12.5
|
107
89
|
expect(t['method']).to match 'customer'
|
108
90
|
|
109
|
-
|
110
|
-
|
111
91
|
#clanup
|
112
92
|
@cards.delete_all(customer['id'])
|
113
93
|
|
114
94
|
end
|
115
95
|
|
116
|
-
|
117
|
-
|
118
96
|
it 'fails to get a non existing transfer' do
|
119
|
-
|
97
|
+
expect { @transfers.get(11111,11111) }.to raise_exception OpenpayTransactionException
|
120
98
|
end
|
121
99
|
|
122
|
-
|
123
100
|
end
|
124
101
|
|
125
|
-
|
126
102
|
describe '.each' do
|
127
103
|
|
128
|
-
|
129
104
|
it 'iterates over a given customer transfers' do
|
130
105
|
|
131
106
|
#create new customer
|
@@ -140,8 +115,6 @@ describe Transfers do
|
|
140
115
|
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
141
116
|
charge=@charges.create(charge_hash,customer['id'])
|
142
117
|
|
143
|
-
|
144
|
-
|
145
118
|
#create customer 2
|
146
119
|
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
147
120
|
customer2=@customers.create(customer_hash)
|
@@ -150,34 +123,62 @@ describe Transfers do
|
|
150
123
|
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
151
124
|
transfer=@transfers.create(customer_hash,customer['id'])
|
152
125
|
|
153
|
-
|
154
126
|
#iterates over transfers
|
155
127
|
@transfers.each(customer2['id']) do |tran|
|
156
|
-
|
157
128
|
expect(tran['amount']).to be_within(0.1).of 12.5
|
158
129
|
expect(tran['method']).to match 'customer'
|
159
|
-
|
160
130
|
end
|
161
131
|
|
162
132
|
#clanup
|
163
133
|
@cards.delete_all(customer['id'])
|
164
134
|
|
135
|
+
end
|
136
|
+
end
|
165
137
|
|
138
|
+
describe '.list' do
|
166
139
|
|
140
|
+
it 'list all transfers under the given filter' do
|
167
141
|
|
168
142
|
|
169
|
-
|
143
|
+
#create new customer
|
144
|
+
customer_hash= FactoryGirl.build(:customer)
|
145
|
+
customer=@customers.create(customer_hash)
|
170
146
|
|
147
|
+
#create new customer card
|
148
|
+
card_hash=FactoryGirl.build(:valid_card)
|
149
|
+
card=@cards.create(card_hash, customer['id'])
|
171
150
|
|
151
|
+
#create charge
|
152
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
153
|
+
charge=@charges.create(charge_hash,customer['id'])
|
172
154
|
|
173
|
-
|
155
|
+
#create customer 2
|
156
|
+
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
157
|
+
customer2=@customers.create(customer_hash)
|
174
158
|
|
159
|
+
#create new transfer
|
160
|
+
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
161
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
162
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
175
163
|
|
164
|
+
#returns all transfers
|
165
|
+
@transfers.all(customer2['id'])
|
166
|
+
expect(@transfers.all(customer2['id']).size ).to be 2
|
176
167
|
|
168
|
+
search_params = OpenpayUtils::SearchParams.new
|
169
|
+
search_params.limit = 1
|
170
|
+
expect(@transfers.list(search_params,customer['id']).size).to eq 1
|
177
171
|
|
178
172
|
|
179
|
-
|
173
|
+
#cleanup
|
174
|
+
@cards.delete_all(customer['id'])
|
175
|
+
@cards.delete_all(customer2['id'])
|
180
176
|
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '.all' do
|
181
182
|
|
182
183
|
it 'returns all customer transfers' do
|
183
184
|
|
@@ -204,7 +205,7 @@ describe Transfers do
|
|
204
205
|
|
205
206
|
|
206
207
|
#returns all transfers
|
207
|
-
|
208
|
+
@transfers.all(customer2['id'])
|
208
209
|
expect(@transfers.all(customer2['id']).size ).to be 1
|
209
210
|
|
210
211
|
#cleanup
|
@@ -212,8 +213,5 @@ describe Transfers do
|
|
212
213
|
|
213
214
|
end
|
214
215
|
|
215
|
-
|
216
216
|
end
|
217
|
-
|
218
|
-
|
219
|
-
end
|
217
|
+
end
|