razorpay 2.4.0 → 3.2.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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.cursorignore +174 -0
  3. data/.github/dependabot.yml +8 -0
  4. data/.github/pull_request_template.md +8 -0
  5. data/.github/workflows/ci.yml +80 -0
  6. data/.github/workflows/ruby.yml +38 -0
  7. data/CHANGELOG.md +85 -1
  8. data/README.md +48 -137
  9. data/documents/Invoice.md +539 -0
  10. data/documents/account.md +449 -0
  11. data/documents/addon.md +191 -0
  12. data/documents/card.md +655 -0
  13. data/documents/customer.md +405 -0
  14. data/documents/dispute.md +301 -0
  15. data/documents/documents.md +65 -0
  16. data/documents/emandate.md +492 -0
  17. data/documents/fund.md +89 -0
  18. data/documents/items.md +208 -0
  19. data/documents/oauth_token.md +142 -0
  20. data/documents/order.md +352 -0
  21. data/documents/papernach.md +738 -0
  22. data/documents/payment.md +1122 -0
  23. data/documents/paymentLink.md +1063 -0
  24. data/documents/paymentVerification.md +79 -0
  25. data/documents/plan.md +184 -0
  26. data/documents/productConfiguration.md +444 -0
  27. data/documents/qrcode.md +439 -0
  28. data/documents/refund.md +325 -0
  29. data/documents/registerEmandate.md +452 -0
  30. data/documents/registerNach.md +653 -0
  31. data/documents/settlement.md +478 -0
  32. data/documents/stakeholder.md +334 -0
  33. data/documents/subscriptions.md +752 -0
  34. data/documents/tokens.md +407 -0
  35. data/documents/transfers.md +821 -0
  36. data/documents/upi.md +545 -0
  37. data/documents/virtualAccount.md +591 -0
  38. data/documents/webhook.md +224 -0
  39. data/lib/razorpay/account.rb +39 -0
  40. data/lib/razorpay/addon.rb +9 -1
  41. data/lib/razorpay/card.rb +4 -0
  42. data/lib/razorpay/constants.rb +7 -2
  43. data/lib/razorpay/customer.rb +31 -0
  44. data/lib/razorpay/dispute.rb +26 -0
  45. data/lib/razorpay/document.rb +19 -0
  46. data/lib/razorpay/fund_account.rb +19 -0
  47. data/lib/razorpay/iin.rb +15 -0
  48. data/lib/razorpay/invoice.rb +8 -0
  49. data/lib/razorpay/item.rb +34 -0
  50. data/lib/razorpay/oauth_token.rb +109 -0
  51. data/lib/razorpay/order.rb +19 -1
  52. data/lib/razorpay/payload_validator.rb +93 -0
  53. data/lib/razorpay/payment.rb +64 -0
  54. data/lib/razorpay/payment_link.rb +36 -0
  55. data/lib/razorpay/payment_method.rb +17 -0
  56. data/lib/razorpay/product.rb +37 -0
  57. data/lib/razorpay/qr_code.rb +34 -0
  58. data/lib/razorpay/refund.rb +4 -0
  59. data/lib/razorpay/request.rb +50 -26
  60. data/lib/razorpay/settlement.rb +39 -0
  61. data/lib/razorpay/stakeholder.rb +39 -0
  62. data/lib/razorpay/subscription.rb +24 -0
  63. data/lib/razorpay/subscription_registration.rb +16 -0
  64. data/lib/razorpay/token.rb +28 -0
  65. data/lib/razorpay/transfer.rb +39 -0
  66. data/lib/razorpay/utility.rb +41 -6
  67. data/lib/razorpay/validation_config.rb +11 -0
  68. data/lib/razorpay/virtual_account.rb +15 -7
  69. data/lib/razorpay/webhook.rb +50 -0
  70. data/lib/razorpay.rb +24 -1
  71. data/razorpay-ruby.gemspec +2 -1
  72. data/test/fixtures/addon_collection.json +60 -0
  73. data/test/fixtures/create_json_payment.json +13 -0
  74. data/test/fixtures/delete_token.json +3 -0
  75. data/test/fixtures/dispute_collection.json +67 -0
  76. data/test/fixtures/dispute_error.json +10 -0
  77. data/test/fixtures/document_error.json +10 -0
  78. data/test/fixtures/downtimes_collection.json +21 -0
  79. data/test/fixtures/empty.json +2 -0
  80. data/test/fixtures/error_customer.json +10 -0
  81. data/test/fixtures/error_eligibility.json +10 -0
  82. data/test/fixtures/error_eligibility_check.json +10 -0
  83. data/test/fixtures/fake_account.json +78 -0
  84. data/test/fixtures/fake_addon.json +3 -3
  85. data/test/fixtures/fake_bank_account.json +9 -0
  86. data/test/fixtures/fake_card_reference.json +5 -0
  87. data/test/fixtures/fake_create_upi_payment.json +3 -0
  88. data/test/fixtures/fake_direct_transfer.json +32 -0
  89. data/test/fixtures/fake_dispute.json +29 -0
  90. data/test/fixtures/fake_document.json +9 -0
  91. data/test/fixtures/fake_downtime.json +14 -0
  92. data/test/fixtures/fake_eligiblity.json +79 -0
  93. data/test/fixtures/fake_fulfillment.json +10 -0
  94. data/test/fixtures/fake_fund_account.json +18 -0
  95. data/test/fixtures/fake_iin_token.json +23 -0
  96. data/test/fixtures/fake_instant_settlement.json +19 -0
  97. data/test/fixtures/fake_item.json +9 -0
  98. data/test/fixtures/fake_oauth_token.json +8 -0
  99. data/test/fixtures/fake_order_transfers.json +88 -0
  100. data/test/fixtures/fake_otp_generate.json +19 -0
  101. data/test/fixtures/fake_otp_resend.json +7 -0
  102. data/test/fixtures/fake_otp_submit.json +5 -0
  103. data/test/fixtures/fake_payment_expanded_details.json +38 -0
  104. data/test/fixtures/fake_payment_expanded_details_card.json +50 -0
  105. data/test/fixtures/fake_payment_link.json +40 -0
  106. data/test/fixtures/fake_pending_update.json +30 -0
  107. data/test/fixtures/fake_product.json +138 -0
  108. data/test/fixtures/fake_qrcode.json +20 -0
  109. data/test/fixtures/fake_qrcode_close.json +22 -0
  110. data/test/fixtures/fake_recurring.json +5 -0
  111. data/test/fixtures/fake_refund.json +1 -1
  112. data/test/fixtures/fake_revoke_token.json +3 -0
  113. data/test/fixtures/fake_rto.json +15 -0
  114. data/test/fixtures/fake_settlement.json +11 -0
  115. data/test/fixtures/fake_settlement_on_demand.json +39 -0
  116. data/test/fixtures/fake_stakeholder.json +29 -0
  117. data/test/fixtures/fake_subscription_pause.json +19 -0
  118. data/test/fixtures/fake_subscription_registration.json +91 -0
  119. data/test/fixtures/fake_subscription_resume.json +19 -0
  120. data/test/fixtures/fake_token.json +31 -0
  121. data/test/fixtures/fake_tokenise_customer.json +40 -0
  122. data/test/fixtures/fake_transfer.json +18 -0
  123. data/test/fixtures/fake_transfer_reverse.json +15 -0
  124. data/test/fixtures/fake_update_payment.json +39 -0
  125. data/test/fixtures/fake_validate_vpa.json +5 -0
  126. data/test/fixtures/fake_virtual_account_allowed.json +46 -0
  127. data/test/fixtures/fake_virtual_account_receiver.json +46 -0
  128. data/test/fixtures/fake_webhook.json +79 -0
  129. data/test/fixtures/fake_webhook_by_account_id.json +22 -0
  130. data/test/fixtures/fetch_tnc.json +11 -0
  131. data/test/fixtures/fund_collection.json +20 -0
  132. data/test/fixtures/item_collection.json +24 -0
  133. data/test/fixtures/order_error.json +10 -0
  134. data/test/fixtures/payment_collection.json +1 -1
  135. data/test/fixtures/payment_error.json +10 -0
  136. data/test/fixtures/payment_link_collection.json +43 -0
  137. data/test/fixtures/payment_link_response.json +3 -0
  138. data/test/fixtures/payment_methods_collection.json +149 -0
  139. data/test/fixtures/qrcode_collection.json +50 -0
  140. data/test/fixtures/qrcode_payments_collection.json +74 -0
  141. data/test/fixtures/reversals_collection.json +22 -0
  142. data/test/fixtures/settlement_collection.json +26 -0
  143. data/test/fixtures/settlement_instant_collection.json +84 -0
  144. data/test/fixtures/settlement_report_collection.json +117 -0
  145. data/test/fixtures/stakeholder_collection.json +35 -0
  146. data/test/fixtures/success.json +3 -0
  147. data/test/fixtures/tokens_collection.json +36 -0
  148. data/test/fixtures/transfer_error.json +10 -0
  149. data/test/fixtures/transfer_settlements_collection.json +38 -0
  150. data/test/fixtures/transfers_collection.json +41 -0
  151. data/test/fixtures/webhook_by_account_collection.json +35 -0
  152. data/test/fixtures/webhook_collection.json +85 -0
  153. data/test/razorpay/test_account.rb +134 -0
  154. data/test/razorpay/test_addon.rb +19 -15
  155. data/test/razorpay/test_card.rb +6 -0
  156. data/test/razorpay/test_customer.rb +132 -3
  157. data/test/razorpay/test_dispute.rb +98 -0
  158. data/test/razorpay/test_document.rb +27 -0
  159. data/test/razorpay/test_fund_account.rb +42 -0
  160. data/test/razorpay/test_iin.rb +23 -0
  161. data/test/razorpay/test_invoice.rb +15 -2
  162. data/test/razorpay/test_item.rb +66 -0
  163. data/test/razorpay/test_oauth_token.rb +105 -0
  164. data/test/razorpay/test_order.rb +66 -1
  165. data/test/razorpay/test_payload_validator.rb +61 -0
  166. data/test/razorpay/test_payment.rb +251 -9
  167. data/test/razorpay/test_payment_link.rb +83 -0
  168. data/test/razorpay/test_plan.rb +2 -2
  169. data/test/razorpay/test_product.rb +67 -0
  170. data/test/razorpay/test_qr_code.rb +63 -0
  171. data/test/razorpay/test_razorpay.rb +19 -2
  172. data/test/razorpay/test_refund.rb +16 -2
  173. data/test/razorpay/test_settlement.rb +76 -0
  174. data/test/razorpay/test_stakeholder.rb +87 -0
  175. data/test/razorpay/test_subscription.rb +72 -9
  176. data/test/razorpay/test_subscription_registration.rb +58 -0
  177. data/test/razorpay/test_token.rb +66 -0
  178. data/test/razorpay/test_transfer.rb +94 -0
  179. data/test/razorpay/test_utility.rb +72 -4
  180. data/test/razorpay/test_virtual_account.rb +64 -17
  181. data/test/razorpay/test_webhook.rb +132 -0
  182. data/test/test_helper.rb +8 -0
  183. metadata +265 -10
  184. data/.travis.yml +0 -22
  185. data/test/razorpay/test_errors.rb +0 -19
@@ -5,7 +5,10 @@ module Razorpay
5
5
  class RazorpayPaymentTest < Minitest::Test
6
6
  def setup
7
7
  @payment_id = 'fake_payment_id'
8
-
8
+ @downtime_id = 'fake_downtime_id'
9
+ @card_id = 'card_7EZLhWkDt05n7V'
10
+ @transfer_id = 'trf_J0FrZYPql4riDx'
11
+ @refund_id = 'fake_refund_id'
9
12
  # Any request that ends with payments/payment_id
10
13
  stub_get(%r{payments\/#{@payment_id}$}, 'fake_payment')
11
14
  stub_get(/payments$/, 'payment_collection')
@@ -23,6 +26,111 @@ module Razorpay
23
26
  assert_equal 'card', payment.method, 'Payment method is accessible'
24
27
  end
25
28
 
29
+ def test_payments_fetch_downtime
30
+ stub_get( %r{payments/downtimes$}, 'downtimes_collection')
31
+ payments = Razorpay::Payment.fetch_payment_downtime
32
+ assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
33
+ refute_empty payments.items, 'payments should be more than one'
34
+ end
35
+
36
+ def test_payments_fetch_downtime_by_id
37
+ stub_get( %r{payments/downtimes/#{@downtime_id}$}, 'fake_downtime')
38
+ payment = Razorpay::Payment.fetch_payment_downtime_by_id(@downtime_id)
39
+ assert_instance_of Razorpay::Entity, payment, 'Payment not an instance of Razorpay::Payment class'
40
+ assert_equal @downtime_id , payment.id
41
+ end
42
+
43
+ def test_payments_fetch_card_details
44
+ stub_get( %r{payments/#{@payment_id}/card$}, 'fake_card')
45
+ card = Razorpay::Payment.fetch_card_details(@payment_id)
46
+ assert_instance_of Razorpay::Card, card, 'Card not an instance of Razorpay::Card class'
47
+ assert_equal @card_id , card.id
48
+ end
49
+
50
+ def test_payments_fetch_multiple_refund_for_payment
51
+ stub_get( %r{payments/#{@payment_id}/refunds$}, 'refund_collection',{})
52
+ payments = Razorpay::Payment.fetch_multiple_refund(@payment_id,{})
53
+ assert_instance_of Razorpay::Collection, payments, 'Payment not an instance of Razorpay::Payment class'
54
+ assert !payments.items.empty?, 'payments should be more than one'
55
+ end
56
+
57
+ def test_payments_fetch_transfers
58
+ stub_get(%r{payments/#{@payment_id}/transfers$}, 'transfers_collection')
59
+ transfers = Razorpay::Payment.fetch(@payment_id).fetch_transfer
60
+ assert_instance_of Razorpay::Collection, transfers, 'Transfers should be an array'
61
+ assert !transfers.items.empty?, 'transfers should be more than one'
62
+ end
63
+
64
+ def test_payments_post_transfers
65
+ param_attr = {
66
+ "transfers": [
67
+ {
68
+ "account": "acc_CPRsN1LkFccllA",
69
+ "amount": 100,
70
+ "currency": "INR",
71
+ "notes": {
72
+ "name": "Gaurav Kumar",
73
+ "roll_no": "IEC2011025"
74
+ },
75
+ "linked_account_notes": [
76
+ "roll_no"
77
+ ],
78
+ "on_hold": true,
79
+ "on_hold_until": 1671222870
80
+ },
81
+ {
82
+ "account": "acc_CNo3jSI8OkFJJJ",
83
+ "amount": 100,
84
+ "currency": "INR",
85
+ "notes": {
86
+ "name": "Saurav Kumar",
87
+ "roll_no": "IEC2011026"
88
+ },
89
+ "linked_account_notes": [
90
+ "roll_no"
91
+ ],
92
+ "on_hold": false
93
+ }
94
+ ]
95
+ }
96
+
97
+ stub_post(%r{payments/#{@payment_id}/transfers$}, 'fake_transfer', param_attr.to_json)
98
+ transfer = Razorpay::Payment.fetch(@payment_id).transfer(param_attr.to_json)
99
+ assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Razorpay::Transfer class'
100
+ assert transfer.on_hold
101
+ end
102
+
103
+ def test_payments_fetch_refunds
104
+ stub_get(%r{payments/#{@payment_id}/refunds/#{@refund_id}$}, 'fake_refund')
105
+ refund = Razorpay::Payment.fetch(@payment_id).fetch_refund(@refund_id)
106
+ assert_instance_of Razorpay::Refund, refund, 'Refund not an instance of Razorpay::Refund class'
107
+ assert_equal @refund_id, refund.id
108
+ end
109
+
110
+ def test_payment_create_recurring
111
+
112
+ payment_attr = {
113
+ "email": "gaurav.kumar@example.com",
114
+ "contact": "9123456789",
115
+ "amount": 1000,
116
+ "currency": "INR",
117
+ "order_id": "order_1Aa00000000002",
118
+ "customer_id": "cust_1Aa00000000001",
119
+ "token": "token_1Aa00000000001",
120
+ "recurring": "1",
121
+ "description": "Creating recurring payment for Gaurav Kumar",
122
+ "notes": {
123
+ "note_key 1": "Beam me up Scotty",
124
+ "note_key 2": "Tea. Earl Gray. Hot."
125
+ }
126
+ }
127
+
128
+ stub_post(%r{payments/create/recurring$}, 'fake_recurring', payment_attr.to_json)
129
+ payment = Razorpay::Payment.create_recurring_payment payment_attr.to_json
130
+ assert_equal 'pay_1Aa00000000001', payment.razorpay_payment_id
131
+
132
+ end
133
+
26
134
  def test_all_payments
27
135
  payments = Razorpay::Payment.all
28
136
  assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
@@ -40,7 +148,7 @@ module Razorpay
40
148
  stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
41
149
  refund = Razorpay::Payment.fetch(@payment_id).refund
42
150
  assert_instance_of Razorpay::Refund, refund
43
- assert_equal refund.payment_id, @payment_id
151
+ assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
44
152
  end
45
153
 
46
154
  def test_payment_refund!
@@ -56,21 +164,30 @@ module Razorpay
56
164
  stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', 'amount=2000')
57
165
  refund = Razorpay::Payment.fetch(@payment_id).refund(amount: 2000)
58
166
  assert_instance_of Razorpay::Refund, refund
59
- assert_equal refund.payment_id, @payment_id
167
+ assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
60
168
  assert_equal refund.amount, 2000
61
169
  end
62
170
 
63
171
  def test_payment_capture
64
- stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
65
- payment = Razorpay::Payment.fetch(@payment_id)
66
- payment = payment.capture(amount: 5100)
172
+
173
+ para_attr = {
174
+ amount: 1000,
175
+ currency: 'INR'
176
+ }
177
+
178
+ stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', para_attr.to_json)
179
+ payment = Razorpay::Payment.fetch(@payment_id).capture(para_attr.to_json)
67
180
  assert_equal 'captured', payment.status
68
181
  end
69
182
 
70
183
  def test_payment_capture!
71
- stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
184
+ para_attr = {
185
+ amount: 1000,
186
+ currency: "INR"
187
+ }
188
+ stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', para_attr.to_json)
72
189
  payment = Razorpay::Payment.fetch(@payment_id)
73
- payment.capture!(amount: 5100)
190
+ payment.capture!(para_attr.to_json)
74
191
  assert_equal 'captured', payment.status
75
192
  end
76
193
 
@@ -79,5 +196,130 @@ module Razorpay
79
196
  payment = Razorpay::Payment.capture(@payment_id, amount: 5100)
80
197
  assert_equal 'captured', payment.status
81
198
  end
82
- end
199
+
200
+ def test_otp_generate
201
+ payment_id = 'pay_FVmAstJWfsD3SO'
202
+ stub_post(%r{payments/#{payment_id}/otp_generate$}, 'fake_otp_generate', {})
203
+ payment = Razorpay::Payment.otp_generate(payment_id)
204
+ assert_equal payment_id, payment.razorpay_payment_id
205
+ end
206
+
207
+ def test_otp_submit
208
+ param_attr = {
209
+ otp: "123456"
210
+ }
211
+ stub_post(%r{payments/#{@payment_id}/otp/submit$}, 'fake_otp_submit', param_attr.to_json)
212
+ payment = Razorpay::Payment.fetch(@payment_id).otp_submit(param_attr.to_json)
213
+ assert_equal @payment_id, payment.razorpay_payment_id
214
+ end
215
+
216
+ def test_otp_resend
217
+ stub_post(%r{payments/#{@payment_id}/otp/resend$}, 'fake_otp_resend', {})
218
+ payment = Razorpay::Payment.fetch(@payment_id).otp_resend
219
+ assert_equal @payment_id, payment.razorpay_payment_id
220
+ end
221
+
222
+ def test_payment_edit
223
+
224
+ payment_attr = {
225
+ "notes": {
226
+ "notes_key_1": 'Beam me up Scotty.',
227
+ "notes_key_2": 'Engage'
228
+ }
229
+ }
230
+ stub_patch(%r{payments\/#{@payment_id}$}, 'fake_update_payment', payment_attr.to_json)
231
+ payment = Razorpay::Payment.fetch(@payment_id).edit(payment_attr.to_json)
232
+ assert_equal 'payment', payment.entity
233
+ assert_equal 'Beam me up Scotty.', payment.notes["notes_key_1"]
234
+ end
235
+
236
+ def test_payment_create_payment_json
237
+
238
+ payment_attr = {
239
+ amount: '100',
240
+ currency: 'INR',
241
+ email: 'gaurav.kumar@example.com',
242
+ contact: '9123456789',
243
+ order_id: 'order_EAkbvXiCJlwhHR',
244
+ method: 'card',
245
+ card: {
246
+ number: '4854980604708430',
247
+ cvv: '123',
248
+ expiry_month: '12',
249
+ expiry_year: '21',
250
+ name: 'Gaurav Kumar'
251
+ }
252
+ }
253
+
254
+ stub_post(%r{payments/create/json$}, 'create_json_payment',payment_attr.to_json)
255
+ payment = Razorpay::Payment.create_json_payment payment_attr.to_json
256
+ assert_equal 'pay_FVmAstJWfsD3SO', payment.razorpay_payment_id
257
+ end
258
+ def test_create_upi
259
+
260
+ param_attr = {
261
+ "amount": 200,
262
+ "currency": "INR",
263
+ "order_id": "order_GAWRjlWkVcRh0V",
264
+ "email": "gaurav.kumar@example.com",
265
+ "contact": "9123456789",
266
+ "method": "upi",
267
+ "customer_id": "cust_EIW4T2etiweBmG",
268
+ "save": 1,
269
+ "ip": "192.168.0.103",
270
+ "referer": "http",
271
+ "user_agent": "Mozilla/5.0",
272
+ "description": "Test flow",
273
+ "notes": {
274
+ "note_key": "value1"
275
+ },
276
+ "upi": {
277
+ "flow": "collect",
278
+ "vpa": "gauravkumar@exampleupi",
279
+ "expiry_time": 5
280
+ }
281
+ }
282
+
283
+ stub_post(%r{payments/create/upi$}, 'fake_create_upi_payment',param_attr.to_json)
284
+ payment = Razorpay::Payment.create_upi param_attr.to_json
285
+ assert_equal 'pay_FVmAstJWfsD3SO', payment.razorpay_payment_id
286
+ end
287
+
288
+ def test_payment_methods
289
+ stub_get(/methods$/, 'payment_methods_collection')
290
+ methods = Razorpay::PaymentMethods.all
291
+ assert_equal 'methods', methods.entity
292
+ end
293
+
294
+ def test_validate_vpa
295
+ param_attr = {
296
+ "vpa": "gauravkumar@exampleupi"
297
+ }
298
+ stub_post(%r{payments/validate/vpa$}, 'fake_validate_vpa',param_attr.to_json)
299
+ payment = Razorpay::Payment.validate_vpa param_attr.to_json
300
+ assert_equal param_attr[:vpa], payment.vpa
301
+ end
302
+
303
+ def test_expand_details_emi
304
+ stub_get("#{BASE_URI}/v1/payments/#{@payment_id}/?expand[]=emi", 'fake_payment_expanded_details')
305
+ payment = Razorpay::Payment.expand_details @payment_id
306
+ assert_equal @payment_id, payment.id
307
+ end
308
+
309
+ def test_expand_details_card
310
+ stub_get("#{BASE_URI}/v1/payments/#{@payment_id}/?expand[]=card", 'fake_payment_expanded_details')
311
+ payment = Razorpay::Payment.expand_details @payment_id
312
+ assert_equal @payment_id, payment.id
313
+ end
314
+
315
+ def test_expand_details_failure
316
+ stub_get(%r{payments\/#{@payment_id}$}, 'payment_error')
317
+ assert_raises(Razorpay::Error) do
318
+ payment = Razorpay::Payment.expand_details(@payment_id)
319
+ if payment.error
320
+ raise Razorpay::Error.new, payment.error['code']
321
+ end
322
+ end
323
+ end
324
+ end
83
325
  end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::PaymentLink
5
+ class RazorpayPaymentLinkTest < Minitest::Test
6
+ def setup
7
+ @payment_link_id = 'plink_J9feMU9xqHQVWX'
8
+
9
+ # Any request that ends with payment_link/payment_link_id
10
+ stub_get(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link')
11
+ stub_get(/payment_links$/, 'payment_link_collection')
12
+ end
13
+
14
+ def test_payment_link_should_be_defined
15
+ refute_nil Razorpay::PaymentLink
16
+ end
17
+
18
+ def test_payment_link_should_be_created
19
+ param_attr = {
20
+ "amount": 2244,
21
+ "currency": "INR",
22
+ "accept_partial": true,
23
+ "first_min_partial_amount": 100,
24
+ "description": "For XYZ purpose",
25
+ "customer": {
26
+ "name": "Gaurav Kumar",
27
+ "email": "gaurav.kumar@example.com",
28
+ "contact": "+919999999999"
29
+ },
30
+ "notify": {
31
+ "sms": true,
32
+ "email": true
33
+ },
34
+ "reminder_enable": true,
35
+ "notes": {
36
+ "policy_name": "Jeevan Bima"
37
+ },
38
+ "callback_url": "https://example-callback-url.com/",
39
+ "callback_method": "get"
40
+ }
41
+
42
+ stub_post(/payment_links$/, 'fake_payment_link', param_attr.to_json)
43
+ payment_link = Razorpay::PaymentLink.create param_attr.to_json
44
+ assert_equal @payment_link_id, payment_link.id
45
+ end
46
+
47
+ def test_edit_payment_link
48
+ para_attr ={
49
+ "reference_id": "TS35",
50
+ "expire_by": 1653347540,
51
+ "reminder_enable":false,
52
+ "notes":{
53
+ "policy_name": "Jeevan Saral"
54
+ }
55
+ }
56
+
57
+ stub_patch(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link', para_attr.to_json)
58
+ payment_link = Razorpay::PaymentLink.edit(@payment_link_id,para_attr.to_json)
59
+ assert_instance_of Razorpay::Entity, payment_link
60
+ assert true, payment_link.accept_partial
61
+ end
62
+
63
+ def test_fetch_all_payment_link
64
+ stub_get(/payment_links$/, 'payment_link_collection')
65
+ payment_link = Razorpay::PaymentLink.all
66
+ assert_instance_of Razorpay::Collection, payment_link
67
+ end
68
+
69
+ def test_fetch_specific_payment
70
+ stub_get(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link')
71
+ payment_link = Razorpay::PaymentLink.fetch(@payment_link_id)
72
+ assert_instance_of Razorpay::Entity, payment_link
73
+ assert_equal payment_link.id, @payment_link_id
74
+ end
75
+
76
+ def test_notify_by_id
77
+ stub_post(%r{payment_links/#{@payment_link_id}/notify_by/email$}, 'payment_link_response',{})
78
+ payment_link = Razorpay::PaymentLink.notify_by(@payment_link_id,"email")
79
+ assert_instance_of Razorpay::Entity, payment_link
80
+ assert true, payment_link.success
81
+ end
82
+ end
83
+ end
@@ -42,9 +42,9 @@ module Razorpay
42
42
  notes: { identifier: 'plan_monthly_1000' }
43
43
  }
44
44
 
45
- stub_post(/plans$/, 'fake_plan', create_plan_stub_url_params)
45
+ stub_post(/plans$/, 'fake_plan', plan_attrs.to_json)
46
46
 
47
- plan = Razorpay::Plan.create plan_attrs
47
+ plan = Razorpay::Plan.create plan_attrs.to_json
48
48
 
49
49
  assert_equal 1, plan.interval, 'Plan interval is accessible'
50
50
  assert_equal 'monthly', plan.period, 'Plan period is accessible'
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Product
5
+ class RazorpayProductonTest < Minitest::Test
6
+ class Product < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @product_id = 'acc_prd_00000000000001'
10
+ @account_id = 'acc_00000000000001'
11
+ @product_name = 'payment_gateway'
12
+ @tnc_id = 'tnc_map_00000000000001'
13
+ # Any request that ends with product_id
14
+ stub_get(%r{/v2/accounts\/#{Regexp.quote(@account_id)}/products\/#{Regexp.quote(@product_id)}$}, 'fake_product')
15
+ end
16
+
17
+ def test_product_should_be_defined
18
+ refute_nil Razorpay::Product
19
+ end
20
+
21
+ def test_product_should_be_available
22
+ product = Razorpay::Product.fetch(@account_id, @product_id)
23
+ assert_instance_of Razorpay::Entity, product, 'product not an instance of Entity class'
24
+ assert_equal @product_id, product.id, 'Product IDs do not match'
25
+ assert_equal @product_name, product.product_name, 'product name is accessible'
26
+ end
27
+
28
+ def test_product_request_product_configuration
29
+
30
+ payload = create_product_payload()
31
+ stub_post(%r{accounts/#{@account_id}/products$}, 'fake_product', payload.to_json)
32
+
33
+ product = Razorpay::Product.request_product_configuration(@account_id, payload.to_json)
34
+ assert_instance_of Razorpay::Entity, product, 'Product not an instance of Entity class'
35
+ assert_equal @product_id, product.id, 'Product IDs do not match'
36
+ assert_equal @product_name, product.product_name, 'product name is accessible'
37
+ end
38
+
39
+ def test_product_edit
40
+
41
+ payload = create_product_payload()
42
+ stub_patch(%r{accounts/#{@account_id}/products/#{@product_id}$}, 'fake_product', payload.to_json)
43
+
44
+ product = Razorpay::Product.edit(@account_id, @product_id, payload.to_json)
45
+ assert_instance_of Razorpay::Entity, product, 'Product not an instance of Entity class'
46
+ assert_equal @product_id, product.id, 'Product IDs do not match'
47
+ assert_equal @product_name, product.product_name, 'product name is accessible'
48
+ end
49
+
50
+ def test_product_fetchTnc
51
+ product_name = "payments"
52
+
53
+ stub_get("#{BASE_URI}/v2/products/#{product_name}/tnc", 'fetch_tnc')
54
+ product = Razorpay::Product.fetch_tnc(product_name)
55
+ assert_instance_of Razorpay::Entity, product, 'Product not an instance of Entity class'
56
+ assert_equal @tnc_id, product.id, 'Product IDs do not match'
57
+ end
58
+
59
+ def create_product_payload
60
+ return {
61
+ "product_name": "payment_gateway",
62
+ "tnc_accepted": true,
63
+ "ip": "233.233.233.234"
64
+ }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::QrCode
5
+ class RazorpayQrCodeTest < Minitest::Test
6
+ def setup
7
+ @qrcode_id = 'qr_HMsVL8HOpbMcjU'
8
+ @customer_id = 'cust_HKsR5se84c5LTO'
9
+ # Any request that ends with qrcode/qrcode_id
10
+ stub_get(%r{payments/qr_codes/#{@qrcode_id}$}, 'fake_qrcode')
11
+ stub_get(%r{payments/qr_codes$}, 'qrcode_collection')
12
+ end
13
+
14
+ def test_qrcode_should_be_defined
15
+ refute_nil Razorpay::QrCode
16
+ end
17
+
18
+ def test_qrcode_should_be_created
19
+ para_attr = {
20
+ "type": "upi_qr",
21
+ "name": "Store_1",
22
+ "usage": "single_use",
23
+ "fixed_amount": true,
24
+ "payment_amount": 300,
25
+ "description": "For Store 1",
26
+ "customer_id": "cust_HKsR5se84c5LTO",
27
+ "close_by": 1681615838,
28
+ "notes": {
29
+ "purpose": "Test UPI QR code notes"
30
+ }
31
+ }
32
+ stub_post(%r{/payments/qr_codes$}, 'fake_qrcode', para_attr.to_json)
33
+ qr_code = Razorpay::QrCode.create(para_attr.to_json)
34
+
35
+ assert_equal @qrcode_id, qr_code.id
36
+ assert_equal @customer_id, qr_code.customer_id
37
+ end
38
+
39
+ def test_fetch_all_qcode
40
+ qr_code = Razorpay::QrCode.all
41
+ assert_instance_of Razorpay::Collection, qr_code
42
+ end
43
+
44
+ def test_fetch_specific_qrcode
45
+ qr_code = Razorpay::QrCode.fetch(@qrcode_id)
46
+ assert_instance_of Razorpay::QrCode, qr_code
47
+ assert_equal qr_code.id, @qrcode_id
48
+ end
49
+
50
+ def test_qrcode_close
51
+ stub_post(%r{payments/qr_codes/#{@qrcode_id}/close$}, 'fake_qrcode_close',{})
52
+ qr_code = Razorpay::QrCode.fetch(@qrcode_id).close
53
+ assert_instance_of Razorpay::QrCode, qr_code
54
+ assert_equal qr_code.id, @qrcode_id
55
+ end
56
+
57
+ def test_qrcode_fetch_payments
58
+ stub_get(%r{payments/qr_codes/#{@qrcode_id}/payments$}, 'qrcode_payments_collection',{})
59
+ qr_code = Razorpay::QrCode.fetch(@qrcode_id).fetch_payments()
60
+ assert_instance_of Razorpay::Collection, qr_code
61
+ end
62
+ end
63
+ end
@@ -22,7 +22,7 @@ module Razorpay
22
22
  stub_get(/$/, 'hello_response')
23
23
  Razorpay.headers = custom_headers
24
24
  Razorpay::Request.new('dummy').make_test_request
25
- user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}"
25
+ user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
26
26
  headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
27
27
  headers = headers.merge(custom_headers)
28
28
  assert_requested :get, 'https://api.razorpay.com/',
@@ -43,11 +43,28 @@ module Razorpay
43
43
  def test_auth_header_and_user_agent
44
44
  stub_get(/$/, 'hello_response')
45
45
  Razorpay::Request.new('dummy').make_test_request
46
- user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}"
46
+ user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
47
47
  headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
48
48
  assert_requested :get, 'https://api.razorpay.com/',
49
49
  headers: headers,
50
50
  times: 1
51
51
  end
52
+
53
+ def test_oauth_setup
54
+ Razorpay.setup_with_oauth('access_token')
55
+ assert_equal 'access_token', Razorpay.access_token
56
+ end
57
+
58
+ # # We mock this request
59
+ def test_auth_header_and_user_agent_for_oauth
60
+ stub_get(/$/, 'hello_response')
61
+ Razorpay.setup_with_oauth('access_token')
62
+ Razorpay::Request.new('dummy').make_test_request
63
+ user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
64
+ headers = { 'User-Agent' => user_agent, 'Authorization' => 'Bearer access_token' }
65
+ assert_requested :get, 'https://api.razorpay.com/',
66
+ headers: headers,
67
+ times: 1
68
+ end
52
69
  end
53
70
  end
@@ -36,7 +36,21 @@ module Razorpay
36
36
  stub_post(/refunds$/, 'fake_refund', "payment_id=#{@payment_id}")
37
37
  refund = Razorpay::Refund.create(payment_id: @payment_id)
38
38
  assert_instance_of Razorpay::Refund, refund
39
- assert_equal refund.payment_id, @payment_id
39
+ assert_equal refund.id, @refund_id
40
+ end
41
+
42
+ def test_edit_refund
43
+ para_attr = {
44
+ "notes": {
45
+ "notes_key_1":"Beam me up Scotty.",
46
+ "notes_key_2":"Engage"
47
+ }
48
+ }
49
+ stub_patch(%r{/refunds/#{@refund_id}$}, 'fake_refund', para_attr.to_json)
50
+ refund = Razorpay::Refund.fetch(@refund_id).edit(para_attr.to_json)
51
+ assert_instance_of Razorpay::Refund, refund
52
+ assert_equal refund.id, @refund_id
40
53
  end
41
- end
54
+ end
42
55
  end
56
+
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Settlement
5
+ class RazorpaySettlementTest < Minitest::Test
6
+ class Item < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @settlement_id = 'setl_DGlQ1Rj8os78Ec'
10
+ @settlement_ondemand_id = 'setlod_FNj7g2YS5J67Rz'
11
+ @addon_id = 'ao_IrSY3UIqDRx7df'
12
+
13
+ # Any request that ends with settlement/settlement_id
14
+ stub_get(%r{settlements\/#{Regexp.quote(@settlement_id)}$}, 'fake_settlement')
15
+ end
16
+
17
+ def test_settlement_should_be_defined
18
+ refute_nil Razorpay::Settlement
19
+ end
20
+
21
+ def test_settlement_should_be_available
22
+ settlement = Razorpay::Settlement.fetch(@settlement_id)
23
+ assert_instance_of Razorpay::Settlement, settlement, 'Settlement not an instance of Settlement class'
24
+ assert_equal @settlement_id, settlement.id, 'Settlement IDs do not match'
25
+ end
26
+
27
+ def test_fetch_all_settlement
28
+ stub_get(/settlements$/, 'settlement_collection')
29
+ settlement = Razorpay::Settlement.all
30
+ assert_instance_of Razorpay::Collection, settlement, 'Settlement should be an array'
31
+ refute_empty settlement.items, 'Settlement should be more than one'
32
+ end
33
+
34
+ def test_settlement_reports
35
+ para_attr = {
36
+ "year": 2022,
37
+ "month":12
38
+ }
39
+ stub_get("#{BASE_URI}/v1/settlements/recon/combined?month=12&year=2022", 'settlement_report_collection')
40
+ settlement = Razorpay::Settlement.reports(para_attr)
41
+ assert_instance_of Razorpay::Collection, settlement, 'Settlement not an instance of Settlement class'
42
+ refute_empty settlement.items, 'Settlement should be more than one'
43
+ end
44
+
45
+ def test_settlement_should_be_created_on_demand
46
+ para_attr = {
47
+ "amount": 1221,
48
+ "settle_full_balance": false,
49
+ "description": "Testing",
50
+ "notes": {
51
+ "notes_key_1": "Tea, Earl Grey, Hot",
52
+ "notes_key_2": "Tea, Earl Grey… decaf."
53
+ }
54
+ }
55
+
56
+ stub_post( %r{settlements/ondemand$},'fake_settlement_on_demand',para_attr.to_json)
57
+ settlement = Razorpay::Settlement.create para_attr.to_json
58
+ assert_instance_of Razorpay::Settlement, settlement, 'Settlement should be an array'
59
+ assert_equal @settlement_id , settlement.id
60
+ end
61
+
62
+ def test_fetch_all_instant_settlement
63
+ stub_get(%r{settlements/ondemand$}, 'settlement_instant_collection')
64
+ settlement = Razorpay::Settlement.fetch_all_ondemand_settlement
65
+ assert_instance_of Razorpay::Collection, settlement, 'Settlement should be an array'
66
+ refute_empty settlement.items, 'Settlement should be more than one'
67
+ end
68
+
69
+ def test_fetch_ondemand_settle_by_id
70
+ stub_get(%r{settlements/ondemand/#{@settlement_id}$}, 'fake_instant_settlement')
71
+ settlement = Razorpay::Settlement.fetch_ondemand_settlement_by_id(@settlement_id)
72
+ assert_equal @settlement_ondemand_id, settlement.id, 'Settlement IDs do not match'
73
+ refute settlement.settle_full_balance
74
+ end
75
+ end
76
+ end