razorpay 2.4.1 → 3.0.0
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/.github/dependabot.yml +8 -0
- data/.github/workflows/ruby.yml +38 -0
- data/CHANGELOG.md +19 -0
- data/README.md +29 -140
- data/documents/Invoice.md +531 -0
- data/documents/addon.md +169 -0
- data/documents/card.md +611 -0
- data/documents/customer.md +161 -0
- data/documents/emandate.md +484 -0
- data/documents/fund.md +87 -0
- data/documents/items.md +184 -0
- data/documents/order.md +230 -0
- data/documents/papernach.md +718 -0
- data/documents/payment.md +636 -0
- data/documents/paymentLink.md +1045 -0
- data/documents/paymentVerification.md +79 -0
- data/documents/plan.md +184 -0
- data/documents/qrcode.md +441 -0
- data/documents/refund.md +324 -0
- data/documents/registerEmandate.md +445 -0
- data/documents/registerNach.md +661 -0
- data/documents/settlement.md +477 -0
- data/documents/subscriptions.md +750 -0
- data/documents/tokens.md +208 -0
- data/documents/transfers.md +684 -0
- data/documents/upi.md +548 -0
- data/documents/virtualAccount.md +586 -0
- data/lib/razorpay/addon.rb +4 -0
- data/lib/razorpay/constants.rb +1 -1
- data/lib/razorpay/customer.rb +15 -0
- data/lib/razorpay/fund_account.rb +19 -0
- data/lib/razorpay/invoice.rb +8 -0
- data/lib/razorpay/item.rb +34 -0
- data/lib/razorpay/order.rb +10 -0
- data/lib/razorpay/payment.rb +52 -0
- data/lib/razorpay/payment_link.rb +36 -0
- data/lib/razorpay/qr_code.rb +34 -0
- data/lib/razorpay/refund.rb +4 -0
- data/lib/razorpay/request.rb +13 -6
- data/lib/razorpay/settlement.rb +39 -0
- data/lib/razorpay/subscription.rb +24 -0
- data/lib/razorpay/subscription_registration.rb +16 -0
- data/lib/razorpay/transfer.rb +35 -0
- data/lib/razorpay/utility.rb +7 -2
- data/lib/razorpay/virtual_account.rb +14 -6
- data/lib/razorpay.rb +7 -0
- 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/downtimes_collection.json +21 -0
- data/test/fixtures/empty.json +2 -0
- data/test/fixtures/fake_addon.json +3 -3
- data/test/fixtures/fake_direct_transfer.json +32 -0
- data/test/fixtures/fake_downtime.json +14 -0
- data/test/fixtures/fake_fund_account.json +18 -0
- data/test/fixtures/fake_instant_settlement.json +19 -0
- data/test/fixtures/fake_item.json +9 -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_link.json +40 -0
- data/test/fixtures/fake_pending_update.json +30 -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_settlement.json +11 -0
- data/test/fixtures/fake_settlement_on_demand.json +39 -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_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_virtual_account_allowed.json +46 -0
- data/test/fixtures/fake_virtual_account_receiver.json +46 -0
- data/test/fixtures/fund_collection.json +20 -0
- data/test/fixtures/item_collection.json +24 -0
- data/test/fixtures/payment_collection.json +1 -1
- data/test/fixtures/payment_link_collection.json +43 -0
- data/test/fixtures/payment_link_response.json +3 -0
- data/test/fixtures/qrcode_collection.json +50 -0
- data/test/fixtures/qrcode_payments_collection.json +74 -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/success.json +3 -0
- data/test/fixtures/tokens_collection.json +36 -0
- data/test/fixtures/transfer_settlements_collection.json +38 -0
- data/test/fixtures/transfers_collection.json +41 -0
- data/test/razorpay/test_addon.rb +15 -15
- data/test/razorpay/test_customer.rb +27 -3
- data/test/razorpay/test_fund_account.rb +42 -0
- data/test/razorpay/test_invoice.rb +15 -2
- data/test/razorpay/test_item.rb +66 -0
- data/test/razorpay/test_order.rb +24 -1
- data/test/razorpay/test_payment.rb +184 -8
- data/test/razorpay/test_payment_link.rb +83 -0
- data/test/razorpay/test_plan.rb +2 -2
- data/test/razorpay/test_qr_code.rb +63 -0
- data/test/razorpay/test_refund.rb +16 -2
- data/test/razorpay/test_settlement.rb +76 -0
- data/test/razorpay/test_subscription.rb +72 -9
- data/test/razorpay/test_subscription_registration.rb +58 -0
- data/test/razorpay/test_transfer.rb +77 -0
- data/test/razorpay/test_utility.rb +32 -0
- data/test/razorpay/test_virtual_account.rb +64 -17
- data/test/test_helper.rb +6 -0
- metadata +138 -9
- data/.travis.yml +0 -22
- data/test/razorpay/test_errors.rb +0 -19
|
@@ -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,77 @@
|
|
|
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}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
|
+
end
|
|
77
|
+
end
|
|
@@ -21,6 +21,38 @@ module Razorpay
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def test_payment_link_signature_verification_exception
|
|
25
|
+
|
|
26
|
+
payment_response = {
|
|
27
|
+
payment_link_id: 'fake_razorpay_payment_link_id',
|
|
28
|
+
payment_link_reference_id: 'fake_reference_id',
|
|
29
|
+
payment_link_status: 'paid',
|
|
30
|
+
razorpay_payment_id: 'pay_IH3d0ara9bSsjQ',
|
|
31
|
+
razorpay_signature: 'b8a6acda585c9b74e9da393c7354c7e685e37e69d30ae654730f042e674e0283'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
35
|
+
|
|
36
|
+
payment_response[:razorpay_signature] = '_dummy_signature' * 4
|
|
37
|
+
assert_raises(SecurityError) do
|
|
38
|
+
Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_payment_link_signature_verification
|
|
43
|
+
|
|
44
|
+
payment_response = {
|
|
45
|
+
payment_link_id: 'fake_razorpay_payment_link_id',
|
|
46
|
+
payment_link_reference_id: 'fake_reference_id',
|
|
47
|
+
payment_link_status: 'paid',
|
|
48
|
+
razorpay_payment_id: 'pay_IH3d0ara9bSsjQ',
|
|
49
|
+
razorpay_signature: 'b8a6acda585c9b74e9da393c7354c7e685e37e69d30ae654730f042e674e0283'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
response = Razorpay::Utility.verify_payment_link_signature(payment_response)
|
|
53
|
+
assert(response)
|
|
54
|
+
end
|
|
55
|
+
|
|
24
56
|
def test_subscription_signature_verification
|
|
25
57
|
payment_response = {
|
|
26
58
|
razorpay_payment_id: 'fake_payment_id',
|
|
@@ -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
|
data/test/test_helper.rb
CHANGED
|
@@ -25,6 +25,12 @@ def stub_get(*args)
|
|
|
25
25
|
stub_request(:get, url).to_return(response)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def stub_delete(*args)
|
|
29
|
+
response = stub_response(*args)
|
|
30
|
+
url = args[0]
|
|
31
|
+
stub_request(:delete, url).to_return(response)
|
|
32
|
+
end
|
|
33
|
+
|
|
28
34
|
def stub_post(*args)
|
|
29
35
|
stub_request_with_body(:post, *args)
|
|
30
36
|
end
|