openpay 0.9.8

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.idea/.name +1 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/OpenPay.iml +614 -0
  6. data/.idea/dictionaries/ronnie.xml +7 -0
  7. data/.idea/encodings.xml +5 -0
  8. data/.idea/misc.xml +5 -0
  9. data/.idea/modules.xml +9 -0
  10. data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +37 -0
  11. data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +37 -0
  12. data/.idea/runConfigurations/all_specs.xml +41 -0
  13. data/.idea/scopes/scope_settings.xml +5 -0
  14. data/.idea/vcs.xml +7 -0
  15. data/Gemfile +11 -0
  16. data/LICENSE.txt +13 -0
  17. data/OpenPay.gemspec +24 -0
  18. data/README.md +370 -0
  19. data/Rakefile +1 -0
  20. data/lib/OpenPay/Cards.rb +76 -0
  21. data/lib/OpenPay/Charges.rb +79 -0
  22. data/lib/OpenPay/Customers.rb +195 -0
  23. data/lib/OpenPay/Fees.rb +5 -0
  24. data/lib/OpenPay/Payouts.rb +59 -0
  25. data/lib/OpenPay/Plans.rb +28 -0
  26. data/lib/OpenPay/Subscriptions.rb +58 -0
  27. data/lib/OpenPay/Transfers.rb +43 -0
  28. data/lib/OpenPay/bankaccounts.rb +66 -0
  29. data/lib/OpenPay/errors/open_pay_exception.rb +51 -0
  30. data/lib/OpenPay/errors/open_pay_exception_factory.rb +58 -0
  31. data/lib/OpenPay/errors/openpay_connection_exception.rb +3 -0
  32. data/lib/OpenPay/errors/openpay_transaction_exception.rb +5 -0
  33. data/lib/OpenPay/open_pay_resource.rb +242 -0
  34. data/lib/OpenPay/open_pay_resource_factory.rb +10 -0
  35. data/lib/OpenPay/openpay_api.rb +63 -0
  36. data/lib/OpenPay/version.rb +3 -0
  37. data/lib/openpay.rb +34 -0
  38. data/test/Factories.rb +258 -0
  39. data/test/spec/bankaccounts_spec.rb +187 -0
  40. data/test/spec/cards_spec.rb +411 -0
  41. data/test/spec/charges_spec.rb +377 -0
  42. data/test/spec/customers_spec.rb +230 -0
  43. data/test/spec/exceptions_spec.rb +138 -0
  44. data/test/spec/fees_spec.rb +113 -0
  45. data/test/spec/openpayresource_spec.rb +52 -0
  46. data/test/spec/payouts_spec.rb +197 -0
  47. data/test/spec/plans_spec.rb +229 -0
  48. data/test/spec/subscriptions_spec.rb +228 -0
  49. data/test/spec/transfers_spec.rb +221 -0
  50. data/test/spec_helper.rb +16 -0
  51. metadata +135 -0
@@ -0,0 +1,411 @@
1
+ require '../spec_helper'
2
+
3
+
4
+ describe Cards do
5
+
6
+
7
+ before(:all) do
8
+
9
+ @merchant_id='mywvupjjs9xdnryxtplq'
10
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
11
+
12
+ @openpay=OpenpayApi.new(@merchant_id, @private_key)
13
+ @cards=@openpay.create(:cards)
14
+ @customers=@openpay.create(:customers)
15
+
16
+ end
17
+
18
+ after(:all) do
19
+ #each test should build and clean it's own mess.
20
+ end
21
+
22
+
23
+ describe '.create' do
24
+
25
+ it 'creates merchant card' do
26
+
27
+ #creates merchant card
28
+ card_hash = FactoryGirl.build(:valid_card)
29
+ cards=@cards.create(card_hash)
30
+ expect(cards).to be_a(Hash)
31
+
32
+ id=cards['id']
33
+ name='Vicente Olmos'
34
+
35
+ #perform check
36
+ card=@cards.get(id)
37
+ expect(card['holder_name']).to match(name)
38
+ expect(card['card_number']).to match('1111')
39
+
40
+ #cleanup
41
+ @cards.delete(card['id'])
42
+
43
+
44
+ end
45
+
46
+
47
+ it 'creates a customer card' do
48
+
49
+ #creates a customer
50
+ card_hash = FactoryGirl.build(:valid_card, holder_name: 'Pepe')
51
+ customers=@openpay.create(:customers)
52
+ customer_hash = FactoryGirl.build(:customer)
53
+ customer=customers.create(customer_hash)
54
+
55
+ #creates a customer card
56
+ cards=@cards.create(card_hash, customer['id'])
57
+ expect(cards).to be_a(Hash)
58
+
59
+ id=cards['id']
60
+
61
+ #performs check
62
+ customer_cards=customers.all_cards(customer['id'])
63
+ expect(customer_cards.size).to be 1
64
+ expect(cards['holder_name']).to match 'Pepe'
65
+
66
+ stored_card=@cards.get(id, customer['id'])
67
+ expect(stored_card['holder_name']).to match 'Pepe'
68
+ expect(stored_card['id']).to match id
69
+
70
+ #cleanup
71
+ @cards.delete(id, customer['id'])
72
+ @customers.delete(customer['id'])
73
+
74
+
75
+ end
76
+
77
+
78
+ it 'fails when trying to create an existing merchant card' do
79
+
80
+ #creates merchant card
81
+ card_hash = FactoryGirl.build(:valid_card)
82
+ card=@cards.create(card_hash)
83
+
84
+ #perform check
85
+ expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
86
+
87
+ #cleanup
88
+ @cards.delete(card['id'])
89
+
90
+ end
91
+
92
+
93
+
94
+ it 'fails when trying to create an existing customer card' do
95
+
96
+ #creates a customer
97
+ card_hash = FactoryGirl.build(:valid_card, holder_name: 'Pepe')
98
+ customers=@openpay.create(:customers)
99
+ customer_hash = FactoryGirl.build(:customer)
100
+ customer=customers.create(customer_hash)
101
+
102
+ #creates a customer card
103
+ card=@cards.create(card_hash, customer['id'])
104
+ expect(card).to be_a(Hash)
105
+
106
+ #performs check
107
+ expect { @cards.create(card_hash,customer['id']) }.to raise_error(OpenpayTransactionException)
108
+
109
+ #cleanup
110
+ @cards.delete(card['id'],customer['id'])
111
+ @customers.delete(customer['id'])
112
+
113
+
114
+ end
115
+
116
+
117
+
118
+ it 'fails when using an expired card' do
119
+ card_hash = FactoryGirl.build(:expired_card)
120
+ #check
121
+ expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
122
+ #extended check
123
+ begin
124
+ @cards.create(card_hash)
125
+ rescue OpenpayTransactionException => e
126
+ expect(e.description).to match 'The card has expired.'
127
+ expect(e.error_code).to be 3002
128
+ end
129
+
130
+ end
131
+
132
+
133
+ it 'fails when using a stolen card' do
134
+ card_json = FactoryGirl.build(:valid_card, card_number: '4000000000000119')
135
+ expect { @cards.create(card_json) }.to raise_error(OpenpayTransactionException)
136
+ end
137
+
138
+ end
139
+
140
+
141
+ describe '.each' do
142
+
143
+ it 'list all existing merchant cards' do
144
+ @cards.each do |card|
145
+ expect(card['expiration_year']).to match '14'
146
+ end
147
+ end
148
+
149
+
150
+ end
151
+
152
+
153
+ describe '.delete' do
154
+
155
+
156
+ it 'deletes a customer card' do
157
+ #creates merchant card
158
+ card_hash = FactoryGirl.build(:valid_card)
159
+ cards=@cards.create(card_hash)
160
+ expect(cards).to be_a(Hash)
161
+
162
+ id=cards['id']
163
+ name='Vicente Olmos'
164
+
165
+ #perform check
166
+ card=@cards.get(id)
167
+ expect(card['holder_name']).to match(name)
168
+ expect(card['card_number']).to match('1111')
169
+
170
+ #cleanup
171
+ @cards.delete(card['id'])
172
+ end
173
+
174
+
175
+
176
+ it 'fails to deletes a non existing card' do
177
+ expect { @cards.delete('1111111') }.to raise_exception(OpenpayTransactionException)
178
+ end
179
+
180
+
181
+ it 'deletes a customer card' do
182
+
183
+ #create customer
184
+ customers=@openpay.create(:customers)
185
+ customer_hash = FactoryGirl.build(:customer, name: 'Juan', last_name: 'Paez')
186
+ customer=customers.create(customer_hash)
187
+
188
+ #create customer card
189
+ card_hash = FactoryGirl.build(:valid_card)
190
+ card=@cards.create(card_hash, customer['id'])
191
+
192
+ #delete card
193
+ @cards.delete(card['id'], customer['id'])
194
+
195
+ #perform check
196
+ expect { @cards.get(card['id'],customer['id'])}.to raise_exception(OpenpayTransactionException)
197
+
198
+ end
199
+
200
+
201
+ it 'fails to deletes a non existing customer card' do
202
+ expect { @cards.delete('1111111', '1111') }.to raise_exception(OpenpayTransactionException)
203
+ end
204
+
205
+
206
+ end
207
+
208
+
209
+ describe '.get' do
210
+
211
+
212
+ it ' gets an existing merchant card' do
213
+
214
+ #create merchant card
215
+ bank_name='Banamex'
216
+ card_hash = FactoryGirl.build(:valid_card)
217
+
218
+ card=@cards.create(card_hash)
219
+ id=card['id']
220
+
221
+ #pass just a single parameter for getting merchant cards
222
+ stored_card = @cards.get(id)
223
+ bank=stored_card['bank_name']
224
+ expect(bank).to match bank_name
225
+
226
+ #cleanup
227
+ @cards.delete(id)
228
+
229
+ end
230
+
231
+
232
+ it 'fails when getting a non existing card' do
233
+ expect { @cards.get('11111') }.to raise_exception(OpenpayTransactionException)
234
+ end
235
+
236
+
237
+ it ' gets an existing customer card' do
238
+
239
+ #create customer
240
+ customer_hash = FactoryGirl.build(:customer)
241
+ customer=@customers.create(customer_hash)
242
+
243
+ #creates card
244
+ bank_name='Banamex'
245
+ card_hash = FactoryGirl.build(:valid_card)
246
+ card=@cards.create(card_hash, customer['id'])
247
+ id=card['id']
248
+
249
+ #two parameters for getting customer cards
250
+ stored_cards = @cards.get(id, customer['id'])
251
+ bank=stored_cards['bank_name']
252
+
253
+ #perform check
254
+ expect(bank).to match bank_name
255
+
256
+ #cleanup
257
+ @cards.delete(id, customer['id'])
258
+
259
+ end
260
+
261
+
262
+ it 'fails when getting a non existing customer card' do
263
+ expect { @cards.get('11111', '1111') }.to raise_exception(OpenpayTransactionException)
264
+ end
265
+
266
+
267
+ end
268
+
269
+
270
+ describe '.all' do
271
+
272
+ it 'list all merchant cards' do
273
+
274
+ #check initial state
275
+ expect(@cards.all.size).to be 0
276
+
277
+ #create merchant card
278
+ card_hash = FactoryGirl.build(:valid_card)
279
+ card=@cards.create(card_hash)
280
+ id=card['id']
281
+
282
+ #perform check
283
+ expect(@cards.all.size).to be 1
284
+
285
+ #cleanup
286
+ @cards.delete(id)
287
+
288
+ end
289
+
290
+
291
+ it 'list all customer cards' do
292
+
293
+
294
+ #create customer
295
+ customer_hash = FactoryGirl.build(:customer)
296
+ customer=@customers.create(customer_hash)
297
+
298
+ #check initial state
299
+ expect(@cards.all(customer['id']).size).to be 0
300
+
301
+ #create customer card
302
+ card_hash = FactoryGirl.build(:valid_card)
303
+ card=@cards.create(card_hash, customer['id'])
304
+ id=card['id']
305
+
306
+ #perform check
307
+ expect(@cards.all(customer['id']).size).to be 1
308
+
309
+ #cleanup
310
+ @cards.delete(id, customer['id'])
311
+
312
+ end
313
+
314
+
315
+ it 'list cards for a non existing customer' do
316
+ expect { @cards.all('111111') }.to raise_exception OpenpayTransactionException
317
+ end
318
+
319
+
320
+ end
321
+
322
+
323
+ describe '.list' do
324
+
325
+ it 'list the merchant cards using a filter' do
326
+
327
+ pending
328
+ #creation[gte]=yyyy-mm-dd
329
+ #creation[lte]=yyyy-mm-dd
330
+ #offset=0&
331
+ #limit=10
332
+ # @cards.list('2000-01-01','2000-01-01',0,10)
333
+
334
+
335
+ end
336
+
337
+
338
+ it 'list the customer cards using a filter' do
339
+ pending
340
+ end
341
+
342
+
343
+ end
344
+
345
+
346
+ describe '.delete_all' do
347
+
348
+ it 'raise an exception when used on Production' do
349
+
350
+ openpayprod=OpenpayApi.new(@merchant_id, @private_key, true)
351
+ cust=openpayprod.create(:customers)
352
+ expect { cust.delete_all }.to raise_error
353
+
354
+ end
355
+
356
+
357
+ it 'deletes all existing merchant cards' do
358
+
359
+ #create merchant card
360
+ card_hash = FactoryGirl.build(:valid_card)
361
+ @cards.create(card_hash)
362
+
363
+ #using json just for fun ...and test
364
+ card2_json = FactoryGirl.build(:valid_card2).to_json
365
+ @cards.create(card2_json)
366
+
367
+
368
+ #perform check
369
+ expect(@cards.all.size).to be 2
370
+
371
+ #cleanup
372
+ @cards.delete_all
373
+
374
+ #perform check
375
+ expect(@cards.all.size).to be 0
376
+
377
+
378
+ end
379
+
380
+ it 'deletes all existing cards for a given customer' do
381
+
382
+
383
+ #creates customer
384
+ customer_hash = FactoryGirl.build(:customer)
385
+ customer=@customers.create(customer_hash)
386
+
387
+ #check initial state
388
+ expect(@cards.all(customer['id']).size).to be 0
389
+
390
+ #create card
391
+ card_hash = FactoryGirl.build(:valid_card)
392
+ card=@cards.create(card_hash, customer['id'])
393
+
394
+ #perform check
395
+ expect(@cards.all(customer['id']).size).to be 1
396
+
397
+ #cleanup
398
+ @cards.delete_all(customer['id'])
399
+
400
+ #check
401
+ expect(@cards.all(customer['id']).size).to be 0
402
+
403
+
404
+
405
+ end
406
+
407
+
408
+ end
409
+
410
+
411
+ end
@@ -0,0 +1,377 @@
1
+
2
+ require '../spec_helper'
3
+
4
+ describe Charges do
5
+
6
+
7
+
8
+
9
+ before(:all) do
10
+
11
+ @merchant_id='mywvupjjs9xdnryxtplq'
12
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
13
+
14
+ @openpay=OpenpayApi.new(@merchant_id,@private_key)
15
+ @customers=@openpay.create(:customers)
16
+
17
+ @charges=@openpay.create(:charges)
18
+ @cards=@openpay.create(:cards)
19
+ @bank_accounts=@openpay.create(:bankaccounts)
20
+
21
+
22
+
23
+ end
24
+
25
+
26
+ after(:all) do
27
+
28
+ end
29
+
30
+
31
+
32
+ describe '.create' do
33
+
34
+ it 'creates a new merchant charge using the card method using a pre-stored card' do
35
+
36
+
37
+ #create card
38
+ card_hash=FactoryGirl.build(:valid_card)
39
+ card=@cards.create(card_hash)
40
+
41
+
42
+
43
+ #create charge attached to prev created card
44
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 101)
45
+ charge=@charges.create(charge_hash)
46
+
47
+ #perform check
48
+ stored_charge=@charges.get(charge['id'])
49
+ expect(stored_charge['amount']).to be_within(0.1).of(101)
50
+
51
+ #clean up
52
+ @cards.delete(card['id'])
53
+
54
+
55
+ end
56
+
57
+
58
+ it 'creates a new customer charge using the card method using a pre-stored card' do
59
+
60
+ #create new customer
61
+ customer_hash= FactoryGirl.build(:customer)
62
+ customer=@customers.create(customer_hash)
63
+
64
+ #create customer card
65
+ card_hash=FactoryGirl.build(:valid_card)
66
+ card=@cards.create(card_hash,customer['id'])
67
+
68
+ #create charge
69
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
70
+ charge=@charges.create(charge_hash,customer['id'])
71
+
72
+ #perform check
73
+ stored_charge=@charges.get(charge['id'],customer['id'])
74
+ expect(stored_charge['amount']).to be_within(0.1).of(1000)
75
+
76
+ #clean up
77
+ @cards.delete(card['id'],customer['id'])
78
+ @customers.delete(customer['id'])
79
+
80
+ end
81
+
82
+
83
+ it 'creates a new customer charge using the bank_account method' do
84
+
85
+ #create new customer
86
+ customer_hash= FactoryGirl.build(:customer)
87
+ customer=@customers.create(customer_hash)
88
+
89
+ #create bank account
90
+ account_hash=FactoryGirl.build(:bank_account)
91
+ account=@bank_accounts.create(account_hash,customer['id'])
92
+
93
+ #create charge
94
+ charge_hash=FactoryGirl.build(:bank_charge, source_id:account['id'],order_id: account['id'])
95
+ charge=@charges.create(charge_hash,customer['id'])
96
+
97
+ #perform check
98
+ stored_charge=@charges.get(charge['id'],customer['id'])
99
+ expect(stored_charge['amount']).to be_within(0.1).of(10000)
100
+
101
+ #clean up
102
+ @bank_accounts.delete(customer['id'],account['id'])
103
+ @customers.delete(customer['id'])
104
+
105
+ end
106
+
107
+
108
+
109
+ end
110
+
111
+
112
+
113
+ describe '.get' do
114
+
115
+
116
+ it 'gets a merchant charge' do
117
+
118
+
119
+ #create card
120
+ card_hash=FactoryGirl.build(:valid_card)
121
+ card=@cards.create(card_hash)
122
+
123
+ #create charge attached to prev created card
124
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 505)
125
+ charge=@charges.create(charge_hash)
126
+
127
+ #perform check
128
+ stored_charge=@charges.get(charge['id'])
129
+ expect(stored_charge['amount']).to be_within(0.1).of(505)
130
+
131
+ #clean up
132
+ @cards.delete(card['id'])
133
+
134
+
135
+
136
+ end
137
+
138
+
139
+ it 'gets a customer charge' do
140
+
141
+ #create new customer
142
+ customer_hash= FactoryGirl.build(:customer)
143
+ customer=@customers.create(customer_hash)
144
+
145
+ #create customer card
146
+ card_hash=FactoryGirl.build(:valid_card)
147
+ card=@cards.create(card_hash,customer['id'])
148
+
149
+ #create charge
150
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000)
151
+ charge=@charges.create(charge_hash,customer['id'])
152
+
153
+ #perform check
154
+ stored_charge=@charges.get(charge['id'],customer['id'])
155
+ expect(stored_charge['amount']).to be_within(0.5).of(4000)
156
+
157
+ #clean up
158
+ @cards.delete(card['id'],customer['id'])
159
+ @customers.delete(customer['id'])
160
+
161
+ end
162
+
163
+
164
+
165
+
166
+
167
+ end
168
+
169
+
170
+
171
+
172
+ describe '.all' do
173
+
174
+ it 'list all merchant charges' do
175
+
176
+ #TODO test can be improved, but since charges cannot be deleted it make this difficult
177
+ expect(@charges.all.size).to be_a Integer
178
+
179
+ end
180
+
181
+
182
+ it 'list all customer charges' do
183
+ #create new customer
184
+ customer_hash= FactoryGirl.build(:customer)
185
+ customer=@customers.create(customer_hash)
186
+
187
+
188
+ expect(@charges.all(customer['id']).size).to be 0
189
+ @customers.delete(customer['id'])
190
+
191
+
192
+ end
193
+
194
+ end
195
+
196
+
197
+
198
+
199
+ describe '.capture' do
200
+
201
+ it 'captures an existing merchant charge' do
202
+ #create new customer
203
+ customer_hash= FactoryGirl.build(:customer)
204
+ customer=@customers.create(customer_hash)
205
+
206
+ #create customer card
207
+ card_hash=FactoryGirl.build(:valid_card)
208
+ card=@cards.create(card_hash,customer['id'])
209
+
210
+ #create charge
211
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000)
212
+ charge=@charges.create(charge_hash,customer['id'])
213
+
214
+ #capture charge
215
+ captured_charge=@charges.capture(charge['id'],customer['id'])
216
+ p captured_charge
217
+
218
+
219
+
220
+ #clean up
221
+ @cards.delete(card['id'],customer['id'])
222
+ @customers.delete(customer['id'])
223
+ end
224
+
225
+
226
+ it 'fails to capture an non existing merchant charge' do
227
+ pending 'check if the cancel method in reality works, documentation has some discrepancies'
228
+ end
229
+
230
+
231
+
232
+ it 'captures an existing customer charge' do
233
+ pending 'check if the cancel method in reality works, documentation has some discrepancies'
234
+ end
235
+
236
+
237
+ end
238
+
239
+
240
+
241
+
242
+ describe '.refund' do
243
+
244
+
245
+
246
+ #Refunds apply only for card charges
247
+ it 'refunds an existing merchant charge' do
248
+ #create card
249
+ card_hash=FactoryGirl.build(:valid_card)
250
+ card=@cards.create(card_hash)
251
+
252
+ #create charge attached to prev created card
253
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 505)
254
+ charge=@charges.create(charge_hash)
255
+
256
+ #creates refund_description
257
+ refund_description=FactoryGirl.build(:refund_description)
258
+ expect(@charges.get(charge['id'])['refund']).to be nil
259
+
260
+ @charges.refund(charge['id'],refund_description)
261
+ expect(@charges.get(charge['id'])['refund']['amount'] ).to be_within(0.1).of(505)
262
+
263
+
264
+ #clean up
265
+ @cards.delete(card['id'])
266
+
267
+ end
268
+
269
+
270
+
271
+
272
+ it 'refunds an existing customer charge' do
273
+ #create new customer
274
+ customer_hash= FactoryGirl.build(:customer)
275
+ customer=@customers.create(customer_hash)
276
+
277
+ #create customer card
278
+ card_hash=FactoryGirl.build(:valid_card)
279
+ card=@cards.create(card_hash,customer['id'])
280
+
281
+ #create charge
282
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000)
283
+ charge=@charges.create(charge_hash,customer['id'])
284
+
285
+ #creates refund_description
286
+ refund_description=FactoryGirl.build(:refund_description)
287
+
288
+
289
+ #perform check
290
+ expect(@charges.get(charge['id'],customer['id'])['refund']).to be nil
291
+ @charges.refund(charge['id'],refund_description,customer['id'])
292
+ expect(@charges.get(charge['id'],customer['id'])['refund']['amount'] ).to be_within(0.1).of(4000)
293
+
294
+ #clean up
295
+ @cards.delete(card['id'],customer['id'])
296
+ @customers.delete(customer['id'])
297
+
298
+ end
299
+
300
+ end
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+ describe '.list' do
311
+
312
+
313
+ it 'list merchant charges' do
314
+ pending
315
+ end
316
+
317
+
318
+
319
+ it 'list customer charges' do
320
+ pending
321
+ end
322
+
323
+
324
+ end
325
+
326
+
327
+ describe '.each' do
328
+
329
+ it 'iterates over merchant charges' do
330
+ @charges.each do |charge|
331
+ #perform check.
332
+ expect(charge['amount']).to be_a Float
333
+ end
334
+ end
335
+
336
+
337
+
338
+ it 'iterate over customer charges' do
339
+
340
+ #create new customer
341
+ customer_hash= FactoryGirl.build(:customer)
342
+ customer=@customers.create(customer_hash)
343
+
344
+ #create customer card
345
+ card_hash=FactoryGirl.build(:valid_card)
346
+ card=@cards.create(card_hash,customer['id'])
347
+
348
+ #create charge
349
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4)
350
+ @charges.create(charge_hash,customer['id'])
351
+ charge2_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'+"2"],amount: 4)
352
+
353
+ @charges.create(charge2_hash,customer['id'])
354
+
355
+
356
+ @charges.each(customer['id']) do |charge|
357
+ expect(charge['operation_type']).to match 'in'
358
+ expect(charge['amount']).to be_within(0.1).of(4)
359
+ end
360
+
361
+
362
+ #cleanup
363
+ @cards.delete(card['id'],customer['id'])
364
+ @customers.delete(customer['id'])
365
+
366
+ end
367
+
368
+ end
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+ end