razorruby 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.editorconfig +12 -0
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +22 -0
- data/.simplecov +3 -0
- data/CHANGELOG.md +168 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +102 -0
- data/Rakefile +26 -0
- data/documents/Invoice.md +539 -0
- data/documents/addon.md +191 -0
- data/documents/card.md +610 -0
- data/documents/customer.md +163 -0
- data/documents/emandate.md +492 -0
- data/documents/fund.md +89 -0
- data/documents/items.md +208 -0
- data/documents/order.md +281 -0
- data/documents/papernach.md +738 -0
- data/documents/payment.md +826 -0
- data/documents/paymentLink.md +1063 -0
- data/documents/paymentVerification.md +79 -0
- data/documents/plan.md +184 -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/subscriptions.md +752 -0
- data/documents/tokens.md +262 -0
- data/documents/transfers.md +781 -0
- data/documents/upi.md +545 -0
- data/documents/virtualAccount.md +591 -0
- data/lib/ca-bundle.crt +3988 -0
- data/lib/extensions/httparty/hash_conversions.rb +44 -0
- data/lib/razorpay/addon.rb +32 -0
- data/lib/razorpay/card.rb +17 -0
- data/lib/razorpay/collection.rb +6 -0
- data/lib/razorpay/constants.rb +6 -0
- data/lib/razorpay/customer.rb +42 -0
- data/lib/razorpay/entity.rb +46 -0
- data/lib/razorpay/errors/bad_request_error.rb +14 -0
- data/lib/razorpay/errors/gateway_error.rb +7 -0
- data/lib/razorpay/errors/razorpay_error.rb +11 -0
- data/lib/razorpay/errors/server_error.rb +7 -0
- data/lib/razorpay/errors.rb +4 -0
- data/lib/razorpay/fund_account.rb +19 -0
- data/lib/razorpay/invoice.rb +68 -0
- data/lib/razorpay/item.rb +34 -0
- data/lib/razorpay/order.rb +39 -0
- data/lib/razorpay/payment.rb +116 -0
- data/lib/razorpay/payment_link.rb +36 -0
- data/lib/razorpay/payment_method.rb +17 -0
- data/lib/razorpay/plan.rb +24 -0
- data/lib/razorpay/qr_code.rb +34 -0
- data/lib/razorpay/refund.rb +27 -0
- data/lib/razorpay/request.rb +119 -0
- data/lib/razorpay/settlement.rb +39 -0
- data/lib/razorpay/subscription.rb +60 -0
- data/lib/razorpay/subscription_registration.rb +16 -0
- data/lib/razorpay/transfer.rb +35 -0
- data/lib/razorpay/utility.rb +57 -0
- data/lib/razorpay/virtual_account.rb +49 -0
- data/lib/razorpay.rb +37 -0
- data/razorpay-ruby.gemspec +36 -0
- data/test/fixtures/addon_collection.json +60 -0
- data/test/fixtures/bad_request_error.json +7 -0
- data/test/fixtures/cancel_invoice.json +44 -0
- data/test/fixtures/cancel_subscription.json +20 -0
- data/test/fixtures/create_json_payment.json +13 -0
- data/test/fixtures/customer_collection.json +22 -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 +24 -0
- data/test/fixtures/fake_captured_payment.json +13 -0
- data/test/fixtures/fake_card.json +9 -0
- data/test/fixtures/fake_create_upi_payment.json +3 -0
- data/test/fixtures/fake_customer.json +8 -0
- data/test/fixtures/fake_customer_edited.json +8 -0
- 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_invoice.json +30 -0
- data/test/fixtures/fake_item.json +9 -0
- data/test/fixtures/fake_order.json +10 -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.json +14 -0
- data/test/fixtures/fake_payment_authorized_webhook.json +40 -0
- data/test/fixtures/fake_payment_bank_transfer.json +12 -0
- data/test/fixtures/fake_payment_link.json +40 -0
- data/test/fixtures/fake_pending_update.json +30 -0
- data/test/fixtures/fake_plan.json +26 -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 +8 -0
- data/test/fixtures/fake_refunded_payment.json +14 -0
- data/test/fixtures/fake_settlement.json +11 -0
- data/test/fixtures/fake_settlement_on_demand.json +39 -0
- data/test/fixtures/fake_subscription.json +20 -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_validate_vpa.json +5 -0
- data/test/fixtures/fake_virtual_account.json +21 -0
- data/test/fixtures/fake_virtual_account_allowed.json +46 -0
- data/test/fixtures/fake_virtual_account_closed.json +21 -0
- data/test/fixtures/fake_virtual_account_collection.json +48 -0
- data/test/fixtures/fake_virtual_account_receiver.json +46 -0
- data/test/fixtures/fund_collection.json +20 -0
- data/test/fixtures/hello_response.json +3 -0
- data/test/fixtures/invoice_collection.json +93 -0
- data/test/fixtures/issue_invoice.json +44 -0
- data/test/fixtures/item_collection.json +24 -0
- data/test/fixtures/order_collection.json +36 -0
- data/test/fixtures/order_payments.json +29 -0
- data/test/fixtures/payment_collection.json +32 -0
- data/test/fixtures/payment_collection_with_one_payment.json +19 -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/plan_collection.json +32 -0
- data/test/fixtures/qrcode_collection.json +50 -0
- data/test/fixtures/qrcode_payments_collection.json +74 -0
- data/test/fixtures/refund_collection.json +30 -0
- data/test/fixtures/refund_collection_for_payment.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/subscription_collection.json +26 -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/fixtures/update_invoice.json +44 -0
- data/test/fixtures/welcome.json +3 -0
- data/test/razorpay/test_addon.rb +76 -0
- data/test/razorpay/test_card.rb +23 -0
- data/test/razorpay/test_customer.rb +69 -0
- data/test/razorpay/test_entity.rb +55 -0
- data/test/razorpay/test_fund_account.rb +42 -0
- data/test/razorpay/test_invoice.rb +143 -0
- data/test/razorpay/test_item.rb +66 -0
- data/test/razorpay/test_order.rb +71 -0
- data/test/razorpay/test_payment.rb +303 -0
- data/test/razorpay/test_payment_link.rb +83 -0
- data/test/razorpay/test_plan.rb +65 -0
- data/test/razorpay/test_qr_code.rb +63 -0
- data/test/razorpay/test_razorpay.rb +53 -0
- data/test/razorpay/test_refund.rb +56 -0
- data/test/razorpay/test_request.rb +15 -0
- data/test/razorpay/test_settlement.rb +76 -0
- data/test/razorpay/test_subscription.rb +190 -0
- data/test/razorpay/test_subscription_registration.rb +58 -0
- data/test/razorpay/test_transfer.rb +77 -0
- data/test/razorpay/test_utility.rb +84 -0
- data/test/razorpay/test_virtual_account.rb +135 -0
- data/test/test_helper.rb +54 -0
- metadata +400 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Plan
|
5
|
+
class RazorpayPlanTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@plan_id = 'fake_plan_id'
|
8
|
+
|
9
|
+
# Any request that ends with plans/plan_id
|
10
|
+
stub_get(%r{plans\/#{Regexp.quote(@plan_id)}$}, 'fake_plan')
|
11
|
+
stub_get(/plans$/, 'plan_collection')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_plan_should_be_defined
|
15
|
+
refute_nil Razorpay::Plan
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_all_plans
|
19
|
+
plans = Razorpay::Plan.all
|
20
|
+
assert_instance_of Razorpay::Collection, plans, 'Plans should be an array'
|
21
|
+
assert !plans.items.empty?, 'Plans should be more than one'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_plan_should_be_available
|
25
|
+
plan = Razorpay::Plan.fetch(@plan_id)
|
26
|
+
assert_instance_of Razorpay::Plan, plan, 'Plan not an instance of Plan class'
|
27
|
+
assert_equal @plan_id, plan.id, 'Plan IDs do not match'
|
28
|
+
assert_equal 1, plan.interval, 'Plan interval is accessible'
|
29
|
+
assert_equal 'monthly', plan.period, 'Plan period is accessible'
|
30
|
+
assert_equal JSON.parse('{"identifier": "plan_monthly_1000"}'), plan.notes, 'Plan notes is accessible'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_plan_should_be_created
|
34
|
+
plan_attrs = {
|
35
|
+
interval: 1, period: 'monthly',
|
36
|
+
item: {
|
37
|
+
name: 'Plan 751..1000',
|
38
|
+
description: 'Share docs + user mgmt',
|
39
|
+
currency: 'INR',
|
40
|
+
amount: 500
|
41
|
+
},
|
42
|
+
notes: { identifier: 'plan_monthly_1000' }
|
43
|
+
}
|
44
|
+
|
45
|
+
stub_post(/plans$/, 'fake_plan', plan_attrs.to_json)
|
46
|
+
|
47
|
+
plan = Razorpay::Plan.create plan_attrs.to_json
|
48
|
+
|
49
|
+
assert_equal 1, plan.interval, 'Plan interval is accessible'
|
50
|
+
assert_equal 'monthly', plan.period, 'Plan period is accessible'
|
51
|
+
assert_equal JSON.parse('{"identifier": "plan_monthly_1000"}'), plan.notes, 'Plan notes is accessible'
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_plan_stub_url_params
|
57
|
+
%w(
|
58
|
+
interval=1&period=monthly&
|
59
|
+
item[name]=Plan%20751..1000&
|
60
|
+
item[description]=Share%20docs%20%2B%20user%20mgmt&item[currency]=INR&
|
61
|
+
item[amount]=500¬es[identifier]=plan_monthly_1000
|
62
|
+
).join
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::QrCode
|
5
|
+
class RazorpayQrCodeTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@qrcode_id = 'qr_HMsVL8HOpbMcjU'
|
8
|
+
@customer_id = 'cust_HKsR5se84c5LTO'
|
9
|
+
# Any request that ends with qrcode/qrcode_id
|
10
|
+
stub_get(%r{payments/qr_codes/#{@qrcode_id}$}, 'fake_qrcode')
|
11
|
+
stub_get(%r{payments/qr_codes$}, 'qrcode_collection')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_qrcode_should_be_defined
|
15
|
+
refute_nil Razorpay::QrCode
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_qrcode_should_be_created
|
19
|
+
para_attr = {
|
20
|
+
"type": "upi_qr",
|
21
|
+
"name": "Store_1",
|
22
|
+
"usage": "single_use",
|
23
|
+
"fixed_amount": true,
|
24
|
+
"payment_amount": 300,
|
25
|
+
"description": "For Store 1",
|
26
|
+
"customer_id": "cust_HKsR5se84c5LTO",
|
27
|
+
"close_by": 1681615838,
|
28
|
+
"notes": {
|
29
|
+
"purpose": "Test UPI QR code notes"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
stub_post(%r{/payments/qr_codes$}, 'fake_qrcode', para_attr.to_json)
|
33
|
+
qr_code = Razorpay::QrCode.create(para_attr.to_json)
|
34
|
+
|
35
|
+
assert_equal @qrcode_id, qr_code.id
|
36
|
+
assert_equal @customer_id, qr_code.customer_id
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fetch_all_qcode
|
40
|
+
qr_code = Razorpay::QrCode.all
|
41
|
+
assert_instance_of Razorpay::Collection, qr_code
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_fetch_specific_qrcode
|
45
|
+
qr_code = Razorpay::QrCode.fetch(@qrcode_id)
|
46
|
+
assert_instance_of Razorpay::QrCode, qr_code
|
47
|
+
assert_equal qr_code.id, @qrcode_id
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_qrcode_close
|
51
|
+
stub_post(%r{payments/qr_codes/#{@qrcode_id}/close$}, 'fake_qrcode_close',{})
|
52
|
+
qr_code = Razorpay::QrCode.fetch(@qrcode_id).close
|
53
|
+
assert_instance_of Razorpay::QrCode, qr_code
|
54
|
+
assert_equal qr_code.id, @qrcode_id
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_qrcode_fetch_payments
|
58
|
+
stub_get(%r{payments/qr_codes/#{@qrcode_id}/payments$}, 'qrcode_payments_collection',{})
|
59
|
+
qr_code = Razorpay::QrCode.fetch(@qrcode_id).fetch_payments()
|
60
|
+
assert_instance_of Razorpay::Collection, qr_code
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
module Razorpay
|
5
|
+
# Tests for Razorpay
|
6
|
+
class RazorpayTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
Razorpay.setup('key_id', 'key_secret')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_razorpay_should_be_defined
|
12
|
+
refute_nil Razorpay
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_setup
|
16
|
+
auth = { username: 'key_id', password: 'key_secret' }
|
17
|
+
assert_equal auth, Razorpay.auth
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_custom_header
|
21
|
+
custom_headers = { 'key' => 'value' }
|
22
|
+
stub_get(/$/, 'hello_response')
|
23
|
+
Razorpay.headers = custom_headers
|
24
|
+
Razorpay::Request.new('dummy').make_test_request
|
25
|
+
user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
|
26
|
+
headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
|
27
|
+
headers = headers.merge(custom_headers)
|
28
|
+
assert_requested :get, 'https://api.razorpay.com/',
|
29
|
+
headers: headers,
|
30
|
+
times: 1
|
31
|
+
end
|
32
|
+
|
33
|
+
# We make a request to the / endpoint to test SSL support
|
34
|
+
def test_sample_request
|
35
|
+
WebMock.allow_net_connect!
|
36
|
+
req = Razorpay::Request.new('dummy')
|
37
|
+
response = req.make_test_request.parsed_response
|
38
|
+
assert_equal 'Welcome to Razorpay API.', response['message']
|
39
|
+
WebMock.disable_net_connect!
|
40
|
+
end
|
41
|
+
|
42
|
+
# We mock this request
|
43
|
+
def test_auth_header_and_user_agent
|
44
|
+
stub_get(/$/, 'hello_response')
|
45
|
+
Razorpay::Request.new('dummy').make_test_request
|
46
|
+
user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
|
47
|
+
headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
|
48
|
+
assert_requested :get, 'https://api.razorpay.com/',
|
49
|
+
headers: headers,
|
50
|
+
times: 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Refund
|
5
|
+
class RazorpayRefundTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@payment_id = 'fake_payment_id'
|
8
|
+
stub_get(%r{payments/#{@payment_id}$}, 'fake_payment')
|
9
|
+
@refund_id = 'fake_refund_id'
|
10
|
+
stub_get(%r{refunds/#{@refund_id}$}, 'fake_refund')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_refund_should_be_defined
|
14
|
+
refute_nil Razorpay::Refund
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_fetch_all_refunds_for_payment
|
18
|
+
stub_get(%r{payments/#{@payment_id}/refunds$}, 'refund_collection_for_payment')
|
19
|
+
refunds = Razorpay::Payment.fetch(@payment_id).refunds
|
20
|
+
assert_instance_of Razorpay::Collection, refunds
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_fetch_all_refunds
|
24
|
+
stub_get(/refunds$/, 'refund_collection')
|
25
|
+
refunds = Razorpay::Refund.all
|
26
|
+
assert_instance_of Razorpay::Collection, refunds
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_fetch_specific_refund
|
30
|
+
refund = Razorpay::Refund.fetch(@refund_id)
|
31
|
+
assert_instance_of Razorpay::Refund, refund
|
32
|
+
assert_equal refund.id, @refund_id
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create_refund
|
36
|
+
stub_post(/refunds$/, 'fake_refund', "payment_id=#{@payment_id}")
|
37
|
+
refund = Razorpay::Refund.create(payment_id: @payment_id)
|
38
|
+
assert_instance_of Razorpay::Refund, refund
|
39
|
+
assert_equal refund.id, @refund_id
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_edit_refund
|
43
|
+
para_attr = {
|
44
|
+
"notes": {
|
45
|
+
"notes_key_1":"Beam me up Scotty.",
|
46
|
+
"notes_key_2":"Engage"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
stub_patch(%r{/refunds/#{@refund_id}$}, 'fake_refund', para_attr.to_json)
|
50
|
+
refund = Razorpay::Refund.fetch(@refund_id).edit(para_attr.to_json)
|
51
|
+
assert_instance_of Razorpay::Refund, refund
|
52
|
+
assert_equal refund.id, @refund_id
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Razorpay
|
5
|
+
# Tests for Razorpay::Entity
|
6
|
+
class RequestTest < Minitest::Test
|
7
|
+
def test_raw_request
|
8
|
+
stub_get('https://api.razorpay.com', 'welcome')
|
9
|
+
|
10
|
+
req = Razorpay::Request.new
|
11
|
+
res = req.raw_request(:get, 'https://api.razorpay.com')
|
12
|
+
assert_equal 'Welcome to Razorpay API.', JSON.parse(res.body)['message']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Settlement
|
5
|
+
class RazorpaySettlementTest < Minitest::Test
|
6
|
+
class Item < Razorpay::Entity; end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@settlement_id = 'setl_DGlQ1Rj8os78Ec'
|
10
|
+
@settlement_ondemand_id = 'setlod_FNj7g2YS5J67Rz'
|
11
|
+
@addon_id = 'ao_IrSY3UIqDRx7df'
|
12
|
+
|
13
|
+
# Any request that ends with settlement/settlement_id
|
14
|
+
stub_get(%r{settlements\/#{Regexp.quote(@settlement_id)}$}, 'fake_settlement')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_settlement_should_be_defined
|
18
|
+
refute_nil Razorpay::Settlement
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_settlement_should_be_available
|
22
|
+
settlement = Razorpay::Settlement.fetch(@settlement_id)
|
23
|
+
assert_instance_of Razorpay::Settlement, settlement, 'Settlement not an instance of Settlement class'
|
24
|
+
assert_equal @settlement_id, settlement.id, 'Settlement IDs do not match'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_fetch_all_settlement
|
28
|
+
stub_get(/settlements$/, 'settlement_collection')
|
29
|
+
settlement = Razorpay::Settlement.all
|
30
|
+
assert_instance_of Razorpay::Collection, settlement, 'Settlement should be an array'
|
31
|
+
refute_empty settlement.items, 'Settlement should be more than one'
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_settlement_reports
|
35
|
+
para_attr = {
|
36
|
+
"year": 2022,
|
37
|
+
"month":12
|
38
|
+
}
|
39
|
+
stub_get("#{BASE_URI}settlements/recon/combined?month=12&year=2022", 'settlement_report_collection')
|
40
|
+
settlement = Razorpay::Settlement.reports(para_attr)
|
41
|
+
assert_instance_of Razorpay::Collection, settlement, 'Settlement not an instance of Settlement class'
|
42
|
+
refute_empty settlement.items, 'Settlement should be more than one'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_settlement_should_be_created_on_demand
|
46
|
+
para_attr = {
|
47
|
+
"amount": 1221,
|
48
|
+
"settle_full_balance": false,
|
49
|
+
"description": "Testing",
|
50
|
+
"notes": {
|
51
|
+
"notes_key_1": "Tea, Earl Grey, Hot",
|
52
|
+
"notes_key_2": "Tea, Earl Grey… decaf."
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
stub_post( %r{settlements/ondemand$},'fake_settlement_on_demand',para_attr.to_json)
|
57
|
+
settlement = Razorpay::Settlement.create para_attr.to_json
|
58
|
+
assert_instance_of Razorpay::Settlement, settlement, 'Settlement should be an array'
|
59
|
+
assert_equal @settlement_id , settlement.id
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_fetch_all_instant_settlement
|
63
|
+
stub_get(%r{settlements/ondemand$}, 'settlement_instant_collection')
|
64
|
+
settlement = Razorpay::Settlement.fetch_all_ondemand_settlement
|
65
|
+
assert_instance_of Razorpay::Collection, settlement, 'Settlement should be an array'
|
66
|
+
refute_empty settlement.items, 'Settlement should be more than one'
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_fetch_ondemand_settle_by_id
|
70
|
+
stub_get(%r{settlements/ondemand/#{@settlement_id}$}, 'fake_instant_settlement')
|
71
|
+
settlement = Razorpay::Settlement.fetch_ondemand_settlement_by_id(@settlement_id)
|
72
|
+
assert_equal @settlement_ondemand_id, settlement.id, 'Settlement IDs do not match'
|
73
|
+
refute settlement.settle_full_balance
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Subscription
|
5
|
+
class RazorpaySubscriptionTest < Minitest::Test
|
6
|
+
class Item < Razorpay::Entity; end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@subscription_id = 'fake_subscription_id'
|
10
|
+
@offer_id = 'offer_JCTD1XMlUmzF6Z'
|
11
|
+
# Any request that ends with subscriptions/subscription_id
|
12
|
+
stub_get(%r{subscriptions\/#{Regexp.quote(@subscription_id)}$}, 'fake_subscription')
|
13
|
+
stub_get(/subscriptions$/, 'subscription_collection')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_subscription_should_be_defined
|
17
|
+
refute_nil Razorpay::Subscription
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_all_subscriptions
|
21
|
+
subscriptions = Razorpay::Subscription.all
|
22
|
+
assert_instance_of Razorpay::Collection, subscriptions, 'Subscriptions should be an array'
|
23
|
+
assert !subscriptions.items.empty?, 'Subscriptions should be more than one'
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_subscription_should_be_available
|
27
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id)
|
28
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
29
|
+
|
30
|
+
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
31
|
+
|
32
|
+
assert_subscription_details(subscription)
|
33
|
+
end
|
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
|
+
|
79
|
+
def test_subscription_should_be_created
|
80
|
+
time_now = Time.now.to_i
|
81
|
+
subscription_attrs = {
|
82
|
+
plan_id: 'fake_plan_id', customer_id: 'fake_customer_id',
|
83
|
+
start_at: time_now, total_count: 12
|
84
|
+
}
|
85
|
+
|
86
|
+
stub_post(/subscriptions$/, 'fake_subscription', subscription_attrs.to_json)
|
87
|
+
|
88
|
+
subscription = Razorpay::Subscription.create subscription_attrs.to_json
|
89
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
90
|
+
|
91
|
+
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
92
|
+
assert_equal 'created', subscription.status, 'Subscription status is accessible'
|
93
|
+
|
94
|
+
assert_subscription_details(subscription)
|
95
|
+
end
|
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
|
+
|
120
|
+
def test_subscription_should_be_created_with_upfront_amount
|
121
|
+
subscription_attrs = {
|
122
|
+
plan_id: 'fake_plan_id',
|
123
|
+
total_count: 12,
|
124
|
+
addons: [
|
125
|
+
{ item: { amount: 100, currency: 'INR' } },
|
126
|
+
{ item: { amount: 200, currency: 'INR' } }
|
127
|
+
]
|
128
|
+
}
|
129
|
+
|
130
|
+
#
|
131
|
+
# Note that the stubbed request has the addons array
|
132
|
+
# indexed, ensuring that the right request is being built
|
133
|
+
#
|
134
|
+
# This test will fail if the request sends
|
135
|
+
# "addons[][item][amount]=100&addons[][item][currency]=INR" instead
|
136
|
+
#
|
137
|
+
stub_post(/subscriptions$/, 'fake_subscription', subscription_attrs.to_json)
|
138
|
+
|
139
|
+
Razorpay::Subscription.create subscription_attrs.to_json
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_subscription_can_be_cancelled_by_subscription_id
|
143
|
+
stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
|
144
|
+
subscription = Razorpay::Subscription.cancel(@subscription_id)
|
145
|
+
|
146
|
+
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
147
|
+
assert_equal 'cancelled', subscription.status, 'Subscription status is accessible'
|
148
|
+
|
149
|
+
assert_subscription_details(subscription)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_subscription_can_be_cancelled_by_subscription_instance
|
153
|
+
stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
|
154
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id)
|
155
|
+
|
156
|
+
assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
|
157
|
+
assert_equal @subscription_id, subscription.id, 'subscription IDs do not match'
|
158
|
+
assert_equal 'created', subscription.status, 'Subscription status is accessible'
|
159
|
+
assert_nil subscription.ended_at, 'Subscription ended_at is accessible'
|
160
|
+
|
161
|
+
subscription = subscription.cancel(cancel_at_cycle_end: 1)
|
162
|
+
|
163
|
+
assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
|
164
|
+
assert_equal 'cancelled', subscription.status, 'Subscription status is accessible'
|
165
|
+
refute_nil subscription.ended_at, 'Subscription ended_at is accessible'
|
166
|
+
|
167
|
+
assert_subscription_details(subscription)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_subscription_can_be_cancelled_by_subscription_instance!
|
171
|
+
stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
|
172
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id)
|
173
|
+
subscription.cancel!
|
174
|
+
assert_equal 'cancelled', subscription.status
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def assert_subscription_details(subscription)
|
180
|
+
assert_equal 'fake_plan_id', subscription.plan_id, 'Subscription plan_id is accessible'
|
181
|
+
assert_equal 'fake_customer_id', subscription.customer_id, 'Subscription customer_id is accessible'
|
182
|
+
assert_equal 12, subscription.total_count, 'Subscription total_count is accessible'
|
183
|
+
assert_equal 0, subscription.paid_count, 'Subscription paid_count is accessible'
|
184
|
+
refute_nil subscription.charge_at, 'Subscription charge_at is accessible'
|
185
|
+
refute_nil subscription.start_at, 'Subscription start_at is accessible'
|
186
|
+
refute_nil subscription.end_at, 'Subscription end_at is accessible'
|
187
|
+
assert_equal [], subscription.notes, 'Subscription notes is accessible'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -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
|