razorpay 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e44bdd7fd838ec1ac184e39eafccd535f4789083
4
- data.tar.gz: f38d503263f55d2e493e9ce046ce671621f2f69f
3
+ metadata.gz: 9694a52cd9fc7e6968d50450c8cd6baedcb13031
4
+ data.tar.gz: c8b1e34dc5549b3d5a3bde42447a4bac74271326
5
5
  SHA512:
6
- metadata.gz: 4b581f65deb6964ebe58bb6a244f72f14f22c56392983cbaf02f307e6793d2b2ac9d57757756d256388d130b19262cc46e7df85fd2b768bbc6e139aafe519937
7
- data.tar.gz: '078dfff04cd5ed1a6c6c9c2be451d8056dfbb5821f0b12fc816750451d0cbe8aba1b877ba4e1d6e03c13f8a8d5e8cd1bd5f061de72849286b9941923243d8af8'
6
+ metadata.gz: 655d3f40379bd8f58ce447fd3d96f6c2420909abf627d6775977a56d8809fd87dfaf4a66a0a341e23f7efe07d971ce146930d919f498d907fa37a9d64fcdef6d
7
+ data.tar.gz: 528df3860b6623d9215b097b5e4b82192ee444c980c5db7d13b618d77beafd8bb0ce1bd5ed46cbce1360a34bd591e0a7b225d376244c0eae9968d402adb42bfb
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ vendor
@@ -1,10 +1,26 @@
1
1
  language: ruby
2
- rvm:
3
- - "2.1.10"
4
- - "2.2.6"
5
- - "2.3.3"
6
- - "2.4.0"
2
+ # List is from https://www.ruby-lang.org/en/downloads/branches/
3
+ # Merged with whatever is the top of each branch at https://www.ruby-lang.org/en/downloads/releases/
4
+ matrix:
5
+ include:
6
+ - rvm: "1.9.3"
7
+ - rvm: "2.0.0"
8
+ - rvm: "2.1.10"
9
+ - rvm: "2.2.9"
10
+ - rvm: "2.3.6"
11
+ - rvm: "2.4.2"
12
+ - rvm: "2.5.0"
13
+ - rvm: "2.5.0"
14
+ env: LINT=rubocop
15
+ allow_failures:
16
+ # These are EOL versions of ruby
17
+ - rvm: "1.9.3"
18
+ - rvm: "2.0.0"
19
+ - rvm: "2.1.10"
7
20
  before_install: gem update --system
8
21
  script:
9
22
  - bundle exec rake test
10
- - bundle exec rake rubocop
23
+ - |
24
+ if [[ "$LINT" == "rubocop" ]] ; then
25
+ bundle exec rake rubocop
26
+ fi
@@ -4,6 +4,10 @@ Changelog for Razorpay-Ruby SDK.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## [2.2.0] - 2018-01-29
8
+ ### Added
9
+ - Support for Subscriptions
10
+
7
11
  ## [2.1.0] - 2017-11-17
8
12
  ### Changed
9
13
  - Generic `Razorpay::Error` is thrown when server is unreachable
@@ -61,7 +65,8 @@ Changelog for Razorpay-Ruby SDK.
61
65
  ### Added
62
66
  - Initial Release
63
67
 
64
- [Unreleased]: https://github.com/razorpay/razorpay-ruby/compare/2.1.0...HEAD
68
+ [Unreleased]: https://github.com/razorpay/razorpay-ruby/compare/2.2.0...HEAD
69
+ [2.2.0]: https://github.com/razorpay/razorpay-ruby/compare/2.1.0...2.2.0
65
70
  [2.1.0]: https://github.com/razorpay/razorpay-ruby/compare/2.0.1...2.1.0
66
71
  [2.1.0.pre]: https://github.com/razorpay/razorpay-ruby/compare/2.0.1...2.1.0.pre
67
72
  [2.0.1]: https://github.com/razorpay/razorpay-ruby/compare/2.0.0...2.0.1
data/README.md CHANGED
@@ -124,6 +124,33 @@ invoice = Razorpay::Invoice.create customer_id: customer.id, amount: 100, curren
124
124
 
125
125
  You can find invoices API documentation at <https://docs.razorpay.com/v1/page/invoices>.
126
126
 
127
+ ### Plan
128
+ ```rb
129
+ # Creating a plan
130
+ plan = Razorpay::Plan.create interval: 1, period: 'monthly', item: { name: 'fake_plan', description: 'fake_desc', currency: 'INR', amount: 500 }, notes: { identifier: 'plan_monthly_super' }
131
+ ```
132
+
133
+ You can find plan API documentation at <https://razorpay.com/docs/subscriptions/api/#plan>.
134
+
135
+ ### Subscription
136
+ ```rb
137
+ # Creating a subscription and starting after 24 hours (24 hours = 60 * 60 * 24)
138
+ subscription = Razorpay::Subscription.create plan_id: plan.id, customer_id: customer.id, start_at: (Time.now + (60 * 60 * 24)).to_i, total_count: 3
139
+ ```
140
+
141
+ You can find subscription API documentation at <https://razorpay.com/docs/subscriptions/api/#subscription>.
142
+
143
+ ### Addon
144
+ ```rb
145
+ # Creating an addon
146
+ subscription_addon = Razorpay::Addon.create subscription.id, item: { name: 'fake_plan', description: 'fake_desc', currency: 'INR', amount: 500 }, quantity: 1
147
+
148
+ # Fetching an addon
149
+ addon = Razorpay::Addon.fetch subscription_addon.id
150
+ ```
151
+
152
+ You can find addon API documentation at <https://razorpay.com/docs/subscriptions/api/#add-on>.
153
+
127
154
  ## Development
128
155
 
129
156
  - Everything is namespaced under the Razorpay module
@@ -143,6 +170,19 @@ You can find invoices API documentation at <https://docs.razorpay.com/v1/page/in
143
170
  5. Push to the branch (`git push origin my-new-feature`)
144
171
  6. Create a new Pull Request
145
172
 
173
+ ## Supported Versions
174
+
175
+ While we support [all currently supported versions of Ruby](https://www.ruby-lang.org/en/downloads/branches/)
176
+ only, the code is tested against the following versions:
177
+
178
+ * 1.9.3
179
+ * 2.0.0
180
+ * 2.1.10
181
+ * 2.2.9
182
+ * 2.3.6
183
+ * 2.4.2
184
+ * 2.5.0
185
+
146
186
  ## Release
147
187
 
148
188
  Steps to follow for a release:
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rake/testtask'
2
- require 'rubocop/rake_task'
2
+
3
+ # Don't try to run rubocop in 1.9.3
4
+ require 'rubocop/rake_task' if RUBY_VERSION >= '2.1.0'
3
5
 
4
6
  Rake::TestTask.new do |t|
5
7
  t.libs << 'test'
@@ -8,7 +10,7 @@ Rake::TestTask.new do |t|
8
10
  end
9
11
 
10
12
  desc 'Run tests'
11
- task default: [:test, :rubocop]
13
+ task default: [:test]
12
14
 
13
15
  desc 'Run rubocop'
14
16
  task :rubocop do
@@ -9,6 +9,9 @@ require 'razorpay/customer'
9
9
  require 'razorpay/constants'
10
10
  require 'razorpay/collection'
11
11
  require 'razorpay/virtual_account'
12
+ require 'razorpay/plan'
13
+ require 'razorpay/subscription'
14
+ require 'razorpay/addon'
12
15
 
13
16
  # Base Razorpay module
14
17
  module Razorpay
@@ -0,0 +1,24 @@
1
+ require 'razorpay/request'
2
+ require 'razorpay/entity'
3
+
4
+ module Razorpay
5
+ # Addon API allows you to fetch and delete
6
+ # subscription-addons with Razorpay
7
+ class Addon < Entity
8
+ def self.request
9
+ Razorpay::Request.new('addons')
10
+ end
11
+
12
+ def self.fetch(id)
13
+ request.fetch id
14
+ end
15
+
16
+ def self.create(subscription_id, options)
17
+ r = request
18
+ # POST /addons is not supported
19
+ # Addon creation endpoint is:
20
+ # POST subscriptions/{sub_id}/addons
21
+ r.request :post, "/subscriptions/#{subscription_id}/addons", options
22
+ end
23
+ end
24
+ end
@@ -2,5 +2,5 @@
2
2
  module Razorpay
3
3
  BASE_URI = 'https://api.razorpay.com/v1/'.freeze
4
4
  TEST_URL = 'https://api.razorpay.com/'.freeze
5
- VERSION = '2.1.0'.freeze
5
+ VERSION = '2.2.0'.freeze
6
6
  end
@@ -20,5 +20,29 @@ module Razorpay
20
20
  def self.all(options = {})
21
21
  request.all options
22
22
  end
23
+
24
+ def self.edit(id, options = {})
25
+ request.patch id, options
26
+ end
27
+
28
+ def self.issue(id)
29
+ request.post "#{id}/issue"
30
+ end
31
+
32
+ def self.cancel(id)
33
+ request.post "#{id}/cancel"
34
+ end
35
+
36
+ def edit(options = {})
37
+ self.class.edit id, options
38
+ end
39
+
40
+ def issue
41
+ self.class.issue id
42
+ end
43
+
44
+ def cancel
45
+ self.class.cancel id
46
+ end
23
47
  end
24
48
  end
@@ -0,0 +1,24 @@
1
+ require 'razorpay/request'
2
+ require 'razorpay/entity'
3
+
4
+ module Razorpay
5
+ # Plan API allows you to create and
6
+ # manage subscription-plans with Razorpay
7
+ class Plan < Entity
8
+ def self.request
9
+ Razorpay::Request.new('plans')
10
+ end
11
+
12
+ def self.create(options)
13
+ request.create options
14
+ end
15
+
16
+ def self.fetch(id)
17
+ request.fetch id
18
+ end
19
+
20
+ def self.all(options = {})
21
+ request.all options
22
+ end
23
+ end
24
+ end
@@ -80,9 +80,7 @@ module Razorpay
80
80
  response = res.parsed_response
81
81
 
82
82
  # if there was an error, throw it
83
- if response.nil? || response.key?('error')
84
- raise_error(response['error'], res.code)
85
- end
83
+ raise_error(response['error'], res.code) if response.nil? || response.key?('error')
86
84
 
87
85
  # There must be a top level entity
88
86
  # This is either one of payment, refund, or collection at present
@@ -0,0 +1,32 @@
1
+ require 'razorpay/request'
2
+ require 'razorpay/entity'
3
+
4
+ module Razorpay
5
+ # Subscription API allows you to create and
6
+ # manage subscriptions with Razorpay
7
+ class Subscription < Entity
8
+ def self.request
9
+ Razorpay::Request.new('subscriptions')
10
+ end
11
+
12
+ def self.create(options)
13
+ request.create options
14
+ end
15
+
16
+ def self.fetch(id)
17
+ request.fetch id
18
+ end
19
+
20
+ def self.all(options = {})
21
+ request.all options
22
+ end
23
+
24
+ def self.cancel(id, options = {})
25
+ request.post "#{id}/cancel", options
26
+ end
27
+
28
+ def cancel(options = {})
29
+ self.class.cancel id, options
30
+ end
31
+ end
32
+ end
@@ -17,10 +17,20 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(/^(test|spec|features)/)
18
18
  spec.require_paths = ['lib']
19
19
 
20
+ spec.add_dependency 'httparty', '~> 0.14'
21
+
20
22
  spec.add_development_dependency 'coveralls', '~> 0.8'
21
- spec.add_development_dependency 'minitest', '~> 5.10'
23
+ spec.add_development_dependency 'minitest', '~> 5.11'
22
24
  spec.add_development_dependency 'rake', '~> 12.0'
23
- spec.add_development_dependency 'rubocop', '~> 0.49'
24
- spec.add_development_dependency 'webmock', '~> 2.3'
25
- spec.add_dependency 'httparty', '~> 0.14'
25
+
26
+ if RUBY_VERSION >= '2.1.0'
27
+ # rubocop is only run in the latest ruby build
28
+ # so we use the latest version and don't switch to a
29
+ # older version for 1.9.3
30
+ spec.add_development_dependency 'rubocop', '~> 0.49'
31
+ spec.add_development_dependency 'webmock', '~> 3.0'
32
+ else
33
+ # Webmock 3.0 does not support Ruby 1.9.3
34
+ spec.add_development_dependency 'webmock', '~> 2.3'
35
+ end
26
36
  end
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "inv_6vRZmJYFAG1mNq",
3
+ "entity": "invoice",
4
+ "receipt": null,
5
+ "invoice_number": null,
6
+ "customer_id": "cust_6vRXClWqnLhV14",
7
+ "customer_details": {
8
+ "customer_name": null,
9
+ "customer_email": "test@razorpay.com",
10
+ "customer_contact": "9876543210",
11
+ "customer_address": null
12
+ },
13
+ "order_id": "order_6vRZmJu7EPEMY0",
14
+ "line_items": [],
15
+ "payment_id": null,
16
+ "expire_by": null,
17
+ "status": "cancelled",
18
+ "issued_at": 1482299421,
19
+ "paid_at": null,
20
+ "cancelled_at": 1482299424,
21
+ "expired_at": null,
22
+ "sms_status": "sent",
23
+ "email_status": "sent",
24
+ "date": 1482299421,
25
+ "partial_payment": false,
26
+ "terms": null,
27
+ "gross_amount": 100,
28
+ "tax_amount": 0,
29
+ "amount": 100,
30
+ "amount_paid": 100,
31
+ "amount_due": 0,
32
+ "description": "Test description",
33
+ "notes": [],
34
+ "currency": "INR",
35
+ "short_url": "http://bit.ly/2i8kSqu",
36
+ "comment": null,
37
+ "view_less": true,
38
+ "type": "invoice",
39
+ "billing_start": null,
40
+ "billing_end": null,
41
+ "group_taxes_amounts": false,
42
+ "user_id": "fake_user_id",
43
+ "created_at": 1482299422
44
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "id": "fake_subscription_id",
3
+ "entity": "subscription",
4
+ "plan_id": "fake_plan_id",
5
+ "customer_id": "fake_customer_id",
6
+ "status": "cancelled",
7
+ "current_start": null,
8
+ "current_end": null,
9
+ "ended_at": 1509494400,
10
+ "quantity": 1,
11
+ "notes": [],
12
+ "charge_at": 1509494400,
13
+ "start_at": 1509494400,
14
+ "end_at": 1538332200,
15
+ "auth_attempts": 0,
16
+ "total_count": 12,
17
+ "paid_count": 0,
18
+ "customer_notify": true,
19
+ "created_at": 1509114729
20
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "fake_addon_id",
3
+ "entity": "addon",
4
+ "item": {
5
+ "id": "fake_item_id",
6
+ "active": true,
7
+ "name": "fake_item_name",
8
+ "description": "fake_item_description",
9
+ "amount": 500,
10
+ "unit_amount": 500,
11
+ "currency": "INR",
12
+ "type": "addon",
13
+ "unit": null,
14
+ "tax_inclusive": false,
15
+ "tax_id": null,
16
+ "tax_group_id": null,
17
+ "created_at": 1511525691,
18
+ "updated_at": 1511525691
19
+ },
20
+ "quantity": 1,
21
+ "created_at": 1511525697,
22
+ "subscription_id": "fake_subscription_id",
23
+ "invoice_id": null
24
+ }
@@ -2,6 +2,7 @@
2
2
  "id": "inv_6vRZmJYFAG1mNq",
3
3
  "entity": "invoice",
4
4
  "receipt": null,
5
+ "invoice_number": null,
5
6
  "customer_id": "cust_6vRXClWqnLhV14",
6
7
  "customer_details": {
7
8
  "customer_name": null,
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "fake_plan_id",
3
+ "entity": "plan",
4
+ "interval": 1,
5
+ "period": "monthly",
6
+ "item": {
7
+ "id": "item_92ARNuCnESXZkj",
8
+ "active": true,
9
+ "name": "Plan 751..1000",
10
+ "description": "Share docs + user mgmt",
11
+ "amount": 2500000,
12
+ "unit_amount": 2500000,
13
+ "currency": "INR",
14
+ "type": "plan",
15
+ "unit": null,
16
+ "tax_inclusive": false,
17
+ "tax_id": null,
18
+ "tax_group_id": null,
19
+ "created_at": 1510841630,
20
+ "updated_at": 1510841630
21
+ },
22
+ "notes": {
23
+ "identifier": "plan_monthly_1000"
24
+ },
25
+ "created_at": 1510841630
26
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "id": "fake_subscription_id",
3
+ "entity": "subscription",
4
+ "plan_id": "fake_plan_id",
5
+ "customer_id": "fake_customer_id",
6
+ "status": "created",
7
+ "current_start": null,
8
+ "current_end": null,
9
+ "ended_at": null,
10
+ "quantity": 1,
11
+ "notes": [],
12
+ "charge_at": 1509494400,
13
+ "start_at": 1509494400,
14
+ "end_at": 1538332200,
15
+ "auth_attempts": 0,
16
+ "total_count": 12,
17
+ "paid_count": 0,
18
+ "customer_notify": true,
19
+ "created_at": 1509114729
20
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "inv_6vRZmJYFAG1mNq",
3
+ "entity": "invoice",
4
+ "receipt": null,
5
+ "invoice_number": null,
6
+ "customer_id": "cust_6vRXClWqnLhV14",
7
+ "customer_details": {
8
+ "customer_name": null,
9
+ "customer_email": "test@razorpay.com",
10
+ "customer_contact": "9876543210",
11
+ "customer_address": null
12
+ },
13
+ "order_id": "order_6vRZmJu7EPEMY0",
14
+ "line_items": [],
15
+ "payment_id": null,
16
+ "expire_by": null,
17
+ "status": "issued",
18
+ "issued_at": 1482299421,
19
+ "paid_at": null,
20
+ "cancelled_at": null,
21
+ "expired_at": null,
22
+ "sms_status": "sent",
23
+ "email_status": "sent",
24
+ "date": 1482299421,
25
+ "partial_payment": false,
26
+ "terms": null,
27
+ "gross_amount": 100,
28
+ "tax_amount": 0,
29
+ "amount": 100,
30
+ "amount_paid": 100,
31
+ "amount_due": 0,
32
+ "description": "Test description",
33
+ "notes": [],
34
+ "currency": "INR",
35
+ "short_url": "http://bit.ly/2i8kSqu",
36
+ "comment": null,
37
+ "view_less": true,
38
+ "type": "invoice",
39
+ "billing_start": null,
40
+ "billing_end": null,
41
+ "group_taxes_amounts": false,
42
+ "user_id": "fake_user_id",
43
+ "created_at": 1482299422
44
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "entity": "collection",
3
+ "count": 1,
4
+ "items": [
5
+ {
6
+ "id": "plan_92ARNuOYid1CoJ",
7
+ "entity": "plan",
8
+ "interval": 1,
9
+ "period": "monthly",
10
+ "item": {
11
+ "id": "item_92ARNuCnESXZkj",
12
+ "active": true,
13
+ "name": "Plan 751..1000",
14
+ "description": "Share docs + user mgmt",
15
+ "amount": 2500000,
16
+ "unit_amount": 2500000,
17
+ "currency": "INR",
18
+ "type": "plan",
19
+ "unit": null,
20
+ "tax_inclusive": false,
21
+ "tax_id": null,
22
+ "tax_group_id": null,
23
+ "created_at": 1510841630,
24
+ "updated_at": 1510841630
25
+ },
26
+ "notes": {
27
+ "identifier": "plan_monthly_1000"
28
+ },
29
+ "created_at": 1510841630
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "entity":"collection",
3
+ "count":10,
4
+ "items": [
5
+ {
6
+ "id": "fake_subscription_id",
7
+ "entity": "subscription",
8
+ "plan_id": "fake_plan_id",
9
+ "customer_id": "fake_customer_id",
10
+ "status": "created",
11
+ "current_start": null,
12
+ "current_end": null,
13
+ "ended_at": null,
14
+ "quantity": 1,
15
+ "notes": [],
16
+ "charge_at": 1509494400,
17
+ "start_at": 1509494400,
18
+ "end_at": 1538332200,
19
+ "auth_attempts": 0,
20
+ "total_count": 12,
21
+ "paid_count": 0,
22
+ "customer_notify": true,
23
+ "created_at": 1509114729
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "inv_6vRZmJYFAG1mNq",
3
+ "entity": "invoice",
4
+ "receipt": "12345678",
5
+ "invoice_number": "12345678",
6
+ "customer_id": "cust_6vRXClWqnLhV14",
7
+ "customer_details": {
8
+ "customer_name": null,
9
+ "customer_email": "test@razorpay.com",
10
+ "customer_contact": "9876543210",
11
+ "customer_address": null
12
+ },
13
+ "order_id": "order_6vRZmJu7EPEMY0",
14
+ "line_items": [],
15
+ "payment_id": null,
16
+ "expire_by": null,
17
+ "status": "issued",
18
+ "issued_at": 1482299421,
19
+ "paid_at": null,
20
+ "cancelled_at": null,
21
+ "expired_at": null,
22
+ "sms_status": "sent",
23
+ "email_status": "sent",
24
+ "date": 1482299421,
25
+ "partial_payment": false,
26
+ "terms": null,
27
+ "gross_amount": 100,
28
+ "tax_amount": 0,
29
+ "amount": 100,
30
+ "amount_paid": 100,
31
+ "amount_due": 0,
32
+ "description": "Test description",
33
+ "notes": [],
34
+ "currency": "INR",
35
+ "short_url": "http://bit.ly/2i8kSqu",
36
+ "comment": null,
37
+ "view_less": true,
38
+ "type": "invoice",
39
+ "billing_start": null,
40
+ "billing_end": null,
41
+ "group_taxes_amounts": false,
42
+ "user_id": "fake_user_id",
43
+ "created_at": 1482299422
44
+ }
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ module Razorpay
4
+ # Tests for Razorpay::Addon
5
+ class RazorpayAddonTest < Minitest::Test
6
+ class Item < Razorpay::Entity; end
7
+
8
+ def setup
9
+ @subscription_id = 'fake_subscription_id'
10
+ @addon_id = 'fake_addon_id'
11
+
12
+ # Any request that ends with addons/addon_id
13
+ stub_get(%r{addons\/#{Regexp.quote(@addon_id)}$}, 'fake_addon')
14
+ end
15
+
16
+ def test_addon_should_be_defined
17
+ refute_nil Razorpay::Addon
18
+ end
19
+
20
+ def test_addon_should_be_available
21
+ addon = Razorpay::Addon.fetch(@addon_id)
22
+ assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
23
+ assert_equal @addon_id, addon.id, 'Addon IDs do not match'
24
+ assert_equal 1, addon.quantity, 'Addon quantity is accessible'
25
+ assert_equal 'fake_subscription_id', addon.subscription_id, 'Addon subscription_id is accessible'
26
+ assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
27
+
28
+ assert_addon_item_details(addon)
29
+ end
30
+
31
+ def test_add_addons_to_subscription
32
+ addon_attrs = {
33
+ item: {
34
+ name: 'fake_addon_name', currency: 'INR', amount: 5000,
35
+ description: 'fake_addon_description'
36
+ },
37
+ quantity: 1
38
+ }
39
+
40
+ stub_post(%r{subscriptions\/#{@subscription_id}\/addons$}, 'fake_addon', create_addon_stub_url_params)
41
+
42
+ addon = Razorpay::Addon.create(@subscription_id, addon_attrs)
43
+ assert_instance_of Razorpay::Addon, addon, 'Addon not an instance of Addon class'
44
+
45
+ assert_equal 'fake_addon_id', addon.id, 'Addon IDs do not match'
46
+ assert_equal 1, addon.quantity, 'Addon quantity is accessible'
47
+ assert_equal 'fake_subscription_id', addon.subscription_id, 'Addon subscription_id is accessible'
48
+ assert_nil addon.invoice_id, 'Addon invoice_id is accessible'
49
+
50
+ assert_addon_item_details(addon)
51
+ end
52
+
53
+ private
54
+
55
+ def assert_addon_item_details(addon)
56
+ addon_item = Item.new(addon.item)
57
+
58
+ assert_equal 'fake_item_id', addon_item.id, 'Addon Item id is accessible'
59
+ assert_equal 'fake_item_name', addon_item.name, 'Addon Item name is accessible'
60
+ assert_equal 'fake_item_description', addon_item.description, 'Addon Item description is accessible'
61
+ assert_equal 'INR', addon_item.currency, 'Addon Item currency is accessible'
62
+ assert_equal 500, addon_item.amount, 'Addon Item amount is accessible'
63
+ end
64
+
65
+ def create_addon_stub_url_params
66
+ %w(
67
+ item[name]=fake_addon_name&item[currency]=INR&item[amount]=5000&
68
+ item[description]=fake_addon_description&quantity=1
69
+ ).join
70
+ end
71
+ end
72
+ end
@@ -41,5 +41,76 @@ module Razorpay
41
41
  assert_instance_of Razorpay::Collection, invoices, 'Invoices should be an array'
42
42
  assert !invoices.items.empty?, 'invoices should be more than one'
43
43
  end
44
+
45
+ def test_invoice_can_be_issued_by_invoice_id
46
+ stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
47
+ invoice = Razorpay::Invoice.issue(@invoice_id)
48
+
49
+ assert_equal 'issued', invoice.status
50
+ refute_nil invoice.issued_at
51
+
52
+ assert_invoice_details(invoice)
53
+ end
54
+
55
+ def test_invoice_can_be_issued_by_invoice_instance
56
+ stub_post(%r{invoices\/#{@invoice_id}\/issue$}, 'issue_invoice', {})
57
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
58
+
59
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
60
+
61
+ invoice = invoice.issue
62
+
63
+ assert_equal 'issued', invoice.status
64
+ refute_nil invoice.issued_at
65
+
66
+ assert_invoice_details(invoice)
67
+ end
68
+
69
+ def test_invoice_can_be_cancelled_by_invoice_id
70
+ stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
71
+ invoice = Razorpay::Invoice.cancel(@invoice_id)
72
+
73
+ assert_equal 'cancelled', invoice.status
74
+ refute_nil invoice.cancelled_at
75
+
76
+ assert_invoice_details(invoice)
77
+ end
78
+
79
+ def test_invoice_can_be_cancelled_by_invoice_instance
80
+ stub_post(%r{invoices\/#{@invoice_id}\/cancel$}, 'cancel_invoice', {})
81
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
82
+
83
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
84
+
85
+ invoice = invoice.cancel
86
+
87
+ assert_equal 'cancelled', invoice.status
88
+ refute_nil invoice.cancelled_at
89
+
90
+ assert_invoice_details(invoice)
91
+ end
92
+
93
+ def test_edit_invoice
94
+ invoice = Razorpay::Invoice.fetch(@invoice_id)
95
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
96
+ assert_nil invoice.invoice_number
97
+
98
+ update_invoice_data = { invoice_number: '12345678' }
99
+ stub_patch(%r{invoices/#{@invoice_id}$}, 'update_invoice', update_invoice_data)
100
+
101
+ invoice = invoice.edit(update_invoice_data)
102
+ assert_instance_of Razorpay::Invoice, invoice, 'invoice not an instance of Razorpay::Invoice class'
103
+ refute_nil invoice.invoice_number
104
+ end
105
+
106
+ private
107
+
108
+ def assert_invoice_details(invoice)
109
+ assert_equal 'cust_6vRXClWqnLhV14', invoice.customer_id
110
+ assert_equal 100, invoice.amount
111
+ assert_equal 'INR', invoice.currency
112
+ assert_equal 'Test description', invoice.description
113
+ assert_equal 'invoice', invoice.type
114
+ end
44
115
  end
45
116
  end
@@ -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', create_plan_stub_url_params)
46
+
47
+ plan = Razorpay::Plan.create plan_attrs
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&notes[identifier]=plan_monthly_1000
62
+ ).join
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,95 @@
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
+
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_created
36
+ time_now = Time.now.to_i
37
+ subscription_attrs = {
38
+ plan_id: 'fake_plan_id', customer_id: 'fake_customer_id',
39
+ start_at: time_now, total_count: 12
40
+ }
41
+
42
+ stub_params = "plan_id=fake_plan_id&customer_id=fake_customer_id&start_at=#{time_now}&total_count=12"
43
+ stub_post(/subscriptions$/, 'fake_subscription', stub_params)
44
+
45
+ subscription = Razorpay::Subscription.create subscription_attrs
46
+ assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
47
+
48
+ assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
49
+ assert_equal 'created', subscription.status, 'Subscription status is accessible'
50
+
51
+ assert_subscription_details(subscription)
52
+ end
53
+
54
+ def test_subscription_can_be_cancelled_by_subscription_id
55
+ stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
56
+ subscription = Razorpay::Subscription.cancel(@subscription_id)
57
+
58
+ assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
59
+ assert_equal 'cancelled', subscription.status, 'Subscription status is accessible'
60
+
61
+ assert_subscription_details(subscription)
62
+ end
63
+
64
+ def test_subscription_can_be_cancelled_by_subscription_instance
65
+ stub_post(%r{subscriptions\/#{@subscription_id}\/cancel$}, 'cancel_subscription', {})
66
+ subscription = Razorpay::Subscription.fetch(@subscription_id)
67
+
68
+ assert_instance_of Razorpay::Subscription, subscription, 'not an instance of Subscription class'
69
+ assert_equal @subscription_id, subscription.id, 'subscription IDs do not match'
70
+ assert_equal 'created', subscription.status, 'Subscription status is accessible'
71
+ assert_nil subscription.ended_at, 'Subscription ended_at is accessible'
72
+
73
+ subscription = subscription.cancel(cancel_at_cycle_end: 1)
74
+
75
+ assert_equal @subscription_id, subscription.id, 'Subscription IDs do not match'
76
+ assert_equal 'cancelled', subscription.status, 'Subscription status is accessible'
77
+ refute_nil subscription.ended_at, 'Subscription ended_at is accessible'
78
+
79
+ assert_subscription_details(subscription)
80
+ end
81
+
82
+ private
83
+
84
+ def assert_subscription_details(subscription)
85
+ assert_equal 'fake_plan_id', subscription.plan_id, 'Subscription plan_id is accessible'
86
+ assert_equal 'fake_customer_id', subscription.customer_id, 'Subscription customer_id is accessible'
87
+ assert_equal 12, subscription.total_count, 'Subscription total_count is accessible'
88
+ assert_equal 0, subscription.paid_count, 'Subscription paid_count is accessible'
89
+ refute_nil subscription.charge_at, 'Subscription charge_at is accessible'
90
+ refute_nil subscription.start_at, 'Subscription start_at is accessible'
91
+ refute_nil subscription.end_at, 'Subscription end_at is accessible'
92
+ assert_equal [], subscription.notes, 'Subscription notes is accessible'
93
+ end
94
+ end
95
+ 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: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhay Rana
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-17 00:00:00.000000000 Z
12
+ date: 2018-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.14'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.14'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: coveralls
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -31,14 +45,14 @@ dependencies:
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: '5.10'
48
+ version: '5.11'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: '5.10'
55
+ version: '5.11'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -73,28 +87,14 @@ dependencies:
73
87
  requirements:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '2.3'
90
+ version: '3.0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '2.3'
84
- - !ruby/object:Gem::Dependency
85
- name: httparty
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '0.14'
91
- type: :runtime
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '0.14'
97
+ version: '3.0'
98
98
  description: Official ruby bindings for the Razorpay API
99
99
  email:
100
100
  - nemo@razorpay.com
@@ -115,6 +115,7 @@ files:
115
115
  - Rakefile
116
116
  - lib/ca-bundle.crt
117
117
  - lib/razorpay.rb
118
+ - lib/razorpay/addon.rb
118
119
  - lib/razorpay/card.rb
119
120
  - lib/razorpay/collection.rb
120
121
  - lib/razorpay/constants.rb
@@ -128,13 +129,18 @@ files:
128
129
  - lib/razorpay/invoice.rb
129
130
  - lib/razorpay/order.rb
130
131
  - lib/razorpay/payment.rb
132
+ - lib/razorpay/plan.rb
131
133
  - lib/razorpay/refund.rb
132
134
  - lib/razorpay/request.rb
135
+ - lib/razorpay/subscription.rb
133
136
  - lib/razorpay/utility.rb
134
137
  - lib/razorpay/virtual_account.rb
135
138
  - razorpay-ruby.gemspec
136
139
  - test/fixtures/bad_request_error.json
140
+ - test/fixtures/cancel_invoice.json
141
+ - test/fixtures/cancel_subscription.json
137
142
  - test/fixtures/customer_collection.json
143
+ - test/fixtures/fake_addon.json
138
144
  - test/fixtures/fake_captured_payment.json
139
145
  - test/fixtures/fake_card.json
140
146
  - test/fixtures/fake_customer.json
@@ -144,19 +150,26 @@ files:
144
150
  - test/fixtures/fake_payment.json
145
151
  - test/fixtures/fake_payment_authorized_webhook.json
146
152
  - test/fixtures/fake_payment_bank_transfer.json
153
+ - test/fixtures/fake_plan.json
147
154
  - test/fixtures/fake_refund.json
155
+ - test/fixtures/fake_subscription.json
148
156
  - test/fixtures/fake_virtual_account.json
149
157
  - test/fixtures/fake_virtual_account_closed.json
150
158
  - test/fixtures/fake_virtual_account_collection.json
151
159
  - test/fixtures/hello_response.json
152
160
  - test/fixtures/invoice_collection.json
161
+ - test/fixtures/issue_invoice.json
153
162
  - test/fixtures/order_collection.json
154
163
  - test/fixtures/order_payments.json
155
164
  - test/fixtures/payment_collection.json
156
165
  - test/fixtures/payment_collection_with_one_payment.json
166
+ - test/fixtures/plan_collection.json
157
167
  - test/fixtures/refund_collection.json
158
168
  - test/fixtures/refund_collection_for_payment.json
169
+ - test/fixtures/subscription_collection.json
170
+ - test/fixtures/update_invoice.json
159
171
  - test/fixtures/welcome.json
172
+ - test/razorpay/test_addon.rb
160
173
  - test/razorpay/test_card.rb
161
174
  - test/razorpay/test_customer.rb
162
175
  - test/razorpay/test_entity.rb
@@ -164,9 +177,11 @@ files:
164
177
  - test/razorpay/test_invoice.rb
165
178
  - test/razorpay/test_order.rb
166
179
  - test/razorpay/test_payment.rb
180
+ - test/razorpay/test_plan.rb
167
181
  - test/razorpay/test_razorpay.rb
168
182
  - test/razorpay/test_refund.rb
169
183
  - test/razorpay/test_request.rb
184
+ - test/razorpay/test_subscription.rb
170
185
  - test/razorpay/test_utility.rb
171
186
  - test/razorpay/test_virtual_account.rb
172
187
  - test/test_helper.rb
@@ -190,13 +205,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
205
  version: '0'
191
206
  requirements: []
192
207
  rubyforge_project:
193
- rubygems_version: 2.6.13
208
+ rubygems_version: 2.5.1
194
209
  signing_key:
195
210
  specification_version: 4
196
211
  summary: Razorpay's Ruby API
197
212
  test_files:
198
213
  - test/fixtures/bad_request_error.json
214
+ - test/fixtures/cancel_invoice.json
215
+ - test/fixtures/cancel_subscription.json
199
216
  - test/fixtures/customer_collection.json
217
+ - test/fixtures/fake_addon.json
200
218
  - test/fixtures/fake_captured_payment.json
201
219
  - test/fixtures/fake_card.json
202
220
  - test/fixtures/fake_customer.json
@@ -206,19 +224,26 @@ test_files:
206
224
  - test/fixtures/fake_payment.json
207
225
  - test/fixtures/fake_payment_authorized_webhook.json
208
226
  - test/fixtures/fake_payment_bank_transfer.json
227
+ - test/fixtures/fake_plan.json
209
228
  - test/fixtures/fake_refund.json
229
+ - test/fixtures/fake_subscription.json
210
230
  - test/fixtures/fake_virtual_account.json
211
231
  - test/fixtures/fake_virtual_account_closed.json
212
232
  - test/fixtures/fake_virtual_account_collection.json
213
233
  - test/fixtures/hello_response.json
214
234
  - test/fixtures/invoice_collection.json
235
+ - test/fixtures/issue_invoice.json
215
236
  - test/fixtures/order_collection.json
216
237
  - test/fixtures/order_payments.json
217
238
  - test/fixtures/payment_collection.json
218
239
  - test/fixtures/payment_collection_with_one_payment.json
240
+ - test/fixtures/plan_collection.json
219
241
  - test/fixtures/refund_collection.json
220
242
  - test/fixtures/refund_collection_for_payment.json
243
+ - test/fixtures/subscription_collection.json
244
+ - test/fixtures/update_invoice.json
221
245
  - test/fixtures/welcome.json
246
+ - test/razorpay/test_addon.rb
222
247
  - test/razorpay/test_card.rb
223
248
  - test/razorpay/test_customer.rb
224
249
  - test/razorpay/test_entity.rb
@@ -226,9 +251,11 @@ test_files:
226
251
  - test/razorpay/test_invoice.rb
227
252
  - test/razorpay/test_order.rb
228
253
  - test/razorpay/test_payment.rb
254
+ - test/razorpay/test_plan.rb
229
255
  - test/razorpay/test_razorpay.rb
230
256
  - test/razorpay/test_refund.rb
231
257
  - test/razorpay/test_request.rb
258
+ - test/razorpay/test_subscription.rb
232
259
  - test/razorpay/test_utility.rb
233
260
  - test/razorpay/test_virtual_account.rb
234
261
  - test/test_helper.rb