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.
- checksums.yaml +4 -4
- data/.cursorignore +174 -0
- data/.github/dependabot.yml +8 -0
- data/.github/pull_request_template.md +8 -0
- data/.github/workflows/ci.yml +80 -0
- data/.github/workflows/ruby.yml +38 -0
- data/CHANGELOG.md +85 -1
- data/README.md +48 -137
- data/documents/Invoice.md +539 -0
- data/documents/account.md +449 -0
- data/documents/addon.md +191 -0
- data/documents/card.md +655 -0
- data/documents/customer.md +405 -0
- data/documents/dispute.md +301 -0
- data/documents/documents.md +65 -0
- data/documents/emandate.md +492 -0
- data/documents/fund.md +89 -0
- data/documents/items.md +208 -0
- data/documents/oauth_token.md +142 -0
- data/documents/order.md +352 -0
- data/documents/papernach.md +738 -0
- data/documents/payment.md +1122 -0
- data/documents/paymentLink.md +1063 -0
- data/documents/paymentVerification.md +79 -0
- data/documents/plan.md +184 -0
- data/documents/productConfiguration.md +444 -0
- data/documents/qrcode.md +439 -0
- data/documents/refund.md +325 -0
- data/documents/registerEmandate.md +452 -0
- data/documents/registerNach.md +653 -0
- data/documents/settlement.md +478 -0
- data/documents/stakeholder.md +334 -0
- data/documents/subscriptions.md +752 -0
- data/documents/tokens.md +407 -0
- data/documents/transfers.md +821 -0
- data/documents/upi.md +545 -0
- data/documents/virtualAccount.md +591 -0
- data/documents/webhook.md +224 -0
- data/lib/razorpay/account.rb +39 -0
- data/lib/razorpay/addon.rb +9 -1
- data/lib/razorpay/card.rb +4 -0
- data/lib/razorpay/constants.rb +7 -2
- data/lib/razorpay/customer.rb +31 -0
- data/lib/razorpay/dispute.rb +26 -0
- data/lib/razorpay/document.rb +19 -0
- data/lib/razorpay/fund_account.rb +19 -0
- data/lib/razorpay/iin.rb +15 -0
- data/lib/razorpay/invoice.rb +8 -0
- data/lib/razorpay/item.rb +34 -0
- data/lib/razorpay/oauth_token.rb +109 -0
- data/lib/razorpay/order.rb +19 -1
- data/lib/razorpay/payload_validator.rb +93 -0
- data/lib/razorpay/payment.rb +64 -0
- data/lib/razorpay/payment_link.rb +36 -0
- data/lib/razorpay/payment_method.rb +17 -0
- data/lib/razorpay/product.rb +37 -0
- data/lib/razorpay/qr_code.rb +34 -0
- data/lib/razorpay/refund.rb +4 -0
- data/lib/razorpay/request.rb +50 -26
- data/lib/razorpay/settlement.rb +39 -0
- data/lib/razorpay/stakeholder.rb +39 -0
- data/lib/razorpay/subscription.rb +24 -0
- data/lib/razorpay/subscription_registration.rb +16 -0
- data/lib/razorpay/token.rb +28 -0
- data/lib/razorpay/transfer.rb +39 -0
- data/lib/razorpay/utility.rb +41 -6
- data/lib/razorpay/validation_config.rb +11 -0
- data/lib/razorpay/virtual_account.rb +15 -7
- data/lib/razorpay/webhook.rb +50 -0
- data/lib/razorpay.rb +24 -1
- data/razorpay-ruby.gemspec +2 -1
- data/test/fixtures/addon_collection.json +60 -0
- data/test/fixtures/create_json_payment.json +13 -0
- data/test/fixtures/delete_token.json +3 -0
- data/test/fixtures/dispute_collection.json +67 -0
- data/test/fixtures/dispute_error.json +10 -0
- data/test/fixtures/document_error.json +10 -0
- data/test/fixtures/downtimes_collection.json +21 -0
- data/test/fixtures/empty.json +2 -0
- data/test/fixtures/error_customer.json +10 -0
- data/test/fixtures/error_eligibility.json +10 -0
- data/test/fixtures/error_eligibility_check.json +10 -0
- data/test/fixtures/fake_account.json +78 -0
- data/test/fixtures/fake_addon.json +3 -3
- data/test/fixtures/fake_bank_account.json +9 -0
- data/test/fixtures/fake_card_reference.json +5 -0
- data/test/fixtures/fake_create_upi_payment.json +3 -0
- data/test/fixtures/fake_direct_transfer.json +32 -0
- data/test/fixtures/fake_dispute.json +29 -0
- data/test/fixtures/fake_document.json +9 -0
- data/test/fixtures/fake_downtime.json +14 -0
- data/test/fixtures/fake_eligiblity.json +79 -0
- data/test/fixtures/fake_fulfillment.json +10 -0
- data/test/fixtures/fake_fund_account.json +18 -0
- data/test/fixtures/fake_iin_token.json +23 -0
- data/test/fixtures/fake_instant_settlement.json +19 -0
- data/test/fixtures/fake_item.json +9 -0
- data/test/fixtures/fake_oauth_token.json +8 -0
- data/test/fixtures/fake_order_transfers.json +88 -0
- data/test/fixtures/fake_otp_generate.json +19 -0
- data/test/fixtures/fake_otp_resend.json +7 -0
- data/test/fixtures/fake_otp_submit.json +5 -0
- data/test/fixtures/fake_payment_expanded_details.json +38 -0
- data/test/fixtures/fake_payment_expanded_details_card.json +50 -0
- data/test/fixtures/fake_payment_link.json +40 -0
- data/test/fixtures/fake_pending_update.json +30 -0
- data/test/fixtures/fake_product.json +138 -0
- data/test/fixtures/fake_qrcode.json +20 -0
- data/test/fixtures/fake_qrcode_close.json +22 -0
- data/test/fixtures/fake_recurring.json +5 -0
- data/test/fixtures/fake_refund.json +1 -1
- data/test/fixtures/fake_revoke_token.json +3 -0
- data/test/fixtures/fake_rto.json +15 -0
- data/test/fixtures/fake_settlement.json +11 -0
- data/test/fixtures/fake_settlement_on_demand.json +39 -0
- data/test/fixtures/fake_stakeholder.json +29 -0
- data/test/fixtures/fake_subscription_pause.json +19 -0
- data/test/fixtures/fake_subscription_registration.json +91 -0
- data/test/fixtures/fake_subscription_resume.json +19 -0
- data/test/fixtures/fake_token.json +31 -0
- data/test/fixtures/fake_tokenise_customer.json +40 -0
- data/test/fixtures/fake_transfer.json +18 -0
- data/test/fixtures/fake_transfer_reverse.json +15 -0
- data/test/fixtures/fake_update_payment.json +39 -0
- data/test/fixtures/fake_validate_vpa.json +5 -0
- data/test/fixtures/fake_virtual_account_allowed.json +46 -0
- data/test/fixtures/fake_virtual_account_receiver.json +46 -0
- data/test/fixtures/fake_webhook.json +79 -0
- data/test/fixtures/fake_webhook_by_account_id.json +22 -0
- data/test/fixtures/fetch_tnc.json +11 -0
- data/test/fixtures/fund_collection.json +20 -0
- data/test/fixtures/item_collection.json +24 -0
- data/test/fixtures/order_error.json +10 -0
- data/test/fixtures/payment_collection.json +1 -1
- data/test/fixtures/payment_error.json +10 -0
- data/test/fixtures/payment_link_collection.json +43 -0
- data/test/fixtures/payment_link_response.json +3 -0
- data/test/fixtures/payment_methods_collection.json +149 -0
- data/test/fixtures/qrcode_collection.json +50 -0
- data/test/fixtures/qrcode_payments_collection.json +74 -0
- data/test/fixtures/reversals_collection.json +22 -0
- data/test/fixtures/settlement_collection.json +26 -0
- data/test/fixtures/settlement_instant_collection.json +84 -0
- data/test/fixtures/settlement_report_collection.json +117 -0
- data/test/fixtures/stakeholder_collection.json +35 -0
- data/test/fixtures/success.json +3 -0
- data/test/fixtures/tokens_collection.json +36 -0
- data/test/fixtures/transfer_error.json +10 -0
- data/test/fixtures/transfer_settlements_collection.json +38 -0
- data/test/fixtures/transfers_collection.json +41 -0
- data/test/fixtures/webhook_by_account_collection.json +35 -0
- data/test/fixtures/webhook_collection.json +85 -0
- data/test/razorpay/test_account.rb +134 -0
- data/test/razorpay/test_addon.rb +19 -15
- data/test/razorpay/test_card.rb +6 -0
- data/test/razorpay/test_customer.rb +132 -3
- data/test/razorpay/test_dispute.rb +98 -0
- data/test/razorpay/test_document.rb +27 -0
- data/test/razorpay/test_fund_account.rb +42 -0
- data/test/razorpay/test_iin.rb +23 -0
- data/test/razorpay/test_invoice.rb +15 -2
- data/test/razorpay/test_item.rb +66 -0
- data/test/razorpay/test_oauth_token.rb +105 -0
- data/test/razorpay/test_order.rb +66 -1
- data/test/razorpay/test_payload_validator.rb +61 -0
- data/test/razorpay/test_payment.rb +251 -9
- data/test/razorpay/test_payment_link.rb +83 -0
- data/test/razorpay/test_plan.rb +2 -2
- data/test/razorpay/test_product.rb +67 -0
- data/test/razorpay/test_qr_code.rb +63 -0
- data/test/razorpay/test_razorpay.rb +19 -2
- data/test/razorpay/test_refund.rb +16 -2
- data/test/razorpay/test_settlement.rb +76 -0
- data/test/razorpay/test_stakeholder.rb +87 -0
- data/test/razorpay/test_subscription.rb +72 -9
- data/test/razorpay/test_subscription_registration.rb +58 -0
- data/test/razorpay/test_token.rb +66 -0
- data/test/razorpay/test_transfer.rb +94 -0
- data/test/razorpay/test_utility.rb +72 -4
- data/test/razorpay/test_virtual_account.rb +64 -17
- data/test/razorpay/test_webhook.rb +132 -0
- data/test/test_helper.rb +8 -0
- metadata +265 -10
- data/.travis.yml +0 -22
- data/test/razorpay/test_errors.rb +0 -19
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Razorpay
|
|
4
|
+
# Tests for Razorpay::Account
|
|
5
|
+
class RazorpayStakeholderonTest < Minitest::Test
|
|
6
|
+
class Stakeholder < Razorpay::Entity; end
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@stakeholder_id = 'sth_00000000000001'
|
|
10
|
+
@account_id = 'acc_00000000000001'
|
|
11
|
+
@email = 'gaurav.kumar@example.com'
|
|
12
|
+
# Any request that ends with stakeholder_id
|
|
13
|
+
stub_get(%r{/v2/accounts\/#{Regexp.quote(@account_id)}/stakeholders\/#{Regexp.quote(@stakeholder_id)}$}, 'fake_stakeholder')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_stakeholder_should_be_defined
|
|
17
|
+
refute_nil Razorpay::Stakeholder
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_stakeholder_should_be_available
|
|
21
|
+
stakeholder = Razorpay::Stakeholder.fetch(@account_id, @stakeholder_id)
|
|
22
|
+
assert_instance_of Razorpay::Stakeholder, stakeholder, 'Stakeholder not an instance of Entity class'
|
|
23
|
+
assert_equal @stakeholder_id, stakeholder.id, 'Stakeholder IDs do not match'
|
|
24
|
+
assert_equal @email, stakeholder.email, 'Stakeholder email is accessible'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_stakeholder_should_be_create
|
|
28
|
+
|
|
29
|
+
payload = create_stakeholder_payload()
|
|
30
|
+
stub_post(%r{accounts/#{@account_id}/stakeholders$}, 'fake_stakeholder', payload.to_json)
|
|
31
|
+
|
|
32
|
+
stakeholder = Razorpay::Stakeholder.create(@account_id, payload.to_json)
|
|
33
|
+
assert_instance_of Razorpay::Stakeholder, stakeholder, 'Stakeholder not an instance of Entity class'
|
|
34
|
+
assert_equal @stakeholder_id, stakeholder.id, 'Stakeholder IDs do not match'
|
|
35
|
+
assert_equal @email, stakeholder.email, 'Stakeholder email is accessible'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_stakeholder_edit
|
|
39
|
+
|
|
40
|
+
payload = create_stakeholder_payload()
|
|
41
|
+
stub_patch(%r{accounts/#{@account_id}/stakeholders/#{@stakeholder_id}$}, 'fake_stakeholder', payload.to_json)
|
|
42
|
+
|
|
43
|
+
stakeholder = Razorpay::Stakeholder.edit(@account_id, @stakeholder_id, payload.to_json)
|
|
44
|
+
assert_instance_of Razorpay::Stakeholder, stakeholder, 'Stakeholder not an instance of Entity class'
|
|
45
|
+
assert_equal @stakeholder_id, stakeholder.id, 'Stakeholder IDs do not match'
|
|
46
|
+
assert_equal @email, stakeholder.email, 'Stakeholder email is accessible'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_fetching_all_stakeholder
|
|
50
|
+
stub_get(%r{accounts/#{@account_id}/stakeholders$}, 'stakeholder_collection')
|
|
51
|
+
orders = Razorpay::Stakeholder.all(@account_id)
|
|
52
|
+
assert_instance_of Razorpay::Collection, orders, 'Orders should be an array'
|
|
53
|
+
assert !orders.items.empty?, 'orders should be more than one'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_stakeholder_payload
|
|
57
|
+
return {
|
|
58
|
+
"percentage_ownership": 10,
|
|
59
|
+
"name": "Gaurav Kumar",
|
|
60
|
+
"email": "gaurav.kumar@example.com",
|
|
61
|
+
"relationship": {
|
|
62
|
+
"director": true,
|
|
63
|
+
"executive": false
|
|
64
|
+
},
|
|
65
|
+
"phone": {
|
|
66
|
+
"primary": "9000090000",
|
|
67
|
+
"secondary": "9000090000"
|
|
68
|
+
},
|
|
69
|
+
"addresses": {
|
|
70
|
+
"residential": {
|
|
71
|
+
"street": "506, Koramangala 1st block",
|
|
72
|
+
"city": "Bengaluru",
|
|
73
|
+
"state": "Karnataka",
|
|
74
|
+
"postal_code": "560034",
|
|
75
|
+
"country": "IN"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"kyc": {
|
|
79
|
+
"pan": "AVOPB1111K"
|
|
80
|
+
},
|
|
81
|
+
"notes": {
|
|
82
|
+
"random_key_by_partner": "random_value"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -7,7 +7,7 @@ module Razorpay
|
|
|
7
7
|
|
|
8
8
|
def setup
|
|
9
9
|
@subscription_id = 'fake_subscription_id'
|
|
10
|
-
|
|
10
|
+
@offer_id = 'offer_JCTD1XMlUmzF6Z'
|
|
11
11
|
# Any request that ends with subscriptions/subscription_id
|
|
12
12
|
stub_get(%r{subscriptions\/#{Regexp.quote(@subscription_id)}$}, 'fake_subscription')
|
|
13
13
|
stub_get(/subscriptions$/, 'subscription_collection')
|
|
@@ -32,6 +32,50 @@ module Razorpay
|
|
|
32
32
|
assert_subscription_details(subscription)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def test_subscription_should_be_pause
|
|
36
|
+
para_attr = {
|
|
37
|
+
"pause_at": "now"
|
|
38
|
+
}
|
|
39
|
+
stub_post(%r{subscriptions/#{@subscription_id}/pause$}, 'fake_subscription_pause',para_attr.to_json)
|
|
40
|
+
subscription = Razorpay::Subscription.pause(@subscription_id, para_attr.to_json)
|
|
41
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
42
|
+
assert_equal "paused", subscription.status
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_subscription_should_be_resume
|
|
46
|
+
para_attr = {
|
|
47
|
+
"resume_at": "now"
|
|
48
|
+
}
|
|
49
|
+
stub_post(%r{subscriptions/#{@subscription_id}/resume$}, 'fake_subscription_resume',para_attr.to_json)
|
|
50
|
+
subscription = Razorpay::Subscription.resume(@subscription_id, para_attr.to_json)
|
|
51
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
52
|
+
assert_equal "resume", subscription.status
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_subscription_pending_update
|
|
56
|
+
stub_get(%r{subscriptions/#{@subscription_id}/retrieve_scheduled_changes$}, 'fake_pending_update')
|
|
57
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id).pending_update
|
|
58
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
59
|
+
assert_equal "active", subscription.status
|
|
60
|
+
refute subscription.customer_notify
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_subscription_cancel_scheduled_changes
|
|
64
|
+
stub_post(%r{subscriptions/#{@subscription_id}/cancel_scheduled_changes$}, 'fake_pending_update', {})
|
|
65
|
+
subscription = Razorpay::Subscription.cancel_scheduled_changes @subscription_id
|
|
66
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
67
|
+
assert_equal "active", subscription.status
|
|
68
|
+
refute subscription.customer_notify
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_subscription_delete_offer
|
|
72
|
+
stub_delete(%r{subscriptions/#{@subscription_id}/#{@offer_id}$}, 'fake_pending_update', {})
|
|
73
|
+
subscription = Razorpay::Subscription.delete_offer(@subscription_id,@offer_id)
|
|
74
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
75
|
+
assert_equal "active", subscription.status
|
|
76
|
+
refute subscription.customer_notify
|
|
77
|
+
end
|
|
78
|
+
|
|
35
79
|
def test_subscription_should_be_created
|
|
36
80
|
time_now = Time.now.to_i
|
|
37
81
|
subscription_attrs = {
|
|
@@ -39,10 +83,9 @@ module Razorpay
|
|
|
39
83
|
start_at: time_now, total_count: 12
|
|
40
84
|
}
|
|
41
85
|
|
|
42
|
-
|
|
43
|
-
stub_post(/subscriptions$/, 'fake_subscription', stub_params)
|
|
86
|
+
stub_post(/subscriptions$/, 'fake_subscription', subscription_attrs.to_json)
|
|
44
87
|
|
|
45
|
-
subscription = Razorpay::Subscription.create subscription_attrs
|
|
88
|
+
subscription = Razorpay::Subscription.create subscription_attrs.to_json
|
|
46
89
|
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
47
90
|
|
|
48
91
|
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
|
@@ -51,6 +94,29 @@ module Razorpay
|
|
|
51
94
|
assert_subscription_details(subscription)
|
|
52
95
|
end
|
|
53
96
|
|
|
97
|
+
def test_subscription_should_be_edited
|
|
98
|
+
|
|
99
|
+
subscription_attrs = {
|
|
100
|
+
"plan_id":"plan_00000000000002",
|
|
101
|
+
"offer_id":"offer_JHD834hjbxzhd38d",
|
|
102
|
+
"quantity":5,
|
|
103
|
+
"remaining_count":5,
|
|
104
|
+
"start_at":1496000432,
|
|
105
|
+
"schedule_change_at":"now",
|
|
106
|
+
"customer_notify":1
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
stub_patch(%r{/subscriptions/#{@subscription_id}$}, 'fake_subscription', subscription_attrs.to_json)
|
|
110
|
+
|
|
111
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id).edit(subscription_attrs.to_json)
|
|
112
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
|
113
|
+
|
|
114
|
+
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
|
115
|
+
assert_equal 'created', subscription.status, 'Subscription status is accessible'
|
|
116
|
+
|
|
117
|
+
#assert_subscription_details(subscription)
|
|
118
|
+
end
|
|
119
|
+
|
|
54
120
|
def test_subscription_should_be_created_with_upfront_amount
|
|
55
121
|
subscription_attrs = {
|
|
56
122
|
plan_id: 'fake_plan_id',
|
|
@@ -68,12 +134,9 @@ module Razorpay
|
|
|
68
134
|
# This test will fail if the request sends
|
|
69
135
|
# "addons[][item][amount]=100&addons[][item][currency]=INR" instead
|
|
70
136
|
#
|
|
71
|
-
|
|
72
|
-
'addons[0][item][amount]=100&addons[0][item][currency]=INR&' \
|
|
73
|
-
'addons[1][item][amount]=200&addons[1][item][currency]=INR'
|
|
74
|
-
stub_post(/subscriptions$/, 'fake_subscription', stub_params)
|
|
137
|
+
stub_post(/subscriptions$/, 'fake_subscription', subscription_attrs.to_json)
|
|
75
138
|
|
|
76
|
-
Razorpay::Subscription.create subscription_attrs
|
|
139
|
+
Razorpay::Subscription.create subscription_attrs.to_json
|
|
77
140
|
end
|
|
78
141
|
|
|
79
142
|
def test_subscription_can_be_cancelled_by_subscription_id
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Razorpay
|
|
4
|
+
# Tests for Razorpay::Addon
|
|
5
|
+
class RazorpaySubscriptionRegistrationTest < Minitest::Test
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@invoice_id = 'inv_JA7OELdAoxbzk7'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_subscription_registration_should_be_defined
|
|
12
|
+
refute_nil Razorpay::SubscriptionRegistration
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_create_registration_link
|
|
16
|
+
param_attr = {
|
|
17
|
+
"customer": {
|
|
18
|
+
"name": "Gaurav Kumar",
|
|
19
|
+
"email": "gaurav.kumar@example.com",
|
|
20
|
+
"contact": 9123456780
|
|
21
|
+
},
|
|
22
|
+
"amount": 0,
|
|
23
|
+
"currency": "INR",
|
|
24
|
+
"type": "link",
|
|
25
|
+
"description": "12 p.m. Meals",
|
|
26
|
+
"subscription_registration": {
|
|
27
|
+
"method": "nach",
|
|
28
|
+
"auth_type": "physical",
|
|
29
|
+
"bank_account": {
|
|
30
|
+
"beneficiary_name": "Gaurav Kumar",
|
|
31
|
+
"account_number": 11214311215411,
|
|
32
|
+
"account_type": "savings",
|
|
33
|
+
"ifsc_code": "HDFC0001233"
|
|
34
|
+
},
|
|
35
|
+
"nach": {
|
|
36
|
+
"form_reference1": "Recurring Payment for Gaurav Kumar",
|
|
37
|
+
"form_reference2": "Method Paper NACH"
|
|
38
|
+
},
|
|
39
|
+
"expire_at": 1648101450,
|
|
40
|
+
"max_amount": 50000
|
|
41
|
+
},
|
|
42
|
+
"receipt": "Receipt No. #12",
|
|
43
|
+
"sms_notify": 1,
|
|
44
|
+
"email_notify": 1,
|
|
45
|
+
"expire_by": 1648101450,
|
|
46
|
+
"notes": {
|
|
47
|
+
"note_key 1": "Beam me up Scotty",
|
|
48
|
+
"note_key 2": "Tea. Earl Gray. Hot."
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
stub_post(%r{/subscription_registration/auth_links$}, 'fake_subscription_registration', param_attr.to_json)
|
|
53
|
+
subscription_registration = Razorpay::SubscriptionRegistration.create(param_attr.to_json)
|
|
54
|
+
assert_instance_of Razorpay::Invoice, subscription_registration
|
|
55
|
+
assert_equal subscription_registration.id, @invoice_id
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Razorpay
|
|
4
|
+
# Tests for Razorpay::Token
|
|
5
|
+
class RazorpayTokenTest < Minitest::Test
|
|
6
|
+
class Token < Razorpay::Entity; end
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@token_id = 'token_00000000000001'
|
|
10
|
+
@customer_id = 'cust_1Aa00000000001'
|
|
11
|
+
@method = 'card'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_token_should_be_defined
|
|
15
|
+
refute_nil Razorpay::Token
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_token_should_be_available
|
|
19
|
+
payload = {
|
|
20
|
+
"id": @token_id
|
|
21
|
+
}
|
|
22
|
+
stub_post(%r{/tokens/fetch$}, 'fake_tokenise_customer', payload.to_json)
|
|
23
|
+
token = Razorpay::Token.fetch(payload.to_json)
|
|
24
|
+
assert_instance_of Razorpay::Token, token, 'token not an instance of Token class'
|
|
25
|
+
assert_equal @token_id, token.id, 'Token IDs do not match'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_token_should_be_delete
|
|
29
|
+
payload = {
|
|
30
|
+
"id": @token_id
|
|
31
|
+
}
|
|
32
|
+
stub_post(%r{/tokens/delete$}, 'empty', payload.to_json)
|
|
33
|
+
token = Razorpay::Token.delete(payload.to_json)
|
|
34
|
+
assert_instance_of Razorpay::Entity, token, 'token not an instance of Entity class'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_token_create
|
|
38
|
+
|
|
39
|
+
payload = create_token_payload()
|
|
40
|
+
stub_post(%r{/tokens$}, 'fake_tokenise_customer', payload.to_json)
|
|
41
|
+
|
|
42
|
+
token = Razorpay::Token.create(payload.to_json)
|
|
43
|
+
assert_instance_of Razorpay::Token, token, 'Token not an instance of Token class'
|
|
44
|
+
assert_equal @token_id, token.id, 'Token IDs do not match'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def create_token_payload
|
|
48
|
+
return {
|
|
49
|
+
"customer_id": "cust_00000000000002",
|
|
50
|
+
"method": "card",
|
|
51
|
+
"card": {
|
|
52
|
+
"number": "4854000000708430",
|
|
53
|
+
"cvv": "123",
|
|
54
|
+
"expiry_month": "12",
|
|
55
|
+
"expiry_year": "24",
|
|
56
|
+
"name": "Gaurav Kumar"
|
|
57
|
+
},
|
|
58
|
+
"authentication": {
|
|
59
|
+
"provider": "razorpay",
|
|
60
|
+
"provider_reference_id": "pay_000000000000"
|
|
61
|
+
},
|
|
62
|
+
"notes": []
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Razorpay
|
|
4
|
+
# Tests for Razorpay::Transfer
|
|
5
|
+
class RazorpayTransferTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
@transfer_id = 'trf_JDEnyfvGu22ECp'
|
|
8
|
+
|
|
9
|
+
# Any request that ends with transfers/transfer_id
|
|
10
|
+
stub_get(%r{/transfers/#{@transfer_id}$}, 'fake_transfer')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_transfer_should_be_defined
|
|
14
|
+
refute_nil Razorpay::Transfer
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_create_transfer_reverse
|
|
18
|
+
para_attr = {
|
|
19
|
+
"amount":100
|
|
20
|
+
}
|
|
21
|
+
stub_post(%r{/transfers/#{@transfer_id}/reversals$}, 'fake_transfer_reverse', para_attr.to_json)
|
|
22
|
+
transfer = Razorpay::Transfer.fetch(@transfer_id)
|
|
23
|
+
transfer.reverse(para_attr.to_json)
|
|
24
|
+
assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Transfer class'
|
|
25
|
+
assert_equal transfer.id, @transfer_id, 'Transfer transfer_id is accessible'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_transfer_edit
|
|
29
|
+
para_attr = {
|
|
30
|
+
"on_hold": "1",
|
|
31
|
+
"on_hold_until": "1679691505"
|
|
32
|
+
}
|
|
33
|
+
stub_patch(%r{/transfers/#{@transfer_id}$}, 'fake_transfer', para_attr.to_json)
|
|
34
|
+
transfer = Razorpay::Transfer.fetch(@transfer_id)
|
|
35
|
+
transfer.edit(para_attr.to_json);
|
|
36
|
+
assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Transfer class'
|
|
37
|
+
assert_equal transfer.id, @transfer_id, 'Transfer transfer_id is accessible'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_transfer_fetch
|
|
41
|
+
transfer = Razorpay::Transfer.fetch(@transfer_id)
|
|
42
|
+
assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Transfer class'
|
|
43
|
+
assert_equal transfer.id, @transfer_id , 'Transfer transfer_id is accessible'
|
|
44
|
+
assert transfer.on_hold
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_transfer_fetch_settlement_details
|
|
48
|
+
stub_get("#{BASE_URI}/v1/transfers/?expand[]=recipient_settlement", 'transfers_collection')
|
|
49
|
+
transfer = Razorpay::Transfer.fetch_settlements
|
|
50
|
+
assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array'
|
|
51
|
+
refute_empty transfer.items , 'Transfer should be more than one'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_transfer_fetch_settlements
|
|
55
|
+
para_attr = {
|
|
56
|
+
"recipient_settlement_id": "setl_DHYJ3dRPqQkAgV"
|
|
57
|
+
}
|
|
58
|
+
stub_get(/transfers/, 'transfer_settlements_collection',para_attr.to_json)
|
|
59
|
+
transfer = Razorpay::Transfer.all para_attr.to_json
|
|
60
|
+
assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array'
|
|
61
|
+
refute_empty transfer.items , 'Transfer should be more than one'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_transfer_direct_transfer
|
|
65
|
+
para_attr = {
|
|
66
|
+
"account": "acc_CPRsN1LkFccllA",
|
|
67
|
+
"amount": 100,
|
|
68
|
+
"currency": "INR"
|
|
69
|
+
}
|
|
70
|
+
stub_post(/transfers/, 'fake_direct_transfer',para_attr.to_json)
|
|
71
|
+
transfer = Razorpay::Transfer.create para_attr.to_json
|
|
72
|
+
assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Transfer class'
|
|
73
|
+
assert_equal transfer.id, @transfer_id , 'Transfer transfer_id is accessible'
|
|
74
|
+
refute transfer.on_hold
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_fetch_reversals
|
|
78
|
+
stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'reversals_collection')
|
|
79
|
+
transfer = Razorpay::Transfer.reversals(@transfer_id)
|
|
80
|
+
assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array'
|
|
81
|
+
refute_empty transfer.items , 'Transfer should be more than one'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_fetch_reversals_exception
|
|
85
|
+
stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'transfer_error')
|
|
86
|
+
assert_raises(Razorpay::Error) do
|
|
87
|
+
transfer = Razorpay::Transfer.reversals(@transfer_id)
|
|
88
|
+
if transfer.error
|
|
89
|
+
raise Razorpay::Error.new, transfer.error['code']
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
|
+
require 'json'
|
|
2
3
|
|
|
3
4
|
module Razorpay
|
|
4
5
|
# Tests for Razorpay::Utility
|
|
@@ -9,9 +10,9 @@ module Razorpay
|
|
|
9
10
|
|
|
10
11
|
def test_payment_signature_verification
|
|
11
12
|
payment_response = {
|
|
12
|
-
razorpay_order_id: '
|
|
13
|
+
razorpay_order_id: 'fake_other_id',
|
|
13
14
|
razorpay_payment_id: 'fake_payment_id',
|
|
14
|
-
razorpay_signature: '
|
|
15
|
+
razorpay_signature: '965ee2de4c5c4e6f006fb0a5a1736d992e5d4d52f9fe10b98c9b97ee169ebe18'
|
|
15
16
|
}
|
|
16
17
|
Razorpay::Utility.verify_payment_signature(payment_response)
|
|
17
18
|
|
|
@@ -21,12 +22,46 @@ module Razorpay
|
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def test_payment_link_signature_verification_exception
|
|
26
|
+
|
|
27
|
+
payment_response = {
|
|
28
|
+
payment_link_id: 'fake_razorpay_payment_link_id',
|
|
29
|
+
payment_link_reference_id: 'fake_reference_id',
|
|
30
|
+
payment_link_status: 'paid',
|
|
31
|
+
razorpay_payment_id: 'pay_IH3d0ara9bSsjQ',
|
|
32
|
+
razorpay_signature: 'b8a6acda585c9b74e9da393c7354c7e685e37e69d30ae654730f042e674e0283'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
36
|
+
|
|
37
|
+
payment_response[:razorpay_signature] = '_dummy_signature' * 4
|
|
38
|
+
assert_raises(SecurityError) do
|
|
39
|
+
Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_payment_link_signature_verification
|
|
44
|
+
|
|
45
|
+
payment_response = {
|
|
46
|
+
payment_link_id: 'fake_razorpay_payment_link_id',
|
|
47
|
+
payment_link_reference_id: 'fake_reference_id',
|
|
48
|
+
payment_link_status: 'paid',
|
|
49
|
+
razorpay_payment_id: 'pay_IH3d0ara9bSsjQ',
|
|
50
|
+
razorpay_signature: 'b8a6acda585c9b74e9da393c7354c7e685e37e69d30ae654730f042e674e0283'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
response = Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
54
|
+
assert(response)
|
|
55
|
+
end
|
|
56
|
+
|
|
24
57
|
def test_subscription_signature_verification
|
|
25
58
|
payment_response = {
|
|
26
|
-
razorpay_subscription_id: 'fake_order_id',
|
|
27
59
|
razorpay_payment_id: 'fake_payment_id',
|
|
28
|
-
|
|
60
|
+
razorpay_subscription_id: 'fake_other_id',
|
|
61
|
+
razorpay_signature: '3dabcab8ca113e7994cf78c80f8d50974ddfb2d380029743f30a6d67934cd845'
|
|
29
62
|
}
|
|
63
|
+
# A different signature is expected here compared to the previous test,
|
|
64
|
+
# since the sorted order of the keys is different in this case
|
|
30
65
|
Razorpay::Utility.verify_payment_signature(payment_response)
|
|
31
66
|
|
|
32
67
|
payment_response[:razorpay_signature] = '_dummy_signature' * 4
|
|
@@ -46,5 +81,38 @@ module Razorpay
|
|
|
46
81
|
Razorpay::Utility.verify_webhook_signature(webhook_body, signature, secret)
|
|
47
82
|
end
|
|
48
83
|
end
|
|
84
|
+
|
|
85
|
+
def test_generate_onboarding_signature
|
|
86
|
+
secret = "EnLs21M47BllR3X8PSFtjtbd"
|
|
87
|
+
timestamp = Time.now.to_i
|
|
88
|
+
body = {
|
|
89
|
+
submerchant_id: 'NSgKfYIR2f9v2y',
|
|
90
|
+
timestamp: timestamp
|
|
91
|
+
}
|
|
92
|
+
encryptedData = Razorpay::Utility.generate_onboarding_signature(body, secret)
|
|
93
|
+
json_data = decrypt(encryptedData, secret)
|
|
94
|
+
body = JSON.parse(json_data)
|
|
95
|
+
assert_equal 'NSgKfYIR2f9v2y', body['submerchant_id'], 'Submerchant IDs do not match'
|
|
96
|
+
assert_equal timestamp, body['timestamp'], 'Timestamps do not match'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def decrypt(data, secret)
|
|
100
|
+
combined_encrypted_data = [data].pack("H*")
|
|
101
|
+
|
|
102
|
+
iv = combined_encrypted_data[0, 12]
|
|
103
|
+
key = secret[0, 16]
|
|
104
|
+
tag = combined_encrypted_data[-16..]
|
|
105
|
+
|
|
106
|
+
encrypted_data = combined_encrypted_data[12...-16]
|
|
107
|
+
|
|
108
|
+
cipher = OpenSSL::Cipher.new('aes-128-gcm')
|
|
109
|
+
cipher.decrypt
|
|
110
|
+
cipher.key = key
|
|
111
|
+
cipher.iv = iv
|
|
112
|
+
cipher.auth_tag = tag
|
|
113
|
+
cipher.auth_data = ""
|
|
114
|
+
|
|
115
|
+
cipher.update(encrypted_data) + cipher.final
|
|
116
|
+
end
|
|
49
117
|
end
|
|
50
118
|
end
|
|
@@ -5,6 +5,8 @@ module Razorpay
|
|
|
5
5
|
class RazorpayVirtualAccountTest < Minitest::Test
|
|
6
6
|
def setup
|
|
7
7
|
@virtual_account_id = 'va_4xbQrmEoA5WJ0G'
|
|
8
|
+
@payment_id = 'fake_payment_id'
|
|
9
|
+
@payer_id = "ba_J3gpYBXh92ZL5M"
|
|
8
10
|
|
|
9
11
|
@virtual_account_create_array = {
|
|
10
12
|
receiver_types: ['bank_account'],
|
|
@@ -21,13 +23,22 @@ module Razorpay
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def test_virtual_account_should_be_created
|
|
26
|
+
|
|
27
|
+
para_attr = {
|
|
28
|
+
"type": "bank_account",
|
|
29
|
+
"bank_account": {
|
|
30
|
+
"ifsc": "RATN0VAAPIS",
|
|
31
|
+
"account_number": "2223330027558515"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
stub_post(
|
|
25
36
|
/virtual_accounts$/,
|
|
26
37
|
'fake_virtual_account',
|
|
27
|
-
|
|
38
|
+
para_attr.to_json
|
|
28
39
|
)
|
|
29
40
|
|
|
30
|
-
virtual_account = Razorpay::VirtualAccount.create
|
|
41
|
+
virtual_account = Razorpay::VirtualAccount.create para_attr.to_json
|
|
31
42
|
assert_equal 'First Virtual Account', virtual_account.description
|
|
32
43
|
assert_equal 'active', virtual_account.status
|
|
33
44
|
refute_empty virtual_account.receivers
|
|
@@ -37,24 +48,15 @@ module Razorpay
|
|
|
37
48
|
end
|
|
38
49
|
|
|
39
50
|
def test_close_virtual_account_class_method
|
|
40
|
-
|
|
51
|
+
stub_post(%r{virtual_accounts/#{@virtual_account_id}/close$}, 'fake_virtual_account_closed', {})
|
|
41
52
|
virtual_account = Razorpay::VirtualAccount.close(@virtual_account_id)
|
|
42
53
|
assert_instance_of Razorpay::VirtualAccount, virtual_account
|
|
43
54
|
assert_equal 'closed', virtual_account.status
|
|
44
55
|
end
|
|
45
56
|
|
|
46
57
|
def test_close_virtual_account
|
|
47
|
-
|
|
48
|
-
virtual_account = Razorpay::VirtualAccount.
|
|
49
|
-
virtual_account = virtual_account.close
|
|
50
|
-
assert_instance_of Razorpay::VirtualAccount, virtual_account
|
|
51
|
-
assert_equal 'closed', virtual_account.status
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_close_virtual_account!
|
|
55
|
-
stub_patch(%r{virtual_accounts/#{@virtual_account_id}$}, 'fake_virtual_account_closed', 'status=closed')
|
|
56
|
-
virtual_account = Razorpay::VirtualAccount.fetch(@virtual_account_id)
|
|
57
|
-
virtual_account.close!
|
|
58
|
+
stub_post(%r{virtual_accounts/#{@virtual_account_id}/close$}, 'fake_virtual_account_closed', {})
|
|
59
|
+
virtual_account = Razorpay::VirtualAccount.close(@virtual_account_id)
|
|
58
60
|
assert_instance_of Razorpay::VirtualAccount, virtual_account
|
|
59
61
|
assert_equal 'closed', virtual_account.status
|
|
60
62
|
end
|
|
@@ -71,9 +73,9 @@ module Razorpay
|
|
|
71
73
|
end
|
|
72
74
|
|
|
73
75
|
def test_fetch_payment_bank_transfer
|
|
74
|
-
stub_get(%r{payments
|
|
75
|
-
stub_get(%r{payments/
|
|
76
|
-
bank_transfer = Razorpay::Payment.fetch(
|
|
76
|
+
stub_get(%r{payments\/#{@payment_id}$}, 'fake_payment')
|
|
77
|
+
stub_get(%r{payments/#{@payment_id}/bank_transfer$}, 'fake_payment_bank_transfer')
|
|
78
|
+
bank_transfer = Razorpay::Payment.fetch(@payment_id).bank_transfer
|
|
77
79
|
assert_equal @virtual_account_id, bank_transfer.virtual_account_id
|
|
78
80
|
assert_equal 'fake_payment_id', bank_transfer.payment_id
|
|
79
81
|
end
|
|
@@ -84,5 +86,50 @@ module Razorpay
|
|
|
84
86
|
assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
|
|
85
87
|
assert !payments.items.empty?, 'Payments should be more than one'
|
|
86
88
|
end
|
|
89
|
+
|
|
90
|
+
def test_virtual_account_add_receivers
|
|
91
|
+
|
|
92
|
+
para_attr = {
|
|
93
|
+
"types": [
|
|
94
|
+
"vpa"
|
|
95
|
+
],
|
|
96
|
+
"vpa": {
|
|
97
|
+
"descriptor": "gauravkumar"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
stub_post(%r{virtual_accounts/#{@virtual_account_id}/receivers$},'fake_virtual_account_receiver',para_attr.to_json)
|
|
102
|
+
|
|
103
|
+
virtual_account = Razorpay::VirtualAccount.add_receiver(@virtual_account_id,para_attr.to_json)
|
|
104
|
+
assert_equal @virtual_account_id , virtual_account.id
|
|
105
|
+
assert_equal 'First Virtual Account', virtual_account.name
|
|
106
|
+
assert_equal 'active', virtual_account.status
|
|
107
|
+
refute_empty virtual_account.receivers
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_virtual_account_allowed_payer
|
|
111
|
+
|
|
112
|
+
para_attr = {
|
|
113
|
+
"types": "bank_account",
|
|
114
|
+
"bank_account": {
|
|
115
|
+
"ifsc": "UTIB0000013",
|
|
116
|
+
"account_number": 914010012345679
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
stub_post(%r{virtual_accounts/#{@virtual_account_id}/allowed_payers$},'fake_virtual_account_allowed',para_attr.to_json)
|
|
121
|
+
|
|
122
|
+
virtual_account = Razorpay::VirtualAccount.allowed_payer(@virtual_account_id,para_attr.to_json)
|
|
123
|
+
assert_equal @virtual_account_id , virtual_account.id
|
|
124
|
+
assert_equal 'Gaurav Kumar', virtual_account.name
|
|
125
|
+
assert_equal 'active', virtual_account.status
|
|
126
|
+
refute_empty virtual_account.allowed_payers
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_virtual_account_delete_payer
|
|
130
|
+
stub_delete(%r{virtual_accounts/#{@virtual_account_id}/allowed_payers/#{@payer_id}$},'empty')
|
|
131
|
+
virtual_account = Razorpay::VirtualAccount.delete_allowed_payer(@virtual_account_id,@payer_id)
|
|
132
|
+
assert_instance_of Razorpay::Entity, virtual_account
|
|
133
|
+
end
|
|
87
134
|
end
|
|
88
135
|
end
|