razorruby 3.0.1

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 (171) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.editorconfig +12 -0
  4. data/.github/dependabot.yml +8 -0
  5. data/.github/workflows/ruby.yml +38 -0
  6. data/.gitignore +23 -0
  7. data/.rubocop.yml +22 -0
  8. data/.simplecov +3 -0
  9. data/CHANGELOG.md +168 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.txt +22 -0
  12. data/README.md +102 -0
  13. data/Rakefile +26 -0
  14. data/documents/Invoice.md +539 -0
  15. data/documents/addon.md +191 -0
  16. data/documents/card.md +610 -0
  17. data/documents/customer.md +163 -0
  18. data/documents/emandate.md +492 -0
  19. data/documents/fund.md +89 -0
  20. data/documents/items.md +208 -0
  21. data/documents/order.md +281 -0
  22. data/documents/papernach.md +738 -0
  23. data/documents/payment.md +826 -0
  24. data/documents/paymentLink.md +1063 -0
  25. data/documents/paymentVerification.md +79 -0
  26. data/documents/plan.md +184 -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/subscriptions.md +752 -0
  33. data/documents/tokens.md +262 -0
  34. data/documents/transfers.md +781 -0
  35. data/documents/upi.md +545 -0
  36. data/documents/virtualAccount.md +591 -0
  37. data/lib/ca-bundle.crt +3988 -0
  38. data/lib/extensions/httparty/hash_conversions.rb +44 -0
  39. data/lib/razorpay/addon.rb +32 -0
  40. data/lib/razorpay/card.rb +17 -0
  41. data/lib/razorpay/collection.rb +6 -0
  42. data/lib/razorpay/constants.rb +6 -0
  43. data/lib/razorpay/customer.rb +42 -0
  44. data/lib/razorpay/entity.rb +46 -0
  45. data/lib/razorpay/errors/bad_request_error.rb +14 -0
  46. data/lib/razorpay/errors/gateway_error.rb +7 -0
  47. data/lib/razorpay/errors/razorpay_error.rb +11 -0
  48. data/lib/razorpay/errors/server_error.rb +7 -0
  49. data/lib/razorpay/errors.rb +4 -0
  50. data/lib/razorpay/fund_account.rb +19 -0
  51. data/lib/razorpay/invoice.rb +68 -0
  52. data/lib/razorpay/item.rb +34 -0
  53. data/lib/razorpay/order.rb +39 -0
  54. data/lib/razorpay/payment.rb +116 -0
  55. data/lib/razorpay/payment_link.rb +36 -0
  56. data/lib/razorpay/payment_method.rb +17 -0
  57. data/lib/razorpay/plan.rb +24 -0
  58. data/lib/razorpay/qr_code.rb +34 -0
  59. data/lib/razorpay/refund.rb +27 -0
  60. data/lib/razorpay/request.rb +119 -0
  61. data/lib/razorpay/settlement.rb +39 -0
  62. data/lib/razorpay/subscription.rb +60 -0
  63. data/lib/razorpay/subscription_registration.rb +16 -0
  64. data/lib/razorpay/transfer.rb +35 -0
  65. data/lib/razorpay/utility.rb +57 -0
  66. data/lib/razorpay/virtual_account.rb +49 -0
  67. data/lib/razorpay.rb +37 -0
  68. data/razorpay-ruby.gemspec +36 -0
  69. data/test/fixtures/addon_collection.json +60 -0
  70. data/test/fixtures/bad_request_error.json +7 -0
  71. data/test/fixtures/cancel_invoice.json +44 -0
  72. data/test/fixtures/cancel_subscription.json +20 -0
  73. data/test/fixtures/create_json_payment.json +13 -0
  74. data/test/fixtures/customer_collection.json +22 -0
  75. data/test/fixtures/delete_token.json +3 -0
  76. data/test/fixtures/downtimes_collection.json +21 -0
  77. data/test/fixtures/empty.json +2 -0
  78. data/test/fixtures/fake_addon.json +24 -0
  79. data/test/fixtures/fake_captured_payment.json +13 -0
  80. data/test/fixtures/fake_card.json +9 -0
  81. data/test/fixtures/fake_create_upi_payment.json +3 -0
  82. data/test/fixtures/fake_customer.json +8 -0
  83. data/test/fixtures/fake_customer_edited.json +8 -0
  84. data/test/fixtures/fake_direct_transfer.json +32 -0
  85. data/test/fixtures/fake_downtime.json +14 -0
  86. data/test/fixtures/fake_fund_account.json +18 -0
  87. data/test/fixtures/fake_instant_settlement.json +19 -0
  88. data/test/fixtures/fake_invoice.json +30 -0
  89. data/test/fixtures/fake_item.json +9 -0
  90. data/test/fixtures/fake_order.json +10 -0
  91. data/test/fixtures/fake_order_transfers.json +88 -0
  92. data/test/fixtures/fake_otp_generate.json +19 -0
  93. data/test/fixtures/fake_otp_resend.json +7 -0
  94. data/test/fixtures/fake_otp_submit.json +5 -0
  95. data/test/fixtures/fake_payment.json +14 -0
  96. data/test/fixtures/fake_payment_authorized_webhook.json +40 -0
  97. data/test/fixtures/fake_payment_bank_transfer.json +12 -0
  98. data/test/fixtures/fake_payment_link.json +40 -0
  99. data/test/fixtures/fake_pending_update.json +30 -0
  100. data/test/fixtures/fake_plan.json +26 -0
  101. data/test/fixtures/fake_qrcode.json +20 -0
  102. data/test/fixtures/fake_qrcode_close.json +22 -0
  103. data/test/fixtures/fake_recurring.json +5 -0
  104. data/test/fixtures/fake_refund.json +8 -0
  105. data/test/fixtures/fake_refunded_payment.json +14 -0
  106. data/test/fixtures/fake_settlement.json +11 -0
  107. data/test/fixtures/fake_settlement_on_demand.json +39 -0
  108. data/test/fixtures/fake_subscription.json +20 -0
  109. data/test/fixtures/fake_subscription_pause.json +19 -0
  110. data/test/fixtures/fake_subscription_registration.json +91 -0
  111. data/test/fixtures/fake_subscription_resume.json +19 -0
  112. data/test/fixtures/fake_token.json +31 -0
  113. data/test/fixtures/fake_transfer.json +18 -0
  114. data/test/fixtures/fake_transfer_reverse.json +15 -0
  115. data/test/fixtures/fake_update_payment.json +39 -0
  116. data/test/fixtures/fake_validate_vpa.json +5 -0
  117. data/test/fixtures/fake_virtual_account.json +21 -0
  118. data/test/fixtures/fake_virtual_account_allowed.json +46 -0
  119. data/test/fixtures/fake_virtual_account_closed.json +21 -0
  120. data/test/fixtures/fake_virtual_account_collection.json +48 -0
  121. data/test/fixtures/fake_virtual_account_receiver.json +46 -0
  122. data/test/fixtures/fund_collection.json +20 -0
  123. data/test/fixtures/hello_response.json +3 -0
  124. data/test/fixtures/invoice_collection.json +93 -0
  125. data/test/fixtures/issue_invoice.json +44 -0
  126. data/test/fixtures/item_collection.json +24 -0
  127. data/test/fixtures/order_collection.json +36 -0
  128. data/test/fixtures/order_payments.json +29 -0
  129. data/test/fixtures/payment_collection.json +32 -0
  130. data/test/fixtures/payment_collection_with_one_payment.json +19 -0
  131. data/test/fixtures/payment_link_collection.json +43 -0
  132. data/test/fixtures/payment_link_response.json +3 -0
  133. data/test/fixtures/payment_methods_collection.json +149 -0
  134. data/test/fixtures/plan_collection.json +32 -0
  135. data/test/fixtures/qrcode_collection.json +50 -0
  136. data/test/fixtures/qrcode_payments_collection.json +74 -0
  137. data/test/fixtures/refund_collection.json +30 -0
  138. data/test/fixtures/refund_collection_for_payment.json +22 -0
  139. data/test/fixtures/settlement_collection.json +26 -0
  140. data/test/fixtures/settlement_instant_collection.json +84 -0
  141. data/test/fixtures/settlement_report_collection.json +117 -0
  142. data/test/fixtures/subscription_collection.json +26 -0
  143. data/test/fixtures/success.json +3 -0
  144. data/test/fixtures/tokens_collection.json +36 -0
  145. data/test/fixtures/transfer_settlements_collection.json +38 -0
  146. data/test/fixtures/transfers_collection.json +41 -0
  147. data/test/fixtures/update_invoice.json +44 -0
  148. data/test/fixtures/welcome.json +3 -0
  149. data/test/razorpay/test_addon.rb +76 -0
  150. data/test/razorpay/test_card.rb +23 -0
  151. data/test/razorpay/test_customer.rb +69 -0
  152. data/test/razorpay/test_entity.rb +55 -0
  153. data/test/razorpay/test_fund_account.rb +42 -0
  154. data/test/razorpay/test_invoice.rb +143 -0
  155. data/test/razorpay/test_item.rb +66 -0
  156. data/test/razorpay/test_order.rb +71 -0
  157. data/test/razorpay/test_payment.rb +303 -0
  158. data/test/razorpay/test_payment_link.rb +83 -0
  159. data/test/razorpay/test_plan.rb +65 -0
  160. data/test/razorpay/test_qr_code.rb +63 -0
  161. data/test/razorpay/test_razorpay.rb +53 -0
  162. data/test/razorpay/test_refund.rb +56 -0
  163. data/test/razorpay/test_request.rb +15 -0
  164. data/test/razorpay/test_settlement.rb +76 -0
  165. data/test/razorpay/test_subscription.rb +190 -0
  166. data/test/razorpay/test_subscription_registration.rb +58 -0
  167. data/test/razorpay/test_transfer.rb +77 -0
  168. data/test/razorpay/test_utility.rb +84 -0
  169. data/test/razorpay/test_virtual_account.rb +135 -0
  170. data/test/test_helper.rb +54 -0
  171. metadata +400 -0
@@ -0,0 +1,143 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Invoice
5
+ class RazorpayInvoiceTest < Minitest::Test
6
+ def setup
7
+ @invoice_id = 'inv_6vRZmJYFAG1mNq'
8
+ @medium = "email"
9
+ # Any request that ends with invoices/invoice_id
10
+ stub_get(%r{invoices/#{@invoice_id}$}, 'fake_invoice')
11
+ end
12
+
13
+ def test_invoice_should_be_defined
14
+ refute_nil Razorpay::Invoice
15
+ end
16
+
17
+ def test_invoice_should_be_created
18
+ stub_post(/invoices$/, 'fake_invoice', 'customer_id=cust_6vRXClWqnLhV14&'\
19
+ 'amount=100&currency=INR&description=Test%20description&type=link')
20
+ invoice = Razorpay::Invoice.create customer_id: 'cust_6vRXClWqnLhV14',
21
+ amount: 100, currency: 'INR',
22
+ description: 'Test description',
23
+ type: 'link'
24
+
25
+ assert_equal 'cust_6vRXClWqnLhV14', invoice.customer_id
26
+ assert_equal 100, invoice.amount
27
+ assert_equal 'INR', invoice.currency
28
+ assert_equal 'Test description', invoice.description
29
+ assert_equal 'link', invoice.type
30
+ end
31
+
32
+ def test_invoices_should_be_fetched
33
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
34
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
35
+ assert_equal @invoice_id, invoice.id, 'invoice IDs do not match'
36
+ end
37
+
38
+ def test_fetching_all_invoices
39
+ stub_get(/invoices$/, 'invoice_collection')
40
+ invoices = Razorpay::Invoice.all
41
+ assert_instance_of Razorpay::Collection, invoices, 'Invoices should be an array'
42
+ assert !invoices.items.empty?, 'invoices should be more than one'
43
+ end
44
+
45
+ def test_invoice_can_be_issued_by_invoice_id
46
+ stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
47
+ invoice = Razorpay::Invoice.issue(@invoice_id)
48
+
49
+ assert_equal 'issued', invoice.status
50
+ refute_nil invoice.issued_at
51
+
52
+ assert_invoice_details(invoice)
53
+ end
54
+
55
+ def test_invoice_can_be_issued_by_invoice_instance
56
+ stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
57
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
58
+
59
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
60
+
61
+ invoice = invoice.issue
62
+
63
+ assert_equal 'issued', invoice.status
64
+ refute_nil invoice.issued_at
65
+
66
+ assert_invoice_details(invoice)
67
+ end
68
+
69
+ def test_invoice_can_be_issued_by_invoice_instance!
70
+ stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
71
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
72
+ invoice.issue!
73
+ assert_equal 'issued', invoice.status
74
+ refute_nil invoice.issued_at
75
+ end
76
+
77
+ def test_invoice_can_be_cancelled_by_invoice_id
78
+ stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
79
+ invoice = Razorpay::Invoice.cancel(@invoice_id)
80
+
81
+ assert_equal 'cancelled', invoice.status
82
+ refute_nil invoice.cancelled_at
83
+
84
+ assert_invoice_details(invoice)
85
+ end
86
+
87
+ def test_invoice_can_be_cancelled_by_invoice_instance
88
+ stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
89
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
90
+
91
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
92
+
93
+ invoice = invoice.cancel
94
+
95
+ assert_equal 'cancelled', invoice.status
96
+ refute_nil invoice.cancelled_at
97
+
98
+ assert_invoice_details(invoice)
99
+ end
100
+
101
+ def test_invoice_can_be_cancelled_by_invoice_instance!
102
+ stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
103
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
104
+ invoice.cancel!
105
+ assert_equal 'cancelled', invoice.status
106
+ refute_nil invoice.cancelled_at
107
+ end
108
+
109
+ def test_edit_invoice!
110
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
111
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
112
+ assert_nil invoice.invoice_number
113
+ update_invoice_data = { invoice_number: '12345678' }
114
+ stub_patch(%r{invoices/#{@invoice_id}$}, 'update_invoice', update_invoice_data)
115
+ invoice.edit!(update_invoice_data)
116
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
117
+ refute_nil invoice.invoice_number
118
+ end
119
+
120
+
121
+ def assert_invoice_details(invoice)
122
+ assert_equal 'cust_6vRXClWqnLhV14', invoice.customer_id
123
+ assert_equal 100, invoice.amount
124
+ assert_equal 'INR', invoice.currency
125
+ assert_equal 'Test description', invoice.description
126
+ assert_equal 'invoice', invoice.type
127
+ end
128
+
129
+ def test_delete_specific_invoice
130
+ stub_delete(%r{invoices/#{@invoice_id}$}, 'empty')
131
+ invoice = Razorpay::Invoice.delete(@invoice_id)
132
+ assert_instance_of Razorpay::Entity, invoice, 'invoice not an instance of Razorpay::Invoice class'
133
+ refute_nil invoice
134
+ end
135
+
136
+ def test_invoice_notifyBy
137
+ stub_post(%r{invoices/#{@invoice_id}/notify_by/#{@medium}$}, 'success', {})
138
+ invoice = Razorpay::Invoice.notify_by(@invoice_id,@medium)
139
+ assert_instance_of Razorpay::Entity, invoice, 'invoice not an instance of Razorpay::Invoice class'
140
+ assert invoice
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Item
5
+ class RazorpayItemTest < Minitest::Test
6
+ def setup
7
+ @item_id = 'item_JDcbIdX9xojCje'
8
+
9
+ # Any request that ends with items/item_id
10
+ stub_get(%r{items/#{@item_id}$}, 'fake_item')
11
+ stub_get(/items$/, 'item_collection')
12
+ end
13
+
14
+ def test_item_should_be_defined
15
+ refute_nil Razorpay::Item
16
+ end
17
+
18
+ def test_item_should_be_created
19
+
20
+ param_attr = {
21
+ "name": "Book / English August",
22
+ "description": "An indian story, Booker prize winner.",
23
+ "amount": 20000,
24
+ "currency": "INR"
25
+ }
26
+
27
+ stub_post(/items$/, 'fake_item', param_attr.to_json)
28
+ items = Razorpay::Item.create(param_attr.to_json)
29
+ assert_equal @item_id, items.id
30
+ assert_equal true, items.active
31
+ end
32
+
33
+ def test_edit_items
34
+
35
+ param_attr = {
36
+ "name": "Book / English August",
37
+ "description": "An indian story, Booker prize winner.",
38
+ "amount": 20000,
39
+ "currency": "INR"
40
+ }
41
+
42
+ stub_patch(%r{items/#{@item_id}$}, 'fake_item', param_attr.to_json)
43
+ item = Razorpay::Item.edit(@item_id, param_attr.to_json)
44
+ assert_instance_of Razorpay::Entity, item
45
+ assert_equal @item_id, item.id, 'Item IDs do not match'
46
+ end
47
+
48
+ def test_fetch_all_items
49
+ items = Razorpay::Item.all
50
+ assert_instance_of Razorpay::Collection, items, 'Items should be an array'
51
+ refute_empty items.items, 'Items should be more than one'
52
+ end
53
+
54
+ def test_fetch_specific_item
55
+ item = Razorpay::Item.fetch(@item_id)
56
+ assert_instance_of Razorpay::Entity, item
57
+ assert_equal @item_id, item.id, 'Item IDs do not match'
58
+ end
59
+
60
+ def test_delete_item
61
+ stub_delete(%r{items/#{@item_id}$}, 'empty')
62
+ item = Razorpay::Item.delete(@item_id)
63
+ assert_instance_of Razorpay::Entity, item
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Order
5
+ class RazorpayOrderTest < Minitest::Test
6
+ def setup
7
+ @order_id = 'order_50sX9hGHZJvjjI'
8
+ @transfer_id = 'trf_DSkl2lXWbiADZG'
9
+ # Any request that ends with orders/order_id
10
+ stub_get(%r{orders/#{@order_id}$}, 'fake_order')
11
+ end
12
+
13
+ def test_order_should_be_defined
14
+ refute_nil Razorpay::Order
15
+ end
16
+
17
+ def test_order_should_be_created
18
+ stub_post(/orders$/, 'fake_order', 'amount=5000&currency=INR&receipt=TEST')
19
+ order = Razorpay::Order.create amount: 5000, currency: 'INR', receipt: 'TEST'
20
+
21
+ assert_equal 5000, order.amount
22
+ assert_equal 'INR', order.currency
23
+ assert_equal 'TEST', order.receipt
24
+ end
25
+
26
+ def test_orders_should_be_fetched
27
+ order = Razorpay::Order.fetch(@order_id)
28
+ assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
29
+ assert_equal @order_id, order.id, 'order IDs do not match'
30
+ end
31
+
32
+ def test_fetching_all_orders
33
+ stub_get(/orders$/, 'order_collection')
34
+ orders = Razorpay::Order.all
35
+ assert_instance_of Razorpay::Collection, orders, 'Orders should be an array'
36
+ assert !orders.items.empty?, 'orders should be more than one'
37
+ end
38
+
39
+ def test_order_payments_should_be_fetched
40
+ stub_get(%r{orders/#{@order_id}/payments$}, 'order_payments')
41
+
42
+ payments = Razorpay::Order.fetch(@order_id).payments
43
+ assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
44
+ assert !payments.items.empty?, 'payments should be more than one'
45
+ assert_equal 'pay_50sbkZA9AcyE5a', payments.items[0]['id'], 'payment id should match'
46
+ end
47
+
48
+ def test_edit_order
49
+ param_attr = {
50
+ "notes": {
51
+ "key1": "value3",
52
+ "key2": "value2"
53
+ }
54
+ }
55
+
56
+ stub_patch(%r{orders/#{@order_id}$}, 'fake_order', param_attr.to_json)
57
+ order = Razorpay::Order.edit(@order_id, param_attr.to_json)
58
+ assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
59
+ assert_equal @order_id, order.id, 'order IDs do not match'
60
+ end
61
+
62
+ def test_fetch_order_transfers
63
+ stub_get("#{BASE_URI}orders/#{@order_id}/?expand[]=transfers&status", 'fake_order_transfers')
64
+ order = Razorpay::Order.fetch_transfer_order(@order_id)
65
+ assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
66
+ assert_equal @order_id, order.id, 'order IDs do not match'
67
+ refute_empty order.transfers["items"]
68
+ assert_equal @transfer_id, order.transfers["items"][0]["id"]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,303 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Payment
5
+ class RazorpayPaymentTest < Minitest::Test
6
+ def setup
7
+ @payment_id = 'fake_payment_id'
8
+ @downtime_id = 'fake_downtime_id'
9
+ @card_id = 'card_7EZLhWkDt05n7V'
10
+ @transfer_id = 'trf_J0FrZYPql4riDx'
11
+ @refund_id = 'fake_refund_id'
12
+ # Any request that ends with payments/payment_id
13
+ stub_get(%r{payments\/#{@payment_id}$}, 'fake_payment')
14
+ stub_get(/payments$/, 'payment_collection')
15
+ end
16
+
17
+ def test_payment_should_be_defined
18
+ refute_nil Razorpay::Payment
19
+ end
20
+
21
+ def test_payments_should_be_available
22
+ payment = Razorpay::Payment.fetch(@payment_id)
23
+ assert_instance_of Razorpay::Payment, payment, 'Payment not an instance of Payment class'
24
+ assert_equal @payment_id, payment.id, 'Payment IDs do not match'
25
+ assert_equal 500, payment.amount, 'Payment amount is accessible'
26
+ assert_equal 'card', payment.method, 'Payment method is accessible'
27
+ end
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
+
134
+ def test_all_payments
135
+ payments = Razorpay::Payment.all
136
+ assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
137
+ assert !payments.items.empty?, 'Payments should be more than one'
138
+ end
139
+
140
+ def test_all_payments_with_options
141
+ query = { 'count' => 1 }
142
+ stub_get(/payments\?count=1$/, 'payment_collection_with_one_payment')
143
+ payments = Razorpay::Payment.all(query)
144
+ assert_equal query['count'], payments.items.size, 'Payments array size should match'
145
+ end
146
+
147
+ def test_payment_refund
148
+ stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
149
+ refund = Razorpay::Payment.fetch(@payment_id).refund
150
+ assert_instance_of Razorpay::Refund, refund
151
+ assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
152
+ end
153
+
154
+ def test_payment_refund!
155
+ payment = Razorpay::Payment.fetch(@payment_id)
156
+ stub_get(%r{payments/#{@payment_id}$}, 'fake_refunded_payment')
157
+ stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
158
+ payment.refund!
159
+ assert_equal 'refunded', payment.status
160
+ end
161
+
162
+ def test_partial_refund
163
+ # For some reason, stub doesn't work if I pass it a hash of post body
164
+ stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', 'amount=2000')
165
+ refund = Razorpay::Payment.fetch(@payment_id).refund(amount: 2000)
166
+ assert_instance_of Razorpay::Refund, refund
167
+ assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
168
+ assert_equal refund.amount, 2000
169
+ end
170
+
171
+ def test_payment_capture
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)
180
+ assert_equal 'captured', payment.status
181
+ end
182
+
183
+ def test_payment_capture!
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)
189
+ payment = Razorpay::Payment.fetch(@payment_id)
190
+ payment.capture!(para_attr.to_json)
191
+ assert_equal 'captured', payment.status
192
+ end
193
+
194
+ def test_payment_capture_without_fetch
195
+ stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
196
+ payment = Razorpay::Payment.capture(@payment_id, amount: 5100)
197
+ assert_equal 'captured', payment.status
198
+ 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
+ end
303
+ 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