chargebee 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +528 -0
  3. data/LICENSE +24 -0
  4. data/README.rdoc +34 -0
  5. data/Rakefile +150 -0
  6. data/chargebee.gemspec +72 -0
  7. data/lib/chargebee.rb +59 -0
  8. data/lib/chargebee/environment.rb +23 -0
  9. data/lib/chargebee/errors.rb +43 -0
  10. data/lib/chargebee/list_result.rb +28 -0
  11. data/lib/chargebee/models/addon.rb +31 -0
  12. data/lib/chargebee/models/address.rb +19 -0
  13. data/lib/chargebee/models/card.rb +32 -0
  14. data/lib/chargebee/models/comment.rb +26 -0
  15. data/lib/chargebee/models/coupon.rb +25 -0
  16. data/lib/chargebee/models/coupon_code.rb +18 -0
  17. data/lib/chargebee/models/customer.rb +77 -0
  18. data/lib/chargebee/models/download.rb +10 -0
  19. data/lib/chargebee/models/estimate.rb +36 -0
  20. data/lib/chargebee/models/event.rb +46 -0
  21. data/lib/chargebee/models/hosted_page.rb +50 -0
  22. data/lib/chargebee/models/invoice.rb +114 -0
  23. data/lib/chargebee/models/model.rb +70 -0
  24. data/lib/chargebee/models/order.rb +31 -0
  25. data/lib/chargebee/models/payment_intent.rb +27 -0
  26. data/lib/chargebee/models/plan.rb +33 -0
  27. data/lib/chargebee/models/portal_session.rb +31 -0
  28. data/lib/chargebee/models/subscription.rb +86 -0
  29. data/lib/chargebee/models/transaction.rb +45 -0
  30. data/lib/chargebee/request.rb +16 -0
  31. data/lib/chargebee/rest.rb +90 -0
  32. data/lib/chargebee/result.rb +100 -0
  33. data/lib/chargebee/util.rb +56 -0
  34. data/lib/ssl/ca-certs.crt +3385 -0
  35. data/spec/chargebee/list_result_spec.rb +53 -0
  36. data/spec/chargebee_spec.rb +99 -0
  37. data/spec/sample_response.rb +73 -0
  38. data/spec/spec_helper.rb +24 -0
  39. metadata +145 -0
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011-2016 ChargeBee, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ = Chargebee Ruby Client Library - API V1
2
+
3
+ The ruby library for integrating with Chargebee Recurring Billing and Subscription Management solution.
4
+
5
+ Chargebee now supports two API versions - {V1}[https://apidocs.chargebee.com/docs/api/v1] and {V2}[https://apidocs.chargebee.com/docs/api]. This library is for our <b>older API version V1</b>. The library for V2 can be found in the {master branch}[https://github.com/chargebee/chargebee-ruby].
6
+
7
+ You'd want to upgrade to V2 to benefit from the new functionality. Click here for the {API V2 Upgradation Guide}[https://apidocs.chargebee.com/docs/api/v1#api-v2-upgradation-guide].
8
+
9
+ == Installation
10
+
11
+ Install the latest version of the gem with the following command...
12
+
13
+ $ sudo gem install chargebee -v '~>1'
14
+
15
+ == Documentation
16
+
17
+ For API reference see {here}[https://apidocs.chargebee.com/docs/api/v1/?lang=ruby]
18
+
19
+ == Usage
20
+
21
+ To create a new subscription:
22
+
23
+ ChargeBee.configure({:api_key => "your_api_key"}, {:site => "your_site"})
24
+ result = ChargeBee::Subscription.create({
25
+ :id => "sub_KyVqDh__dev__NTn4VZZ1",
26
+ :plan_id => "basic",
27
+ })
28
+ subscription = result.subscription
29
+ puts "created subscription is #{subscription}"
30
+
31
+ == License
32
+
33
+ See the LICENSE file.
34
+
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ # require 'rake/rdoctask'
64
+ # Rake::RDocTask.new do |rdoc|
65
+ # rdoc.rdoc_dir = 'rdoc'
66
+ # rdoc.title = "#{name} #{version}"
67
+ # rdoc.rdoc_files.include('README*')
68
+ # rdoc.rdoc_files.include('lib/**/*.rb')
69
+ # end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
84
+ #############################################################################
85
+ #
86
+ # Packaging tasks
87
+ #
88
+ #############################################################################
89
+
90
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push origin v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ desc "Build #{gem_file} into the pkg directory"
104
+ task :build => :gemspec do
105
+ sh "mkdir -p pkg"
106
+ sh "gem build #{gemspec_file}"
107
+ sh "mv #{gem_file} pkg"
108
+ end
109
+
110
+ desc "Generate #{gemspec_file}"
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ desc "Validate #{gemspec_file}"
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}", "lib/ssl"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file, `#{name}` dir and `lib/ssl` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
@@ -0,0 +1,72 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'chargebee'
7
+ s.version = '1.7.4'
8
+ s.date = '2019-08-14'
9
+
10
+ s.summary = "Ruby client for Chargebee API."
11
+ s.description = "Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com."
12
+
13
+ s.authors = ['Rajaraman S', 'Thiyagarajan T']
14
+ s.email = ['rr@chargebee.com', 'thiyagu@chargebee.com']
15
+ s.homepage = 'https://apidocs.chargebee.com/api/docs?lang=ruby'
16
+
17
+
18
+ s.require_paths = %w[lib]
19
+
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.extra_rdoc_files = %w[README.rdoc LICENSE]
22
+
23
+ s.add_dependency('json_pure', '~> 1.5')
24
+ s.add_dependency('rest-client', '~> 1.4')
25
+
26
+ s.add_development_dependency('rspec', '~> 3.0.0')
27
+ s.add_development_dependency('mocha')
28
+
29
+ # = MANIFEST =
30
+ s.files = %w[
31
+ CHANGELOG.md
32
+ LICENSE
33
+ README.rdoc
34
+ Rakefile
35
+ chargebee.gemspec
36
+ lib/chargebee.rb
37
+ lib/chargebee/environment.rb
38
+ lib/chargebee/errors.rb
39
+ lib/chargebee/list_result.rb
40
+ lib/chargebee/models/addon.rb
41
+ lib/chargebee/models/address.rb
42
+ lib/chargebee/models/card.rb
43
+ lib/chargebee/models/comment.rb
44
+ lib/chargebee/models/coupon.rb
45
+ lib/chargebee/models/coupon_code.rb
46
+ lib/chargebee/models/customer.rb
47
+ lib/chargebee/models/download.rb
48
+ lib/chargebee/models/estimate.rb
49
+ lib/chargebee/models/event.rb
50
+ lib/chargebee/models/hosted_page.rb
51
+ lib/chargebee/models/invoice.rb
52
+ lib/chargebee/models/model.rb
53
+ lib/chargebee/models/order.rb
54
+ lib/chargebee/models/payment_intent.rb
55
+ lib/chargebee/models/plan.rb
56
+ lib/chargebee/models/portal_session.rb
57
+ lib/chargebee/models/subscription.rb
58
+ lib/chargebee/models/transaction.rb
59
+ lib/chargebee/request.rb
60
+ lib/chargebee/rest.rb
61
+ lib/chargebee/result.rb
62
+ lib/chargebee/util.rb
63
+ lib/ssl/ca-certs.crt
64
+ spec/chargebee/list_result_spec.rb
65
+ spec/chargebee_spec.rb
66
+ spec/sample_response.rb
67
+ spec/spec_helper.rb
68
+ ]
69
+ # = MANIFEST =
70
+
71
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*\.rb/ }
72
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/chargebee/environment'
2
+ require File.dirname(__FILE__) + '/chargebee/rest'
3
+ require File.dirname(__FILE__) + '/chargebee/util'
4
+ require File.dirname(__FILE__) + '/chargebee/request'
5
+ require File.dirname(__FILE__) + '/chargebee/result'
6
+ require File.dirname(__FILE__) + '/chargebee/list_result'
7
+
8
+ require File.dirname(__FILE__) + '/chargebee/errors'
9
+
10
+ require File.dirname(__FILE__) + '/chargebee/models/model'
11
+ require File.dirname(__FILE__) + '/chargebee/models/subscription'
12
+ require File.dirname(__FILE__) + '/chargebee/models/customer'
13
+ require File.dirname(__FILE__) + '/chargebee/models/card'
14
+ require File.dirname(__FILE__) + '/chargebee/models/address'
15
+ require File.dirname(__FILE__) + '/chargebee/models/transaction'
16
+ require File.dirname(__FILE__) + '/chargebee/models/invoice'
17
+ require File.dirname(__FILE__) + '/chargebee/models/order'
18
+ require File.dirname(__FILE__) + '/chargebee/models/estimate'
19
+ require File.dirname(__FILE__) + '/chargebee/models/hosted_page'
20
+ require File.dirname(__FILE__) + '/chargebee/models/event'
21
+ require File.dirname(__FILE__) + '/chargebee/models/plan'
22
+ require File.dirname(__FILE__) + '/chargebee/models/addon'
23
+ require File.dirname(__FILE__) + '/chargebee/models/coupon'
24
+ require File.dirname(__FILE__) + '/chargebee/models/coupon_code'
25
+ require File.dirname(__FILE__) + '/chargebee/models/comment'
26
+ require File.dirname(__FILE__) + '/chargebee/models/portal_session'
27
+ require File.dirname(__FILE__) + '/chargebee/models/download'
28
+ require File.dirname(__FILE__) + '/chargebee/models/payment_intent'
29
+
30
+ module ChargeBee
31
+
32
+ VERSION = '1.7.4'
33
+
34
+ @@default_env = nil
35
+ @@verify_ca_certs = true
36
+ @@ca_cert_path = File.join(File.dirname(__FILE__), '/ssl/ca-certs.crt')
37
+
38
+ def self.configure(options)
39
+ @@default_env = Environment.new(options)
40
+ end
41
+
42
+ def self.default_env
43
+ @@default_env
44
+ end
45
+
46
+ def self.verify_ca_certs=(verify)
47
+ @@verify_ca_certs = verify
48
+ end
49
+
50
+ def self.verify_ca_certs?
51
+ @@verify_ca_certs
52
+ end
53
+
54
+ def self.ca_cert_path
55
+ @@ca_cert_path
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,23 @@
1
+ module ChargeBee
2
+ class Environment
3
+ API_VERSION = "v1"
4
+ attr_accessor :api_key, :site
5
+ attr_reader :api_endpoint
6
+
7
+ def initialize(options)
8
+ [:api_key, :site].each do |attr|
9
+ instance_variable_set "@#{attr}", options[attr]
10
+ end
11
+ if($CHARGEBEE_DOMAIN == nil)
12
+ @api_endpoint = "https://#{@site}.chargebee.com/api/#{API_VERSION}"
13
+ else
14
+ @api_endpoint = "#{$ENV_PROTOCOL == nil ? "http": "https"}://#{@site}.#{$CHARGEBEE_DOMAIN}/api/#{API_VERSION}"
15
+ end
16
+ end
17
+
18
+ def api_url(url)
19
+ url = @api_endpoint + url
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module ChargeBee
2
+
3
+ class Error < StandardError
4
+ attr_reader :original_error
5
+
6
+ def initialize(message=nil,original_error = nil)
7
+ super message
8
+ @original_error = original_error
9
+ end
10
+ end
11
+
12
+ class IOError < Error; end
13
+
14
+ class APIError < Error
15
+
16
+ attr_reader :http_status_code, :message, :type, :api_error_code, :param, :json_obj,
17
+ #Deprecated attributes
18
+ :http_code, :http_body, :error_code
19
+
20
+ def initialize(http_code=nil, json_obj = nil)
21
+ super json_obj[:message]
22
+ @json_obj = json_obj
23
+ @http_status_code = http_code
24
+ @type = json_obj[:type]
25
+ @api_error_code = json_obj[:api_error_code]
26
+ @param = json_obj[:param]
27
+
28
+ #Deprecated attributes
29
+ @error_code = json_obj[:error_code]
30
+ @http_code = http_code
31
+ @http_body = json_obj.to_s
32
+ end
33
+
34
+ end
35
+
36
+
37
+ class OperationFailedError < APIError; end
38
+
39
+ class InvalidRequestError < APIError; end
40
+
41
+ class PaymentError < APIError; end
42
+
43
+ end
@@ -0,0 +1,28 @@
1
+ require 'forwardable'
2
+
3
+ module ChargeBee
4
+ class ListResult
5
+ extend Forwardable
6
+ include Enumerable
7
+
8
+ def_delegator :@list, :each, :each
9
+ def_delegator :@list, :length, :length
10
+
11
+ attr_reader :next_offset
12
+
13
+ def initialize(response, next_offset=nil)
14
+ @response = response
15
+ @list = Array.new
16
+ @next_offset = JSON.parse(next_offset).to_s if next_offset
17
+ initItems()
18
+ end
19
+
20
+ private
21
+ def initItems()
22
+ @response.each do |item|
23
+ @list.push(Result.new(item))
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module ChargeBee
2
+ class Addon < Model
3
+
4
+ attr_accessor :id, :name, :invoice_name, :description, :type, :charge_type, :price, :period,
5
+ :period_unit, :unit, :status, :archived_at, :enabled_in_portal, :invoice_notes, :taxable, :meta_data
6
+
7
+ # OPERATIONS
8
+ #-----------
9
+
10
+ def self.create(params, env=nil, headers={})
11
+ Request.send('post', uri_path("addons"), params, env, headers)
12
+ end
13
+
14
+ def self.update(id, params={}, env=nil, headers={})
15
+ Request.send('post', uri_path("addons",id.to_s), params, env, headers)
16
+ end
17
+
18
+ def self.list(params={}, env=nil, headers={})
19
+ Request.send('get', uri_path("addons"), params, env, headers)
20
+ end
21
+
22
+ def self.retrieve(id, env=nil, headers={})
23
+ Request.send('get', uri_path("addons",id.to_s), {}, env, headers)
24
+ end
25
+
26
+ def self.delete(id, env=nil, headers={})
27
+ Request.send('post', uri_path("addons",id.to_s,"delete"), {}, env, headers)
28
+ end
29
+
30
+ end # ~Addon
31
+ end # ~ChargeBee