razorpay 2.4.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::FundAccount
|
5
|
+
class RazorpayFundAccountTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@customer_id = 'cust_J3oSNi1KgzqVEX'
|
8
|
+
@fund_account_id = 'fa_J8B38pGr1Tfv8k'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_fund_account_should_be_defined
|
12
|
+
refute_nil Razorpay::FundAccount
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_fund_account_should_be_created
|
16
|
+
|
17
|
+
param_attr = {
|
18
|
+
"customer_id": "cust_Aa000000000001",
|
19
|
+
"account_type": "bank_account",
|
20
|
+
"bank_account": {
|
21
|
+
"name": "Gaurav Kumar",
|
22
|
+
"account_number": "11214311215411",
|
23
|
+
"ifsc": "HDFC0000053"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
stub_post(/fund_accounts$/, 'fake_fund_account', param_attr.to_json)
|
28
|
+
fund_account = Razorpay::FundAccount.create param_attr.to_json
|
29
|
+
assert_equal @customer_id, fund_account.customer_id
|
30
|
+
assert_equal @fund_account_id, fund_account.id
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_fetch_all_fund_accounts
|
34
|
+
|
35
|
+
para_attr = {"customer_id": @customer_id}
|
36
|
+
stub_get(/fund_accounts/, 'fund_collection', para_attr.to_json)
|
37
|
+
fund_accounts = Razorpay::FundAccount.all(para_attr.to_json)
|
38
|
+
assert_instance_of Razorpay::Collection, fund_accounts, 'FundAccounts should be an array'
|
39
|
+
assert !fund_accounts.items.empty?, 'FundAccounts should be more than one'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -5,7 +5,7 @@ module Razorpay
|
|
5
5
|
class RazorpayInvoiceTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@invoice_id = 'inv_6vRZmJYFAG1mNq'
|
8
|
-
|
8
|
+
@medium = "email"
|
9
9
|
# Any request that ends with invoices/invoice_id
|
10
10
|
stub_get(%r{invoices/#{@invoice_id}$}, 'fake_invoice')
|
11
11
|
end
|
@@ -117,7 +117,6 @@ module Razorpay
|
|
117
117
|
refute_nil invoice.invoice_number
|
118
118
|
end
|
119
119
|
|
120
|
-
private
|
121
120
|
|
122
121
|
def assert_invoice_details(invoice)
|
123
122
|
assert_equal 'cust_6vRXClWqnLhV14', invoice.customer_id
|
@@ -126,5 +125,19 @@ module Razorpay
|
|
126
125
|
assert_equal 'Test description', invoice.description
|
127
126
|
assert_equal 'invoice', invoice.type
|
128
127
|
end
|
128
|
+
|
129
|
+
def test_delete_specific_invoice
|
130
|
+
stub_delete(%r{invoices/#{@invoice_id}$}, 'empty')
|
131
|
+
invoice = Razorpay::Invoice.delete(@invoice_id)
|
132
|
+
assert_instance_of Razorpay::Entity, invoice, 'invoice not an instance of Razorpay::Invoice class'
|
133
|
+
refute_nil invoice
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_invoice_notifyBy
|
137
|
+
stub_post(%r{invoices/#{@invoice_id}/notify_by/#{@medium}$}, 'success', {})
|
138
|
+
invoice = Razorpay::Invoice.notify_by(@invoice_id,@medium)
|
139
|
+
assert_instance_of Razorpay::Entity, invoice, 'invoice not an instance of Razorpay::Invoice class'
|
140
|
+
assert invoice
|
141
|
+
end
|
129
142
|
end
|
130
143
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Item
|
5
|
+
class RazorpayItemTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@item_id = 'item_JDcbIdX9xojCje'
|
8
|
+
|
9
|
+
# Any request that ends with items/item_id
|
10
|
+
stub_get(%r{items/#{@item_id}$}, 'fake_item')
|
11
|
+
stub_get(/items$/, 'item_collection')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_item_should_be_defined
|
15
|
+
refute_nil Razorpay::Item
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_item_should_be_created
|
19
|
+
|
20
|
+
param_attr = {
|
21
|
+
"name": "Book / English August",
|
22
|
+
"description": "An indian story, Booker prize winner.",
|
23
|
+
"amount": 20000,
|
24
|
+
"currency": "INR"
|
25
|
+
}
|
26
|
+
|
27
|
+
stub_post(/items$/, 'fake_item', param_attr.to_json)
|
28
|
+
items = Razorpay::Item.create(param_attr.to_json)
|
29
|
+
assert_equal @item_id, items.id
|
30
|
+
assert_equal true, items.active
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_edit_items
|
34
|
+
|
35
|
+
param_attr = {
|
36
|
+
"name": "Book / English August",
|
37
|
+
"description": "An indian story, Booker prize winner.",
|
38
|
+
"amount": 20000,
|
39
|
+
"currency": "INR"
|
40
|
+
}
|
41
|
+
|
42
|
+
stub_patch(%r{items/#{@item_id}$}, 'fake_item', param_attr.to_json)
|
43
|
+
item = Razorpay::Item.edit(@item_id, param_attr.to_json)
|
44
|
+
assert_instance_of Razorpay::Entity, item
|
45
|
+
assert_equal @item_id, item.id, 'Item IDs do not match'
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_fetch_all_items
|
49
|
+
items = Razorpay::Item.all
|
50
|
+
assert_instance_of Razorpay::Collection, items, 'Items should be an array'
|
51
|
+
refute_empty items.items, 'Items should be more than one'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_fetch_specific_item
|
55
|
+
item = Razorpay::Item.fetch(@item_id)
|
56
|
+
assert_instance_of Razorpay::Entity, item
|
57
|
+
assert_equal @item_id, item.id, 'Item IDs do not match'
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_delete_item
|
61
|
+
stub_delete(%r{items/#{@item_id}$}, 'empty')
|
62
|
+
item = Razorpay::Item.delete(@item_id)
|
63
|
+
assert_instance_of Razorpay::Entity, item
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/test/razorpay/test_order.rb
CHANGED
@@ -5,7 +5,7 @@ module Razorpay
|
|
5
5
|
class RazorpayOrderTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@order_id = 'order_50sX9hGHZJvjjI'
|
8
|
-
|
8
|
+
@transfer_id = 'trf_DSkl2lXWbiADZG'
|
9
9
|
# Any request that ends with orders/order_id
|
10
10
|
stub_get(%r{orders/#{@order_id}$}, 'fake_order')
|
11
11
|
end
|
@@ -44,5 +44,28 @@ module Razorpay
|
|
44
44
|
assert !payments.items.empty?, 'payments should be more than one'
|
45
45
|
assert_equal 'pay_50sbkZA9AcyE5a', payments.items[0]['id'], 'payment id should match'
|
46
46
|
end
|
47
|
+
|
48
|
+
def test_edit_order
|
49
|
+
param_attr = {
|
50
|
+
"notes": {
|
51
|
+
"key1": "value3",
|
52
|
+
"key2": "value2"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
stub_patch(%r{orders/#{@order_id}$}, 'fake_order', param_attr.to_json)
|
57
|
+
order = Razorpay::Order.edit(@order_id, param_attr.to_json)
|
58
|
+
assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
|
59
|
+
assert_equal @order_id, order.id, 'order IDs do not match'
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_fetch_order_transfers
|
63
|
+
stub_get("#{BASE_URI}orders/#{@order_id}/?expand[]=transfers&status", 'fake_order_transfers')
|
64
|
+
order = Razorpay::Order.fetch_transfer_order(@order_id)
|
65
|
+
assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
|
66
|
+
assert_equal @order_id, order.id, 'order IDs do not match'
|
67
|
+
refute_empty order.transfers["items"]
|
68
|
+
assert_equal @transfer_id, order.transfers["items"][0]["id"]
|
69
|
+
end
|
47
70
|
end
|
48
71
|
end
|
@@ -5,7 +5,10 @@ module Razorpay
|
|
5
5
|
class RazorpayPaymentTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@payment_id = 'fake_payment_id'
|
8
|
-
|
8
|
+
@downtime_id = 'fake_downtime_id'
|
9
|
+
@card_id = 'card_7EZLhWkDt05n7V'
|
10
|
+
@transfer_id = 'trf_J0FrZYPql4riDx'
|
11
|
+
@refund_id = 'fake_refund_id'
|
9
12
|
# Any request that ends with payments/payment_id
|
10
13
|
stub_get(%r{payments\/#{@payment_id}$}, 'fake_payment')
|
11
14
|
stub_get(/payments$/, 'payment_collection')
|
@@ -23,6 +26,111 @@ module Razorpay
|
|
23
26
|
assert_equal 'card', payment.method, 'Payment method is accessible'
|
24
27
|
end
|
25
28
|
|
29
|
+
def test_payments_fetch_downtime
|
30
|
+
stub_get( %r{payments/downtimes$}, 'downtimes_collection')
|
31
|
+
payments = Razorpay::Payment.fetch_payment_downtime
|
32
|
+
assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
|
33
|
+
refute_empty payments.items, 'payments should be more than one'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_payments_fetch_downtime_by_id
|
37
|
+
stub_get( %r{payments/downtimes/#{@downtime_id}$}, 'fake_downtime')
|
38
|
+
payment = Razorpay::Payment.fetch_payment_downtime_by_id(@downtime_id)
|
39
|
+
assert_instance_of Razorpay::Entity, payment, 'Payment not an instance of Razorpay::Payment class'
|
40
|
+
assert_equal @downtime_id , payment.id
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_payments_fetch_card_details
|
44
|
+
stub_get( %r{payments/#{@payment_id}/card$}, 'fake_card')
|
45
|
+
card = Razorpay::Payment.fetch_card_details(@payment_id)
|
46
|
+
assert_instance_of Razorpay::Card, card, 'Card not an instance of Razorpay::Card class'
|
47
|
+
assert_equal @card_id , card.id
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_payments_fetch_multiple_refund_for_payment
|
51
|
+
stub_get( %r{payments/#{@payment_id}/refunds$}, 'refund_collection',{})
|
52
|
+
payments = Razorpay::Payment.fetch_multiple_refund(@payment_id,{})
|
53
|
+
assert_instance_of Razorpay::Collection, payments, 'Payment not an instance of Razorpay::Payment class'
|
54
|
+
assert !payments.items.empty?, 'payments should be more than one'
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_payments_fetch_transfers
|
58
|
+
stub_get(%r{payments/#{@payment_id}/transfers$}, 'transfers_collection')
|
59
|
+
transfers = Razorpay::Payment.fetch(@payment_id).fetch_transfer
|
60
|
+
assert_instance_of Razorpay::Collection, transfers, 'Transfers should be an array'
|
61
|
+
assert !transfers.items.empty?, 'transfers should be more than one'
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_payments_post_transfers
|
65
|
+
param_attr = {
|
66
|
+
"transfers": [
|
67
|
+
{
|
68
|
+
"account": "acc_CPRsN1LkFccllA",
|
69
|
+
"amount": 100,
|
70
|
+
"currency": "INR",
|
71
|
+
"notes": {
|
72
|
+
"name": "Gaurav Kumar",
|
73
|
+
"roll_no": "IEC2011025"
|
74
|
+
},
|
75
|
+
"linked_account_notes": [
|
76
|
+
"roll_no"
|
77
|
+
],
|
78
|
+
"on_hold": true,
|
79
|
+
"on_hold_until": 1671222870
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"account": "acc_CNo3jSI8OkFJJJ",
|
83
|
+
"amount": 100,
|
84
|
+
"currency": "INR",
|
85
|
+
"notes": {
|
86
|
+
"name": "Saurav Kumar",
|
87
|
+
"roll_no": "IEC2011026"
|
88
|
+
},
|
89
|
+
"linked_account_notes": [
|
90
|
+
"roll_no"
|
91
|
+
],
|
92
|
+
"on_hold": false
|
93
|
+
}
|
94
|
+
]
|
95
|
+
}
|
96
|
+
|
97
|
+
stub_post(%r{payments/#{@payment_id}/transfers$}, 'fake_transfer', param_attr.to_json)
|
98
|
+
transfer = Razorpay::Payment.fetch(@payment_id).transfer(param_attr.to_json)
|
99
|
+
assert_instance_of Razorpay::Transfer, transfer, 'Transfer not an instance of Razorpay::Transfer class'
|
100
|
+
assert transfer.on_hold
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_payments_fetch_refunds
|
104
|
+
stub_get(%r{payments/#{@payment_id}/refunds/#{@refund_id}$}, 'fake_refund')
|
105
|
+
refund = Razorpay::Payment.fetch(@payment_id).fetch_refund(@refund_id)
|
106
|
+
assert_instance_of Razorpay::Refund, refund, 'Refund not an instance of Razorpay::Refund class'
|
107
|
+
assert_equal @refund_id, refund.id
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_payment_create_recurring
|
111
|
+
|
112
|
+
payment_attr = {
|
113
|
+
"email": "gaurav.kumar@example.com",
|
114
|
+
"contact": "9123456789",
|
115
|
+
"amount": 1000,
|
116
|
+
"currency": "INR",
|
117
|
+
"order_id": "order_1Aa00000000002",
|
118
|
+
"customer_id": "cust_1Aa00000000001",
|
119
|
+
"token": "token_1Aa00000000001",
|
120
|
+
"recurring": "1",
|
121
|
+
"description": "Creating recurring payment for Gaurav Kumar",
|
122
|
+
"notes": {
|
123
|
+
"note_key 1": "Beam me up Scotty",
|
124
|
+
"note_key 2": "Tea. Earl Gray. Hot."
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
stub_post(%r{payments/create/recurring$}, 'fake_recurring', payment_attr.to_json)
|
129
|
+
payment = Razorpay::Payment.create_recurring_payment payment_attr.to_json
|
130
|
+
assert_equal 'pay_1Aa00000000001', payment.razorpay_payment_id
|
131
|
+
|
132
|
+
end
|
133
|
+
|
26
134
|
def test_all_payments
|
27
135
|
payments = Razorpay::Payment.all
|
28
136
|
assert_instance_of Razorpay::Collection, payments, 'Payments should be an array'
|
@@ -40,7 +148,7 @@ module Razorpay
|
|
40
148
|
stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
|
41
149
|
refund = Razorpay::Payment.fetch(@payment_id).refund
|
42
150
|
assert_instance_of Razorpay::Refund, refund
|
43
|
-
assert_equal refund.payment_id,
|
151
|
+
assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
|
44
152
|
end
|
45
153
|
|
46
154
|
def test_payment_refund!
|
@@ -56,21 +164,30 @@ module Razorpay
|
|
56
164
|
stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', 'amount=2000')
|
57
165
|
refund = Razorpay::Payment.fetch(@payment_id).refund(amount: 2000)
|
58
166
|
assert_instance_of Razorpay::Refund, refund
|
59
|
-
assert_equal refund.payment_id,
|
167
|
+
assert_equal refund.payment_id, "pay_FFX5FdEYx8jPwA"
|
60
168
|
assert_equal refund.amount, 2000
|
61
169
|
end
|
62
170
|
|
63
171
|
def test_payment_capture
|
64
|
-
|
65
|
-
|
66
|
-
|
172
|
+
|
173
|
+
para_attr = {
|
174
|
+
amount: 1000,
|
175
|
+
currency: 'INR'
|
176
|
+
}
|
177
|
+
|
178
|
+
stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', para_attr.to_json)
|
179
|
+
payment = Razorpay::Payment.fetch(@payment_id).capture(para_attr.to_json)
|
67
180
|
assert_equal 'captured', payment.status
|
68
181
|
end
|
69
182
|
|
70
183
|
def test_payment_capture!
|
71
|
-
|
184
|
+
para_attr = {
|
185
|
+
amount: 1000,
|
186
|
+
currency: "INR"
|
187
|
+
}
|
188
|
+
stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', para_attr.to_json)
|
72
189
|
payment = Razorpay::Payment.fetch(@payment_id)
|
73
|
-
payment.capture!(
|
190
|
+
payment.capture!(para_attr.to_json)
|
74
191
|
assert_equal 'captured', payment.status
|
75
192
|
end
|
76
193
|
|
@@ -79,5 +196,64 @@ module Razorpay
|
|
79
196
|
payment = Razorpay::Payment.capture(@payment_id, amount: 5100)
|
80
197
|
assert_equal 'captured', payment.status
|
81
198
|
end
|
199
|
+
|
200
|
+
def test_otp_generate
|
201
|
+
payment_id = 'pay_FVmAstJWfsD3SO'
|
202
|
+
stub_post(%r{payments/#{payment_id}/otp_generate$}, 'fake_otp_generate', {})
|
203
|
+
payment = Razorpay::Payment.otp_generate(payment_id)
|
204
|
+
assert_equal payment_id, payment.razorpay_payment_id
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_otp_submit
|
208
|
+
param_attr = {
|
209
|
+
otp: "123456"
|
210
|
+
}
|
211
|
+
stub_post(%r{payments/#{@payment_id}/otp/submit$}, 'fake_otp_submit', param_attr.to_json)
|
212
|
+
payment = Razorpay::Payment.fetch(@payment_id).otp_submit(param_attr.to_json)
|
213
|
+
assert_equal @payment_id, payment.razorpay_payment_id
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_otp_resend
|
217
|
+
stub_post(%r{payments/#{@payment_id}/otp/resend$}, 'fake_otp_resend', {})
|
218
|
+
payment = Razorpay::Payment.fetch(@payment_id).otp_resend
|
219
|
+
assert_equal @payment_id, payment.razorpay_payment_id
|
220
|
+
|
221
|
+
def test_payment_edit
|
222
|
+
|
223
|
+
payment_attr = {
|
224
|
+
"notes": {
|
225
|
+
"notes_key_1": 'Beam me up Scotty.',
|
226
|
+
"notes_key_2": 'Engage'
|
227
|
+
}
|
228
|
+
}
|
229
|
+
stub_patch(%r{payments\/#{@payment_id}$}, 'fake_update_payment', payment_attr.to_json)
|
230
|
+
payment = Razorpay::Payment.fetch(@payment_id).edit(payment_attr.to_json)
|
231
|
+
assert_equal 'payment', payment.entity
|
232
|
+
assert_equal 'Beam me up Scotty.', payment.notes["notes_key_1"]
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_payment_create_payment_json
|
236
|
+
|
237
|
+
payment_attr = {
|
238
|
+
amount: '100',
|
239
|
+
currency: 'INR',
|
240
|
+
email: 'gaurav.kumar@example.com',
|
241
|
+
contact: '9123456789',
|
242
|
+
order_id: 'order_EAkbvXiCJlwhHR',
|
243
|
+
method: 'card',
|
244
|
+
card: {
|
245
|
+
number: '4854980604708430',
|
246
|
+
cvv: '123',
|
247
|
+
expiry_month: '12',
|
248
|
+
expiry_year: '21',
|
249
|
+
name: 'Gaurav Kumar'
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
stub_post(%r{payments/create/json$}, 'create_json_payment',payment_attr.to_json)
|
254
|
+
payment = Razorpay::Payment.create_json_payment payment_attr.to_json
|
255
|
+
assert_equal 'pay_FVmAstJWfsD3SO', payment.razorpay_payment_id
|
256
|
+
end
|
257
|
+
end
|
82
258
|
end
|
83
259
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::PaymentLink
|
5
|
+
class RazorpayPaymentLinkTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@payment_link_id = 'plink_J9feMU9xqHQVWX'
|
8
|
+
|
9
|
+
# Any request that ends with payment_link/payment_link_id
|
10
|
+
stub_get(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link')
|
11
|
+
stub_get(/payment_links$/, 'payment_link_collection')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_payment_link_should_be_defined
|
15
|
+
refute_nil Razorpay::PaymentLink
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_payment_link_should_be_created
|
19
|
+
param_attr = {
|
20
|
+
"amount": 2244,
|
21
|
+
"currency": "INR",
|
22
|
+
"accept_partial": true,
|
23
|
+
"first_min_partial_amount": 100,
|
24
|
+
"description": "For XYZ purpose",
|
25
|
+
"customer": {
|
26
|
+
"name": "Gaurav Kumar",
|
27
|
+
"email": "gaurav.kumar@example.com",
|
28
|
+
"contact": "+919999999999"
|
29
|
+
},
|
30
|
+
"notify": {
|
31
|
+
"sms": true,
|
32
|
+
"email": true
|
33
|
+
},
|
34
|
+
"reminder_enable": true,
|
35
|
+
"notes": {
|
36
|
+
"policy_name": "Jeevan Bima"
|
37
|
+
},
|
38
|
+
"callback_url": "https://example-callback-url.com/",
|
39
|
+
"callback_method": "get"
|
40
|
+
}
|
41
|
+
|
42
|
+
stub_post(/payment_links$/, 'fake_payment_link', param_attr.to_json)
|
43
|
+
payment_link = Razorpay::PaymentLink.create param_attr.to_json
|
44
|
+
assert_equal @payment_link_id, payment_link.id
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_edit_payment_link
|
48
|
+
para_attr ={
|
49
|
+
"reference_id": "TS35",
|
50
|
+
"expire_by": 1653347540,
|
51
|
+
"reminder_enable":false,
|
52
|
+
"notes":{
|
53
|
+
"policy_name": "Jeevan Saral"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
stub_patch(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link', para_attr.to_json)
|
58
|
+
payment_link = Razorpay::PaymentLink.edit(@payment_link_id,para_attr.to_json)
|
59
|
+
assert_instance_of Razorpay::Entity, payment_link
|
60
|
+
assert true, payment_link.accept_partial
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_fetch_all_payment_link
|
64
|
+
stub_get(/payment_links$/, 'payment_link_collection')
|
65
|
+
payment_link = Razorpay::PaymentLink.all
|
66
|
+
assert_instance_of Razorpay::Collection, payment_link
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_fetch_specific_payment
|
70
|
+
stub_get(%r{payment_links/#{@payment_link_id}$}, 'fake_payment_link')
|
71
|
+
payment_link = Razorpay::PaymentLink.fetch(@payment_link_id)
|
72
|
+
assert_instance_of Razorpay::Entity, payment_link
|
73
|
+
assert_equal payment_link.id, @payment_link_id
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_notify_by_id
|
77
|
+
stub_post(%r{payment_links/#{@payment_link_id}/notify_by/email$}, 'payment_link_response',{})
|
78
|
+
payment_link = Razorpay::PaymentLink.notify_by(@payment_link_id,"email")
|
79
|
+
assert_instance_of Razorpay::Entity, payment_link
|
80
|
+
assert true, payment_link.success
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/test/razorpay/test_plan.rb
CHANGED
@@ -42,9 +42,9 @@ module Razorpay
|
|
42
42
|
notes: { identifier: 'plan_monthly_1000' }
|
43
43
|
}
|
44
44
|
|
45
|
-
stub_post(/plans$/, 'fake_plan',
|
45
|
+
stub_post(/plans$/, 'fake_plan', plan_attrs.to_json)
|
46
46
|
|
47
|
-
plan = Razorpay::Plan.create plan_attrs
|
47
|
+
plan = Razorpay::Plan.create plan_attrs.to_json
|
48
48
|
|
49
49
|
assert_equal 1, plan.interval, 'Plan interval is accessible'
|
50
50
|
assert_equal 'monthly', plan.period, 'Plan period is accessible'
|
@@ -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
|
@@ -36,7 +36,21 @@ module Razorpay
|
|
36
36
|
stub_post(/refunds$/, 'fake_refund', "payment_id=#{@payment_id}")
|
37
37
|
refund = Razorpay::Refund.create(payment_id: @payment_id)
|
38
38
|
assert_instance_of Razorpay::Refund, refund
|
39
|
-
assert_equal 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
|
40
53
|
end
|
41
|
-
end
|
54
|
+
end
|
42
55
|
end
|
56
|
+
|
@@ -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
|