razorpay 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/documents/generic.md +150 -0
- data/lib/razorpay/constants.rb +27 -1
- data/lib/razorpay/generic.rb +39 -0
- data/lib/razorpay/request.rb +6 -0
- data/lib/razorpay.rb +1 -0
- data/test/razorpay/test_generic.rb +112 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59699530109b442fdc1c6a26cb1df4c906af476b1df20a09847dcda7ca3b5633
|
4
|
+
data.tar.gz: d04d833b06a6b461f4ed2892a3fac80e33e6c43456598f4933b33036909f8337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a922d53c0aae270f874ac9160dc23112937361bcee7716a393e554ad94e1b999c00918a7a3fa1cf43fd1f3d2c8fbcad586b6f61e9a8cab712b264195a68c5e6a
|
7
|
+
data.tar.gz: 2fab3f791c26bceb31d30d7e02ba6b273e9db3ce0b1d250cbe1a4afe29a9e05ded085793085dd503e10c65c3f65f4ed2a004219daff9cca30b0bd4e02c5420b6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,8 @@ If you are using rails, the right place to do this might be `config/initializers
|
|
70
70
|
- [Register NACH and Charge First Payment Together](documents/registerNach.md)
|
71
71
|
- [Payment Verification](documents/paymentVerification.md)
|
72
72
|
- [Webhook](documents/webhook.md)
|
73
|
+
- [Generic](documents/generic.md)
|
74
|
+
|
73
75
|
## Development
|
74
76
|
|
75
77
|
- Everything is namespaced under the Razorpay module
|
@@ -0,0 +1,150 @@
|
|
1
|
+
## Generic Access point
|
2
|
+
|
3
|
+
|
4
|
+
```rb
|
5
|
+
Razorpay.setup('key_id', 'key_secret')
|
6
|
+
```
|
7
|
+
|
8
|
+
### Method Signature
|
9
|
+
```rb
|
10
|
+
Razorpay::Generic.new(entity).do(url, method, payload, version)
|
11
|
+
```
|
12
|
+
|
13
|
+
**Parameters:**
|
14
|
+
|
15
|
+
| Name | Type | Description |
|
16
|
+
|---------------|-------------|---------------------------------------------|
|
17
|
+
| entity* | string | The endpoint to which the request will be made. (e.g., "contacts" or "accounts") |
|
18
|
+
| url* | string | Add params or query or query (e.g., "/order_000000000000001" or "?count=1") |
|
19
|
+
| method* | string | The HTTP method for the request (e.g., 'Get', 'Post', 'Put', 'Patch', 'Delete'). |
|
20
|
+
| payload | object | The data to be sent with the request.|
|
21
|
+
| version | string | Add version (e.g., "v1" or "v2") |
|
22
|
+
|
23
|
+
-------------------------------------------------------------------------------------------------------
|
24
|
+
|
25
|
+
### Create a contacts using POST
|
26
|
+
|
27
|
+
```rb
|
28
|
+
|
29
|
+
payload = {
|
30
|
+
"name": "Gaurav Kumar",
|
31
|
+
"email": "gaurav.kumar@example.com",
|
32
|
+
"contact": "9123456789",
|
33
|
+
"type": "employee",
|
34
|
+
"reference_id":"Acme Contact ID 12345",
|
35
|
+
"notes": {
|
36
|
+
"notes_key_1":"Tea, Earl Grey, Hot",
|
37
|
+
"notes_key_2":"Tea, Earl Grey… decaf.",
|
38
|
+
},
|
39
|
+
}
|
40
|
+
|
41
|
+
Razorpay::Generic.new("contacts").do("/", "Post", payload)
|
42
|
+
```
|
43
|
+
|
44
|
+
**Response:**
|
45
|
+
|
46
|
+
```json
|
47
|
+
{
|
48
|
+
"id": "cont_00000000000001",
|
49
|
+
"entity": "contact",
|
50
|
+
"name": "Gaurav Kumar",
|
51
|
+
"contact": "9123456789",
|
52
|
+
"email": "gaurav.kumar@example.com",
|
53
|
+
"type": "employee",
|
54
|
+
"reference_id": "Acme Contact ID 12345",
|
55
|
+
"batch_id": null,
|
56
|
+
"active": true,
|
57
|
+
"notes": {
|
58
|
+
"notes_key_1": "Tea, Earl Grey, Hot",
|
59
|
+
"notes_key_2": "Tea, Earl Grey… decaf."
|
60
|
+
},
|
61
|
+
"created_at": 1545320320
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
-------------------------------------------------------------------------------------------------------
|
66
|
+
|
67
|
+
### Fetch an order using GET
|
68
|
+
|
69
|
+
```rb
|
70
|
+
Razorpay::Generic.new("orders").do("/order_00000000000001", "Get", {})
|
71
|
+
```
|
72
|
+
|
73
|
+
**Response:**
|
74
|
+
|
75
|
+
```json
|
76
|
+
{
|
77
|
+
"amount": 307,
|
78
|
+
"amount_due": 0,
|
79
|
+
"amount_paid": 307,
|
80
|
+
"attempts": 1,
|
81
|
+
"created_at": 1695625101,
|
82
|
+
"currency": "INR",
|
83
|
+
"entity": "order",
|
84
|
+
"id": "order_00000000000001",
|
85
|
+
"notes": [],
|
86
|
+
"offer_id": null,
|
87
|
+
"receipt": "851617",
|
88
|
+
"status": "paid"
|
89
|
+
}
|
90
|
+
```
|
91
|
+
|
92
|
+
-------------------------------------------------------------------------------------------------------
|
93
|
+
|
94
|
+
### Fetch payments of a linked account using headers
|
95
|
+
|
96
|
+
```rb
|
97
|
+
Razorpay.headers = {"X-Razorpay-Account" => "acc_00000000000001"}
|
98
|
+
|
99
|
+
Razorpay::Generic.new("payments").do("/pay_00000000000001", "Get", {})
|
100
|
+
```
|
101
|
+
|
102
|
+
**Response:**
|
103
|
+
|
104
|
+
```json
|
105
|
+
{
|
106
|
+
"entity": "collection",
|
107
|
+
"count": 2,
|
108
|
+
"items": [
|
109
|
+
{
|
110
|
+
"id": "pay_00000000000001",
|
111
|
+
"entity": "payment",
|
112
|
+
"amount": 10000,
|
113
|
+
"currency": "INR",
|
114
|
+
"status": "captured",
|
115
|
+
"order_id": "order_00000000000001",
|
116
|
+
"invoice_id": null,
|
117
|
+
"international": false,
|
118
|
+
"method": "netbanking",
|
119
|
+
"amount_refunded": 0,
|
120
|
+
"refund_status": null,
|
121
|
+
"captured": true,
|
122
|
+
"description": "#JJCqaOhFihfkVE",
|
123
|
+
"card_id": null,
|
124
|
+
"bank": "YESB",
|
125
|
+
"wallet": null,
|
126
|
+
"vpa": null,
|
127
|
+
"email": "john.example@example.com",
|
128
|
+
"contact": "9999999999",
|
129
|
+
"notes": [],
|
130
|
+
"fee": 236,
|
131
|
+
"tax": 36,
|
132
|
+
"error_code": null,
|
133
|
+
"error_description": null,
|
134
|
+
"error_source": null,
|
135
|
+
"error_step": null,
|
136
|
+
"error_reason": null,
|
137
|
+
"acquirer_data": {
|
138
|
+
"bank_transaction_id": "2118867"
|
139
|
+
},
|
140
|
+
"created_at": 1649932775
|
141
|
+
}
|
142
|
+
]
|
143
|
+
}
|
144
|
+
```
|
145
|
+
|
146
|
+
-------------------------------------------------------------------------------------------------------
|
147
|
+
|
148
|
+
**PN: * indicates mandatory fields**
|
149
|
+
<br>
|
150
|
+
<br>
|
data/lib/razorpay/constants.rb
CHANGED
@@ -2,5 +2,31 @@
|
|
2
2
|
module Razorpay
|
3
3
|
BASE_URI = 'https://api.razorpay.com'.freeze
|
4
4
|
TEST_URL = 'https://api.razorpay.com/'.freeze
|
5
|
-
VERSION = '3.
|
5
|
+
VERSION = '3.2.0'.freeze
|
6
|
+
ENTITIES_LIST = {
|
7
|
+
"cards" => "card",
|
8
|
+
"invoices" => "invoice",
|
9
|
+
"refunds" => "refund",
|
10
|
+
"orders" => "order",
|
11
|
+
"payments" => "payment",
|
12
|
+
"customers" => "customer",
|
13
|
+
"plans" => "plan",
|
14
|
+
"virtual_accounts" => "virtualAccount",
|
15
|
+
"addons" => "addon",
|
16
|
+
"subscriptions" => "subscriptions",
|
17
|
+
"subscription_registrations" => "subscription_registrations",
|
18
|
+
"transfers" => "transfers",
|
19
|
+
"payment_links" => "payment_links",
|
20
|
+
"settlements" => "settlements",
|
21
|
+
"qr_codes" => "qr_codes",
|
22
|
+
"items" => "items",
|
23
|
+
"fund_accounts" => "fund_accounts",
|
24
|
+
"webhooks" => "webhook",
|
25
|
+
"payment_methods" => "payment_methods",
|
26
|
+
"products" => "products",
|
27
|
+
"tokens" => "tokens",
|
28
|
+
"iins" => "iins",
|
29
|
+
"stakeholders" => "stakeholders",
|
30
|
+
"accounts" => "accounts"
|
31
|
+
}
|
6
32
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'razorpay/request'
|
2
|
+
|
3
|
+
|
4
|
+
module Razorpay
|
5
|
+
class Generic
|
6
|
+
def initialize(entity)
|
7
|
+
@entity = entity
|
8
|
+
end
|
9
|
+
|
10
|
+
def request()
|
11
|
+
Razorpay::Request.new(@entity)
|
12
|
+
end
|
13
|
+
|
14
|
+
def do(url="", method="Get", options={}, version="v1")
|
15
|
+
r = self.request
|
16
|
+
r.doesEntityExist(@entity)
|
17
|
+
|
18
|
+
case method
|
19
|
+
when "Get"
|
20
|
+
r.get url, options, version
|
21
|
+
|
22
|
+
when "Post"
|
23
|
+
r.post url, options, version
|
24
|
+
|
25
|
+
when "Patch"
|
26
|
+
r.patch url, options, version
|
27
|
+
|
28
|
+
when "Put"
|
29
|
+
r.put url, options, version
|
30
|
+
|
31
|
+
when "Delete"
|
32
|
+
r.delete url, version
|
33
|
+
|
34
|
+
else
|
35
|
+
warn("Unsupported method or error occurred")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/razorpay/request.rb
CHANGED
@@ -115,5 +115,11 @@ module Razorpay
|
|
115
115
|
# We got an unknown error, cast it to Error for now
|
116
116
|
raise Razorpay::Error.new, 'Unknown Error'
|
117
117
|
end
|
118
|
+
|
119
|
+
def doesEntityExist(entity)
|
120
|
+
if (Razorpay::ENTITIES_LIST.include?(entity))
|
121
|
+
warn("Warning: The entity already has a specific function. Consider using it instead.")
|
122
|
+
end
|
123
|
+
end
|
118
124
|
end
|
119
125
|
end
|
data/lib/razorpay.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Razorpay
|
4
|
+
# Tests for Razorpay::Addon
|
5
|
+
class RazorpayGenericTest < Minitest::Test
|
6
|
+
class Generic < Razorpay::Entity; end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@order_id = 'order_50sX9hGHZJvjjI'
|
10
|
+
@customer_id = 'cust_6vRXClWqnLhV14'
|
11
|
+
@invoice_id = 'inv_6vRZmJYFAG1mNq'
|
12
|
+
@addon_id = 'ao_IrSY3UIqDRx7df'
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_generic_should_be_defined
|
16
|
+
refute_nil Razorpay::Generic
|
17
|
+
end
|
18
|
+
|
19
|
+
# Test fetch endpoint by order entity
|
20
|
+
def test_generic_orders_should_be_fetch
|
21
|
+
stub_get(%r{orders/#{@order_id}$}, 'fake_order')
|
22
|
+
|
23
|
+
client = Razorpay::Generic.new("orders")
|
24
|
+
|
25
|
+
order = client.do(@order_id)
|
26
|
+
|
27
|
+
assert_equal 5000, order.amount
|
28
|
+
assert_equal 'INR', order.currency
|
29
|
+
assert_equal 'TEST', order.receipt
|
30
|
+
end
|
31
|
+
|
32
|
+
# Test post endpoint by order entity
|
33
|
+
def test_generic_orders_should_be_create
|
34
|
+
para_attr = {
|
35
|
+
"amount": 5000
|
36
|
+
}
|
37
|
+
|
38
|
+
stub_post("#{BASE_URI}/v1/orders/", 'fake_order', para_attr.to_json)
|
39
|
+
|
40
|
+
client = Razorpay::Generic.new("orders")
|
41
|
+
order = client.do("", "Post", para_attr.to_json)
|
42
|
+
assert_equal 5000, order.amount
|
43
|
+
assert_equal 'INR', order.currency
|
44
|
+
assert_equal 'TEST', order.receipt
|
45
|
+
end
|
46
|
+
|
47
|
+
# Test fetch endpoint by order entity
|
48
|
+
def test_generic_orders_should_be_edit
|
49
|
+
para_attr = {
|
50
|
+
"notes": {
|
51
|
+
"purpose": "Test UPI QR code notes uodate"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
stub_patch("#{BASE_URI}/v1/orders/#{@order_id}", 'fake_order', para_attr.to_json)
|
56
|
+
|
57
|
+
client = Razorpay::Generic.new("orders")
|
58
|
+
order = client.do(@order_id, "Patch", para_attr.to_json)
|
59
|
+
assert_equal 5000, order.amount
|
60
|
+
assert_equal 'INR', order.currency
|
61
|
+
assert_equal 'TEST', order.receipt
|
62
|
+
end
|
63
|
+
|
64
|
+
# Test post endpoint by order entity
|
65
|
+
def test_generic_customer_should_be_create
|
66
|
+
para_attr = {
|
67
|
+
"name": "Gaurav Kumar",
|
68
|
+
"contact": 9123456780,
|
69
|
+
"email": "gaurav.kumar@example.com",
|
70
|
+
"notes": {
|
71
|
+
"notes_key_1": "Tea, Earl Grey, Hot",
|
72
|
+
"notes_key_2": "Tea, Earl Grey… decaf."
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
stub_post("#{BASE_URI}/v1/customers/", 'fake_customer', para_attr.to_json)
|
77
|
+
|
78
|
+
client = Razorpay::Generic.new("customers")
|
79
|
+
customer = client.do("","Post", para_attr.to_json)
|
80
|
+
assert_equal 'test@razorpay.com', customer.email
|
81
|
+
assert_equal '9876543210', customer.contact
|
82
|
+
end
|
83
|
+
|
84
|
+
# Test put endpoint by order entity
|
85
|
+
def test_generic_customer_should_be_edit
|
86
|
+
para_attr = {
|
87
|
+
"contact": 9123456780,
|
88
|
+
}
|
89
|
+
|
90
|
+
stub_put("#{BASE_URI}/v1/customers/#{@customer_id}", 'fake_customer', para_attr.to_json)
|
91
|
+
|
92
|
+
client = Razorpay::Generic.new("customers")
|
93
|
+
customer = client.do(@customer_id, "Put", para_attr.to_json)
|
94
|
+
assert_equal 'test@razorpay.com', customer.email
|
95
|
+
assert_equal '9876543210', customer.contact
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_generic_delete_specific_invoice
|
99
|
+
stub_delete(%r{invoices/#{@invoice_id}$}, 'empty')
|
100
|
+
client = Razorpay::Generic.new("invoices")
|
101
|
+
invoice = client.do("#{@invoice_id}", "Delete")
|
102
|
+
refute_nil invoice
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_generic_delete_addon
|
106
|
+
stub_delete(%r{addons/#{@addon_id}$}, 'empty')
|
107
|
+
client = Razorpay::Generic.new("addons")
|
108
|
+
addon = client.do("#{@addon_id}", "Delete")
|
109
|
+
refute_nil addon
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: razorpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhay Rana
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- documents/customer.md
|
138
138
|
- documents/emandate.md
|
139
139
|
- documents/fund.md
|
140
|
+
- documents/generic.md
|
140
141
|
- documents/items.md
|
141
142
|
- documents/order.md
|
142
143
|
- documents/papernach.md
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- lib/razorpay/errors/razorpay_error.rb
|
174
175
|
- lib/razorpay/errors/server_error.rb
|
175
176
|
- lib/razorpay/fund_account.rb
|
177
|
+
- lib/razorpay/generic.rb
|
176
178
|
- lib/razorpay/iin.rb
|
177
179
|
- lib/razorpay/invoice.rb
|
178
180
|
- lib/razorpay/item.rb
|
@@ -293,6 +295,7 @@ files:
|
|
293
295
|
- test/razorpay/test_customer.rb
|
294
296
|
- test/razorpay/test_entity.rb
|
295
297
|
- test/razorpay/test_fund_account.rb
|
298
|
+
- test/razorpay/test_generic.rb
|
296
299
|
- test/razorpay/test_iin.rb
|
297
300
|
- test/razorpay/test_invoice.rb
|
298
301
|
- test/razorpay/test_item.rb
|
@@ -437,6 +440,7 @@ test_files:
|
|
437
440
|
- test/razorpay/test_customer.rb
|
438
441
|
- test/razorpay/test_entity.rb
|
439
442
|
- test/razorpay/test_fund_account.rb
|
443
|
+
- test/razorpay/test_generic.rb
|
440
444
|
- test/razorpay/test_iin.rb
|
441
445
|
- test/razorpay/test_invoice.rb
|
442
446
|
- test/razorpay/test_item.rb
|