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
@@ -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,35 @@
1
+ {
2
+ "entity": "collection",
3
+ "items": [
4
+ {
5
+ "id": "GZ13yPHLJof9IE",
6
+ "entity": "stakeholder",
7
+ "relationship": {
8
+ "director": true
9
+ },
10
+ "phone": {
11
+ "primary": "9000090000",
12
+ "secondary": "9000090000"
13
+ },
14
+ "notes": {
15
+ "random_key_by_partner": "random_value"
16
+ },
17
+ "kyc": {
18
+ "pan": "AVOPB1111K"
19
+ },
20
+ "name": "Gaurav Kumar",
21
+ "email": "gaurav.kumar@acme.org",
22
+ "percentage_ownership": 10,
23
+ "addresses": {
24
+ "residential": {
25
+ "street": "506, Koramangala 1st block",
26
+ "city": "Bengaluru",
27
+ "state": "Karnataka",
28
+ "postal_code": "560034",
29
+ "country": "in"
30
+ }
31
+ }
32
+ }
33
+ ],
34
+ "count": 1
35
+ }
@@ -0,0 +1,85 @@
1
+ {
2
+ "entity": "collection",
3
+ "count": 1,
4
+ "items": [
5
+ {
6
+ "id": "KTBSNfvnYlcKnH",
7
+ "created_at": 1665648343,
8
+ "updated_at": 1695729722,
9
+ "service": "api-test",
10
+ "owner_id": "Hn1ukn2d32Fqww",
11
+ "owner_type": "merchant",
12
+ "disabled_at": 1665736246,
13
+ "url": "https://www.linkedin.com",
14
+ "created_by": "Hn1ukgebfkBJ4L",
15
+ "secret_exists": true,
16
+ "created_by_email": "ankit.das@razorpay.com",
17
+ "entity": "webhook",
18
+ "active": true,
19
+ "events": {
20
+ "payment.authorized": false,
21
+ "payment.failed": false,
22
+ "payment.captured": false,
23
+ "payment.dispute.created": false,
24
+ "order.paid": false,
25
+ "invoice.paid": false,
26
+ "invoice.partially_paid": false,
27
+ "invoice.expired": false,
28
+ "subscription.authenticated": false,
29
+ "subscription.paused": false,
30
+ "subscription.resumed": false,
31
+ "subscription.activated": false,
32
+ "subscription.pending": false,
33
+ "subscription.halted": false,
34
+ "subscription.charged": false,
35
+ "subscription.cancelled": false,
36
+ "subscription.completed": false,
37
+ "subscription.updated": false,
38
+ "settlement.processed": false,
39
+ "virtual_account.credited": false,
40
+ "virtual_account.created": false,
41
+ "virtual_account.closed": false,
42
+ "qr_code.closed": false,
43
+ "qr_code.created": false,
44
+ "qr_code.credited": false,
45
+ "payment.dispute.won": false,
46
+ "payment.dispute.lost": false,
47
+ "payment.dispute.closed": false,
48
+ "payment.dispute.under_review": false,
49
+ "payment.dispute.action_required": false,
50
+ "fund_account.validation.completed": false,
51
+ "fund_account.validation.failed": false,
52
+ "payout.processed": false,
53
+ "payout.reversed": false,
54
+ "payment.downtime.started": false,
55
+ "payment.downtime.updated": false,
56
+ "payment.downtime.resolved": false,
57
+ "payout.initiated": false,
58
+ "refund.speed_changed": false,
59
+ "refund.processed": false,
60
+ "refund.failed": false,
61
+ "refund.created": true,
62
+ "transfer.processed": false,
63
+ "transfer.failed": false,
64
+ "account.under_review": false,
65
+ "account.needs_clarification": false,
66
+ "account.activated": false,
67
+ "account.rejected": false,
68
+ "account.updated": false,
69
+ "payout.updated": false,
70
+ "payout.rejected": false,
71
+ "payout.pending": false,
72
+ "payment_link.paid": false,
73
+ "payment_link.partially_paid": false,
74
+ "payment_link.expired": false,
75
+ "payment_link.cancelled": false,
76
+ "zapier.payment_page.paid.v1": false,
77
+ "shiprocket.payment_page.paid.v1": false,
78
+ "product.route.under_review": false,
79
+ "product.route.activated": false,
80
+ "product.route.needs_clarification": false,
81
+ "product.route.rejected": false
82
+ }
83
+ }
84
+ ]
85
+ }
@@ -0,0 +1,134 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Account
5
+ class RazorpayAccountonTest < Minitest::Test
6
+ class Account < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @account_id = 'acc_00000000000001'
10
+ @email = 'gauriagain.kumar@example.org'
11
+ # Any request that ends with account/account_id
12
+ stub_get(%r{/v2/accounts\/#{Regexp.quote(@account_id)}$}, 'fake_account')
13
+ end
14
+
15
+ def test_account_should_be_defined
16
+ refute_nil Razorpay::Account
17
+ end
18
+
19
+ def test_account_should_be_available
20
+ account = Razorpay::Account.fetch(@account_id)
21
+ assert_instance_of Razorpay::Entity, account, 'Account not an instance of Entity class'
22
+ assert_equal @account_id, account.id, 'Account IDs do not match'
23
+ assert_equal @email, account.email, 'Account email is accessible'
24
+ end
25
+
26
+ def test_account_should_be_created
27
+
28
+ payload = create_account_payload()
29
+
30
+ stub_post(/accounts$/,'fake_account',payload.to_json)
31
+
32
+ account = Razorpay::Account.create payload.to_json
33
+ assert_instance_of Razorpay::Entity, account
34
+ assert_equal @account_id, account.id
35
+ end
36
+
37
+ def test_account_edit
38
+
39
+ param_attr = {
40
+ "notes": {
41
+ "internal_ref_id": "111111"
42
+ }
43
+ }
44
+
45
+ stub_patch(%r{accounts/#{@account_id}$}, 'fake_account', param_attr.to_json)
46
+
47
+ account = Razorpay::Account.edit(@account_id, param_attr.to_json)
48
+ assert_instance_of Razorpay::Entity, account
49
+ assert_equal @account_id, account.id
50
+ end
51
+
52
+ def test_delete_account
53
+ stub_delete(%r{accounts/#{@account_id}$}, 'fake_account')
54
+ account = Razorpay::Account.delete(@account_id)
55
+ assert_instance_of Razorpay::Entity, account
56
+ assert_equal @account_id, account.id
57
+ end
58
+
59
+ def create_account_payload
60
+ return {
61
+ "email": "gauriagainqzy.kumar@example.org",
62
+ "phone": "9000090000",
63
+ "legal_business_name": "Acme Corp",
64
+ "business_type": "partnership",
65
+ "customer_facing_business_name": "Example",
66
+ "profile": {
67
+ "category": "healthcare",
68
+ "subcategory": "clinic",
69
+ "description": "Healthcare E-commerce platform",
70
+ "addresses": {
71
+ "operation": {
72
+ "street1": "507, Koramangala 6th block",
73
+ "street2": "Kormanagala",
74
+ "city": "Bengaluru",
75
+ "state": "Karnataka",
76
+ "postal_code": 560047,
77
+ "country": "IN"
78
+ },
79
+ "registered": {
80
+ "street1": "507, Koramangala 1st block",
81
+ "street2": "MG Road",
82
+ "city": "Bengaluru",
83
+ "state": "Karnataka",
84
+ "postal_code": 560034,
85
+ "country": "IN"
86
+ }
87
+ },
88
+ "business_model": "Online Clothing ( men, women, ethnic, modern ) fashion and lifestyle, accessories, t-shirt, shirt, track pant, shoes."
89
+ },
90
+ "legal_info": {
91
+ "pan": "AAACL1234C",
92
+ "gst": "18AABCU9603R1ZM"
93
+ },
94
+ "brand": {
95
+ "color": "FFFFFF"
96
+ },
97
+ "notes": {
98
+ "internal_ref_id": "111111"
99
+ },
100
+ "contact_name": "Gaurav Kumar",
101
+ "contact_info": {
102
+ "chargeback": {
103
+ "email": "cb@example.org"
104
+ },
105
+ "refund": {
106
+ "email": "cb@example.org"
107
+ },
108
+ "support": {
109
+ "email": "support@example.org",
110
+ "phone": "9999999998",
111
+ "policy_url": "https://www.google.com"
112
+ }
113
+ },
114
+ "apps": {
115
+ "websites": [
116
+ "https://www.example.org"
117
+ ],
118
+ "android": [
119
+ {
120
+ "url": "playstore.example.org",
121
+ "name": "Example"
122
+ }
123
+ ],
124
+ "ios": [
125
+ {
126
+ "url": "appstore.example.org",
127
+ "name": "Example"
128
+ }
129
+ ]
130
+ }
131
+ }
132
+ end
133
+ end
134
+ end
@@ -6,8 +6,8 @@ module Razorpay
6
6
  class Item < Razorpay::Entity; end
7
7
 
8
8
  def setup
9
- @subscription_id = 'fake_subscription_id'
10
- @addon_id = 'fake_addon_id'
9
+ @subscription_id = 'sub_00000000000001'
10
+ @addon_id = 'ao_IrSY3UIqDRx7df'
11
11
 
12
12
  # Any request that ends with addons/addon_id
13
13
  stub_get(%r{addons\/#{Regexp.quote(@addon_id)}$}, 'fake_addon')
@@ -22,12 +22,19 @@ module Razorpay
22
22
  assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
23
23
  assert_equal @addon_id, addon.id, 'Addon IDs do not match'
24
24
  assert_equal 1, addon.quantity, 'Addon quantity is accessible'
25
- assert_equal 'fake_subscription_id', addon.subscription_id, 'Addon subscription_id is accessible'
25
+ assert_equal @subscription_id, addon.subscription_id, 'Addon subscription_id is accessible'
26
26
  assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
27
27
 
28
28
  assert_addon_item_details(addon)
29
29
  end
30
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
+
31
38
  def test_add_addons_to_subscription
32
39
  addon_attrs = {
33
40
  item: {
@@ -37,36 +44,33 @@ module Razorpay
37
44
  quantity: 1
38
45
  }
39
46
 
40
- stub_post(%r{subscriptions\/#{@subscription_id}\/addons$}, 'fake_addon', create_addon_stub_url_params)
47
+ stub_post(%r{subscriptions\/#{@subscription_id}\/addons$}, 'fake_addon', addon_attrs.to_json)
41
48
 
42
- addon = Razorpay::Addon.create(@subscription_id, addon_attrs)
49
+ addon = Razorpay::Addon.create(@subscription_id, addon_attrs.to_json)
43
50
  assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
44
51
 
45
- assert_equal 'fake_addon_id', addon.id, 'Addon IDs do not match'
52
+ assert_equal @addon_id, addon.id, 'Addon IDs do not match'
46
53
  assert_equal 1, addon.quantity, 'Addon quantity is accessible'
47
- assert_equal 'fake_subscription_id', addon.subscription_id, 'Addon subscription_id is accessible'
54
+ assert_equal @subscription_id, addon.subscription_id, 'Addon subscription_id is accessible'
48
55
  assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
49
56
 
50
57
  assert_addon_item_details(addon)
51
58
  end
52
59
 
53
- private
54
-
55
60
  def assert_addon_item_details(addon)
56
61
  addon_item = Item.new(addon.item)
57
62
 
58
- assert_equal 'fake_item_id', addon_item.id, 'Addon Item id is accessible'
63
+ assert_equal 'item_00000000000001', addon_item.id, 'Addon Item id is accessible'
59
64
  assert_equal 'fake_item_name', addon_item.name, 'Addon Item name is accessible'
60
65
  assert_equal 'fake_item_description', addon_item.description, 'Addon Item description is accessible'
61
66
  assert_equal 'INR', addon_item.currency, 'Addon Item currency is accessible'
62
67
  assert_equal 500, addon_item.amount, 'Addon Item amount is accessible'
63
68
  end
64
69
 
65
- def create_addon_stub_url_params
66
- %w(
67
- item[name]=fake_addon_name&item[currency]=INR&item[amount]=5000&
68
- item[description]=fake_addon_description&quantity=1
69
- ).join
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
70
74
  end
71
75
  end
72
76
  end
@@ -19,5 +19,11 @@ module Razorpay
19
19
  assert_instance_of Razorpay::Card, card, 'card not an instance of Razorpay::Card class'
20
20
  assert_equal @card_id, card.id, 'card IDs do not match'
21
21
  end
22
+
23
+ def test_request_card_reference_should_be_fetched
24
+ stub_post(%r{cards/fingerprints$}, 'fake_card_reference', {"number": "4111111111111111"})
25
+ card = Razorpay::Card.request_card_reference({"number": "4111111111111111"})
26
+ assert_instance_of Razorpay::Entity, card, 'card not an instance of Razorpay::Card class'
27
+ end
22
28
  end
23
29
  end
@@ -5,10 +5,11 @@ module Razorpay
5
5
  class RazorpayCustomerTest < Minitest::Test
6
6
  def setup
7
7
  @customer_id = 'cust_6vRXClWqnLhV14'
8
-
8
+ @token_id = "token_FHfn3rIiM1Z8nr"
9
+ @bank_id = "ba_Evg09Ll05SIPSD"
10
+ @eligibilityId = "elig_F1cxDoHWD4fkQt"
9
11
  # Any request that ends with customers/customer_id
10
12
  stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
11
- stub_get(/customers$/, 'customer_collection')
12
13
  end
13
14
 
14
15
  def test_customer_should_be_defined
@@ -32,14 +33,142 @@ module Razorpay
32
33
  end
33
34
 
34
35
  def test_fetch_all_customers
36
+ stub_get(/customers$/, 'customer_collection')
35
37
  customers = Razorpay::Customer.all
36
38
  assert_instance_of Razorpay::Collection, customers
37
39
  end
38
40
 
39
41
  def test_fetch_specific_customer
42
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
40
43
  customer = Razorpay::Customer.fetch(@customer_id)
41
44
  assert_instance_of Razorpay::Customer, customer
42
- assert_equal customer.id, @customer_id
45
+ assert_equal "test@razorpay.com", customer.email
46
+ end
47
+
48
+ def test_customer_fetch_tokens
49
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
50
+ stub_get(%r{customers/cust_6vRXClWqnLhV14/tokens$}, 'tokens_collection')
51
+ tokens = Razorpay::Customer.fetch(@customer_id).fetchTokens
52
+ assert_instance_of Razorpay::Collection, tokens, 'Tokens should be an array'
53
+ refute_empty tokens.items, 'tokens should be more than one'
54
+ end
55
+
56
+ def test_customer_fetch_token
57
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
58
+ stub_get(%r{customers/cust_6vRXClWqnLhV14/tokens/token_FHfn3rIiM1Z8nr$}, 'fake_token')
59
+ token = Razorpay::Customer.fetch(@customer_id).fetchToken("token_FHfn3rIiM1Z8nr")
60
+ assert_instance_of Razorpay::Token, token, 'Token not an instance of Razorpay::Entity class'
61
+ assert_equal "token_FHfn3rIiM1Z8nr", token.id
62
+ end
63
+
64
+ def test_customer_delete_token
65
+ stub_get(%r{customers/#{@customer_id}$}, 'fake_customer')
66
+ stub_delete(%r{customers/cust_6vRXClWqnLhV14/tokens/token_FHfn3rIiM1Z8nr$}, 'delete_token')
67
+ token = Razorpay::Customer.fetch(@customer_id).deleteToken("token_FHfn3rIiM1Z8nr")
68
+ assert token.deleted
69
+ end
70
+
71
+ def test_customer_add_bank_account
72
+ para_attr = {
73
+ "ifsc_code": "UTIB0000194",
74
+ "account_number": "916010082985661",
75
+ "beneficiary_name": "Pratheek",
76
+ "beneficiary_address1": "address 1",
77
+ "beneficiary_address2": "address 2",
78
+ "beneficiary_address3": "address 3",
79
+ "beneficiary_address4": "address 4",
80
+ "beneficiary_email": "random@email.com",
81
+ "beneficiary_mobile": "8762489310",
82
+ "beneficiary_city": "Bangalore",
83
+ "beneficiary_state": "KA",
84
+ "beneficiary_country": "IN"
85
+ }
86
+
87
+ stub_post(%r{customers/#{@customer_id}/bank_account$}, 'fake_bank_account', para_attr.to_json)
88
+ bankAccount = Razorpay::Customer.add_bank_account(@customer_id, para_attr.to_json)
89
+ assert bankAccount.bank_name
90
+ end
91
+
92
+ def test_customer_add_bank_account_exception
93
+ para_attr = {}
94
+ stub_post(%r{customers/#{@customer_id}/bank_account$}, 'error_customer', para_attr.to_json)
95
+ assert_raises(Razorpay::Error) do
96
+ customer = Razorpay::Customer.add_bank_account(@customer_id, para_attr.to_json)
97
+ if customer.error
98
+ raise Razorpay::Error.new, customer.error['code']
99
+ end
100
+ end
101
+ end
102
+
103
+ def test_customer_delete_bank_account
104
+ stub_delete(%r{customers/#{@customer_id}/bank_account/#{@bank_id}$}, 'success')
105
+ bankAccount = Razorpay::Customer.delete_bank_account(@customer_id, @bank_id)
106
+ assert bankAccount.success
107
+ end
108
+
109
+ def test_customer_delete_bank_account_exception
110
+ stub_delete(%r{customers/#{@customer_id}/bank_account/#{@bank_id}$}, 'error_customer')
111
+ assert_raises(Razorpay::Error) do
112
+ customer = Razorpay::Customer.delete_bank_account(@customer_id,@bank_id)
113
+ if customer.error
114
+ raise Razorpay::Error.new, customer.error['code']
115
+ end
116
+ end
117
+ end
118
+
119
+ def test_customer_request_eligiblity_check
120
+ para_attr = {
121
+ "inquiry": "affordability",
122
+ "amount": 500000,
123
+ "currency": "INR",
124
+ "customer": {
125
+ "id": "cust_KhP5dO1dKmc0Rm",
126
+ "contact": "+918220276214",
127
+ "ip": "105.106.107.108",
128
+ "referrer": "https://merchansite.com/example/paybill",
129
+ "user_agent": "Mozilla/5.0"
130
+ }
131
+ }
132
+ stub_post(%r{customers/eligibility$}, 'fake_eligiblity', para_attr.to_json)
133
+ bankAccount = Razorpay::Customer.request_eligibility_check(para_attr.to_json)
134
+ assert bankAccount.amount
135
+ end
136
+
137
+ def test_customer_fetch_eligiblity_check_exception
138
+ para_attr = {
139
+ "inquiry": "affordability",
140
+ "currency": "INR",
141
+ "customer": {
142
+ "id": "cust_KhP5dO1dKmc0Rm",
143
+ "contact": "+918220276214",
144
+ "ip": "105.106.107.108",
145
+ "referrer": "https://merchansite.com/example/paybill",
146
+ "user_agent": "Mozilla/5.0"
147
+ }
148
+ }
149
+ stub_post(%r{customers/eligibility$}, 'error_eligibility_check', para_attr.to_json)
150
+ assert_raises(Razorpay::Error) do
151
+ customer = Razorpay::Customer.request_eligibility_check(para_attr.to_json)
152
+ if customer.error
153
+ raise Razorpay::Error.new, customer.error['code']
154
+ end
155
+ end
156
+ end
157
+
158
+ def test_customer_fetch_eligiblity
159
+ stub_get(%r{customers/eligibility/#{@eligibilityId}$}, 'fake_eligiblity')
160
+ bankAccount = Razorpay::Customer.fetch_eligibility(@eligibilityId)
161
+ assert bankAccount.amount
162
+ end
163
+
164
+ def test_customer_fetch_eligiblity_exception
165
+ stub_get(%r{customers/eligibility/#{@eligibilityId}$}, 'error_eligibility_check')
166
+ assert_raises(Razorpay::Error) do
167
+ customer = Razorpay::Customer.fetch_eligibility(@eligibilityId)
168
+ if customer.error
169
+ raise Razorpay::Error.new, customer.error['code']
170
+ end
171
+ end
43
172
  end
44
173
  end
45
174
  end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+
5
+ class RazorpayDisputeonTest < Minitest::Test
6
+ class Dispute < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @dispute_id = 'disp_XXXXXXXXXXXXX'
10
+
11
+ # Any request that ends with disputes/dispute_id
12
+ stub_get(%r{disputes\/#{Regexp.quote(@dispute_id)}$}, 'fake_dispute')
13
+ end
14
+
15
+ def test_dispute_should_be_defined
16
+ refute_nil Razorpay::Addon
17
+ end
18
+
19
+ def test_addon_should_be_available
20
+ dispute = Razorpay::Dispute.fetch(@dispute_id)
21
+ assert_instance_of Razorpay::Dispute, dispute, 'Dispute not an instance of Dispute class'
22
+ assert_equal @dispute_id, dispute.id
23
+ assert_equal 'INR', dispute.currency
24
+ end
25
+
26
+ def test_addon_should_be_available_failure
27
+ stub_get(%r{disputes\/#{Regexp.quote(@dispute_id)}$}, 'dispute_error')
28
+ assert_raises(Razorpay::Error) do
29
+ dispute = Razorpay::Dispute.fetch(@dispute_id)
30
+ if dispute.error
31
+ raise Razorpay::Error.new, dispute.error['code']
32
+ end
33
+ end
34
+ end
35
+
36
+ def test_fetch_all_dispute
37
+ stub_get(/disputes$/, 'dispute_collection')
38
+ dispute = Razorpay::Dispute.all
39
+ assert_instance_of Razorpay::Collection, dispute, 'Dispute should be an array'
40
+ refute_empty dispute.items, 'Dispute should be more than one'
41
+ end
42
+
43
+ def test_dispute_accept
44
+ param_attr = {}
45
+
46
+ stub_post(%r{disputes\/#{@dispute_id}\/accept$}, 'fake_dispute', param_attr.to_json)
47
+
48
+ dispute = Razorpay::Dispute.accept(@dispute_id, param_attr.to_json)
49
+ assert_instance_of Razorpay::Dispute, dispute, 'Dispute not an instance of Dispute class'
50
+
51
+ assert_equal @dispute_id, dispute.id, 'Dispute IDs do not match'
52
+ assert_equal 10000, dispute.amount
53
+ assert_equal 0, dispute.amount_deducted
54
+ end
55
+
56
+ def test_dispute_accept_failure
57
+ param_attr = {}
58
+ stub_post(%r{disputes\/#{@dispute_id}\/accept$}, 'dispute_error', param_attr.to_json)
59
+ assert_raises(Razorpay::Error) do
60
+ dispute = Razorpay::Dispute.accept(@dispute_id, param_attr.to_json)
61
+ if dispute.error
62
+ raise Razorpay::Error.new, dispute.error['code']
63
+ end
64
+ end
65
+ end
66
+
67
+ def test_dispute_contest
68
+
69
+ param_attr = {
70
+ "billing_proof": [
71
+ "doc_EFtmUsbwpXwBG9",
72
+ "doc_EFtmUsbwpXwBG8"
73
+ ],
74
+ "action": "submit"
75
+ }
76
+
77
+ stub_patch(%r{disputes\/#{@dispute_id}\/contest$}, 'fake_dispute', param_attr.to_json)
78
+
79
+ dispute = Razorpay::Dispute.contest(@dispute_id, param_attr.to_json)
80
+ assert_instance_of Razorpay::Dispute, dispute, 'Dispute not an instance of Dispute class'
81
+
82
+ assert_equal @dispute_id, dispute.id, 'Dispute IDs do not match'
83
+ assert_equal 10000, dispute.amount
84
+ assert_equal 0, dispute.amount_deducted
85
+ end
86
+
87
+ def test_dispute_contest_failure
88
+ param_attr = {}
89
+ stub_patch(%r{disputes\/#{@dispute_id}\/contest$}, 'dispute_error', param_attr.to_json)
90
+ assert_raises(Razorpay::Error) do
91
+ dispute = Razorpay::Dispute.contest(@dispute_id, param_attr.to_json)
92
+ if dispute.error
93
+ raise Razorpay::Error.new, dispute.error['code']
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end