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,117 @@
1
+ {
2
+ "entity": "collection",
3
+ "count": 4,
4
+ "items": [
5
+ {
6
+ "entity_id": "pay_DEXrnipqTmWVGE",
7
+ "type": "payment",
8
+ "debit": 0,
9
+ "credit": 97100,
10
+ "amount": 100000,
11
+ "currency": "INR",
12
+ "fee": 2900,
13
+ "tax": 0,
14
+ "on_hold": false,
15
+ "settled": true,
16
+ "created_at": 1567692556,
17
+ "settled_at": 1568176960,
18
+ "settlement_id": "setl_DGlQ1Rj8os78Ec",
19
+ "posted_at": null,
20
+ "credit_type": "default",
21
+ "description": "Recurring Payment via Subscription",
22
+ "notes": "{}",
23
+ "payment_id": null,
24
+ "settlement_utr": "1568176960vxp0rj",
25
+ "order_id": "order_DEXrnRiR3SNDHA",
26
+ "order_receipt": null,
27
+ "method": "card",
28
+ "card_network": "MasterCard",
29
+ "card_issuer": "KARB",
30
+ "card_type": "credit",
31
+ "dispute_id": null
32
+ },
33
+ {
34
+ "entity_id": "rfnd_DGRcGzZSLyEdg1",
35
+ "type": "refund",
36
+ "debit": 242500,
37
+ "credit": 0,
38
+ "amount": 242500,
39
+ "currency": "INR",
40
+ "fee": 0,
41
+ "tax": 0,
42
+ "on_hold": false,
43
+ "settled": true,
44
+ "created_at": 1568107224,
45
+ "settled_at": 1568176960,
46
+ "settlement_id": "setl_DGlQ1Rj8os78Ec",
47
+ "posted_at": null,
48
+ "credit_type": "default",
49
+ "description": null,
50
+ "notes": "{}",
51
+ "payment_id": "pay_DEXq1pACSqFxtS",
52
+ "settlement_utr": "1568176960vxp0rj",
53
+ "order_id": "order_DEXpmZgffXNvuI",
54
+ "order_receipt": null,
55
+ "method": "card",
56
+ "card_network": "MasterCard",
57
+ "card_issuer": "KARB",
58
+ "card_type": "credit",
59
+ "dispute_id": null
60
+ },
61
+ {
62
+ "entity_id": "trf_DEUoCEtdsJgvl7",
63
+ "type": "transfer",
64
+ "debit": 100296,
65
+ "credit": 0,
66
+ "amount": 100000,
67
+ "currency": "INR",
68
+ "fee": 296,
69
+ "tax": 46,
70
+ "on_hold": false,
71
+ "settled": true,
72
+ "created_at": 1567681786,
73
+ "settled_at": 1568176960,
74
+ "settlement_id": "setl_DGlQ1Rj8os78Ec",
75
+ "posted_at": null,
76
+ "credit_type": "default",
77
+ "description": null,
78
+ "notes": null,
79
+ "payment_id": "pay_DEApNNTR6xmqJy",
80
+ "settlement_utr": "1568176960vxp0rj",
81
+ "order_id": null,
82
+ "order_receipt": null,
83
+ "method": null,
84
+ "card_network": null,
85
+ "card_issuer": null,
86
+ "card_type": null,
87
+ "dispute_id": null
88
+ },
89
+ {
90
+ "entity_id": "adj_EhcHONhX4ChgNC",
91
+ "type": "adjustment",
92
+ "debit": 0,
93
+ "credit": 1012,
94
+ "amount": 1012,
95
+ "currency": "INR",
96
+ "fee": 0,
97
+ "tax": 0,
98
+ "on_hold": false,
99
+ "settled": true,
100
+ "created_at": 1567681786,
101
+ "settled_at": 1568176960,
102
+ "settlement_id": "setl_DGlQ1Rj8os78Ec",
103
+ "posted_at": null,
104
+ "description": "test reason",
105
+ "notes": null,
106
+ "payment_id": null,
107
+ "settlement_utr": null,
108
+ "order_id": null,
109
+ "order_receipt": null,
110
+ "method": null,
111
+ "card_network": null,
112
+ "card_issuer": null,
113
+ "card_type": null,
114
+ "dispute_id": null
115
+ }
116
+ ]
117
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "entity":"collection",
3
+ "count":10,
4
+ "items": [
5
+ {
6
+ "id": "fake_subscription_id",
7
+ "entity": "subscription",
8
+ "plan_id": "fake_plan_id",
9
+ "customer_id": "fake_customer_id",
10
+ "status": "created",
11
+ "current_start": null,
12
+ "current_end": null,
13
+ "ended_at": null,
14
+ "quantity": 1,
15
+ "notes": [],
16
+ "charge_at": 1509494400,
17
+ "start_at": 1509494400,
18
+ "end_at": 1538332200,
19
+ "auth_attempts": 0,
20
+ "total_count": 12,
21
+ "paid_count": 0,
22
+ "customer_notify": true,
23
+ "created_at": 1509114729
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "success": true
3
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "entity": "collection",
3
+ "count": 1,
4
+ "items": [
5
+ {
6
+ "id": "token_Ip8u7q7FA77Q30",
7
+ "entity": "token",
8
+ "token": "BZpWWtYHnSJfoi",
9
+ "bank": "HDFC",
10
+ "wallet": null,
11
+ "method": "emandate",
12
+ "vpa": null,
13
+ "recurring": true,
14
+ "recurring_details": {
15
+ "status": "confirmed",
16
+ "failure_reason": null
17
+ },
18
+ "auth_type": "debitcard",
19
+ "mrn": null,
20
+ "used_at": 1647012394,
21
+ "created_at": 1643368664,
22
+ "bank_details": {
23
+ "beneficiary_name": "Gaurav Kumar",
24
+ "account_number": "11214311215411",
25
+ "ifsc": "HDFC0001233",
26
+ "account_type": "savings"
27
+ },
28
+ "max_amount": 50000,
29
+ "expired_at": 2147483647,
30
+ "notes": [
31
+
32
+ ],
33
+ "dcc_enabled": false
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "entity":"collection",
3
+ "count":1,
4
+ "items":[
5
+ {
6
+ "id":"trf_DGSTeXzBkEVh48",
7
+ "entity":"transfer",
8
+ "transfer_status":"processed",
9
+ "settlement_status":null,
10
+ "source":"pay_DGSRhvMbOqeCe7",
11
+ "recipient":"acc_CMaomTz4o0FOFz",
12
+ "amount":500,
13
+ "currency":"INR",
14
+ "amount_reversed":0,
15
+ "notes":[
16
+
17
+ ],
18
+ "fees":2,
19
+ "tax":0,
20
+ "on_hold":false,
21
+ "on_hold_until":null,
22
+ "recipient_settlement_id":"setl_DHYJ3dRPqQkAgV",
23
+ "created_at":1568110256,
24
+ "linked_account_notes":[
25
+
26
+ ],
27
+ "processed_at":1568110297,
28
+ "error":{
29
+ "code":null,
30
+ "description":null,
31
+ "field":null,
32
+ "source":null,
33
+ "step":null,
34
+ "reason":null
35
+ }
36
+ }
37
+ ]
38
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "entity": "collection",
3
+ "count": 1,
4
+ "items": [
5
+ {
6
+ "id": "trf_J0FrZYPql4riDx",
7
+ "entity": "transfer",
8
+ "status": "processed",
9
+ "source": "pay_I6i1edcUUytu9p",
10
+ "recipient": "acc_I0QRP7PpvaHhpB",
11
+ "amount": 100,
12
+ "currency": "INR",
13
+ "amount_reversed": 0,
14
+ "fees": 1,
15
+ "tax": 0,
16
+ "notes": {
17
+ "name": "Saurav Kumar",
18
+ "roll_no": "IEC2011026"
19
+ },
20
+ "linked_account_notes": [
21
+ "roll_no"
22
+ ],
23
+ "on_hold": true,
24
+ "on_hold_until": null,
25
+ "settlement_status": "on_hold",
26
+ "recipient_settlement_id": null,
27
+ "created_at": 1645794911,
28
+ "processed_at": 1645794911,
29
+ "error": {
30
+ "code": null,
31
+ "description": null,
32
+ "reason": null,
33
+ "field": null,
34
+ "step": null,
35
+ "id": "trf_J0FrZYPql4riDx",
36
+ "source": null,
37
+ "metadata": null
38
+ }
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "inv_6vRZmJYFAG1mNq",
3
+ "entity": "invoice",
4
+ "receipt": "12345678",
5
+ "invoice_number": "12345678",
6
+ "customer_id": "cust_6vRXClWqnLhV14",
7
+ "customer_details": {
8
+ "customer_name": null,
9
+ "customer_email": "test@razorpay.com",
10
+ "customer_contact": "9876543210",
11
+ "customer_address": null
12
+ },
13
+ "order_id": "order_6vRZmJu7EPEMY0",
14
+ "line_items": [],
15
+ "payment_id": null,
16
+ "expire_by": null,
17
+ "status": "issued",
18
+ "issued_at": 1482299421,
19
+ "paid_at": null,
20
+ "cancelled_at": null,
21
+ "expired_at": null,
22
+ "sms_status": "sent",
23
+ "email_status": "sent",
24
+ "date": 1482299421,
25
+ "partial_payment": false,
26
+ "terms": null,
27
+ "gross_amount": 100,
28
+ "tax_amount": 0,
29
+ "amount": 100,
30
+ "amount_paid": 100,
31
+ "amount_due": 0,
32
+ "description": "Test description",
33
+ "notes": [],
34
+ "currency": "INR",
35
+ "short_url": "http://bit.ly/2i8kSqu",
36
+ "comment": null,
37
+ "view_less": true,
38
+ "type": "invoice",
39
+ "billing_start": null,
40
+ "billing_end": null,
41
+ "group_taxes_amounts": false,
42
+ "user_id": "fake_user_id",
43
+ "created_at": 1482299422
44
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "message": "Welcome to Razorpay API."
3
+ }
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Addon
5
+ class RazorpayAddonTest < Minitest::Test
6
+ class Item < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @subscription_id = 'sub_00000000000001'
10
+ @addon_id = 'ao_IrSY3UIqDRx7df'
11
+
12
+ # Any request that ends with addons/addon_id
13
+ stub_get(%r{addons\/#{Regexp.quote(@addon_id)}$}, 'fake_addon')
14
+ end
15
+
16
+ def test_addon_should_be_defined
17
+ refute_nil Razorpay::Addon
18
+ end
19
+
20
+ def test_addon_should_be_available
21
+ addon = Razorpay::Addon.fetch(@addon_id)
22
+ assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
23
+ assert_equal @addon_id, addon.id, 'Addon IDs do not match'
24
+ assert_equal 1, addon.quantity, 'Addon quantity is accessible'
25
+ assert_equal @subscription_id, addon.subscription_id, 'Addon subscription_id is accessible'
26
+ assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
27
+
28
+ assert_addon_item_details(addon)
29
+ end
30
+
31
+ def test_fetch_all_addon
32
+ stub_get(/addons$/, 'addon_collection')
33
+ addons = Razorpay::Addon.all
34
+ assert_instance_of Razorpay::Collection, addons, 'Addons should be an array'
35
+ refute_empty addons.items, 'Addon should be more than one'
36
+ end
37
+
38
+ def test_add_addons_to_subscription
39
+ addon_attrs = {
40
+ item: {
41
+ name: 'fake_addon_name', currency: 'INR', amount: 5000,
42
+ description: 'fake_addon_description'
43
+ },
44
+ quantity: 1
45
+ }
46
+
47
+ stub_post(%r{subscriptions\/#{@subscription_id}\/addons$}, 'fake_addon', addon_attrs.to_json)
48
+
49
+ addon = Razorpay::Addon.create(@subscription_id, addon_attrs.to_json)
50
+ assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
51
+
52
+ assert_equal @addon_id, addon.id, 'Addon IDs do not match'
53
+ assert_equal 1, addon.quantity, 'Addon quantity is accessible'
54
+ assert_equal @subscription_id, addon.subscription_id, 'Addon subscription_id is accessible'
55
+ assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
56
+
57
+ assert_addon_item_details(addon)
58
+ end
59
+
60
+ def assert_addon_item_details(addon)
61
+ addon_item = Item.new(addon.item)
62
+
63
+ assert_equal 'item_00000000000001', addon_item.id, 'Addon Item id is accessible'
64
+ assert_equal 'fake_item_name', addon_item.name, 'Addon Item name is accessible'
65
+ assert_equal 'fake_item_description', addon_item.description, 'Addon Item description is accessible'
66
+ assert_equal 'INR', addon_item.currency, 'Addon Item currency is accessible'
67
+ assert_equal 500, addon_item.amount, 'Addon Item amount is accessible'
68
+ end
69
+
70
+ def test_delete_addon
71
+ stub_delete(%r{addons/#{@addon_id}$}, 'empty')
72
+ addon = Razorpay::Addon.delete(@addon_id)
73
+ assert_instance_of Razorpay::Entity, addon
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Card
5
+ class RazorpayCardTest < Minitest::Test
6
+ def setup
7
+ @card_id = 'card_7EZLhWkDt05n7V'
8
+
9
+ # Any request that ends with cards/card_id
10
+ stub_get(%r{cards/#{@card_id}$}, 'fake_card')
11
+ end
12
+
13
+ def test_card_should_be_defined
14
+ refute_nil Razorpay::Card
15
+ end
16
+
17
+ def test_cards_should_be_fetched
18
+ card = Razorpay::Card.fetch(@card_id)
19
+ assert_instance_of Razorpay::Card, card, 'card not an instance of Razorpay::Card class'
20
+ assert_equal @card_id, card.id, 'card IDs do not match'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Customer
5
+ class RazorpayCustomerTest < Minitest::Test
6
+ def setup
7
+ @customer_id = 'cust_6vRXClWqnLhV14'
8
+ @token_id = "token_FHfn3rIiM1Z8nr"
9
+ # Any request that ends with customers/customer_id
10
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
11
+ end
12
+
13
+ def test_customer_should_be_defined
14
+ refute_nil Razorpay::Customer
15
+ end
16
+
17
+ def test_customer_should_be_created
18
+ stub_post(/customers$/, 'fake_customer', 'email=test%40razorpay.com&contact=9876543210')
19
+ customer = Razorpay::Customer.create email: 'test@razorpay.com', contact: '9876543210'
20
+
21
+ assert_equal 'test@razorpay.com', customer.email
22
+ assert_equal '9876543210', customer.contact
23
+ end
24
+
25
+ def test_edit_customer
26
+ new_email = 'test.edit@razorpay.com'
27
+ stub_put(%r{customers/#{@customer_id}$}, 'fake_customer_edited', "email=#{new_email}")
28
+ customer = Razorpay::Customer.edit(@customer_id, "email=#{new_email}")
29
+ assert_instance_of Razorpay::Customer, customer
30
+ assert_equal customer.email, new_email
31
+ end
32
+
33
+ def test_fetch_all_customers
34
+ stub_get(/customers$/, 'customer_collection')
35
+ customers = Razorpay::Customer.all
36
+ assert_instance_of Razorpay::Collection, customers
37
+ end
38
+
39
+ def test_fetch_specific_customer
40
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
41
+ customer = Razorpay::Customer.fetch(@customer_id)
42
+ assert_instance_of Razorpay::Customer, customer
43
+ assert_equal "test@razorpay.com", customer.email
44
+ end
45
+
46
+ # def test_customer_fetch_tokens
47
+ # stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
48
+ # stub_get(%r{customers/cust_6vRXClWqnLhV14/tokens$}, 'tokens_collection')
49
+ # tokens = Razorpay::Customer.fetch(@customer_id).fetchTokens
50
+ # assert_instance_of Razorpay::Collection, tokens, 'Tokens should be an array'
51
+ # refute_empty tokens.items, 'tokens should be more than one'
52
+ # end
53
+
54
+ def test_customer_fetch_token
55
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
56
+ stub_get(%r{customers/cust_6vRXClWqnLhV14/tokens/token_FHfn3rIiM1Z8nr$}, 'fake_token')
57
+ token = Razorpay::Customer.fetch(@customer_id).fetchToken("token_FHfn3rIiM1Z8nr")
58
+ assert_instance_of Razorpay::Entity, token, 'Token not an instance of Razorpay::Entity class'
59
+ assert_equal "token_FHfn3rIiM1Z8nr", token.id
60
+ end
61
+
62
+ def test_customer_delete_token
63
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
64
+ stub_delete(%r{customers/cust_6vRXClWqnLhV14/tokens/token_FHfn3rIiM1Z8nr$}, 'delete_token')
65
+ token = Razorpay::Customer.fetch(@customer_id).deleteToken("token_FHfn3rIiM1Z8nr")
66
+ assert token.deleted
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+ require 'ostruct'
3
+
4
+ module Razorpay
5
+ # Tests for Razorpay::Entity
6
+ class EntityTest < Minitest::Test
7
+ def setup
8
+ @hash = { 'a' => 1 }
9
+ @entity = Entity.new(@hash)
10
+ end
11
+
12
+ def test_create_instance
13
+ res = OpenStruct.new(parsed_response: { 'entity' => 'non_existent_entity' })
14
+ entity = Razorpay::Request.new('dummy').create_instance(res)
15
+ assert_instance_of Razorpay::Entity, entity
16
+ end
17
+
18
+ def test_raise_error
19
+ error = { 'code' => 'NON_EXISTENT_ERROR', 'description' => 'Unknown error' }
20
+ assert_raises(Razorpay::Error) { Razorpay::Request.new('dummy').raise_error(error, 500) }
21
+ end
22
+
23
+ def test_raise_error_server_unreachable
24
+ assert_raises(Razorpay::Error) { Razorpay::Request.new('dummy').raise_error(nil, nil) }
25
+ end
26
+
27
+ def test_respond_to_missing_method
28
+ order_id = 'order_50sX9hGHZJvjjI'
29
+ stub_get(%r{orders/#{order_id}$}, 'fake_order')
30
+ order = Razorpay::Order.fetch(order_id)
31
+ assert_equal order.respond_to?(:non_existent_method), false
32
+
33
+ payment_id = 'fake_payment_id'
34
+ stub_get(%r{payments/#{payment_id}$}, 'fake_payment')
35
+ payment = Razorpay::Payment.fetch(payment_id)
36
+ assert_equal payment.respond_to?(:method), true
37
+ end
38
+
39
+ def test_attribute_get
40
+ assert_equal @hash['a'], @entity.a
41
+ end
42
+
43
+ def test_json_conversion
44
+ assert_equal '{"a":1}', @entity.to_json
45
+ end
46
+
47
+ def test_json_conversion_with_args
48
+ assert_equal '{"a": 1}', @entity.to_json(space: ' ')
49
+ end
50
+
51
+ def test_invalid_attribute_get
52
+ assert_raises(NoMethodError, 'It must raise a NoMethodError on invalid attribute') { @entity.b }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::FundAccount
5
+ class RazorpayFundAccountTest < Minitest::Test
6
+ def setup
7
+ @customer_id = 'cust_J3oSNi1KgzqVEX'
8
+ @fund_account_id = 'fa_J8B38pGr1Tfv8k'
9
+ end
10
+
11
+ def test_fund_account_should_be_defined
12
+ refute_nil Razorpay::FundAccount
13
+ end
14
+
15
+ def test_fund_account_should_be_created
16
+
17
+ param_attr = {
18
+ "customer_id": "cust_Aa000000000001",
19
+ "account_type": "bank_account",
20
+ "bank_account": {
21
+ "name": "Gaurav Kumar",
22
+ "account_number": "11214311215411",
23
+ "ifsc": "HDFC0000053"
24
+ }
25
+ }
26
+
27
+ stub_post(/fund_accounts$/, 'fake_fund_account', param_attr.to_json)
28
+ fund_account = Razorpay::FundAccount.create param_attr.to_json
29
+ assert_equal @customer_id, fund_account.customer_id
30
+ assert_equal @fund_account_id, fund_account.id
31
+ end
32
+
33
+ def test_fetch_all_fund_accounts
34
+
35
+ para_attr = {"customer_id": @customer_id}
36
+ stub_get(/fund_accounts/, 'fund_collection', para_attr.to_json)
37
+ fund_accounts = Razorpay::FundAccount.all(para_attr.to_json)
38
+ assert_instance_of Razorpay::Collection, fund_accounts, 'FundAccounts should be an array'
39
+ assert !fund_accounts.items.empty?, 'FundAccounts should be more than one'
40
+ end
41
+ end
42
+ end