razorpay 3.2.1 → 3.2.3

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +18 -1
  4. data/documents/customer.md +242 -0
  5. data/documents/dispute.md +301 -0
  6. data/documents/documents.md +65 -0
  7. data/documents/oauth_token.md +142 -0
  8. data/documents/order.md +71 -0
  9. data/documents/payment.md +253 -0
  10. data/documents/transfers.md +40 -0
  11. data/lib/razorpay/constants.rb +6 -1
  12. data/lib/razorpay/customer.rb +16 -0
  13. data/lib/razorpay/dispute.rb +26 -0
  14. data/lib/razorpay/document.rb +19 -0
  15. data/lib/razorpay/oauth_token.rb +109 -0
  16. data/lib/razorpay/order.rb +8 -0
  17. data/lib/razorpay/payload_validator.rb +93 -0
  18. data/lib/razorpay/payment.rb +4 -0
  19. data/lib/razorpay/request.rb +24 -7
  20. data/lib/razorpay/transfer.rb +4 -0
  21. data/lib/razorpay/utility.rb +24 -0
  22. data/lib/razorpay/validation_config.rb +11 -0
  23. data/lib/razorpay.rb +10 -1
  24. data/test/fixtures/dispute_collection.json +67 -0
  25. data/test/fixtures/dispute_error.json +10 -0
  26. data/test/fixtures/document_error.json +10 -0
  27. data/test/fixtures/error_customer.json +10 -0
  28. data/test/fixtures/error_eligibility.json +10 -0
  29. data/test/fixtures/error_eligibility_check.json +10 -0
  30. data/test/fixtures/fake_bank_account.json +9 -0
  31. data/test/fixtures/fake_dispute.json +29 -0
  32. data/test/fixtures/fake_document.json +9 -0
  33. data/test/fixtures/fake_eligiblity.json +79 -0
  34. data/test/fixtures/fake_fulfillment.json +10 -0
  35. data/test/fixtures/fake_oauth_token.json +8 -0
  36. data/test/fixtures/fake_payment_expanded_details.json +38 -0
  37. data/test/fixtures/fake_payment_expanded_details_card.json +50 -0
  38. data/test/fixtures/fake_revoke_token.json +3 -0
  39. data/test/fixtures/fake_rto.json +15 -0
  40. data/test/fixtures/order_error.json +10 -0
  41. data/test/fixtures/payment_error.json +10 -0
  42. data/test/fixtures/reversals_collection.json +22 -0
  43. data/test/fixtures/transfer_error.json +10 -0
  44. data/test/razorpay/test_customer.rb +105 -0
  45. data/test/razorpay/test_dispute.rb +98 -0
  46. data/test/razorpay/test_document.rb +27 -0
  47. data/test/razorpay/test_oauth_token.rb +105 -0
  48. data/test/razorpay/test_order.rb +43 -1
  49. data/test/razorpay/test_payload_validator.rb +61 -0
  50. data/test/razorpay/test_payment.rb +23 -1
  51. data/test/razorpay/test_razorpay.rb +17 -0
  52. data/test/razorpay/test_transfer.rb +17 -0
  53. data/test/razorpay/test_utility.rb +34 -0
  54. metadata +59 -3
@@ -0,0 +1,38 @@
1
+ {
2
+ "id": "fake_payment_id",
3
+ "entity": "payment",
4
+ "amount": 200000,
5
+ "currency": "INR",
6
+ "status": "authorized",
7
+ "order_id": null,
8
+ "invoice_id": null,
9
+ "international": false,
10
+ "method": "emi",
11
+ "amount_refunded": 0,
12
+ "refund_status": null,
13
+ "captured": false,
14
+ "description": null,
15
+ "card_id": "card_DG4ZdUO3xABb20",
16
+ "bank": "ICIC",
17
+ "wallet": null,
18
+ "vpa": null,
19
+ "email": "gaurav@example.com",
20
+ "contact": "+919972000005",
21
+ "notes": [],
22
+ "fee": null,
23
+ "tax": null,
24
+ "error_code": null,
25
+ "error_description": null,
26
+ "error_source": null,
27
+ "error_step": null,
28
+ "error_reason": null,
29
+ "emi": {
30
+ "issuer": "ICIC",
31
+ "rate": 1300,
32
+ "duration": 6
33
+ },
34
+ "acquirer_data": {
35
+ "auth_code": "828553"
36
+ },
37
+ "created_at": 1568026077
38
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "id": "fake_payment_id",
3
+ "entity": "payment",
4
+ "amount": 100,
5
+ "currency": "INR",
6
+ "status": "failed",
7
+ "order_id": "order_H9o58N6qmLYQKC",
8
+ "invoice_id": null,
9
+ "terminal_id": "term_G5kJnYM9GhhLYT",
10
+ "international": false,
11
+ "method": "card",
12
+ "amount_refunded": 0,
13
+ "refund_status": null,
14
+ "captured": false,
15
+ "description": null,
16
+ "card_id": "card_H9oR0ocen1cmZq",
17
+ "card": {
18
+ "id": "card_H9oR0ocen1cmZq",
19
+ "entity": "card",
20
+ "name": "Gaurav",
21
+ "last4": "1213",
22
+ "network": "RuPay",
23
+ "type": "credit",
24
+ "issuer": "UTIB",
25
+ "international": false,
26
+ "emi": false,
27
+ "sub_type": "business"
28
+ },
29
+ "bank": null,
30
+ "wallet": null,
31
+ "vpa": null,
32
+ "email": "gaurav.kumar@example.com",
33
+ "contact": "+919000090000",
34
+ "notes": {
35
+ "email": "gaurav.kumar@example.com",
36
+ "phone": "09000090000"
37
+ },
38
+ "fee": null,
39
+ "tax": null,
40
+ "error_code": "BAD_REQUEST_ERROR",
41
+ "error_description": "Card issuer is invalid",
42
+ "error_source": "customer",
43
+ "error_step": "payment_authentication",
44
+ "error_reason": "incorrect_card_details",
45
+ "acquirer_data": {
46
+ "auth_code": null,
47
+ "authentication_reference_number": "100222021120200000000742753928"
48
+ },
49
+ "created_at": 1620807547
50
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "message": "Token Revoked"
3
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "risk_tier": "high",
3
+ "rto_reasons": [
4
+ {
5
+ "reason": "short_shipping_address",
6
+ "description": "Short shipping address",
7
+ "bucket": "address"
8
+ },
9
+ {
10
+ "reason": "address_pincode_state_mismatch",
11
+ "description": "Incorrect pincode state entered",
12
+ "bucket": "address"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "error": {
3
+ "code": "BAD_REQUEST_ERROR",
4
+ "description": "The id provided does not exist",
5
+ "source": "business",
6
+ "step": "payment_initiation",
7
+ "reason": "input_validation_failed",
8
+ "metadata": {}
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "error": {
3
+ "code": "BAD_REQUEST_ERROR",
4
+ "description": "The id provided does not exist",
5
+ "source": "business",
6
+ "step": "payment_initiation",
7
+ "reason": "input_validation_failed",
8
+ "metadata": {}
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "entity":"collection",
3
+ "count":1,
4
+ "items":[
5
+ {
6
+ "id":"rvrsl_Lt09xvyzskI7KZ",
7
+ "entity":"reversal",
8
+ "transfer_id":"trf_Lt048W7cgLdo1u",
9
+ "amount":50000,
10
+ "fee":0,
11
+ "tax":0,
12
+ "currency":"INR",
13
+ "notes":[
14
+
15
+ ],
16
+ "initiator_id":"Ghri4beeOuMTAb",
17
+ "customer_refund_id":null,
18
+ "utr":null,
19
+ "created_at":1684822489
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "error": {
3
+ "code": "BAD_REQUEST_ERROR",
4
+ "description": "The id provided does not exist",
5
+ "source": "business",
6
+ "step": "payment_initiation",
7
+ "reason": "input_validation_failed",
8
+ "metadata": {}
9
+ }
10
+ }
@@ -6,6 +6,8 @@ module Razorpay
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
13
  end
@@ -65,5 +67,108 @@ module Razorpay
65
67
  token = Razorpay::Customer.fetch(@customer_id).deleteToken("token_FHfn3rIiM1Z8nr")
66
68
  assert token.deleted
67
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
172
+ end
68
173
  end
69
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
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Document
5
+ class RazorpayDocumentTest < Minitest::Test
6
+ def setup
7
+ @document_id = 'doc_O4KCaSbX4BjA6I'
8
+ # Any request that ends with document/document_id
9
+ stub_get(%r{documents/#{@document_id}$}, 'fake_document')
10
+ end
11
+
12
+ def test_document_should_be_defined
13
+ refute_nil Razorpay::Document
14
+ end
15
+
16
+ def test_document_should_be_defined_exception
17
+ para_attr = {}
18
+ stub_get(%r{documents/#{@document_id}$}, 'document_error')
19
+ assert_raises(Razorpay::Error) do
20
+ document = Razorpay::Document.fetch(@document_id)
21
+ if document.error
22
+ raise Razorpay::Error.new, document.error['code']
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::OauthToken
5
+ class RazorpayOAuthTokenTest < Minitest::Test
6
+ class OAuthToken < Razorpay::Entity; end
7
+
8
+ def test_get_auth_url
9
+ options = {
10
+ 'client_id' => '8DXCMTshWSWECc',
11
+ 'redirect_uri' => 'https://example.com/razorpay_callback',
12
+ 'state' => 'NOBYtv8r6c75ex6WZ',
13
+ 'scopes' => ["read_write"]
14
+ }
15
+
16
+ expected_auth_url = "https://auth.razorpay.com/authorize?response_type=code&client_id=8DXCMTshWSWECc&redirect_uri=https%3A%2F%2Fexample.com%2Frazorpay_callback&state=NOBYtv8r6c75ex6WZ&scope%5B%5D=read_write"
17
+ auth_url = Razorpay::OAuthToken.get_auth_url(options)
18
+ assert_equal expected_auth_url, auth_url
19
+ end
20
+
21
+ def test_request_validation_for_get_auth_url
22
+ options = {
23
+ 'client_id' => '8DXCMTshWSWECc',
24
+ 'redirect_uri' => 'https://example.com/razorpay_callback',
25
+ 'scopes' => ["read_write"]
26
+ }
27
+ assert_raises(Razorpay::Error) do
28
+ Razorpay::OAuthToken.get_auth_url(options)
29
+ end
30
+ end
31
+
32
+ def test_get_access_token
33
+ options = {
34
+ 'client_id' => '8DXCMTshWSWECc',
35
+ 'client_secret' => 'AESSECRETKEY',
36
+ 'grant_type' => 'client_credentials',
37
+ 'redirect_uri' => 'http://example.com/razorpay_callback',
38
+ 'mode' => 'test'
39
+ }
40
+ stub_post(/token$/,'fake_oauth_token',options)
41
+ oauth_token = Razorpay::OAuthToken.get_access_token(options)
42
+ assert_instance_of Razorpay::Entity, oauth_token, 'OAuthToken not an instance of Entity class'
43
+ assert_equal 'rzp_test_oauth_9xu1rkZqoXlClS', oauth_token.public_token, 'Public Tokens do not match'
44
+ end
45
+
46
+ def test_get_access_token_validation_failure
47
+ options = {
48
+ 'client_id' => '8DXCMTshWSWECc',
49
+ 'grant_type' => 'client_credentials',
50
+ 'redirect_uri' => 'http://example.com/razorpay_callback',
51
+ 'mode' => 'test'
52
+ }
53
+ assert_raises(Razorpay::Error) do
54
+ Razorpay::OAuthToken.get_access_token(options)
55
+ end
56
+ end
57
+
58
+ def test_refresh_token
59
+ options = {
60
+ 'client_id' => '8DXCMTshWSWECc',
61
+ 'client_secret' => 'AESSECRETKEY',
62
+ 'refresh_token' => 'def5020096e1c470c901d34cd60fa53abdaf3662sa0'
63
+ }
64
+ expected_request_payload = options.merge('grant_type': 'refresh_token')
65
+ stub_post(/token$/,'fake_oauth_token',expected_request_payload)
66
+ oauth_token = Razorpay::OAuthToken.refresh_token(options)
67
+ assert_instance_of Razorpay::Entity, oauth_token, 'OAuthToken not an instance of Entity class'
68
+ assert_equal 'rzp_test_oauth_9xu1rkZqoXlClS', oauth_token.public_token, 'Public Tokens do not match'
69
+ end
70
+
71
+ def test_refresh_token_validation_failure
72
+ options = {
73
+ 'client_id' => '8DXCMTshWSWECc',
74
+ 'refresh_token' => 'def5020096e1c470c901d34cd60fa53abdaf3662sa0'
75
+ }
76
+ assert_raises(Razorpay::Error) do
77
+ Razorpay::OAuthToken.refresh_token(options)
78
+ end
79
+ end
80
+
81
+ def test_revoke_token
82
+ options = {
83
+ 'client_id' => '8DXCMTshWSWECc',
84
+ 'client_secret' => 'AESSECRETKEY',
85
+ 'token_type_hint' => 'access_token',
86
+ 'token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJKQTFwODVudE1ySEpoQSIsImp0aSI6IkpPZkd0aHFDTmhqQUhTIiwiaWF0IjoxNjUxMTI0NTU0LCJuYmYiOjE2NTExMjQ1NTQsInN1YiI6IiIsImV4cCI6MTY1ODk4Njk1Miw'
87
+ }
88
+ stub_post(/revoke$/,'fake_revoke_token',options)
89
+ oauth_token = Razorpay::OAuthToken.revoke_token(options)
90
+ assert_instance_of Razorpay::Entity, oauth_token, 'OAuthToken not an instance of Entity class'
91
+ assert_equal 'Token Revoked', oauth_token.message, 'Messages do not match'
92
+ end
93
+
94
+ def test_revoke_token_validation_failure
95
+ options = {
96
+ 'client_id' => '8DXCMTshWSWECc',
97
+ 'client_secret' => 'AESSECRETKEY',
98
+ 'token_type_hint' => 'access_token'
99
+ }
100
+ assert_raises(Razorpay::Error) do
101
+ Razorpay::OAuthToken.revoke_token(options)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -66,6 +66,48 @@ module Razorpay
66
66
  assert_equal @order_id, order.id, 'order IDs do not match'
67
67
  refute_empty order.transfers["items"]
68
68
  assert_equal @transfer_id, order.transfers["items"][0]["id"]
69
- end
69
+ end
70
+
71
+ def test_view_rto
72
+ stub_post(%r{orders/#{@order_id}/rto_review$}, 'fake_rto', {})
73
+ order = Razorpay::Order.view_rto(@order_id)
74
+ assert !order.rto_reasons.empty?, 'orders should be more than one'
75
+ end
76
+
77
+ def test_view_rto_exception
78
+ stub_post(%r{orders/#{@order_id}/rto_review$}, 'order_error', {})
79
+ assert_raises(Razorpay::Error) do
80
+ order = Razorpay::Order.view_rto(@order_id)
81
+ if order.error
82
+ raise Razorpay::Error.new, order.error['code']
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_fulfillment
88
+ param_attr = {
89
+ "payment_method": "upi",
90
+ "shipping": {
91
+ "waybill": "123456789",
92
+ "status": "rto",
93
+ "provider": "Bluedart"
94
+ }
95
+ }
96
+
97
+ stub_post(%r{orders/#{@order_id}/fulfillment$}, 'fake_fulfillment', param_attr.to_json)
98
+ order = Razorpay::Order.edit_fulfillment(@order_id, param_attr.to_json)
99
+ assert_equal "upi", order.payment_method, 'order payment method do not match'
100
+ end
101
+
102
+ def test_fulfillment_exception
103
+ para_attr = {}
104
+ stub_post(%r{orders/#{@order_id}/fulfillment$}, 'order_error', para_attr.to_json)
105
+ assert_raises(Razorpay::Error) do
106
+ order = Razorpay::Order.edit_fulfillment(@order_id, para_attr.to_json)
107
+ if order.error
108
+ raise Razorpay::Error.new, order.error['code']
109
+ end
110
+ end
111
+ end
70
112
  end
71
113
  end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+ require 'razorpay/validation_config'
3
+
4
+ module Razorpay
5
+ # Tests for Razorpay::PayloadValidator
6
+ class RazorpayPayloadValidatorTest < Minitest::Test
7
+ def test_validate_mode
8
+ payload = {
9
+ 'mode1' => 'test',
10
+ 'mode2' => 'live'
11
+ }
12
+ assert_silent do
13
+ Razorpay::PayloadValidator.validate(payload, [
14
+ Razorpay::ValidationConfig.new('mode1', [:mode]),
15
+ Razorpay::ValidationConfig.new('mode2', [:mode]),
16
+ ])
17
+ end
18
+ end
19
+
20
+ def test_mode_validation_failure
21
+ payload = {
22
+ 'mode' => 'testvalue'
23
+ }
24
+ assert_raises(Razorpay::Error) do
25
+ Razorpay::PayloadValidator.validate(payload, [
26
+ Razorpay::ValidationConfig.new('mode', [:mode])
27
+ ])
28
+ end
29
+ end
30
+
31
+ def test_url_validation_failure
32
+ payload = {
33
+ 'redirect_uri' => 'test.com'
34
+ }
35
+ assert_raises(Razorpay::Error) do
36
+ Razorpay::PayloadValidator.validate(payload, [
37
+ Razorpay::ValidationConfig.new('redirect_uri', [:url])
38
+ ])
39
+ end
40
+ end
41
+
42
+ def test_non_null_validation_failure
43
+ assert_raises(Razorpay::Error) do
44
+ Razorpay::PayloadValidator.validate({}, [
45
+ Razorpay::ValidationConfig.new('redirect_uri', [:non_null])
46
+ ])
47
+ end
48
+ end
49
+
50
+ def test_id_validation_failure
51
+ payload = {
52
+ 'client_id' => 'fjidhf'
53
+ }
54
+ assert_raises(Razorpay::Error) do
55
+ Razorpay::PayloadValidator.validate({}, [
56
+ Razorpay::ValidationConfig.new('client_id', [:id])
57
+ ])
58
+ end
59
+ end
60
+ end
61
+ end
@@ -298,6 +298,28 @@ module Razorpay
298
298
  stub_post(%r{payments/validate/vpa$}, 'fake_validate_vpa',param_attr.to_json)
299
299
  payment = Razorpay::Payment.validate_vpa param_attr.to_json
300
300
  assert_equal param_attr[:vpa], payment.vpa
301
- end
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
302
324
  end
303
325
  end