chargebee 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +150 -0
- data/chargebee.gemspec +53 -15
- data/lib/chargebee.rb +18 -1
- data/lib/chargebee/model.rb +47 -0
- data/lib/chargebee/models/address.rb +19 -0
- data/lib/chargebee/models/invoice.rb +10 -2
- data/lib/chargebee/models/subscription.rb +1 -1
- data/lib/chargebee/rest.rb +14 -5
- data/lib/chargebee/result.rb +4 -0
- data/lib/ssl/ca-certs.crt +3385 -0
- data/spec/chargebee_spec.rb +106 -0
- data/spec/sample_response.rb +82 -0
- data/spec/spec_helper.rb +24 -0
- metadata +25 -15
@@ -0,0 +1,106 @@
|
|
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
|
+
:card => {
|
17
|
+
:first_name => "Rajaraman",
|
18
|
+
:last_name => "Santhanam",
|
19
|
+
:number => "4111111111111111",
|
20
|
+
:expiry_month => "1",
|
21
|
+
:expiry_year => "2024",
|
22
|
+
:cvv => "007"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
after = {
|
26
|
+
"id"=>"sub_KyVq7DNSNM7CSD",
|
27
|
+
"plan_id"=>"free",
|
28
|
+
"addons[id][0]"=>"monitor",
|
29
|
+
"addons[quantity][0]"=>2,
|
30
|
+
"addons[id][1]"=>"ssl",
|
31
|
+
"card[first_name]"=>"Rajaraman",
|
32
|
+
"card[last_name]"=>"Santhanam",
|
33
|
+
"card[number]"=>"4111111111111111",
|
34
|
+
"card[expiry_month]"=>"1",
|
35
|
+
"card[expiry_year]"=>"2024",
|
36
|
+
"card[cvv]"=>"007"}
|
37
|
+
ChargeBee::Util.serialize(before).should eq(after)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "symbolize_keys should convert keys to symbols" do
|
41
|
+
before = {
|
42
|
+
'id' => 'sub_KyVq4P__dev__NTWxbJx1',
|
43
|
+
'plan_id' => 'basic',
|
44
|
+
'addons' => [{ 'id' => 'ssl' }, {'id' => 'sms', 'quantity' => '10'}]
|
45
|
+
}
|
46
|
+
after = {
|
47
|
+
:id => 'sub_KyVq4P__dev__NTWxbJx1',
|
48
|
+
:plan_id => 'basic',
|
49
|
+
:addons => [{ :id => 'ssl' }, {:id => 'sms', :quantity => '10'}],
|
50
|
+
}
|
51
|
+
ChargeBee::Util.symbolize_keys(before).should eq(after)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should properly convert the response json into proper object" do
|
55
|
+
@request.expects(:execute).once.returns(mock_response(simple_subscription))
|
56
|
+
result = ChargeBee::Subscription.retrieve("simple_subscription")
|
57
|
+
s = result.subscription
|
58
|
+
s.id.should eq("simple_subscription")
|
59
|
+
s.plan_id.should eq('basic')
|
60
|
+
c = result.customer
|
61
|
+
c.first_name.should eq('simple')
|
62
|
+
c.last_name.should eq('subscription')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should properly convert the nested response json into proper object with sub types" do
|
66
|
+
@request.expects(:execute).once.returns(mock_response(nested_subscription))
|
67
|
+
result = ChargeBee::Subscription.retrieve("nested_subscription")
|
68
|
+
s = result.subscription
|
69
|
+
s.id.should eq("nested_subscription")
|
70
|
+
a = s.addons
|
71
|
+
a.length.should eq(2)
|
72
|
+
a[0].id.should eq("monitor")
|
73
|
+
a[0].quantity.should eq("10")
|
74
|
+
a[1].id.should eq("ssl")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should properly convert the list response json into proper result object" do
|
78
|
+
@request.expects(:execute).once.returns(mock_response(list_subscriptions))
|
79
|
+
result = ChargeBee::Subscription.list({:limit => 2})
|
80
|
+
result.length.should eq(2)
|
81
|
+
result.each do |i|
|
82
|
+
i.subscription.id.should eq('sample_subscription')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should parse event api response and provide the content properly" do
|
87
|
+
@request.expects(:execute).once.returns(mock_response(sample_event))
|
88
|
+
result = ChargeBee::Event.retrieve("sample_event")
|
89
|
+
event = result.event
|
90
|
+
s = event.content.subscription
|
91
|
+
event.id.should eq('ev_KyVqDX__dev__NTgtUgx1')
|
92
|
+
s.id.should eq('sample_subscription')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should raise APIError when error response is received" do
|
96
|
+
response = mock_response(sample_error, 400)
|
97
|
+
begin
|
98
|
+
@request.expects(:execute).once.raises(RestClient::ExceptionWithResponse.new(response, 400))
|
99
|
+
ChargeBee::Subscription.create({:id => "invalid_subscription"})
|
100
|
+
rescue ChargeBee::APIError => e
|
101
|
+
e.http_code.should eq(400)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,82 @@
|
|
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
|
74
|
+
|
75
|
+
def sample_error
|
76
|
+
{
|
77
|
+
:http_code => "400",
|
78
|
+
:error_code => "param_not_present",
|
79
|
+
:message => "plan_id is not present",
|
80
|
+
:param => "plan_id"
|
81
|
+
}
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -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
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: chargebee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rajaraman S
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-05-
|
14
|
+
date: 2012-05-26 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json_pure
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: "0"
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
|
-
description: Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com
|
60
|
+
description: Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com.
|
61
61
|
email:
|
62
62
|
- rr@chargebee.com
|
63
63
|
- thiyagu@chargebee.com
|
@@ -65,14 +65,20 @@ executables: []
|
|
65
65
|
|
66
66
|
extensions: []
|
67
67
|
|
68
|
-
extra_rdoc_files:
|
69
|
-
|
70
|
-
files:
|
68
|
+
extra_rdoc_files:
|
71
69
|
- README.rdoc
|
72
70
|
- LICENSE
|
71
|
+
files:
|
72
|
+
- LICENSE
|
73
|
+
- README.rdoc
|
74
|
+
- Rakefile
|
75
|
+
- chargebee.gemspec
|
76
|
+
- lib/chargebee.rb
|
73
77
|
- lib/chargebee/api_error.rb
|
74
78
|
- lib/chargebee/environment.rb
|
75
79
|
- lib/chargebee/list_result.rb
|
80
|
+
- lib/chargebee/model.rb
|
81
|
+
- lib/chargebee/models/address.rb
|
76
82
|
- lib/chargebee/models/card.rb
|
77
83
|
- lib/chargebee/models/customer.rb
|
78
84
|
- lib/chargebee/models/event.rb
|
@@ -86,14 +92,16 @@ files:
|
|
86
92
|
- lib/chargebee/result.rb
|
87
93
|
- lib/chargebee/util.rb
|
88
94
|
- lib/chargebee/version.rb
|
89
|
-
- lib/
|
90
|
-
-
|
91
|
-
|
95
|
+
- lib/ssl/ca-certs.crt
|
96
|
+
- spec/chargebee_spec.rb
|
97
|
+
- spec/sample_response.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://apidocs.chargebee.com/api/docs?lang=ruby
|
92
100
|
licenses: []
|
93
101
|
|
94
102
|
post_install_message:
|
95
|
-
rdoc_options:
|
96
|
-
|
103
|
+
rdoc_options:
|
104
|
+
- --charset=UTF-8
|
97
105
|
require_paths:
|
98
106
|
- lib
|
99
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -113,7 +121,9 @@ requirements: []
|
|
113
121
|
rubyforge_project:
|
114
122
|
rubygems_version: 1.8.15
|
115
123
|
signing_key:
|
116
|
-
specification_version:
|
117
|
-
summary: Ruby client for Chargebee API
|
118
|
-
test_files:
|
119
|
-
|
124
|
+
specification_version: 2
|
125
|
+
summary: Ruby client for Chargebee API.
|
126
|
+
test_files:
|
127
|
+
- spec/chargebee_spec.rb
|
128
|
+
- spec/sample_response.rb
|
129
|
+
- spec/spec_helper.rb
|