razorpay 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +7 -1
- data/README.md +13 -0
- data/lib/razorpay/constants.rb +1 -1
- data/lib/razorpay/entity.rb +13 -0
- data/lib/razorpay/invoice.rb +12 -0
- data/lib/razorpay/payment.rb +10 -0
- data/lib/razorpay/subscription.rb +4 -0
- data/lib/razorpay/utility.rb +1 -1
- data/lib/razorpay/virtual_account.rb +8 -0
- data/razorpay-ruby.gemspec +1 -1
- data/test/fixtures/fake_refunded_payment.json +14 -0
- data/test/razorpay/test_invoice.rb +18 -4
- data/test/razorpay/test_payment.rb +16 -1
- data/test/razorpay/test_subscription.rb +7 -0
- data/test/razorpay/test_utility.rb +14 -0
- data/test/razorpay/test_virtual_account.rb +17 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8a703b64189d31348ac44fccf9edef384ff5af
|
4
|
+
data.tar.gz: f007b3cd479849931bda5fc5f59d584f4a15e18b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0c677d255482d7378c2eecf523d3ee8ae9d106af592885613d6c08a4a2b5be24c39c9c1c8dba270029336e1a1a56dc385358b48e90ff3e80adf638dedcf266
|
7
|
+
data.tar.gz: 942c7c1247d66d697b4f597125d5c2c145112e0ea62f1fa14c4fe5835c03607a13fdcce26c36185a4ccd0fd08cd08fbaeb260a4751e2983c105c7a9d0229a22c
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ Changelog for Razorpay-Ruby SDK.
|
|
4
4
|
|
5
5
|
## Unreleased
|
6
6
|
|
7
|
+
## [2.3.0] - 2018-04-20
|
8
|
+
### Added
|
9
|
+
- Support for subscription signature verification
|
10
|
+
- Bang! methods (`capture!`, `refund!`) that update the calling entity
|
11
|
+
|
7
12
|
## [2.2.0] - 2018-01-29
|
8
13
|
### Added
|
9
14
|
- Support for Subscriptions
|
@@ -65,7 +70,8 @@ Changelog for Razorpay-Ruby SDK.
|
|
65
70
|
### Added
|
66
71
|
- Initial Release
|
67
72
|
|
68
|
-
[Unreleased]: https://github.com/razorpay/razorpay-ruby/compare/2.
|
73
|
+
[Unreleased]: https://github.com/razorpay/razorpay-ruby/compare/2.3.0...HEAD
|
74
|
+
[2.3.0]: https://github.com/razorpay/razorpay-ruby/compare/2.2.0...2.3.0
|
69
75
|
[2.2.0]: https://github.com/razorpay/razorpay-ruby/compare/2.1.0...2.2.0
|
70
76
|
[2.1.0]: https://github.com/razorpay/razorpay-ruby/compare/2.0.1...2.1.0
|
71
77
|
[2.1.0.pre]: https://github.com/razorpay/razorpay-ruby/compare/2.0.1...2.1.0.pre
|
data/README.md
CHANGED
@@ -60,6 +60,19 @@ refund = Razorpay::Refund.create(payment_id:"payment_id")
|
|
60
60
|
Razorpay::Refund.fetch(refund.id)
|
61
61
|
```
|
62
62
|
|
63
|
+
If payment is captured or refunded via `capture!` or `refund!`, then the calling object is also updated:
|
64
|
+
```rb
|
65
|
+
payment = Razorpay::Payment.fetch('payment_id')
|
66
|
+
payment.status
|
67
|
+
# 'authorized'
|
68
|
+
payment.capture!
|
69
|
+
payment.status
|
70
|
+
# 'captured'
|
71
|
+
payment.refund!
|
72
|
+
payment.status
|
73
|
+
# 'refunded'
|
74
|
+
```
|
75
|
+
|
63
76
|
For other applications (such as fetching payments and refunds),
|
64
77
|
see our online documentation on <https://docs.razorpay.com>
|
65
78
|
|
data/lib/razorpay/constants.rb
CHANGED
data/lib/razorpay/entity.rb
CHANGED
@@ -5,6 +5,8 @@ module Razorpay
|
|
5
5
|
# This saves data in a hash internally, and makes it available
|
6
6
|
# via direct methods
|
7
7
|
class Entity
|
8
|
+
attr_reader :attributes
|
9
|
+
|
8
10
|
def initialize(attributes)
|
9
11
|
@attributes = attributes
|
10
12
|
end
|
@@ -29,5 +31,16 @@ module Razorpay
|
|
29
31
|
def to_json
|
30
32
|
@attributes.to_json
|
31
33
|
end
|
34
|
+
|
35
|
+
# Mutates the entity in accordance with
|
36
|
+
# the block passed to this construct
|
37
|
+
#
|
38
|
+
# Used to implement bang methods, by calling
|
39
|
+
# the non-bang method in the passed block
|
40
|
+
def with_a_bang
|
41
|
+
mutated_entity = yield
|
42
|
+
@attributes = mutated_entity.attributes
|
43
|
+
mutated_entity
|
44
|
+
end
|
32
45
|
end
|
33
46
|
end
|
data/lib/razorpay/invoice.rb
CHANGED
@@ -37,12 +37,24 @@ module Razorpay
|
|
37
37
|
self.class.edit id, options
|
38
38
|
end
|
39
39
|
|
40
|
+
def edit!(options = {})
|
41
|
+
with_a_bang { edit options }
|
42
|
+
end
|
43
|
+
|
40
44
|
def issue
|
41
45
|
self.class.issue id
|
42
46
|
end
|
43
47
|
|
48
|
+
def issue!
|
49
|
+
with_a_bang { issue }
|
50
|
+
end
|
51
|
+
|
44
52
|
def cancel
|
45
53
|
self.class.cancel id
|
46
54
|
end
|
55
|
+
|
56
|
+
def cancel!
|
57
|
+
with_a_bang { cancel }
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
data/lib/razorpay/payment.rb
CHANGED
@@ -27,10 +27,20 @@ module Razorpay
|
|
27
27
|
self.class.request.post "#{id}/refund", options
|
28
28
|
end
|
29
29
|
|
30
|
+
def refund!(options = {})
|
31
|
+
refund = refund options
|
32
|
+
with_a_bang { self.class.request.fetch id }
|
33
|
+
refund
|
34
|
+
end
|
35
|
+
|
30
36
|
def capture(options)
|
31
37
|
self.class.request.post "#{id}/capture", options
|
32
38
|
end
|
33
39
|
|
40
|
+
def capture!(options)
|
41
|
+
with_a_bang { capture options }
|
42
|
+
end
|
43
|
+
|
34
44
|
def refunds
|
35
45
|
self.class.request.get "#{id}/refunds"
|
36
46
|
end
|
data/lib/razorpay/utility.rb
CHANGED
@@ -5,7 +5,7 @@ module Razorpay
|
|
5
5
|
class Utility
|
6
6
|
def self.verify_payment_signature(attributes)
|
7
7
|
signature = attributes[:razorpay_signature]
|
8
|
-
order_id = attributes[:razorpay_order_id]
|
8
|
+
order_id = attributes[:razorpay_order_id] || attributes[:razorpay_subscription_id]
|
9
9
|
payment_id = attributes[:razorpay_payment_id]
|
10
10
|
|
11
11
|
data = [order_id, payment_id].join '|'
|
@@ -25,6 +25,14 @@ module Razorpay
|
|
25
25
|
request.patch id, status: 'closed'
|
26
26
|
end
|
27
27
|
|
28
|
+
def close
|
29
|
+
self.class.request.patch id, status: 'closed'
|
30
|
+
end
|
31
|
+
|
32
|
+
def close!
|
33
|
+
with_a_bang { close }
|
34
|
+
end
|
35
|
+
|
28
36
|
def payments(options = {})
|
29
37
|
r = self.class.request
|
30
38
|
r.request :get, "/virtual_accounts/#{id}/payments", options
|
data/razorpay-ruby.gemspec
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"id": "fake_payment_id",
|
3
|
+
"entity": "payment",
|
4
|
+
"amount": 500,
|
5
|
+
"currency": "INR",
|
6
|
+
"status": "refunded",
|
7
|
+
"amount_refunded": 500,
|
8
|
+
"refund_status": null,
|
9
|
+
"error_code": null,
|
10
|
+
"error_description": null,
|
11
|
+
"udf": {},
|
12
|
+
"created_at": 1400826750,
|
13
|
+
"method": "card"
|
14
|
+
}
|
@@ -66,6 +66,14 @@ module Razorpay
|
|
66
66
|
assert_invoice_details(invoice)
|
67
67
|
end
|
68
68
|
|
69
|
+
def test_invoice_can_be_issued_by_invoice_instance!
|
70
|
+
stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
|
71
|
+
invoice = Razorpay::Invoice.fetch(@invoice_id)
|
72
|
+
invoice.issue!
|
73
|
+
assert_equal 'issued', invoice.status
|
74
|
+
refute_nil invoice.issued_at
|
75
|
+
end
|
76
|
+
|
69
77
|
def test_invoice_can_be_cancelled_by_invoice_id
|
70
78
|
stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
|
71
79
|
invoice = Razorpay::Invoice.cancel(@invoice_id)
|
@@ -90,15 +98,21 @@ module Razorpay
|
|
90
98
|
assert_invoice_details(invoice)
|
91
99
|
end
|
92
100
|
|
93
|
-
def
|
101
|
+
def test_invoice_can_be_cancelled_by_invoice_instance!
|
102
|
+
stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
|
103
|
+
invoice = Razorpay::Invoice.fetch(@invoice_id)
|
104
|
+
invoice.cancel!
|
105
|
+
assert_equal 'cancelled', invoice.status
|
106
|
+
refute_nil invoice.cancelled_at
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_edit_invoice!
|
94
110
|
invoice = Razorpay::Invoice.fetch(@invoice_id)
|
95
111
|
assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
|
96
112
|
assert_nil invoice.invoice_number
|
97
|
-
|
98
113
|
update_invoice_data = { invoice_number: '12345678' }
|
99
114
|
stub_patch(%r{invoices/#{@invoice_id}$}, 'update_invoice', update_invoice_data)
|
100
|
-
|
101
|
-
invoice = invoice.edit(update_invoice_data)
|
115
|
+
invoice.edit!(update_invoice_data)
|
102
116
|
assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
|
103
117
|
refute_nil invoice.invoice_number
|
104
118
|
end
|
@@ -7,7 +7,7 @@ module Razorpay
|
|
7
7
|
@payment_id = 'fake_payment_id'
|
8
8
|
|
9
9
|
# Any request that ends with payments/payment_id
|
10
|
-
stub_get(%r{payments\/#{
|
10
|
+
stub_get(%r{payments\/#{@payment_id}$}, 'fake_payment')
|
11
11
|
stub_get(/payments$/, 'payment_collection')
|
12
12
|
end
|
13
13
|
|
@@ -43,6 +43,14 @@ module Razorpay
|
|
43
43
|
assert_equal refund.payment_id, @payment_id
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_payment_refund!
|
47
|
+
payment = Razorpay::Payment.fetch(@payment_id)
|
48
|
+
stub_get(%r{payments/#{@payment_id}$}, 'fake_refunded_payment')
|
49
|
+
stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', {})
|
50
|
+
payment.refund!
|
51
|
+
assert_equal 'refunded', payment.status
|
52
|
+
end
|
53
|
+
|
46
54
|
def test_partial_refund
|
47
55
|
# For some reason, stub doesn't work if I pass it a hash of post body
|
48
56
|
stub_post(%r{payments/#{@payment_id}/refund$}, 'fake_refund', 'amount=2000')
|
@@ -59,6 +67,13 @@ module Razorpay
|
|
59
67
|
assert_equal 'captured', payment.status
|
60
68
|
end
|
61
69
|
|
70
|
+
def test_payment_capture!
|
71
|
+
stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
|
72
|
+
payment = Razorpay::Payment.fetch(@payment_id)
|
73
|
+
payment.capture!(amount: 5100)
|
74
|
+
assert_equal 'captured', payment.status
|
75
|
+
end
|
76
|
+
|
62
77
|
def test_payment_capture_without_fetch
|
63
78
|
stub_post(%r{payments/#{@payment_id}/capture$}, 'fake_captured_payment', 'amount=5100')
|
64
79
|
payment = Razorpay::Payment.capture(@payment_id, amount: 5100)
|
@@ -79,6 +79,13 @@ module Razorpay
|
|
79
79
|
assert_subscription_details(subscription)
|
80
80
|
end
|
81
81
|
|
82
|
+
def test_subscription_can_be_cancelled_by_subscription_instance!
|
83
|
+
stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
|
84
|
+
subscription = Razorpay::Subscription.fetch(@subscription_id)
|
85
|
+
subscription.cancel!
|
86
|
+
assert_equal 'cancelled', subscription.status
|
87
|
+
end
|
88
|
+
|
82
89
|
private
|
83
90
|
|
84
91
|
def assert_subscription_details(subscription)
|
@@ -21,6 +21,20 @@ module Razorpay
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_subscription_signature_verification
|
25
|
+
payment_response = {
|
26
|
+
razorpay_subscription_id: 'fake_order_id',
|
27
|
+
razorpay_payment_id: 'fake_payment_id',
|
28
|
+
razorpay_signature: 'b2335e3b0801106b84a7faff035df56ecffde06918c9ddd1f0fafbb37a51cc89'
|
29
|
+
}
|
30
|
+
Razorpay::Utility.verify_payment_signature(payment_response)
|
31
|
+
|
32
|
+
payment_response[:razorpay_signature] = '_dummy_signature' * 4
|
33
|
+
assert_raises(SecurityError) do
|
34
|
+
Razorpay::Utility.verify_payment_signature(payment_response)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
24
38
|
def test_webhook_signature_verification
|
25
39
|
webhook_body = fixture_file('fake_payment_authorized_webhook')
|
26
40
|
secret = 'chosen_webhook_secret'
|
@@ -36,13 +36,29 @@ module Razorpay
|
|
36
36
|
assert_includes receiver.keys, 'account_number'
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def test_close_virtual_account_class_method
|
40
40
|
stub_patch(%r{virtual_accounts/#{@virtual_account_id}$}, 'fake_virtual_account_closed', 'status=closed')
|
41
41
|
virtual_account = Razorpay::VirtualAccount.close(@virtual_account_id)
|
42
42
|
assert_instance_of Razorpay::VirtualAccount, virtual_account
|
43
43
|
assert_equal 'closed', virtual_account.status
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_close_virtual_account
|
47
|
+
stub_patch(%r{virtual_accounts/#{@virtual_account_id}$}, 'fake_virtual_account_closed', 'status=closed')
|
48
|
+
virtual_account = Razorpay::VirtualAccount.fetch(@virtual_account_id)
|
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
|
+
assert_instance_of Razorpay::VirtualAccount, virtual_account
|
59
|
+
assert_equal 'closed', virtual_account.status
|
60
|
+
end
|
61
|
+
|
46
62
|
def test_fetch_all_virtual_accounts
|
47
63
|
virtual_accounts = Razorpay::VirtualAccount.all
|
48
64
|
assert_instance_of Razorpay::Collection, virtual_accounts
|
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: 2.
|
4
|
+
version: 2.3.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: 2018-
|
12
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- test/fixtures/fake_payment_bank_transfer.json
|
153
153
|
- test/fixtures/fake_plan.json
|
154
154
|
- test/fixtures/fake_refund.json
|
155
|
+
- test/fixtures/fake_refunded_payment.json
|
155
156
|
- test/fixtures/fake_subscription.json
|
156
157
|
- test/fixtures/fake_virtual_account.json
|
157
158
|
- test/fixtures/fake_virtual_account_closed.json
|
@@ -226,6 +227,7 @@ test_files:
|
|
226
227
|
- test/fixtures/fake_payment_bank_transfer.json
|
227
228
|
- test/fixtures/fake_plan.json
|
228
229
|
- test/fixtures/fake_refund.json
|
230
|
+
- test/fixtures/fake_refunded_payment.json
|
229
231
|
- test/fixtures/fake_subscription.json
|
230
232
|
- test/fixtures/fake_virtual_account.json
|
231
233
|
- test/fixtures/fake_virtual_account_closed.json
|