openpay_copemx 3.0.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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +1984 -0
  7. data/Rakefile +16 -0
  8. data/lib/openpay/bankaccounts.rb +58 -0
  9. data/lib/openpay/cards.rb +73 -0
  10. data/lib/openpay/charges.rb +101 -0
  11. data/lib/openpay/colombia/cards_co.rb +73 -0
  12. data/lib/openpay/colombia/charges_co.rb +76 -0
  13. data/lib/openpay/colombia/customers_co.rb +166 -0
  14. data/lib/openpay/colombia/plans_co.rb +17 -0
  15. data/lib/openpay/colombia/pse_co.rb +17 -0
  16. data/lib/openpay/colombia/subscriptions_co.rb +50 -0
  17. data/lib/openpay/colombia/tokens_co.rb +5 -0
  18. data/lib/openpay/colombia/webhooks_co.rb +5 -0
  19. data/lib/openpay/customers.rb +200 -0
  20. data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
  21. data/lib/openpay/errors/openpay_exception.rb +29 -0
  22. data/lib/openpay/errors/openpay_exception_factory.rb +56 -0
  23. data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
  24. data/lib/openpay/fees.rb +5 -0
  25. data/lib/openpay/open_pay_resource.rb +295 -0
  26. data/lib/openpay/open_pay_resource_factory.rb +17 -0
  27. data/lib/openpay/openpay_api.rb +72 -0
  28. data/lib/openpay/payouts.rb +55 -0
  29. data/lib/openpay/peru/cards_pe.rb +73 -0
  30. data/lib/openpay/peru/charges_pe.rb +76 -0
  31. data/lib/openpay/peru/checkouts_pe.rb +51 -0
  32. data/lib/openpay/peru/customers_pe.rb +79 -0
  33. data/lib/openpay/peru/tokens_pe.rb +5 -0
  34. data/lib/openpay/peru/webhooks_pe.rb +5 -0
  35. data/lib/openpay/plans.rb +17 -0
  36. data/lib/openpay/points.rb +10 -0
  37. data/lib/openpay/subscriptions.rb +50 -0
  38. data/lib/openpay/tokens.rb +7 -0
  39. data/lib/openpay/transfers.rb +39 -0
  40. data/lib/openpay/utils/country.rb +3 -0
  41. data/lib/openpay/utils/search_params.rb +24 -0
  42. data/lib/openpay/webhooks.rb +9 -0
  43. data/lib/openpay.rb +55 -0
  44. data/lib/version.rb +3 -0
  45. data/openpay.gemspec +30 -0
  46. data/test/Factories.rb +524 -0
  47. data/test/spec/bankaccounts_spec.rb +52 -0
  48. data/test/spec/cards_spec.rb +437 -0
  49. data/test/spec/charges_spec.rb +382 -0
  50. data/test/spec/colombia/cards_col_spec.rb +364 -0
  51. data/test/spec/colombia/charges_col_spec.rb +258 -0
  52. data/test/spec/colombia/customers_co_spec.rb +151 -0
  53. data/test/spec/colombia/plans_col_spec.rb +133 -0
  54. data/test/spec/colombia/pse_col_spec.rb +49 -0
  55. data/test/spec/colombia/subscriptions_col_spec.rb +230 -0
  56. data/test/spec/colombia/tokens_col_spec.rb +38 -0
  57. data/test/spec/customers_spec.rb +172 -0
  58. data/test/spec/exceptions_spec.rb +105 -0
  59. data/test/spec/fees_spec.rb +166 -0
  60. data/test/spec/openpayresource_spec.rb +54 -0
  61. data/test/spec/payouts_spec.rb +231 -0
  62. data/test/spec/peru/cards_pe_spec.rb +363 -0
  63. data/test/spec/peru/charges_pe_spec.rb +218 -0
  64. data/test/spec/peru/checkouts_pe_spec.rb +71 -0
  65. data/test/spec/peru/customers_pe_spec.rb +151 -0
  66. data/test/spec/peru/tokens_pe_spec.rb +38 -0
  67. data/test/spec/peru/webhook_pe_spec.rb +50 -0
  68. data/test/spec/plans_spec.rb +158 -0
  69. data/test/spec/points_spec.rb +26 -0
  70. data/test/spec/requesttimeout_spec.rb +22 -0
  71. data/test/spec/subscriptions_spec.rb +294 -0
  72. data/test/spec/transfers_spec.rb +219 -0
  73. data/test/spec/utils/search_params_spec.rb +36 -0
  74. data/test/spec_helper.rb +24 -0
  75. metadata +219 -0
@@ -0,0 +1,26 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'Points' do
4
+
5
+ before(:all) do
6
+
7
+ @merchant_id='mhbzmkji20dhu9kq3r2i'
8
+ @private_key='sk_0070ce5a12d948e0a0c9b5b8b7ff51ae'
9
+
10
+ @openpay=OpenpayApi.new(@merchant_id,@private_key,"mx")
11
+ @points=@openpay.create(:points)
12
+
13
+ end
14
+
15
+ after(:all) do
16
+
17
+ end
18
+
19
+ describe '.get' do
20
+ it 'Card Points ' do
21
+ point=@points.getPointsBalance('ka2fi3h6ikppavewn5ne')
22
+ puts point.to_s
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../spec_helper'
2
+
3
+
4
+ describe 'Request timeout exception' do
5
+
6
+ before(:all) do
7
+
8
+ @merchant_id='mywvupjjs9xdnryxtplq'
9
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
10
+
11
+ #LOG.level=Logger::DEBUG
12
+
13
+ @openpay=OpenpayApi.new(@merchant_id, @private_key, false, 0,"mx")
14
+ @charges=@openpay.create(:charges)
15
+
16
+ end
17
+
18
+ it 'raise an OpenpayConnectionException when the operation timeouts' do
19
+ expect{@charges.all}.to raise_error(OpenpayConnectionException)
20
+ end
21
+
22
+ end
@@ -0,0 +1,294 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Subscriptions do
4
+
5
+ before(:all) do
6
+
7
+ @merchant_id='mywvupjjs9xdnryxtplq'
8
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
9
+
10
+ #LOG.level=Logger::DEBUG
11
+
12
+ @openpay=OpenpayApi.new(@merchant_id, @private_key,"mx")
13
+ @customers=@openpay.create(:customers)
14
+ @cards=@openpay.create(:cards)
15
+ @charges=@openpay.create(:charges)
16
+
17
+ @plans=@openpay.create(:plans)
18
+
19
+ @subscriptions=@openpay.create(:subscriptions)
20
+
21
+ end
22
+
23
+ it 'has all required methods' do
24
+ %w(all each create get list delete).each do |meth|
25
+ expect(@subscriptions).to respond_to(meth)
26
+ end
27
+ end
28
+
29
+ describe '.create' do
30
+
31
+ it 'creates a subscription' do
32
+
33
+ #creates a customer
34
+ customer_hash=FactoryBot.build(:customer)
35
+ customer=@customers.create(customer_hash)
36
+
37
+ #creates a customer card
38
+ card_hash=FactoryBot.build(:valid_card)
39
+ card=@cards.create(card_hash, customer['id'])
40
+
41
+ #creates a plan
42
+ plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
43
+ plan=@plans.create(plan_hash)
44
+
45
+ #creates subscription
46
+ subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
47
+ subscription=@subscriptions.create(subscription_hash, customer['id'])
48
+
49
+ #performs check
50
+ saved_subscription=@subscriptions.get(subscription['id'], customer['id'])
51
+ expect(saved_subscription['plan_id']).to eq(plan['id'])
52
+
53
+ #cleanup
54
+ @subscriptions.delete(subscription['id'], customer['id'])
55
+
56
+ end
57
+
58
+ end
59
+
60
+ describe '.get' do
61
+
62
+ it 'gets customer subscriptions' do
63
+
64
+ #creates a customer
65
+ customer_hash=FactoryBot.build(:customer)
66
+ customer=@customers.create(customer_hash)
67
+
68
+ #creates a customer card
69
+ card_hash=FactoryBot.build(:valid_card)
70
+ card=@cards.create(card_hash, customer['id'])
71
+
72
+ #creates a plan
73
+ plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
74
+ plan=@plans.create(plan_hash)
75
+
76
+ #creates subscription
77
+ subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
78
+ subscription=@subscriptions.create(subscription_hash, customer['id'])
79
+
80
+ #get customer subscription
81
+ stored_s=@subscriptions.get(subscription['id'], customer['id'])
82
+
83
+ #performs check
84
+ expect(stored_s['status']).to match 'trial'
85
+
86
+ #cleanup
87
+ @subscriptions.delete(subscription['id'], customer['id'])
88
+
89
+ end
90
+
91
+ end
92
+
93
+ describe '.update' do
94
+
95
+ it 'updates customer subscription' do
96
+
97
+ time = Time.now + (60*60*24*2);
98
+ time = time.strftime("%Y-%m-%d")
99
+ #creates a customer
100
+ customer_hash=FactoryBot.build(:customer)
101
+ customer=@customers.create(customer_hash)
102
+
103
+ #creates a customer card
104
+ card_hash=FactoryBot.build(:valid_card)
105
+ card=@cards.create(card_hash, customer['id'])
106
+
107
+ #creates a plan
108
+ plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
109
+ plan=@plans.create(plan_hash)
110
+
111
+ #creates subscription
112
+ subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
113
+ subscription=@subscriptions.create(subscription_hash, customer['id'])
114
+
115
+ #get customer subscription
116
+ stored_s=@subscriptions.get(subscription['id'], customer['id'])
117
+
118
+ #performs check
119
+ expect(stored_s['status']).to match 'trial'
120
+ subscription_update_hash={ trial_end_date: time }
121
+ sleep(20)
122
+ stored_s=@subscriptions.update(subscription['id'], customer['id'], subscription_update_hash)
123
+ expect(stored_s['trial_end_date']).to eq time
124
+
125
+ #cleanup
126
+ @subscriptions.delete(subscription['id'], customer['id'])
127
+
128
+ end
129
+
130
+ end
131
+
132
+ describe '.all' do
133
+
134
+ it 'returns all subscriptions for a given customer' do
135
+
136
+ #creates a customer
137
+ customer_hash= FactoryBot.build(:customer)
138
+ customer=@customers.create(customer_hash)
139
+
140
+ #creates a customer card
141
+ card_hash= FactoryBot.build(:valid_card)
142
+ card=@cards.create(card_hash, customer['id'])
143
+
144
+ #creates a plan
145
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
146
+ plan=@plans.create(plan_hash)
147
+
148
+ #creates subscription
149
+ subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
150
+ expect(@subscriptions.all(customer['id']).size).to be 0
151
+ subscription=@subscriptions.create(subscription_hash, customer['id'])
152
+
153
+ #performs check
154
+ expect(@subscriptions.all(customer['id']).size).to be 1
155
+
156
+ #cleanup
157
+ @subscriptions.delete(subscription['id'], customer['id'])
158
+
159
+ end
160
+
161
+ end
162
+
163
+ describe '.list' do
164
+
165
+ it 'list subscriptions based on given filter' do
166
+ #creates a customer
167
+ customer_hash= FactoryBot.build(:customer)
168
+ customer=@customers.create(customer_hash)
169
+
170
+ #creates a customer card
171
+ card_hash= FactoryBot.build(:valid_card)
172
+ card=@cards.create(card_hash, customer['id'])
173
+
174
+ #creates a plan
175
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
176
+ plan=@plans.create(plan_hash)
177
+
178
+ #creates subscription
179
+ subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
180
+ expect(@subscriptions.all(customer['id']).size).to be 0
181
+ subscription1=@subscriptions.create(subscription_hash, customer['id'])
182
+ subscription2=@subscriptions.create(subscription_hash, customer['id'])
183
+
184
+ #performs check
185
+ expect(@subscriptions.all(customer['id']).size).to be 2
186
+
187
+ search_params = OpenpayUtils::SearchParams.new
188
+ search_params.limit = 1
189
+ expect(@subscriptions.all(customer['id']).size).to be 2
190
+ expect(@subscriptions.list(search_params, customer['id']).size).to be 1
191
+
192
+ #cleanup
193
+ @subscriptions.delete(subscription1['id'], customer['id'])
194
+ @subscriptions.delete(subscription2['id'], customer['id'])
195
+ end
196
+
197
+ end
198
+
199
+ describe '.each' do
200
+
201
+ it 'iterates over all subscriptions for a given customer' do
202
+
203
+ #creates a customer
204
+ customer_hash= FactoryBot.build(:customer)
205
+ customer=@customers.create(customer_hash)
206
+
207
+ #creates a customer card
208
+ card_hash= FactoryBot.build(:valid_card)
209
+ card=@cards.create(card_hash, customer['id'])
210
+
211
+ #creates a plan
212
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
213
+ plan=@plans.create(plan_hash)
214
+
215
+ #creates subscription
216
+ subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
217
+ expect(@subscriptions.all(customer['id']).size).to be 0
218
+ @subscriptions.create(subscription_hash, customer['id'])
219
+
220
+ #performs check
221
+ @subscriptions.each(customer['id']) do |stored_s|
222
+ #check and clean
223
+ expect(stored_s['status']).to match 'trial'
224
+ @subscriptions.delete(stored_s['id'],customer['id'])
225
+ end
226
+ expect(@subscriptions.all(customer['id']).size).to be 0
227
+
228
+ end
229
+
230
+ end
231
+
232
+ describe '.delete' do
233
+
234
+ it 'deletes an existing subscription for a given customer' do
235
+
236
+ #creates a customer
237
+ customer_hash= FactoryBot.build(:customer)
238
+ customer=@customers.create(customer_hash)
239
+
240
+ #creates a customer card
241
+ card_hash= FactoryBot.build(:valid_card)
242
+ card=@cards.create(card_hash, customer['id'])
243
+
244
+ #creates a plan
245
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
246
+ plan=@plans.create(plan_hash)
247
+
248
+ #creates subscription
249
+ subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
250
+ expect(@subscriptions.all(customer['id']).size).to be 0
251
+ subscription=@subscriptions.create(subscription_hash, customer['id'])
252
+
253
+ #performs check
254
+ expect(@subscriptions.all(customer['id']).size).to be 1
255
+
256
+ #cleanup
257
+ @subscriptions.delete(subscription['id'], customer['id'])
258
+
259
+ end
260
+
261
+ end
262
+
263
+ describe '.delete_all' do
264
+
265
+ it 'deletes all existing subscription for a given customer' do
266
+
267
+ #creates a customer
268
+ customer_hash= FactoryBot.build(:customer)
269
+ customer=@customers.create(customer_hash)
270
+
271
+ #creates a customer card
272
+ card_hash= FactoryBot.build(:valid_card)
273
+ card=@cards.create(card_hash, customer['id'])
274
+
275
+ #creates a plan
276
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
277
+ plan=@plans.create(plan_hash)
278
+
279
+ #creates subscriptions
280
+ subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
281
+ expect(@subscriptions.all(customer['id']).size).to be 0
282
+ @subscriptions.create(subscription_hash, customer['id'])
283
+ @subscriptions.create(subscription_hash, customer['id'])
284
+
285
+ #perform check and clean up
286
+ expect(@subscriptions.all(customer['id']).size).to be 2
287
+ @subscriptions.delete_all(customer['id'])
288
+ expect(@subscriptions.all(customer['id']).size).to be 0
289
+
290
+ end
291
+
292
+ end
293
+
294
+ end
@@ -0,0 +1,219 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Transfers do
4
+
5
+ before(:all) do
6
+
7
+ @merchant_id = 'mywvupjjs9xdnryxtplq'
8
+ @private_key = 'sk_92b25d3baec149e6b428d81abfe37006'
9
+
10
+ #LOG.level=Logger::DEBUG
11
+
12
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "mx")
13
+ @customers = @openpay.create(:customers)
14
+ @cards = @openpay.create(:cards)
15
+ @charges = @openpay.create(:charges)
16
+
17
+ @bank_accounts = @openpay.create(:bankaccounts)
18
+ @transfers = @openpay.create(:transfers)
19
+
20
+ end
21
+
22
+ it 'has all required methods' do
23
+ %w(all each create get list delete).each do |meth|
24
+ expect(@bank_accounts).to respond_to(meth)
25
+ end
26
+ end
27
+
28
+ describe '.create' do
29
+
30
+ it 'transfers money from customer to customer' do
31
+
32
+ #create new customer
33
+ customer_hash = FactoryBot.build(:customer)
34
+ customer = @customers.create(customer_hash)
35
+ #create new customer card
36
+ card_hash = FactoryBot.build(:valid_card)
37
+ card = @cards.create(card_hash, customer['id'])
38
+
39
+ #create charge
40
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
41
+ charge = @charges.create(charge_hash, customer['id'])
42
+
43
+ #create customer 2
44
+ customer_hash = FactoryBot.build(:customer, name: 'Alejandro')
45
+ customer2 = @customers.create(customer_hash)
46
+
47
+ sleep(50)
48
+ #create new transfer
49
+ customer_hash = FactoryBot.build(:transfer, customer_id: customer2['id'])
50
+ transfer = @transfers.create(customer_hash, customer['id'])
51
+ t = @transfers.get(transfer['id'], customer['id'])
52
+
53
+ expect(t['amount']).to be_within(0.1).of 12.5
54
+ expect(t['method']).to match 'customer'
55
+
56
+ #clanup
57
+ @cards.delete_all(customer['id'])
58
+
59
+ end
60
+
61
+ end
62
+
63
+ describe 'get' do
64
+
65
+ it 'gets a customer transfer' do
66
+
67
+ #create new customer
68
+ customer_hash = FactoryBot.build(:customer)
69
+ customer = @customers.create(customer_hash)
70
+
71
+ #create new customer card
72
+ card_hash = FactoryBot.build(:valid_card)
73
+ card = @cards.create(card_hash, customer['id'])
74
+
75
+ #create charge
76
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
77
+ charge = @charges.create(charge_hash, customer['id'])
78
+
79
+ #create customer 2
80
+ customer_hash = FactoryBot.build(:customer, name: 'Alejandro')
81
+ customer2 = @customers.create(customer_hash)
82
+
83
+ sleep(50)
84
+ #create new transfer
85
+ customer_hash = FactoryBot.build(:transfer, customer_id: customer2['id'])
86
+
87
+ transfer = @transfers.create(customer_hash, customer['id'])
88
+ t = @transfers.get(transfer['id'], customer['id'])
89
+ expect(t).to be_a Hash
90
+ expect(t['amount']).to be_within(0.1).of 12.5
91
+ expect(t['method']).to match 'customer'
92
+
93
+ #clanup
94
+ @cards.delete_all(customer['id'])
95
+
96
+ end
97
+
98
+ it 'fails to get a non existing transfer' do
99
+ expect { @transfers.get(11111, 11111) }.to raise_exception OpenpayTransactionException
100
+ end
101
+
102
+ end
103
+ describe '.each' do
104
+
105
+ it 'iterates over a given customer transfers' do
106
+
107
+ #create new customer
108
+ customer_hash = FactoryBot.build(:customer)
109
+ customer = @customers.create(customer_hash)
110
+
111
+ #create new customer card
112
+ card_hash = FactoryBot.build(:valid_card)
113
+ card = @cards.create(card_hash, customer['id'])
114
+
115
+ #create charge
116
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
117
+ charge = @charges.create(charge_hash, customer['id'])
118
+
119
+ #create customer 2
120
+ customer_hash = FactoryBot.build(:customer, name: 'Alejandro')
121
+ customer2 = @customers.create(customer_hash)
122
+
123
+ sleep(50)
124
+ #create new transfer
125
+ customer_hash = FactoryBot.build(:transfer, customer_id: customer2['id'])
126
+ transfer = @transfers.create(customer_hash, customer['id'])
127
+
128
+ #iterates over transfers
129
+ @transfers.each(customer2['id']) do |tran|
130
+ expect(tran['amount']).to be_within(0.1).of 12.5
131
+ expect(tran['method']).to match 'customer'
132
+ end
133
+
134
+ #clanup
135
+ @cards.delete_all(customer['id'])
136
+
137
+ end
138
+ end
139
+
140
+ describe '.list' do
141
+
142
+ it 'list all transfers under the given filter' do
143
+
144
+ #create new customer
145
+ customer_hash = FactoryBot.build(:customer)
146
+ customer = @customers.create(customer_hash)
147
+
148
+ #create new customer card
149
+ card_hash = FactoryBot.build(:valid_card)
150
+ card = @cards.create(card_hash, customer['id'])
151
+
152
+ #create charge
153
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
154
+ charge = @charges.create(charge_hash, customer['id'])
155
+
156
+ #create customer 2
157
+ customer_hash = FactoryBot.build(:customer, name: 'Alejandro')
158
+ customer2 = @customers.create(customer_hash)
159
+
160
+ sleep(50)
161
+ #create new transfer
162
+ customer_hash = FactoryBot.build(:transfer, customer_id: customer2['id'])
163
+ transfer = @transfers.create(customer_hash, customer['id'])
164
+ transfer = @transfers.create(customer_hash, customer['id'])
165
+
166
+ #returns all transfers
167
+ @transfers.all(customer2['id'])
168
+ expect(@transfers.all(customer2['id']).size).to be 2
169
+
170
+ search_params = OpenpayUtils::SearchParams.new
171
+ search_params.limit = 1
172
+ expect(@transfers.list(search_params, customer['id']).size).to eq 1
173
+
174
+ #cleanup
175
+ @cards.delete_all(customer['id'])
176
+ @cards.delete_all(customer2['id'])
177
+
178
+ end
179
+
180
+ end
181
+
182
+ describe '.all' do
183
+
184
+ it 'returns all customer transfers' do
185
+
186
+ #create new customer
187
+ customer_hash = FactoryBot.build(:customer)
188
+ customer = @customers.create(customer_hash)
189
+
190
+ #create new customer card
191
+ card_hash = FactoryBot.build(:valid_card)
192
+ card = @cards.create(card_hash, customer['id'])
193
+
194
+ #create charge
195
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
196
+ charge = @charges.create(charge_hash, customer['id'])
197
+
198
+ #create customer 2
199
+ customer_hash = FactoryBot.build(:customer, name: 'Alejandro')
200
+ customer2 = @customers.create(customer_hash)
201
+
202
+ sleep(50)
203
+
204
+ #create new transfer
205
+ customer_hash = FactoryBot.build(:transfer, customer_id: customer2['id'])
206
+ transfer = @transfers.create(customer_hash, customer['id'])
207
+
208
+ #returns all transfers
209
+ @transfers.all(customer2['id'])
210
+ expect(@transfers.all(customer2['id']).size).to be 1
211
+
212
+ #cleanup
213
+ @cards.delete_all(customer['id'])
214
+
215
+ end
216
+
217
+ end
218
+
219
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../../spec_helper'
2
+ include OpenpayUtils
3
+
4
+ describe OpenpayUtils do
5
+
6
+ describe SearchParams do
7
+
8
+ subject(:search_params) { SearchParams.new }
9
+
10
+ describe 'setters and getters' do
11
+
12
+ it 'sets and gets a given value' do
13
+ val = "val"
14
+ search_params.val = val
15
+ expect(search_params.val).to eq(val)
16
+ end
17
+
18
+ it 'sets and gets a non existing attribute' do
19
+ expect(search_params.val).to eq(nil)
20
+ end
21
+ end
22
+
23
+ describe '.to_s' do
24
+ it 'generates the filter string based on the attributes' do
25
+ creation_date = "2013-11-01"
26
+ search_params.creation_gte = creation_date
27
+ limit = 2
28
+ search_params.limit = limit
29
+ amount = 100
30
+ search_params.amount_lte = amount
31
+ expect(search_params.to_s).to eq("?creation%5Bgte%5D=2013-11-01&limit=2&amount%5Blte%5D=100")
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,24 @@
1
+ $: << '.'
2
+ $: << 'lib'
3
+ $: << 'lib/openpay'
4
+
5
+ require 'openpay'
6
+ require 'factory_bot'
7
+ #uncomment below to test on travis-ci
8
+ # FactoryBot.find_definitions
9
+ require 'Factories'
10
+ require 'rspec'
11
+ require 'json_spec'
12
+
13
+ RSpec.configure do |config|
14
+ config.include FactoryBot::Syntax::Methods
15
+
16
+ #uncomment below to test on local
17
+ #config.before(:suite) {FactoryBot.reload}
18
+
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ config.include JsonSpec::Helpers
22
+ end
23
+
24
+ end