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
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe ChargeBee::ListResult do
4
+ let(:response) do
5
+ {:list=>
6
+ [{:customer=>
7
+ {:id=>"d0cus3orh6gnjgha1i",
8
+ :first_name=>"Test Name1",
9
+ :last_name=>"Test last name 1",
10
+ :email=>"name1@gmail.com",
11
+ :auto_collection=>"on",
12
+ :created_at=>1346258514,
13
+ :object=>"customer",
14
+ :card_status=>"valid"},
15
+ :card=>
16
+ {:customer_id=>"d0cus3orh6gnjgha1i",
17
+ :status=>"valid",
18
+ :gateway=>"chargebee",
19
+ :first_name=>"Test Name1",
20
+ :last_name=>"Test last name 1",
21
+ :iin=>"32122",
22
+ :last4=>"1333",
23
+ :card_type=>"visa",
24
+ :expiry_month=>8,
25
+ :expiry_year=>2013,
26
+ :billing_addr1=>"Flat 11",
27
+ :billing_addr2=>"51 Strit",
28
+ :billing_city=>"Bristol",
29
+ :billing_state=>"Somerset",
30
+ :billing_zip=>"BS1 4HQ",
31
+ :object=>"card",
32
+ :masked_number=>"21323****4323"}},
33
+ {:customer=>
34
+ {:id=>"cwtid6smh67tq3z51l",
35
+ :first_name=>"Test Name 2",
36
+ :last_name=>"Test last name 2",
37
+ :email=>"name2@gmail.com",
38
+ :auto_collection=>"on",
39
+ :created_at=>1345724673,
40
+ :object=>"customer",
41
+ :card_status=>"no_card"}}],
42
+ :next_offset=>"[\"1345724673000\",\"1510\"]"}
43
+ end
44
+
45
+ before do
46
+ ChargeBee::Rest.stubs(:request).returns(response)
47
+ end
48
+
49
+ it "returns list object, with next offset attribute" do
50
+ list = ChargeBee::Request.send(:customer, "http://url.com", {:limit => 2})
51
+ list.next_offset.should =~ ["1345724673000", "1510"]
52
+ end
53
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'rest_client'
3
+ require 'sample_response'
4
+
5
+ describe "chargebee" do
6
+
7
+ before(:all) do
8
+ @request = RestClient::Request
9
+ end
10
+
11
+ it "serialize should convert the hash to acceptable format" do
12
+ before = {
13
+ :id => "sub_KyVq7DNSNM7CSD",
14
+ :plan_id => "free",
15
+ :addons => [{:id => "monitor", :quantity => 2}, {:id => "ssl"}],
16
+ :addon_ids => ["addon_one", "addon_two"],
17
+ :card => {
18
+ :first_name => "Rajaraman",
19
+ :last_name => "Santhanam",
20
+ :number => "4111111111111111",
21
+ :expiry_month => "1",
22
+ :expiry_year => "2024",
23
+ :cvv => "007"
24
+ }
25
+ }
26
+ after = {
27
+ "id"=>"sub_KyVq7DNSNM7CSD",
28
+ "plan_id"=>"free",
29
+ "addons[id][0]"=>"monitor",
30
+ "addons[quantity][0]"=>"2",
31
+ "addons[id][1]"=>"ssl",
32
+ "addon_ids[0]"=>"addon_one",
33
+ "addon_ids[1]"=>"addon_two",
34
+ "card[first_name]"=>"Rajaraman",
35
+ "card[last_name]"=>"Santhanam",
36
+ "card[number]"=>"4111111111111111",
37
+ "card[expiry_month]"=>"1",
38
+ "card[expiry_year]"=>"2024",
39
+ "card[cvv]"=>"007"}
40
+ ChargeBee::Util.serialize(before).should eq(after)
41
+ end
42
+
43
+ it "symbolize_keys should convert keys to symbols" do
44
+ before = {
45
+ 'id' => 'sub_KyVq4P__dev__NTWxbJx1',
46
+ 'plan_id' => 'basic',
47
+ 'addons' => [{ 'id' => 'ssl' }, {'id' => 'sms', 'quantity' => '10'}]
48
+ }
49
+ after = {
50
+ :id => 'sub_KyVq4P__dev__NTWxbJx1',
51
+ :plan_id => 'basic',
52
+ :addons => [{ :id => 'ssl' }, {:id => 'sms', :quantity => '10'}],
53
+ }
54
+ ChargeBee::Util.symbolize_keys(before).should eq(after)
55
+ end
56
+
57
+ it "should properly convert the response json into proper object" do
58
+ @request.expects(:execute).once.returns(mock_response(simple_subscription))
59
+ result = ChargeBee::Subscription.retrieve("simple_subscription")
60
+ s = result.subscription
61
+ s.id.should eq("simple_subscription")
62
+ s.plan_id.should eq('basic')
63
+ c = result.customer
64
+ c.first_name.should eq('simple')
65
+ c.last_name.should eq('subscription')
66
+ end
67
+
68
+ it "should properly convert the nested response json into proper object with sub types" do
69
+ @request.expects(:execute).once.returns(mock_response(nested_subscription))
70
+ result = ChargeBee::Subscription.retrieve("nested_subscription")
71
+ s = result.subscription
72
+ s.id.should eq("nested_subscription")
73
+ a = s.addons
74
+ a.length.should eq(2)
75
+ a[0].id.should eq("monitor")
76
+ a[0].quantity.should eq("10")
77
+ a[1].id.should eq("ssl")
78
+ end
79
+
80
+ it "should properly convert the list response json into proper result object" do
81
+ @request.expects(:execute).once.returns(mock_response(list_subscriptions))
82
+ result = ChargeBee::Subscription.list({:limit => 2})
83
+ result.length.should eq(2)
84
+ result.each do |i|
85
+ i.subscription.id.should eq('sample_subscription')
86
+ end
87
+ end
88
+
89
+ it "should parse event api response and provide the content properly" do
90
+ @request.expects(:execute).once.returns(mock_response(sample_event))
91
+ result = ChargeBee::Event.retrieve("sample_event")
92
+ event = result.event
93
+ s = event.content.subscription
94
+ event.id.should eq('ev_KyVqDX__dev__NTgtUgx1')
95
+ s.id.should eq('sample_subscription')
96
+ end
97
+
98
+ end
99
+
@@ -0,0 +1,73 @@
1
+
2
+ def api_index_urls()
3
+ {
4
+ :urls => ["http://mannar-test.localcb.com:8080/api/v1/subscriptions",
5
+ "http://mannar-test.localcb.com:8080/api/v1/customers",
6
+ "http://mannar-test.localcb.com:8080/api/v1/cards",
7
+ "http://mannar-test.localcb.com:8080/api/v1/invoices",
8
+ "http://mannar-test.localcb.com:8080/api/v1/transactions",
9
+ "http://mannar-test.localcb.com:8080/api/v1/hosted_pages",
10
+ "http://mannar-test.localcb.com:8080/api/v1/events"],
11
+ :version => "v1"
12
+ }
13
+ end
14
+
15
+ def simple_subscription
16
+ {
17
+ :subscription => {
18
+ :id => 'simple_subscription',
19
+ :plan_id => 'basic'
20
+ },
21
+ :customer => {
22
+ :first_name => 'simple',
23
+ :last_name => 'subscription'
24
+ }
25
+ }
26
+ end
27
+
28
+ def nested_subscription
29
+ {
30
+ :subscription => {
31
+ :id => 'nested_subscription',
32
+ :plan_id => 'basic',
33
+ :addons => [
34
+ {:id => 'monitor', :quantity => '10'},
35
+ {:id => 'ssl'}
36
+ ]
37
+ }
38
+ }
39
+ end
40
+
41
+ def test_subscription
42
+ {
43
+ :subscription => {
44
+ :id => "sample_subscription",
45
+ :plan_id => "basic"
46
+ }
47
+ }
48
+ end
49
+
50
+ def list_subscriptions()
51
+ {:list => [test_subscription, test_subscription]}
52
+ end
53
+
54
+ def sample_event()
55
+ {:event => {
56
+ :id => 'ev_KyVqDX__dev__NTgtUgx1',
57
+ :occurred_at => 1325356232,
58
+ :event_type => "payment_collected",
59
+ :webhook_status => "succeeded",
60
+ :content => {
61
+ :subscription => {
62
+ :id => 'sample_subscription',
63
+ :plan_id => 'basic',
64
+ :plan_quantity=> 1,
65
+ },
66
+ :customer => {
67
+ :first_name => "Sample",
68
+ :last_name => "Subscription",
69
+ },
70
+ }
71
+ }
72
+ }
73
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../lib/chargebee'
2
+
3
+ require 'rspec'
4
+ require 'pp'
5
+ require 'mocha'
6
+ require 'json'
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :mocha
10
+ end
11
+
12
+ def mock_response(body, code=200)
13
+ body = body.to_json if !(body.kind_of? String)
14
+ m = mock
15
+ m.instance_variable_set('@resp_values', { :body => body, :code => code })
16
+ def m.body; @resp_values[:body]; end
17
+ def m.code; @resp_values[:code]; end
18
+ m
19
+ end
20
+
21
+ ChargeBee.configure(
22
+ :api_key => "dummy_api_key",
23
+ :site => "dummy_site"
24
+ )
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chargebee
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.4
5
+ platform: ruby
6
+ authors:
7
+ - Rajaraman S
8
+ - Thiyagarajan T
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json_pure
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rest-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.4'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 3.0.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 3.0.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: mocha
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com.
71
+ email:
72
+ - rr@chargebee.com
73
+ - thiyagu@chargebee.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files:
77
+ - README.rdoc
78
+ - LICENSE
79
+ files:
80
+ - CHANGELOG.md
81
+ - LICENSE
82
+ - README.rdoc
83
+ - Rakefile
84
+ - chargebee.gemspec
85
+ - lib/chargebee.rb
86
+ - lib/chargebee/environment.rb
87
+ - lib/chargebee/errors.rb
88
+ - lib/chargebee/list_result.rb
89
+ - lib/chargebee/models/addon.rb
90
+ - lib/chargebee/models/address.rb
91
+ - lib/chargebee/models/card.rb
92
+ - lib/chargebee/models/comment.rb
93
+ - lib/chargebee/models/coupon.rb
94
+ - lib/chargebee/models/coupon_code.rb
95
+ - lib/chargebee/models/customer.rb
96
+ - lib/chargebee/models/download.rb
97
+ - lib/chargebee/models/estimate.rb
98
+ - lib/chargebee/models/event.rb
99
+ - lib/chargebee/models/hosted_page.rb
100
+ - lib/chargebee/models/invoice.rb
101
+ - lib/chargebee/models/model.rb
102
+ - lib/chargebee/models/order.rb
103
+ - lib/chargebee/models/payment_intent.rb
104
+ - lib/chargebee/models/plan.rb
105
+ - lib/chargebee/models/portal_session.rb
106
+ - lib/chargebee/models/subscription.rb
107
+ - lib/chargebee/models/transaction.rb
108
+ - lib/chargebee/request.rb
109
+ - lib/chargebee/rest.rb
110
+ - lib/chargebee/result.rb
111
+ - lib/chargebee/util.rb
112
+ - lib/ssl/ca-certs.crt
113
+ - spec/chargebee/list_result_spec.rb
114
+ - spec/chargebee_spec.rb
115
+ - spec/sample_response.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://apidocs.chargebee.com/api/docs?lang=ruby
118
+ licenses: []
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options:
122
+ - --charset=UTF-8
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5
138
+ signing_key:
139
+ specification_version: 2
140
+ summary: Ruby client for Chargebee API.
141
+ test_files:
142
+ - spec/chargebee/list_result_spec.rb
143
+ - spec/chargebee_spec.rb
144
+ - spec/sample_response.rb
145
+ - spec/spec_helper.rb