chargebee 1.7.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -105
- data/README.rdoc +16 -14
- data/Rakefile +150 -150
- data/chargebee.gemspec +6 -3
- data/lib/chargebee.rb +5 -2
- data/lib/chargebee/environment.rb +1 -1
- data/lib/chargebee/list_result.rb +28 -28
- data/lib/chargebee/models/card.rb +2 -6
- data/lib/chargebee/models/credit_note.rb +44 -0
- data/lib/chargebee/models/credit_note_estimate.rb +23 -0
- data/lib/chargebee/models/customer.rb +7 -7
- data/lib/chargebee/models/estimate.rb +1 -15
- data/lib/chargebee/models/hosted_page.rb +0 -8
- data/lib/chargebee/models/invoice.rb +26 -10
- data/lib/chargebee/models/invoice_estimate.rb +23 -0
- data/lib/chargebee/models/model.rb +34 -3
- data/lib/chargebee/models/subscription_estimate.rb +10 -0
- data/lib/chargebee/models/transaction.rb +10 -10
- data/lib/chargebee/result.rb +75 -26
- data/lib/chargebee/util.rb +56 -56
- data/lib/ssl/ca-certs.crt +3385 -3385
- data/spec/chargebee/list_result_spec.rb +53 -53
- data/spec/chargebee_spec.rb +99 -99
- data/spec/sample_response.rb +1 -1
- data/spec/spec_helper.rb +24 -24
- metadata +6 -3
- data/lib/chargebee/models/payment_intent.rb +0 -27
@@ -1,53 +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
|
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
|
data/spec/chargebee_spec.rb
CHANGED
@@ -1,99 +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
|
-
|
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
|
+
|
data/spec/sample_response.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,24 +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
|
-
)
|
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
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargebee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajaraman S
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_pure
|
@@ -92,18 +92,21 @@ files:
|
|
92
92
|
- lib/chargebee/models/comment.rb
|
93
93
|
- lib/chargebee/models/coupon.rb
|
94
94
|
- lib/chargebee/models/coupon_code.rb
|
95
|
+
- lib/chargebee/models/credit_note.rb
|
96
|
+
- lib/chargebee/models/credit_note_estimate.rb
|
95
97
|
- lib/chargebee/models/customer.rb
|
96
98
|
- lib/chargebee/models/download.rb
|
97
99
|
- lib/chargebee/models/estimate.rb
|
98
100
|
- lib/chargebee/models/event.rb
|
99
101
|
- lib/chargebee/models/hosted_page.rb
|
100
102
|
- lib/chargebee/models/invoice.rb
|
103
|
+
- lib/chargebee/models/invoice_estimate.rb
|
101
104
|
- lib/chargebee/models/model.rb
|
102
105
|
- lib/chargebee/models/order.rb
|
103
|
-
- lib/chargebee/models/payment_intent.rb
|
104
106
|
- lib/chargebee/models/plan.rb
|
105
107
|
- lib/chargebee/models/portal_session.rb
|
106
108
|
- lib/chargebee/models/subscription.rb
|
109
|
+
- lib/chargebee/models/subscription_estimate.rb
|
107
110
|
- lib/chargebee/models/transaction.rb
|
108
111
|
- lib/chargebee/request.rb
|
109
112
|
- lib/chargebee/rest.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ChargeBee
|
2
|
-
class PaymentIntent < Model
|
3
|
-
|
4
|
-
class PaymentAttempt < Model
|
5
|
-
attr_accessor :id, :status, :id_at_gateway, :error_code, :error_text, :created_at, :modified_at
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :id, :status, :currency_code, :amount, :gateway_account_id, :expires_at, :reference_id,
|
9
|
-
:created_at, :modified_at, :customer_id, :gateway, :active_payment_attempt
|
10
|
-
|
11
|
-
# OPERATIONS
|
12
|
-
#-----------
|
13
|
-
|
14
|
-
def self.create(params, env=nil, headers={})
|
15
|
-
Request.send('post', uri_path("payment_intents"), params, env, headers)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.update(id, params={}, env=nil, headers={})
|
19
|
-
Request.send('post', uri_path("payment_intents",id.to_s), params, env, headers)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.retrieve(id, env=nil, headers={})
|
23
|
-
Request.send('get', uri_path("payment_intents",id.to_s), {}, env, headers)
|
24
|
-
end
|
25
|
-
|
26
|
-
end # ~PaymentIntent
|
27
|
-
end # ~ChargeBee
|