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,382 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Charges do
4
+
5
+ before(:all) do
6
+
7
+ @merchant_id = 'mywvupjjs9xdnryxtplq'
8
+ @private_key = 'sk_92b25d3baec149e6b428d81abfe37006'
9
+
10
+ @openpay = OpenpayApi.new(@merchant_id, @private_key)
11
+ @customers = @openpay.create(:customers)
12
+
13
+ #LOG.level=Logger::DEBUG
14
+
15
+ @charges = @openpay.create(:charges)
16
+ @cards = @openpay.create(:cards)
17
+ @bank_accounts = @openpay.create(:bankaccounts)
18
+
19
+ # @cards.delete_all
20
+
21
+ end
22
+
23
+ it 'has all required methods' do
24
+ %w(all each create get list delete).each do |meth|
25
+ expect(@charges).to respond_to(meth)
26
+ end
27
+ end
28
+
29
+ describe '.create' do
30
+
31
+ it 'creates a new merchant charge using the card method using a pre-stored card' do
32
+
33
+ #create card
34
+ card_hash = FactoryBot.build(:valid_card)
35
+ card = @cards.create(card_hash)
36
+
37
+ #create charge attached to prev created card
38
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 101)
39
+ charge = @charges.create(charge_hash)
40
+
41
+ #perform check
42
+ stored_charge = @charges.get(charge['id'])
43
+ expect(stored_charge['amount']).to be_within(0.1).of(101)
44
+
45
+ #clean up
46
+ @cards.delete(card['id'])
47
+
48
+ end
49
+
50
+ it 'creates a new customer charge using the card method using a pre-stored card' do
51
+
52
+ #create new customer
53
+ customer_hash = FactoryBot.build(:customer)
54
+ customer = @customers.create(customer_hash)
55
+
56
+ #create customer card
57
+ card_hash = FactoryBot.build(:valid_card)
58
+ card = @cards.create(card_hash, customer['id'])
59
+
60
+ #create charge
61
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
62
+ charge = @charges.create(charge_hash, customer['id'])
63
+
64
+ #perform check
65
+ stored_charge = @charges.get(charge['id'], customer['id'])
66
+ expect(stored_charge['amount']).to be_within(0.1).of(1000)
67
+
68
+ #clean up
69
+ @cards.delete(card['id'], customer['id'])
70
+
71
+ #no se puede borrar usuario por transacciones asociadas
72
+ # @customers.delete(customer['id'])
73
+
74
+ end
75
+
76
+ end
77
+
78
+ describe '.get' do
79
+
80
+ it 'gets a merchant charge' do
81
+
82
+ #create card
83
+ card_hash = FactoryBot.build(:valid_card)
84
+ card = @cards.create(card_hash)
85
+
86
+ #create charge attached to prev created card
87
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 505)
88
+ charge = @charges.create(charge_hash)
89
+
90
+ #perform check
91
+ stored_charge = @charges.get(charge['id'])
92
+ expect(stored_charge['amount']).to be_within(0.1).of(505)
93
+
94
+ #clean up
95
+ @cards.delete(card['id'])
96
+
97
+ end
98
+
99
+ it 'gets a customer charge' do
100
+
101
+ #create new customer
102
+ customer_hash = FactoryBot.build(:customer)
103
+ customer = @customers.create(customer_hash)
104
+
105
+ #create customer card
106
+ card_hash = FactoryBot.build(:valid_card)
107
+ card = @cards.create(card_hash, customer['id'])
108
+
109
+ #create charge
110
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000)
111
+ charge = @charges.create(charge_hash, customer['id'])
112
+
113
+ #perform check
114
+ stored_charge = @charges.get(charge['id'], customer['id'])
115
+ expect(stored_charge['amount']).to be_within(0.5).of(4000)
116
+
117
+ #clean up
118
+ @cards.delete(card['id'], customer['id'])
119
+
120
+ # no se puede borrar usuario por transacciones asociadas
121
+ # @customers.delete(customer['id'])
122
+
123
+ end
124
+
125
+ end
126
+
127
+ describe '.all' do
128
+
129
+ it 'all merchant charges' do
130
+ #TODO test can be improved, but since charges cannot be deleted it make this difficult
131
+ expect(@charges.all.size).to be_a Integer
132
+ end
133
+
134
+ it 'all customer charges' do
135
+ #create new customer
136
+ customer_hash = FactoryBot.build(:customer)
137
+ customer = @customers.create(customer_hash)
138
+
139
+ expect(@charges.all(customer['id']).size).to be 0
140
+ @customers.delete(customer['id'])
141
+
142
+ end
143
+
144
+ end
145
+
146
+ describe '.capture' do
147
+
148
+ it 'captures a merchant card charge' do
149
+
150
+ #create new customer
151
+ customer_hash = FactoryBot.build(:customer)
152
+ customer = @customers.create(customer_hash)
153
+
154
+ #create merchant card
155
+ card_hash = FactoryBot.build(:valid_card)
156
+ card = @cards.create(card_hash)
157
+
158
+ #create merchant charge
159
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000, capture: 'false')
160
+ charge = @charges.create(charge_hash)
161
+
162
+ #capture merchant charge
163
+ @charges.capture(charge['id'])
164
+
165
+ #clean up
166
+ @cards.delete(card['id'])
167
+ @customers.delete(customer['id'])
168
+
169
+ end
170
+
171
+ it 'captures a customer card charge' do
172
+ #create new customer
173
+ customer_hash = FactoryBot.build(:customer)
174
+ customer = @customers.create(customer_hash)
175
+
176
+ #create customer card
177
+ card_hash = FactoryBot.build(:valid_card)
178
+ card = @cards.create(card_hash, customer['id'])
179
+
180
+ #create charge
181
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000, capture: 'false')
182
+ charge = @charges.create(charge_hash, customer['id'])
183
+
184
+ #capture customer charge
185
+ @charges.capture(charge['id'], customer['id'])
186
+
187
+ #clean up
188
+ @cards.delete(card['id'], customer['id'])
189
+ # No se puede borrar usuario por transacciones asociadas
190
+ # @customers.delete(customer['id'])
191
+ end
192
+
193
+ end
194
+
195
+ describe '.confirm_capture' do
196
+
197
+ it 'confirms a capture on a merchant charge' do
198
+
199
+ #create new customer
200
+ customer_hash = FactoryBot.build(:customer)
201
+ customer = @customers.create(customer_hash)
202
+
203
+ #create merchant card
204
+ card_hash = FactoryBot.build(:valid_card)
205
+ card = @cards.create(card_hash)
206
+
207
+ #create merchant charge
208
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000, capture: 'false')
209
+ charge = @charges.create(charge_hash)
210
+
211
+ confirm_capture_options = { transaction_id: charge['id'], amount: 100 }
212
+
213
+ #confirm capture
214
+ res = @charges.confirm_capture(confirm_capture_options)
215
+ expect(res['amount']).to eq 100
216
+
217
+ #clean up
218
+ @cards.delete(card['id'])
219
+ @customers.delete(customer['id'])
220
+
221
+ end
222
+
223
+ it 'confirms a capture on a customer charge' do
224
+
225
+ customer_hash = FactoryBot.build(:customer)
226
+ customer = @customers.create(customer_hash)
227
+
228
+ #create customer card
229
+ card_hash = FactoryBot.build(:valid_card)
230
+ card = @cards.create(card_hash, customer['id'])
231
+
232
+ #create charge
233
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000, capture: 'false')
234
+ charge = @charges.create(charge_hash, customer['id'])
235
+
236
+ confirm_capture_options = { customer_id: customer['id'], transaction_id: charge['id'], amount: 100 }
237
+
238
+ #confirm capture
239
+ res = @charges.confirm_capture(confirm_capture_options)
240
+ expect(res['amount']).to eq 100
241
+
242
+ #clean up
243
+ @cards.delete(card['id'], customer['id'])
244
+
245
+ # No se puede borrar usuario por transacciones asociadas
246
+ #@customers.delete(customer['id'])
247
+
248
+ end
249
+
250
+ end
251
+
252
+ describe '.refund' do
253
+
254
+ #Refunds apply only for card charges
255
+ it 'refunds an existing merchant charge' do
256
+ #create card
257
+ card_hash = FactoryBot.build(:valid_card)
258
+ card = @cards.create(card_hash)
259
+
260
+ #create charge attached to prev created card
261
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 505)
262
+ charge = @charges.create(charge_hash)
263
+
264
+ #creates refund_description
265
+ refund_description = FactoryBot.build(:refund_description)
266
+ expect(@charges.get(charge['id'])['refund']).to be nil
267
+
268
+ @charges.refund(charge['id'], refund_description)
269
+ expect(@charges.get(charge['id'])['refund']['amount']).to be_within(0.1).of(505)
270
+
271
+ #clean up
272
+ @cards.delete(card['id'])
273
+
274
+ end
275
+
276
+ it 'refunds an existing customer charge' do
277
+ #create new customer
278
+ customer_hash = FactoryBot.build(:customer)
279
+ customer = @customers.create(customer_hash)
280
+
281
+ #create customer card
282
+ card_hash = FactoryBot.build(:valid_card)
283
+ card = @cards.create(card_hash, customer['id'])
284
+
285
+ #create charge
286
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 100)
287
+ charge = @charges.create(charge_hash, customer['id'])
288
+
289
+ #creates refund_description
290
+ refund_description = FactoryBot.build(:refund_description)
291
+
292
+ #perform check
293
+ expect(@charges.get(charge['id'], customer['id'])['refund']).to be nil
294
+ sleep(50)
295
+ @charges.refund(charge['id'], refund_description, customer['id'])
296
+
297
+ expect(@charges.get(charge['id'], customer['id'])['refund']['amount']).to be_within(0.1).of(100)
298
+
299
+ #clean up
300
+ @cards.delete(card['id'], customer['id'])
301
+
302
+ # No se puede borrar usuario por transacciones asociadas
303
+ # @customers.delete(customer['id'])
304
+
305
+ end
306
+
307
+ end
308
+
309
+ describe '.list' do
310
+
311
+ it 'list customer charges' do
312
+
313
+ #create new customer
314
+ customer_hash = FactoryBot.build(:customer)
315
+ customer = @customers.create(customer_hash)
316
+ #create customer card
317
+ card_hash = FactoryBot.build(:valid_card)
318
+ card = @cards.create(card_hash, customer['id'])
319
+ #create charge
320
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
321
+ charge = @charges.create(charge_hash, customer['id'])
322
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'] + "1")
323
+ charge2 = @charges.create(charge_hash, customer['id'])
324
+ #perform check
325
+ search_params = OpenpayUtils::SearchParams.new
326
+ search_params.limit = 1
327
+ search_params.creation_gte = '2000-01-01'
328
+ search_params.amount_gte = 1
329
+ expect(@charges.all(customer['id']).size).to eq 2
330
+ expect(@charges.list(search_params, customer['id']).size).to eq 1
331
+ #clean up
332
+ @cards.delete(card['id'], customer['id'])
333
+
334
+ # No se puede borrar usuario por transacciones asociadas
335
+ # @customers.delete(customer['id'])
336
+
337
+ end
338
+
339
+ end
340
+
341
+ describe '.each' do
342
+
343
+ it 'iterates over merchant charges' do
344
+ @charges.each do |charge|
345
+ #perform check.
346
+ expect(charge['amount']).to be_a Float
347
+ end
348
+ end
349
+
350
+ it 'iterate over customer charges' do
351
+
352
+ #create new customer
353
+ customer_hash = FactoryBot.build(:customer)
354
+ customer = @customers.create(customer_hash)
355
+
356
+ #create customer card
357
+ card_hash = FactoryBot.build(:valid_card)
358
+ card = @cards.create(card_hash, customer['id'])
359
+
360
+ #create charge
361
+ charge_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4)
362
+ @charges.create(charge_hash, customer['id'])
363
+ charge2_hash = FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id' + "2"], amount: 4)
364
+
365
+ @charges.create(charge2_hash, customer['id'])
366
+
367
+ @charges.each(customer['id']) do |charge|
368
+ expect(charge['operation_type']).to match 'in'
369
+ expect(charge['amount']).to be_within(0.1).of(4)
370
+ end
371
+
372
+ #cleanup
373
+ @cards.delete(card['id'], customer['id'])
374
+
375
+ # No se puede borrar usuario por transacciones asociadas
376
+ # @customers.delete(customer['id'])
377
+
378
+ end
379
+
380
+ end
381
+
382
+ end