razorpay 3.0.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -2
  3. data/CHANGELOG.md +17 -0
  4. data/README.md +6 -0
  5. data/documents/account.md +449 -0
  6. data/documents/card.md +45 -0
  7. data/documents/generic.md +150 -0
  8. data/documents/payment.md +44 -1
  9. data/documents/productConfiguration.md +444 -0
  10. data/documents/stakeholder.md +334 -0
  11. data/documents/tokens.md +146 -1
  12. data/documents/webhook.md +224 -0
  13. data/lib/razorpay/account.rb +39 -0
  14. data/lib/razorpay/addon.rb +1 -1
  15. data/lib/razorpay/card.rb +4 -0
  16. data/lib/razorpay/constants.rb +28 -2
  17. data/lib/razorpay/generic.rb +39 -0
  18. data/lib/razorpay/iin.rb +15 -0
  19. data/lib/razorpay/order.rb +1 -1
  20. data/lib/razorpay/product.rb +37 -0
  21. data/lib/razorpay/request.rb +22 -16
  22. data/lib/razorpay/stakeholder.rb +39 -0
  23. data/lib/razorpay/token.rb +28 -0
  24. data/lib/razorpay/virtual_account.rb +1 -1
  25. data/lib/razorpay/webhook.rb +50 -0
  26. data/lib/razorpay.rb +7 -0
  27. data/test/fixtures/fake_account.json +78 -0
  28. data/test/fixtures/fake_card_reference.json +5 -0
  29. data/test/fixtures/fake_iin_token.json +23 -0
  30. data/test/fixtures/fake_product.json +138 -0
  31. data/test/fixtures/fake_stakeholder.json +29 -0
  32. data/test/fixtures/fake_tokenise_customer.json +40 -0
  33. data/test/fixtures/fake_webhook.json +79 -0
  34. data/test/fixtures/fake_webhook_by_account_id.json +22 -0
  35. data/test/fixtures/fetch_tnc.json +11 -0
  36. data/test/fixtures/stakeholder_collection.json +35 -0
  37. data/test/fixtures/webhook_by_account_collection.json +35 -0
  38. data/test/fixtures/webhook_collection.json +85 -0
  39. data/test/razorpay/test_account.rb +134 -0
  40. data/test/razorpay/test_card.rb +6 -0
  41. data/test/razorpay/test_customer.rb +8 -8
  42. data/test/razorpay/test_generic.rb +112 -0
  43. data/test/razorpay/test_iin.rb +23 -0
  44. data/test/razorpay/test_order.rb +1 -1
  45. data/test/razorpay/test_product.rb +67 -0
  46. data/test/razorpay/test_settlement.rb +1 -1
  47. data/test/razorpay/test_stakeholder.rb +87 -0
  48. data/test/razorpay/test_token.rb +66 -0
  49. data/test/razorpay/test_transfer.rb +1 -1
  50. data/test/razorpay/test_webhook.rb +132 -0
  51. metadata +52 -2
@@ -0,0 +1,132 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Webhook
5
+ class RazorpayWebhookonTest < Minitest::Test
6
+ class Webhook < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @webhook_id = 'H000000000000H'
10
+ @account_id = 'acc_00000000000001'
11
+ @alert_email = 'gaurav.kumar@example.com'
12
+ # Any request that ends with webhook_id
13
+ end
14
+
15
+ def test_product_should_be_defined
16
+ refute_nil Razorpay::Webhook
17
+ end
18
+
19
+ def test_webhook_with_account_id_should_be_available
20
+ stub_get(%r{/v2/accounts\/#{Regexp.quote(@account_id)}/webhooks\/#{Regexp.quote(@webhook_id)}$}, 'fake_webhook_by_account_id')
21
+ webhook = Razorpay::Webhook.fetch(@webhook_id, @account_id)
22
+ assert_instance_of Razorpay::Webhook, webhook, 'webhook not an instance of Webhook class'
23
+ assert_equal @webhook_id, webhook.id, 'Webhook IDs do not match'
24
+ assert_equal @alert_email, webhook.alert_email, 'webhook alert_email is accessible'
25
+ end
26
+
27
+ def test_webhook_with_account_id_should_be_create
28
+ payload = create_webhook_payload_by_account()
29
+ stub_post(%r{/v2/accounts/#{@account_id}/webhooks$}, 'fake_webhook_by_account_id', payload.to_json)
30
+
31
+ webhook = Razorpay::Webhook.create(payload.to_json, @account_id)
32
+ assert_instance_of Razorpay::Webhook, webhook, 'Webhook not an instance of Webhook class'
33
+ assert_equal @webhook_id, webhook.id, 'Webhook IDs do not match'
34
+ assert_equal @alert_email, webhook.alert_email, 'webhook alert_email is accessible'
35
+ end
36
+
37
+ def test_webhook_should_be_create
38
+ payload = create_webhook_payload()
39
+ stub_post(%r{/webhooks$}, 'fake_webhook', payload.to_json)
40
+
41
+ webhook = Razorpay::Webhook.create(payload.to_json)
42
+ assert_instance_of Razorpay::Webhook, webhook, 'Webhook not an instance of Webhook class'
43
+ assert_equal @webhook_id, webhook.id, 'Webhook IDs do not match'
44
+ assert_equal @alert_email, webhook.created_by_email, 'webhook alert_email is accessible'
45
+ end
46
+
47
+ def test_webhook_with_account_id_should_be_edit
48
+ payload = edit_webhook_payload_by_account()
49
+ stub_patch(%r{/v2/accounts/#{@account_id}/webhooks/#{@webhook_id}$}, 'fake_webhook_by_account_id', payload.to_json)
50
+
51
+ webhook = Razorpay::Webhook.edit(payload.to_json, @webhook_id, @account_id)
52
+ assert_instance_of Razorpay::Webhook, webhook, 'Webhook not an instance of Webhook class'
53
+ assert_equal @webhook_id, webhook.id, 'Webhook IDs do not match'
54
+ assert_equal @alert_email, webhook.alert_email, 'webhook alert_email is accessible'
55
+ end
56
+
57
+ def test_webhook_should_be_edit
58
+ payload = edit_webhook_payload()
59
+ stub_put(%r{/webhooks/#{@webhook_id}$}, 'fake_webhook', payload.to_json)
60
+
61
+ webhook = Razorpay::Webhook.edit(payload.to_json, @webhook_id)
62
+ assert_instance_of Razorpay::Webhook, webhook, 'Webhook not an instance of Webhook class'
63
+ assert_equal @webhook_id, webhook.id, 'Webhook IDs do not match'
64
+ assert_equal @alert_email, webhook.created_by_email, 'webhook alert_email is accessible'
65
+ end
66
+
67
+ def test_webhook_fetch_webhooks_by_account
68
+ stub_get(%r{/v2/accounts/#{@account_id}/webhooks$}, 'webhook_by_account_collection', {})
69
+
70
+ webhook = Razorpay::Webhook.all({}, @account_id)
71
+ assert_instance_of Razorpay::Collection, webhook, 'Webhook not an instance of Webhook class'
72
+ refute_empty webhook.items , 'Webhook should be more than one'
73
+ end
74
+
75
+ def test_webhook_fetch_webhooks
76
+ stub_get(%r{/webhooks$}, 'webhook_collection')
77
+
78
+ webhook = Razorpay::Webhook.all()
79
+ assert_instance_of Razorpay::Collection, webhook, 'Webhook not an instance of Webhook class'
80
+ refute_empty webhook.items , 'Webhook should be more than one'
81
+ end
82
+
83
+ def create_webhook_payload_by_account
84
+ return {
85
+ "url": "https://google.com",
86
+ "alert_email": "gaurav.kumar@example.com",
87
+ "secret": "12345",
88
+ "events": [
89
+ "payment.authorized",
90
+ "payment.failed",
91
+ "payment.captured",
92
+ "payment.dispute.created",
93
+ "refund.failed",
94
+ "refund.created"
95
+ ]
96
+ }
97
+ end
98
+
99
+ def edit_webhook_payload_by_account
100
+ return {
101
+ "url": "https://google.com",
102
+ "alert_email": "gaurav.kumar@example.com",
103
+ "secret": "12345",
104
+ "events": [
105
+ "payment.authorized"
106
+ ]
107
+ }
108
+ end
109
+
110
+ def create_webhook_payload
111
+ return {
112
+ "url": "https://google.com",
113
+ "alert_email": "gaurav.kumar@example.com",
114
+ "secret": "12345",
115
+ "events": {
116
+ "payment.authorized": "true",
117
+ "refund.created": "true",
118
+ "subscription.charged": "true"
119
+ }
120
+ }
121
+ end
122
+
123
+ def edit_webhook_payload
124
+ return {
125
+ "url": "https://google.com",
126
+ "events": {
127
+ "payment.authorized": "true",
128
+ }
129
+ }
130
+ end
131
+ end
132
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: razorpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhay Rana
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-10-13 00:00:00.000000000 Z
12
+ date: 2023-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -131,11 +131,13 @@ files:
131
131
  - README.md
132
132
  - Rakefile
133
133
  - documents/Invoice.md
134
+ - documents/account.md
134
135
  - documents/addon.md
135
136
  - documents/card.md
136
137
  - documents/customer.md
137
138
  - documents/emandate.md
138
139
  - documents/fund.md
140
+ - documents/generic.md
139
141
  - documents/items.md
140
142
  - documents/order.md
141
143
  - documents/papernach.md
@@ -143,19 +145,23 @@ files:
143
145
  - documents/paymentLink.md
144
146
  - documents/paymentVerification.md
145
147
  - documents/plan.md
148
+ - documents/productConfiguration.md
146
149
  - documents/qrcode.md
147
150
  - documents/refund.md
148
151
  - documents/registerEmandate.md
149
152
  - documents/registerNach.md
150
153
  - documents/settlement.md
154
+ - documents/stakeholder.md
151
155
  - documents/subscriptions.md
152
156
  - documents/tokens.md
153
157
  - documents/transfers.md
154
158
  - documents/upi.md
155
159
  - documents/virtualAccount.md
160
+ - documents/webhook.md
156
161
  - lib/ca-bundle.crt
157
162
  - lib/extensions/httparty/hash_conversions.rb
158
163
  - lib/razorpay.rb
164
+ - lib/razorpay/account.rb
159
165
  - lib/razorpay/addon.rb
160
166
  - lib/razorpay/card.rb
161
167
  - lib/razorpay/collection.rb
@@ -168,6 +174,8 @@ files:
168
174
  - lib/razorpay/errors/razorpay_error.rb
169
175
  - lib/razorpay/errors/server_error.rb
170
176
  - lib/razorpay/fund_account.rb
177
+ - lib/razorpay/generic.rb
178
+ - lib/razorpay/iin.rb
171
179
  - lib/razorpay/invoice.rb
172
180
  - lib/razorpay/item.rb
173
181
  - lib/razorpay/order.rb
@@ -175,15 +183,19 @@ files:
175
183
  - lib/razorpay/payment_link.rb
176
184
  - lib/razorpay/payment_method.rb
177
185
  - lib/razorpay/plan.rb
186
+ - lib/razorpay/product.rb
178
187
  - lib/razorpay/qr_code.rb
179
188
  - lib/razorpay/refund.rb
180
189
  - lib/razorpay/request.rb
181
190
  - lib/razorpay/settlement.rb
191
+ - lib/razorpay/stakeholder.rb
182
192
  - lib/razorpay/subscription.rb
183
193
  - lib/razorpay/subscription_registration.rb
194
+ - lib/razorpay/token.rb
184
195
  - lib/razorpay/transfer.rb
185
196
  - lib/razorpay/utility.rb
186
197
  - lib/razorpay/virtual_account.rb
198
+ - lib/razorpay/webhook.rb
187
199
  - razorpay-ruby.gemspec
188
200
  - test/fixtures/addon_collection.json
189
201
  - test/fixtures/bad_request_error.json
@@ -194,15 +206,18 @@ files:
194
206
  - test/fixtures/delete_token.json
195
207
  - test/fixtures/downtimes_collection.json
196
208
  - test/fixtures/empty.json
209
+ - test/fixtures/fake_account.json
197
210
  - test/fixtures/fake_addon.json
198
211
  - test/fixtures/fake_captured_payment.json
199
212
  - test/fixtures/fake_card.json
213
+ - test/fixtures/fake_card_reference.json
200
214
  - test/fixtures/fake_create_upi_payment.json
201
215
  - test/fixtures/fake_customer.json
202
216
  - test/fixtures/fake_customer_edited.json
203
217
  - test/fixtures/fake_direct_transfer.json
204
218
  - test/fixtures/fake_downtime.json
205
219
  - test/fixtures/fake_fund_account.json
220
+ - test/fixtures/fake_iin_token.json
206
221
  - test/fixtures/fake_instant_settlement.json
207
222
  - test/fixtures/fake_invoice.json
208
223
  - test/fixtures/fake_item.json
@@ -217,6 +232,7 @@ files:
217
232
  - test/fixtures/fake_payment_link.json
218
233
  - test/fixtures/fake_pending_update.json
219
234
  - test/fixtures/fake_plan.json
235
+ - test/fixtures/fake_product.json
220
236
  - test/fixtures/fake_qrcode.json
221
237
  - test/fixtures/fake_qrcode_close.json
222
238
  - test/fixtures/fake_recurring.json
@@ -224,11 +240,13 @@ files:
224
240
  - test/fixtures/fake_refunded_payment.json
225
241
  - test/fixtures/fake_settlement.json
226
242
  - test/fixtures/fake_settlement_on_demand.json
243
+ - test/fixtures/fake_stakeholder.json
227
244
  - test/fixtures/fake_subscription.json
228
245
  - test/fixtures/fake_subscription_pause.json
229
246
  - test/fixtures/fake_subscription_registration.json
230
247
  - test/fixtures/fake_subscription_resume.json
231
248
  - test/fixtures/fake_token.json
249
+ - test/fixtures/fake_tokenise_customer.json
232
250
  - test/fixtures/fake_transfer.json
233
251
  - test/fixtures/fake_transfer_reverse.json
234
252
  - test/fixtures/fake_update_payment.json
@@ -238,6 +256,9 @@ files:
238
256
  - test/fixtures/fake_virtual_account_closed.json
239
257
  - test/fixtures/fake_virtual_account_collection.json
240
258
  - test/fixtures/fake_virtual_account_receiver.json
259
+ - test/fixtures/fake_webhook.json
260
+ - test/fixtures/fake_webhook_by_account_id.json
261
+ - test/fixtures/fetch_tnc.json
241
262
  - test/fixtures/fund_collection.json
242
263
  - test/fixtures/hello_response.json
243
264
  - test/fixtures/invoice_collection.json
@@ -258,34 +279,44 @@ files:
258
279
  - test/fixtures/settlement_collection.json
259
280
  - test/fixtures/settlement_instant_collection.json
260
281
  - test/fixtures/settlement_report_collection.json
282
+ - test/fixtures/stakeholder_collection.json
261
283
  - test/fixtures/subscription_collection.json
262
284
  - test/fixtures/success.json
263
285
  - test/fixtures/tokens_collection.json
264
286
  - test/fixtures/transfer_settlements_collection.json
265
287
  - test/fixtures/transfers_collection.json
266
288
  - test/fixtures/update_invoice.json
289
+ - test/fixtures/webhook_by_account_collection.json
290
+ - test/fixtures/webhook_collection.json
267
291
  - test/fixtures/welcome.json
292
+ - test/razorpay/test_account.rb
268
293
  - test/razorpay/test_addon.rb
269
294
  - test/razorpay/test_card.rb
270
295
  - test/razorpay/test_customer.rb
271
296
  - test/razorpay/test_entity.rb
272
297
  - test/razorpay/test_fund_account.rb
298
+ - test/razorpay/test_generic.rb
299
+ - test/razorpay/test_iin.rb
273
300
  - test/razorpay/test_invoice.rb
274
301
  - test/razorpay/test_item.rb
275
302
  - test/razorpay/test_order.rb
276
303
  - test/razorpay/test_payment.rb
277
304
  - test/razorpay/test_payment_link.rb
278
305
  - test/razorpay/test_plan.rb
306
+ - test/razorpay/test_product.rb
279
307
  - test/razorpay/test_qr_code.rb
280
308
  - test/razorpay/test_razorpay.rb
281
309
  - test/razorpay/test_refund.rb
282
310
  - test/razorpay/test_request.rb
283
311
  - test/razorpay/test_settlement.rb
312
+ - test/razorpay/test_stakeholder.rb
284
313
  - test/razorpay/test_subscription.rb
285
314
  - test/razorpay/test_subscription_registration.rb
315
+ - test/razorpay/test_token.rb
286
316
  - test/razorpay/test_transfer.rb
287
317
  - test/razorpay/test_utility.rb
288
318
  - test/razorpay/test_virtual_account.rb
319
+ - test/razorpay/test_webhook.rb
289
320
  - test/test_helper.rb
290
321
  homepage: https://razorpay.com/
291
322
  licenses:
@@ -320,15 +351,18 @@ test_files:
320
351
  - test/fixtures/delete_token.json
321
352
  - test/fixtures/downtimes_collection.json
322
353
  - test/fixtures/empty.json
354
+ - test/fixtures/fake_account.json
323
355
  - test/fixtures/fake_addon.json
324
356
  - test/fixtures/fake_captured_payment.json
325
357
  - test/fixtures/fake_card.json
358
+ - test/fixtures/fake_card_reference.json
326
359
  - test/fixtures/fake_create_upi_payment.json
327
360
  - test/fixtures/fake_customer.json
328
361
  - test/fixtures/fake_customer_edited.json
329
362
  - test/fixtures/fake_direct_transfer.json
330
363
  - test/fixtures/fake_downtime.json
331
364
  - test/fixtures/fake_fund_account.json
365
+ - test/fixtures/fake_iin_token.json
332
366
  - test/fixtures/fake_instant_settlement.json
333
367
  - test/fixtures/fake_invoice.json
334
368
  - test/fixtures/fake_item.json
@@ -343,6 +377,7 @@ test_files:
343
377
  - test/fixtures/fake_payment_link.json
344
378
  - test/fixtures/fake_pending_update.json
345
379
  - test/fixtures/fake_plan.json
380
+ - test/fixtures/fake_product.json
346
381
  - test/fixtures/fake_qrcode.json
347
382
  - test/fixtures/fake_qrcode_close.json
348
383
  - test/fixtures/fake_recurring.json
@@ -350,11 +385,13 @@ test_files:
350
385
  - test/fixtures/fake_refunded_payment.json
351
386
  - test/fixtures/fake_settlement.json
352
387
  - test/fixtures/fake_settlement_on_demand.json
388
+ - test/fixtures/fake_stakeholder.json
353
389
  - test/fixtures/fake_subscription.json
354
390
  - test/fixtures/fake_subscription_pause.json
355
391
  - test/fixtures/fake_subscription_registration.json
356
392
  - test/fixtures/fake_subscription_resume.json
357
393
  - test/fixtures/fake_token.json
394
+ - test/fixtures/fake_tokenise_customer.json
358
395
  - test/fixtures/fake_transfer.json
359
396
  - test/fixtures/fake_transfer_reverse.json
360
397
  - test/fixtures/fake_update_payment.json
@@ -364,6 +401,9 @@ test_files:
364
401
  - test/fixtures/fake_virtual_account_closed.json
365
402
  - test/fixtures/fake_virtual_account_collection.json
366
403
  - test/fixtures/fake_virtual_account_receiver.json
404
+ - test/fixtures/fake_webhook.json
405
+ - test/fixtures/fake_webhook_by_account_id.json
406
+ - test/fixtures/fetch_tnc.json
367
407
  - test/fixtures/fund_collection.json
368
408
  - test/fixtures/hello_response.json
369
409
  - test/fixtures/invoice_collection.json
@@ -384,32 +424,42 @@ test_files:
384
424
  - test/fixtures/settlement_collection.json
385
425
  - test/fixtures/settlement_instant_collection.json
386
426
  - test/fixtures/settlement_report_collection.json
427
+ - test/fixtures/stakeholder_collection.json
387
428
  - test/fixtures/subscription_collection.json
388
429
  - test/fixtures/success.json
389
430
  - test/fixtures/tokens_collection.json
390
431
  - test/fixtures/transfer_settlements_collection.json
391
432
  - test/fixtures/transfers_collection.json
392
433
  - test/fixtures/update_invoice.json
434
+ - test/fixtures/webhook_by_account_collection.json
435
+ - test/fixtures/webhook_collection.json
393
436
  - test/fixtures/welcome.json
437
+ - test/razorpay/test_account.rb
394
438
  - test/razorpay/test_addon.rb
395
439
  - test/razorpay/test_card.rb
396
440
  - test/razorpay/test_customer.rb
397
441
  - test/razorpay/test_entity.rb
398
442
  - test/razorpay/test_fund_account.rb
443
+ - test/razorpay/test_generic.rb
444
+ - test/razorpay/test_iin.rb
399
445
  - test/razorpay/test_invoice.rb
400
446
  - test/razorpay/test_item.rb
401
447
  - test/razorpay/test_order.rb
402
448
  - test/razorpay/test_payment.rb
403
449
  - test/razorpay/test_payment_link.rb
404
450
  - test/razorpay/test_plan.rb
451
+ - test/razorpay/test_product.rb
405
452
  - test/razorpay/test_qr_code.rb
406
453
  - test/razorpay/test_razorpay.rb
407
454
  - test/razorpay/test_refund.rb
408
455
  - test/razorpay/test_request.rb
409
456
  - test/razorpay/test_settlement.rb
457
+ - test/razorpay/test_stakeholder.rb
410
458
  - test/razorpay/test_subscription.rb
411
459
  - test/razorpay/test_subscription_registration.rb
460
+ - test/razorpay/test_token.rb
412
461
  - test/razorpay/test_transfer.rb
413
462
  - test/razorpay/test_utility.rb
414
463
  - test/razorpay/test_virtual_account.rb
464
+ - test/razorpay/test_webhook.rb
415
465
  - test/test_helper.rb