chargebee 2.6.2 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1483 -1473
- data/LICENSE +24 -24
- data/README.rdoc +41 -41
- data/Rakefile +150 -150
- data/chargebee.gemspec +2 -2
- data/lib/.DS_Store +0 -0
- data/lib/chargebee.rb +85 -85
- data/lib/chargebee/environment.rb +28 -28
- data/lib/chargebee/errors.rb +43 -43
- data/lib/chargebee/list_result.rb +28 -28
- data/lib/chargebee/models/addon.rb +45 -45
- data/lib/chargebee/models/address.rb +18 -18
- data/lib/chargebee/models/card.rb +32 -32
- data/lib/chargebee/models/comment.rb +25 -25
- data/lib/chargebee/models/contact.rb +10 -10
- data/lib/chargebee/models/coupon.rb +40 -40
- data/lib/chargebee/models/coupon_code.rb +25 -25
- data/lib/chargebee/models/coupon_set.rb +37 -37
- data/lib/chargebee/models/credit_note.rb +77 -77
- data/lib/chargebee/models/credit_note_estimate.rb +35 -35
- data/lib/chargebee/models/customer.rb +120 -120
- data/lib/chargebee/models/download.rb +9 -9
- data/lib/chargebee/models/estimate.rb +46 -46
- data/lib/chargebee/models/event.rb +45 -45
- data/lib/chargebee/models/export.rb +86 -82
- data/lib/chargebee/models/gift.rb +42 -42
- data/lib/chargebee/models/hosted_page.rb +77 -73
- data/lib/chargebee/models/invoice.rb +172 -172
- data/lib/chargebee/models/invoice_estimate.rb +35 -35
- data/lib/chargebee/models/model.rb +101 -101
- data/lib/chargebee/models/order.rb +76 -76
- data/lib/chargebee/models/payment_source.rb +71 -70
- data/lib/chargebee/models/plan.rb +59 -59
- data/lib/chargebee/models/portal_session.rb +30 -30
- data/lib/chargebee/models/promotional_credit.rb +30 -30
- data/lib/chargebee/models/quote.rb +72 -72
- data/lib/chargebee/models/resource_migration.rb +13 -13
- data/lib/chargebee/models/site_migration_detail.rb +14 -14
- data/lib/chargebee/models/subscription.rb +137 -137
- data/lib/chargebee/models/subscription_estimate.rb +13 -13
- data/lib/chargebee/models/third_party_payment_method.rb +9 -9
- data/lib/chargebee/models/time_machine.rb +46 -46
- data/lib/chargebee/models/transaction.rb +62 -58
- data/lib/chargebee/models/unbilled_charge.rb +31 -31
- data/lib/chargebee/models/virtual_bank_account.rb +26 -26
- data/lib/chargebee/request.rb +27 -27
- data/lib/chargebee/rest.rb +92 -90
- data/lib/chargebee/result.rb +240 -240
- 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/errors_spec.rb +23 -23
- data/spec/sample_response.rb +73 -73
- data/spec/spec_helper.rb +24 -24
- metadata +2 -2
@@ -1,32 +1,32 @@
|
|
1
|
-
module ChargeBee
|
2
|
-
class UnbilledCharge < Model
|
3
|
-
|
4
|
-
class Tier < Model
|
5
|
-
attr_accessor :starting_unit, :ending_unit, :quantity_used, :unit_amount
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :id, :customer_id, :subscription_id, :date_from, :date_to, :unit_amount, :pricing_model,
|
9
|
-
:quantity, :amount, :currency_code, :discount_amount, :description, :entity_type, :entity_id,
|
10
|
-
:is_voided, :voided_at, :tiers, :deleted
|
11
|
-
|
12
|
-
# OPERATIONS
|
13
|
-
#-----------
|
14
|
-
|
15
|
-
def self.invoice_unbilled_charges(params={}, env=nil, headers={})
|
16
|
-
Request.send('post', uri_path("unbilled_charges","invoice_unbilled_charges"), params, env, headers)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.delete(id, env=nil, headers={})
|
20
|
-
Request.send('post', uri_path("unbilled_charges",id.to_s,"delete"), {}, env, headers)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.list(params={}, env=nil, headers={})
|
24
|
-
Request.send_list_request('get', uri_path("unbilled_charges"), params, env, headers)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.invoice_now_estimate(params={}, env=nil, headers={})
|
28
|
-
Request.send('post', uri_path("unbilled_charges","invoice_now_estimate"), params, env, headers)
|
29
|
-
end
|
30
|
-
|
31
|
-
end # ~UnbilledCharge
|
1
|
+
module ChargeBee
|
2
|
+
class UnbilledCharge < Model
|
3
|
+
|
4
|
+
class Tier < Model
|
5
|
+
attr_accessor :starting_unit, :ending_unit, :quantity_used, :unit_amount
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :id, :customer_id, :subscription_id, :date_from, :date_to, :unit_amount, :pricing_model,
|
9
|
+
:quantity, :amount, :currency_code, :discount_amount, :description, :entity_type, :entity_id,
|
10
|
+
:is_voided, :voided_at, :tiers, :deleted
|
11
|
+
|
12
|
+
# OPERATIONS
|
13
|
+
#-----------
|
14
|
+
|
15
|
+
def self.invoice_unbilled_charges(params={}, env=nil, headers={})
|
16
|
+
Request.send('post', uri_path("unbilled_charges","invoice_unbilled_charges"), params, env, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.delete(id, env=nil, headers={})
|
20
|
+
Request.send('post', uri_path("unbilled_charges",id.to_s,"delete"), {}, env, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.list(params={}, env=nil, headers={})
|
24
|
+
Request.send_list_request('get', uri_path("unbilled_charges"), params, env, headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.invoice_now_estimate(params={}, env=nil, headers={})
|
28
|
+
Request.send('post', uri_path("unbilled_charges","invoice_now_estimate"), params, env, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
end # ~UnbilledCharge
|
32
32
|
end # ~ChargeBee
|
@@ -1,27 +1,27 @@
|
|
1
|
-
module ChargeBee
|
2
|
-
class VirtualBankAccount < Model
|
3
|
-
|
4
|
-
attr_accessor :id, :customer_id, :email, :bank_name, :account_number, :routing_number, :swift_code,
|
5
|
-
:gateway, :gateway_account_id, :reference_id, :deleted
|
6
|
-
|
7
|
-
# OPERATIONS
|
8
|
-
#-----------
|
9
|
-
|
10
|
-
def self.create_using_permanent_token(params, env=nil, headers={})
|
11
|
-
Request.send('post', uri_path("virtual_bank_accounts","create_using_permanent_token"), params, env, headers)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.create(params, env=nil, headers={})
|
15
|
-
Request.send('post', uri_path("virtual_bank_accounts"), params, env, headers)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.retrieve(id, env=nil, headers={})
|
19
|
-
Request.send('get', uri_path("virtual_bank_accounts",id.to_s), {}, env, headers)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.list(params={}, env=nil, headers={})
|
23
|
-
Request.send_list_request('get', uri_path("virtual_bank_accounts"), params, env, headers)
|
24
|
-
end
|
25
|
-
|
26
|
-
end # ~VirtualBankAccount
|
1
|
+
module ChargeBee
|
2
|
+
class VirtualBankAccount < Model
|
3
|
+
|
4
|
+
attr_accessor :id, :customer_id, :email, :bank_name, :account_number, :routing_number, :swift_code,
|
5
|
+
:gateway, :gateway_account_id, :resource_version, :updated_at, :created_at, :reference_id, :deleted
|
6
|
+
|
7
|
+
# OPERATIONS
|
8
|
+
#-----------
|
9
|
+
|
10
|
+
def self.create_using_permanent_token(params, env=nil, headers={})
|
11
|
+
Request.send('post', uri_path("virtual_bank_accounts","create_using_permanent_token"), params, env, headers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create(params, env=nil, headers={})
|
15
|
+
Request.send('post', uri_path("virtual_bank_accounts"), params, env, headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.retrieve(id, env=nil, headers={})
|
19
|
+
Request.send('get', uri_path("virtual_bank_accounts",id.to_s), {}, env, headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.list(params={}, env=nil, headers={})
|
23
|
+
Request.send_list_request('get', uri_path("virtual_bank_accounts"), params, env, headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
end # ~VirtualBankAccount
|
27
27
|
end # ~ChargeBee
|
data/lib/chargebee/request.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
module ChargeBee
|
2
|
-
class Request
|
3
|
-
|
4
|
-
def self.send_list_request(method, url, params={}, env=nil, headers={})
|
5
|
-
serialized = {}
|
6
|
-
params.each do |k, v|
|
7
|
-
if(v.kind_of? Array)
|
8
|
-
v = v.to_json
|
9
|
-
end
|
10
|
-
serialized["#{k}"] = v
|
11
|
-
end
|
12
|
-
self.send(method, url, serialized, env, headers)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.send(method, url, params={}, env=nil, headers={})
|
16
|
-
env ||= ChargeBee.default_env
|
17
|
-
ser_params = Util.serialize(params)
|
18
|
-
resp = Rest.request(method, url, env, ser_params||={}, headers)
|
19
|
-
if resp.has_key?(:list)
|
20
|
-
ListResult.new(resp[:list], resp[:next_offset])
|
21
|
-
else
|
22
|
-
Result.new(resp)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
1
|
+
module ChargeBee
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def self.send_list_request(method, url, params={}, env=nil, headers={})
|
5
|
+
serialized = {}
|
6
|
+
params.each do |k, v|
|
7
|
+
if(v.kind_of? Array)
|
8
|
+
v = v.to_json
|
9
|
+
end
|
10
|
+
serialized["#{k}"] = v
|
11
|
+
end
|
12
|
+
self.send(method, url, serialized, env, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.send(method, url, params={}, env=nil, headers={})
|
16
|
+
env ||= ChargeBee.default_env
|
17
|
+
ser_params = Util.serialize(params)
|
18
|
+
resp = Rest.request(method, url, env, ser_params||={}, headers)
|
19
|
+
if resp.has_key?(:list)
|
20
|
+
ListResult.new(resp[:list], resp[:next_offset])
|
21
|
+
else
|
22
|
+
Result.new(resp)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/chargebee/rest.rb
CHANGED
@@ -1,90 +1,92 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module ChargeBee
|
5
|
-
module Rest
|
6
|
-
|
7
|
-
def self.request(method, url, env, params=nil, headers={})
|
8
|
-
raise Error.new('No environment configured.') unless env
|
9
|
-
api_key = env.api_key
|
10
|
-
|
11
|
-
if(ChargeBee.verify_ca_certs?)
|
12
|
-
ssl_opts = {
|
13
|
-
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
14
|
-
:ssl_ca_file => ChargeBee.ca_cert_path
|
15
|
-
}
|
16
|
-
else
|
17
|
-
ssl_opts = {
|
18
|
-
:verify_ssl => false
|
19
|
-
}
|
20
|
-
end
|
21
|
-
case method.to_s.downcase.to_sym
|
22
|
-
when :get, :head, :delete
|
23
|
-
headers = { :params => params }.merge(headers)
|
24
|
-
payload = nil
|
25
|
-
else
|
26
|
-
payload = params
|
27
|
-
end
|
28
|
-
|
29
|
-
user_agent = ChargeBee.user_agent
|
30
|
-
headers = {
|
31
|
-
"User-Agent" => user_agent,
|
32
|
-
:accept => :json
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
raise
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
raise
|
81
|
-
elsif("
|
82
|
-
raise
|
83
|
-
|
84
|
-
raise
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module ChargeBee
|
5
|
+
module Rest
|
6
|
+
|
7
|
+
def self.request(method, url, env, params=nil, headers={})
|
8
|
+
raise Error.new('No environment configured.') unless env
|
9
|
+
api_key = env.api_key
|
10
|
+
|
11
|
+
if(ChargeBee.verify_ca_certs?)
|
12
|
+
ssl_opts = {
|
13
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
14
|
+
:ssl_ca_file => ChargeBee.ca_cert_path
|
15
|
+
}
|
16
|
+
else
|
17
|
+
ssl_opts = {
|
18
|
+
:verify_ssl => false
|
19
|
+
}
|
20
|
+
end
|
21
|
+
case method.to_s.downcase.to_sym
|
22
|
+
when :get, :head, :delete
|
23
|
+
headers = { :params => params }.merge(headers)
|
24
|
+
payload = nil
|
25
|
+
else
|
26
|
+
payload = params
|
27
|
+
end
|
28
|
+
|
29
|
+
user_agent = ChargeBee.user_agent
|
30
|
+
headers = {
|
31
|
+
"User-Agent" => user_agent,
|
32
|
+
:accept => :json,
|
33
|
+
"Lang-Version" => RUBY_VERSION,
|
34
|
+
"OS-Version" => RUBY_PLATFORM
|
35
|
+
}.merge(headers)
|
36
|
+
opts = {
|
37
|
+
:method => method,
|
38
|
+
:url => env.api_url(url),
|
39
|
+
:user => api_key,
|
40
|
+
:headers => headers,
|
41
|
+
:payload => payload,
|
42
|
+
:open_timeout => 50,
|
43
|
+
:timeout => 100
|
44
|
+
}.merge(ssl_opts)
|
45
|
+
|
46
|
+
begin
|
47
|
+
response = RestClient::Request.execute(opts)
|
48
|
+
rescue RestClient::ExceptionWithResponse => e
|
49
|
+
if rcode = e.http_code and rbody = e.http_body
|
50
|
+
raise handle_for_error(e, rcode, rbody)
|
51
|
+
else
|
52
|
+
raise IOError.new("IO Exception when trying to connect to chargebee with url #{opts[:url]} . Reason #{e}",e)
|
53
|
+
end
|
54
|
+
rescue Exception => e
|
55
|
+
raise IOError.new("IO Exception when trying to connect to chargebee with url #{opts[:url]} . Reason #{e}",e)
|
56
|
+
end
|
57
|
+
rbody = response.body
|
58
|
+
rcode = response.code
|
59
|
+
begin
|
60
|
+
resp = JSON.parse(rbody)
|
61
|
+
rescue Exception => e
|
62
|
+
raise Error.new("Response not in JSON format. Probably not a ChargeBee response \n #{rbody.inspect}",e)
|
63
|
+
end
|
64
|
+
resp = Util.symbolize_keys(resp)
|
65
|
+
resp
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.handle_for_error(e, rcode=nil, rbody=nil)
|
69
|
+
if(rcode == 204)
|
70
|
+
raise Error.new("No response returned by the chargebee api. The http status code is #{rcode}")
|
71
|
+
end
|
72
|
+
begin
|
73
|
+
error_obj = JSON.parse(rbody)
|
74
|
+
error_obj = Util.symbolize_keys(error_obj)
|
75
|
+
rescue Exception => e
|
76
|
+
raise Error.new("Error response not in JSON format. The http status code is #{rcode} \n #{rbody.inspect}",e)
|
77
|
+
end
|
78
|
+
type = error_obj[:type]
|
79
|
+
if("payment" == type)
|
80
|
+
raise PaymentError.new(rcode, error_obj)
|
81
|
+
elsif("operation_failed" == type)
|
82
|
+
raise OperationFailedError.new(rcode, error_obj)
|
83
|
+
elsif("invalid_request" == type)
|
84
|
+
raise InvalidRequestError.new(rcode, error_obj)
|
85
|
+
else
|
86
|
+
raise APIError.new(rcode, error_obj)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
data/lib/chargebee/result.rb
CHANGED
@@ -1,240 +1,240 @@
|
|
1
|
-
module ChargeBee
|
2
|
-
class Result
|
3
|
-
|
4
|
-
def initialize(response)
|
5
|
-
@response = response
|
6
|
-
end
|
7
|
-
|
8
|
-
def subscription()
|
9
|
-
subscription = get(:subscription, Subscription,
|
10
|
-
{:addons => Subscription::Addon, :event_based_addons => Subscription::EventBasedAddon, :charged_event_based_addons => Subscription::ChargedEventBasedAddon, :coupons => Subscription::Coupon, :shipping_address => Subscription::ShippingAddress, :referral_info => Subscription::ReferralInfo});
|
11
|
-
return subscription;
|
12
|
-
end
|
13
|
-
|
14
|
-
def customer()
|
15
|
-
customer = get(:customer, Customer,
|
16
|
-
{:billing_address => Customer::BillingAddress, :referral_urls => Customer::ReferralUrl, :contacts => Customer::Contact, :payment_method => Customer::PaymentMethod, :balances => Customer::Balance});
|
17
|
-
return customer;
|
18
|
-
end
|
19
|
-
|
20
|
-
def contact()
|
21
|
-
contact = get(:contact, Contact);
|
22
|
-
return contact;
|
23
|
-
end
|
24
|
-
|
25
|
-
def payment_source()
|
26
|
-
payment_source = get(:payment_source, PaymentSource,
|
27
|
-
{:card => PaymentSource::Card, :bank_account => PaymentSource::BankAccount, :amazon_payment => PaymentSource::AmazonPayment, :paypal => PaymentSource::Paypal});
|
28
|
-
return payment_source;
|
29
|
-
end
|
30
|
-
|
31
|
-
def third_party_payment_method()
|
32
|
-
third_party_payment_method = get(:third_party_payment_method, ThirdPartyPaymentMethod);
|
33
|
-
return third_party_payment_method;
|
34
|
-
end
|
35
|
-
|
36
|
-
def virtual_bank_account()
|
37
|
-
virtual_bank_account = get(:virtual_bank_account, VirtualBankAccount);
|
38
|
-
return virtual_bank_account;
|
39
|
-
end
|
40
|
-
|
41
|
-
def card()
|
42
|
-
card = get(:card, Card);
|
43
|
-
return card;
|
44
|
-
end
|
45
|
-
|
46
|
-
def promotional_credit()
|
47
|
-
promotional_credit = get(:promotional_credit, PromotionalCredit);
|
48
|
-
return promotional_credit;
|
49
|
-
end
|
50
|
-
|
51
|
-
def invoice()
|
52
|
-
invoice = get(:invoice, Invoice,
|
53
|
-
{:line_items => Invoice::LineItem, :discounts => Invoice::Discount, :line_item_discounts => Invoice::LineItemDiscount, :taxes => Invoice::Tax, :line_item_taxes => Invoice::LineItemTax, :line_item_tiers => Invoice::LineItemTier, :linked_payments => Invoice::LinkedPayment, :applied_credits => Invoice::AppliedCredit, :adjustment_credit_notes => Invoice::AdjustmentCreditNote, :issued_credit_notes => Invoice::IssuedCreditNote, :linked_orders => Invoice::LinkedOrder, :notes => Invoice::Note, :shipping_address => Invoice::ShippingAddress, :billing_address => Invoice::BillingAddress});
|
54
|
-
return invoice;
|
55
|
-
end
|
56
|
-
|
57
|
-
def credit_note()
|
58
|
-
credit_note = get(:credit_note, CreditNote,
|
59
|
-
{:line_items => CreditNote::LineItem, :discounts => CreditNote::Discount, :line_item_discounts => CreditNote::LineItemDiscount, :line_item_tiers => CreditNote::LineItemTier, :taxes => CreditNote::Tax, :line_item_taxes => CreditNote::LineItemTax, :linked_refunds => CreditNote::LinkedRefund, :allocations => CreditNote::Allocation});
|
60
|
-
return credit_note;
|
61
|
-
end
|
62
|
-
|
63
|
-
def unbilled_charge()
|
64
|
-
unbilled_charge = get(:unbilled_charge, UnbilledCharge,
|
65
|
-
{:tiers => UnbilledCharge::Tier});
|
66
|
-
return unbilled_charge;
|
67
|
-
end
|
68
|
-
|
69
|
-
def order()
|
70
|
-
order = get(:order, Order,
|
71
|
-
{:order_line_items => Order::OrderLineItem, :shipping_address => Order::ShippingAddress, :billing_address => Order::BillingAddress, :line_item_taxes => Order::LineItemTax, :line_item_discounts => Order::LineItemDiscount, :linked_credit_notes => Order::LinkedCreditNote});
|
72
|
-
return order;
|
73
|
-
end
|
74
|
-
|
75
|
-
def gift()
|
76
|
-
gift = get(:gift, Gift,
|
77
|
-
{:gifter => Gift::Gifter, :gift_receiver => Gift::GiftReceiver, :gift_timelines => Gift::GiftTimeline});
|
78
|
-
return gift;
|
79
|
-
end
|
80
|
-
|
81
|
-
def transaction()
|
82
|
-
transaction = get(:transaction, Transaction,
|
83
|
-
{:linked_invoices => Transaction::LinkedInvoice, :linked_credit_notes => Transaction::LinkedCreditNote, :linked_refunds => Transaction::LinkedRefund, :linked_payments => Transaction::LinkedPayment});
|
84
|
-
return transaction;
|
85
|
-
end
|
86
|
-
|
87
|
-
def hosted_page()
|
88
|
-
hosted_page = get(:hosted_page, HostedPage);
|
89
|
-
return hosted_page;
|
90
|
-
end
|
91
|
-
|
92
|
-
def estimate()
|
93
|
-
estimate = get(:estimate, Estimate, {},
|
94
|
-
{:subscription_estimate => SubscriptionEstimate, :invoice_estimate => InvoiceEstimate, :invoice_estimates => InvoiceEstimate, :next_invoice_estimate => InvoiceEstimate, :credit_note_estimates => CreditNoteEstimate, :unbilled_charge_estimates => UnbilledCharge});
|
95
|
-
estimate.init_dependant(@response[:estimate], :subscription_estimate,
|
96
|
-
{:shipping_address => SubscriptionEstimate::ShippingAddress});
|
97
|
-
estimate.init_dependant(@response[:estimate], :invoice_estimate,
|
98
|
-
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
99
|
-
estimate.init_dependant(@response[:estimate], :next_invoice_estimate,
|
100
|
-
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
101
|
-
estimate.init_dependant_list(@response[:estimate], :invoice_estimates,
|
102
|
-
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
103
|
-
estimate.init_dependant_list(@response[:estimate], :credit_note_estimates,
|
104
|
-
{:line_items => CreditNoteEstimate::LineItem, :discounts => CreditNoteEstimate::Discount, :taxes => CreditNoteEstimate::Tax, :line_item_taxes => CreditNoteEstimate::LineItemTax, :line_item_discounts => CreditNoteEstimate::LineItemDiscount, :line_item_tiers => CreditNoteEstimate::LineItemTier});
|
105
|
-
estimate.init_dependant_list(@response[:estimate], :unbilled_charge_estimates,
|
106
|
-
{:tiers => UnbilledCharge::Tier});
|
107
|
-
return estimate;
|
108
|
-
end
|
109
|
-
|
110
|
-
def quote()
|
111
|
-
quote = get(:quote, Quote,
|
112
|
-
{:line_items => Quote::LineItem, :discounts => Quote::Discount, :line_item_discounts => Quote::LineItemDiscount, :taxes => Quote::Tax, :line_item_taxes => Quote::LineItemTax, :shipping_address => Quote::ShippingAddress, :billing_address => Quote::BillingAddress});
|
113
|
-
return quote;
|
114
|
-
end
|
115
|
-
|
116
|
-
def plan()
|
117
|
-
plan = get(:plan, Plan,
|
118
|
-
{:tiers => Plan::Tier, :applicable_addons => Plan::ApplicableAddon, :attached_addons => Plan::AttachedAddon, :event_based_addons => Plan::EventBasedAddon});
|
119
|
-
return plan;
|
120
|
-
end
|
121
|
-
|
122
|
-
def addon()
|
123
|
-
addon = get(:addon, Addon,
|
124
|
-
{:tiers => Addon::Tier});
|
125
|
-
return addon;
|
126
|
-
end
|
127
|
-
|
128
|
-
def coupon()
|
129
|
-
coupon = get(:coupon, Coupon);
|
130
|
-
return coupon;
|
131
|
-
end
|
132
|
-
|
133
|
-
def coupon_set()
|
134
|
-
coupon_set = get(:coupon_set, CouponSet);
|
135
|
-
return coupon_set;
|
136
|
-
end
|
137
|
-
|
138
|
-
def coupon_code()
|
139
|
-
coupon_code = get(:coupon_code, CouponCode);
|
140
|
-
return coupon_code;
|
141
|
-
end
|
142
|
-
|
143
|
-
def address()
|
144
|
-
address = get(:address, Address);
|
145
|
-
return address;
|
146
|
-
end
|
147
|
-
|
148
|
-
def event()
|
149
|
-
event = get(:event, Event,
|
150
|
-
{:webhooks => Event::Webhook});
|
151
|
-
return event;
|
152
|
-
end
|
153
|
-
|
154
|
-
def comment()
|
155
|
-
comment = get(:comment, Comment);
|
156
|
-
return comment;
|
157
|
-
end
|
158
|
-
|
159
|
-
def download()
|
160
|
-
download = get(:download, Download);
|
161
|
-
return download;
|
162
|
-
end
|
163
|
-
|
164
|
-
def portal_session()
|
165
|
-
portal_session = get(:portal_session, PortalSession,
|
166
|
-
{:linked_customers => PortalSession::LinkedCustomer});
|
167
|
-
return portal_session;
|
168
|
-
end
|
169
|
-
|
170
|
-
def site_migration_detail()
|
171
|
-
site_migration_detail = get(:site_migration_detail, SiteMigrationDetail);
|
172
|
-
return site_migration_detail;
|
173
|
-
end
|
174
|
-
|
175
|
-
def resource_migration()
|
176
|
-
resource_migration = get(:resource_migration, ResourceMigration);
|
177
|
-
return resource_migration;
|
178
|
-
end
|
179
|
-
|
180
|
-
def time_machine()
|
181
|
-
time_machine = get(:time_machine, TimeMachine);
|
182
|
-
return time_machine;
|
183
|
-
end
|
184
|
-
|
185
|
-
def export()
|
186
|
-
export = get(:export, Export,
|
187
|
-
{:download => Export::Download});
|
188
|
-
return export;
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
def unbilled_charges()
|
193
|
-
unbilled_charges = get_list(:unbilled_charges, UnbilledCharge,
|
194
|
-
{:tiers => UnbilledCharge::Tier});
|
195
|
-
return unbilled_charges;
|
196
|
-
end
|
197
|
-
|
198
|
-
def credit_notes()
|
199
|
-
credit_notes = get_list(:credit_notes, CreditNote,
|
200
|
-
{:line_items => CreditNote::LineItem, :discounts => CreditNote::Discount, :line_item_discounts => CreditNote::LineItemDiscount, :line_item_tiers => CreditNote::LineItemTier, :taxes => CreditNote::Tax, :line_item_taxes => CreditNote::LineItemTax, :linked_refunds => CreditNote::LinkedRefund, :allocations => CreditNote::Allocation});
|
201
|
-
return credit_notes;
|
202
|
-
end
|
203
|
-
|
204
|
-
def invoices()
|
205
|
-
invoices = get_list(:invoices, Invoice,
|
206
|
-
{:line_items => Invoice::LineItem, :discounts => Invoice::Discount, :line_item_discounts => Invoice::LineItemDiscount, :taxes => Invoice::Tax, :line_item_taxes => Invoice::LineItemTax, :line_item_tiers => Invoice::LineItemTier, :linked_payments => Invoice::LinkedPayment, :applied_credits => Invoice::AppliedCredit, :adjustment_credit_notes => Invoice::AdjustmentCreditNote, :issued_credit_notes => Invoice::IssuedCreditNote, :linked_orders => Invoice::LinkedOrder, :notes => Invoice::Note, :shipping_address => Invoice::ShippingAddress, :billing_address => Invoice::BillingAddress});
|
207
|
-
return invoices;
|
208
|
-
end
|
209
|
-
|
210
|
-
|
211
|
-
private
|
212
|
-
def get_list(type, klass, sub_types = {}, dependant_types = {}, dependant_sub_types = {})
|
213
|
-
if(@response[type] == nil)
|
214
|
-
return nil
|
215
|
-
end
|
216
|
-
set_val = Array.new
|
217
|
-
@response[type].each do |obj|
|
218
|
-
case obj
|
219
|
-
when Hash
|
220
|
-
model = klass.construct(obj, sub_types, dependant_types)
|
221
|
-
dependant_sub_types.each do |k,v|
|
222
|
-
model.init_dependant(obj, k, v);
|
223
|
-
end
|
224
|
-
set_val.push(model)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
return instance_variable_set("@#{type}", set_val)
|
228
|
-
end
|
229
|
-
|
230
|
-
private
|
231
|
-
def get(type, klass, sub_types = {}, dependant_types = {})
|
232
|
-
return klass.construct(@response[type], sub_types, dependant_types)
|
233
|
-
end
|
234
|
-
|
235
|
-
def to_s(*args)
|
236
|
-
JSON.pretty_generate(@response)
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|
240
|
-
end
|
1
|
+
module ChargeBee
|
2
|
+
class Result
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscription()
|
9
|
+
subscription = get(:subscription, Subscription,
|
10
|
+
{:addons => Subscription::Addon, :event_based_addons => Subscription::EventBasedAddon, :charged_event_based_addons => Subscription::ChargedEventBasedAddon, :coupons => Subscription::Coupon, :shipping_address => Subscription::ShippingAddress, :referral_info => Subscription::ReferralInfo});
|
11
|
+
return subscription;
|
12
|
+
end
|
13
|
+
|
14
|
+
def customer()
|
15
|
+
customer = get(:customer, Customer,
|
16
|
+
{:billing_address => Customer::BillingAddress, :referral_urls => Customer::ReferralUrl, :contacts => Customer::Contact, :payment_method => Customer::PaymentMethod, :balances => Customer::Balance});
|
17
|
+
return customer;
|
18
|
+
end
|
19
|
+
|
20
|
+
def contact()
|
21
|
+
contact = get(:contact, Contact);
|
22
|
+
return contact;
|
23
|
+
end
|
24
|
+
|
25
|
+
def payment_source()
|
26
|
+
payment_source = get(:payment_source, PaymentSource,
|
27
|
+
{:card => PaymentSource::Card, :bank_account => PaymentSource::BankAccount, :amazon_payment => PaymentSource::AmazonPayment, :paypal => PaymentSource::Paypal});
|
28
|
+
return payment_source;
|
29
|
+
end
|
30
|
+
|
31
|
+
def third_party_payment_method()
|
32
|
+
third_party_payment_method = get(:third_party_payment_method, ThirdPartyPaymentMethod);
|
33
|
+
return third_party_payment_method;
|
34
|
+
end
|
35
|
+
|
36
|
+
def virtual_bank_account()
|
37
|
+
virtual_bank_account = get(:virtual_bank_account, VirtualBankAccount);
|
38
|
+
return virtual_bank_account;
|
39
|
+
end
|
40
|
+
|
41
|
+
def card()
|
42
|
+
card = get(:card, Card);
|
43
|
+
return card;
|
44
|
+
end
|
45
|
+
|
46
|
+
def promotional_credit()
|
47
|
+
promotional_credit = get(:promotional_credit, PromotionalCredit);
|
48
|
+
return promotional_credit;
|
49
|
+
end
|
50
|
+
|
51
|
+
def invoice()
|
52
|
+
invoice = get(:invoice, Invoice,
|
53
|
+
{:line_items => Invoice::LineItem, :discounts => Invoice::Discount, :line_item_discounts => Invoice::LineItemDiscount, :taxes => Invoice::Tax, :line_item_taxes => Invoice::LineItemTax, :line_item_tiers => Invoice::LineItemTier, :linked_payments => Invoice::LinkedPayment, :applied_credits => Invoice::AppliedCredit, :adjustment_credit_notes => Invoice::AdjustmentCreditNote, :issued_credit_notes => Invoice::IssuedCreditNote, :linked_orders => Invoice::LinkedOrder, :notes => Invoice::Note, :shipping_address => Invoice::ShippingAddress, :billing_address => Invoice::BillingAddress});
|
54
|
+
return invoice;
|
55
|
+
end
|
56
|
+
|
57
|
+
def credit_note()
|
58
|
+
credit_note = get(:credit_note, CreditNote,
|
59
|
+
{:line_items => CreditNote::LineItem, :discounts => CreditNote::Discount, :line_item_discounts => CreditNote::LineItemDiscount, :line_item_tiers => CreditNote::LineItemTier, :taxes => CreditNote::Tax, :line_item_taxes => CreditNote::LineItemTax, :linked_refunds => CreditNote::LinkedRefund, :allocations => CreditNote::Allocation});
|
60
|
+
return credit_note;
|
61
|
+
end
|
62
|
+
|
63
|
+
def unbilled_charge()
|
64
|
+
unbilled_charge = get(:unbilled_charge, UnbilledCharge,
|
65
|
+
{:tiers => UnbilledCharge::Tier});
|
66
|
+
return unbilled_charge;
|
67
|
+
end
|
68
|
+
|
69
|
+
def order()
|
70
|
+
order = get(:order, Order,
|
71
|
+
{:order_line_items => Order::OrderLineItem, :shipping_address => Order::ShippingAddress, :billing_address => Order::BillingAddress, :line_item_taxes => Order::LineItemTax, :line_item_discounts => Order::LineItemDiscount, :linked_credit_notes => Order::LinkedCreditNote});
|
72
|
+
return order;
|
73
|
+
end
|
74
|
+
|
75
|
+
def gift()
|
76
|
+
gift = get(:gift, Gift,
|
77
|
+
{:gifter => Gift::Gifter, :gift_receiver => Gift::GiftReceiver, :gift_timelines => Gift::GiftTimeline});
|
78
|
+
return gift;
|
79
|
+
end
|
80
|
+
|
81
|
+
def transaction()
|
82
|
+
transaction = get(:transaction, Transaction,
|
83
|
+
{:linked_invoices => Transaction::LinkedInvoice, :linked_credit_notes => Transaction::LinkedCreditNote, :linked_refunds => Transaction::LinkedRefund, :linked_payments => Transaction::LinkedPayment});
|
84
|
+
return transaction;
|
85
|
+
end
|
86
|
+
|
87
|
+
def hosted_page()
|
88
|
+
hosted_page = get(:hosted_page, HostedPage);
|
89
|
+
return hosted_page;
|
90
|
+
end
|
91
|
+
|
92
|
+
def estimate()
|
93
|
+
estimate = get(:estimate, Estimate, {},
|
94
|
+
{:subscription_estimate => SubscriptionEstimate, :invoice_estimate => InvoiceEstimate, :invoice_estimates => InvoiceEstimate, :next_invoice_estimate => InvoiceEstimate, :credit_note_estimates => CreditNoteEstimate, :unbilled_charge_estimates => UnbilledCharge});
|
95
|
+
estimate.init_dependant(@response[:estimate], :subscription_estimate,
|
96
|
+
{:shipping_address => SubscriptionEstimate::ShippingAddress});
|
97
|
+
estimate.init_dependant(@response[:estimate], :invoice_estimate,
|
98
|
+
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
99
|
+
estimate.init_dependant(@response[:estimate], :next_invoice_estimate,
|
100
|
+
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
101
|
+
estimate.init_dependant_list(@response[:estimate], :invoice_estimates,
|
102
|
+
{:line_items => InvoiceEstimate::LineItem, :discounts => InvoiceEstimate::Discount, :taxes => InvoiceEstimate::Tax, :line_item_taxes => InvoiceEstimate::LineItemTax, :line_item_tiers => InvoiceEstimate::LineItemTier, :line_item_discounts => InvoiceEstimate::LineItemDiscount});
|
103
|
+
estimate.init_dependant_list(@response[:estimate], :credit_note_estimates,
|
104
|
+
{:line_items => CreditNoteEstimate::LineItem, :discounts => CreditNoteEstimate::Discount, :taxes => CreditNoteEstimate::Tax, :line_item_taxes => CreditNoteEstimate::LineItemTax, :line_item_discounts => CreditNoteEstimate::LineItemDiscount, :line_item_tiers => CreditNoteEstimate::LineItemTier});
|
105
|
+
estimate.init_dependant_list(@response[:estimate], :unbilled_charge_estimates,
|
106
|
+
{:tiers => UnbilledCharge::Tier});
|
107
|
+
return estimate;
|
108
|
+
end
|
109
|
+
|
110
|
+
def quote()
|
111
|
+
quote = get(:quote, Quote,
|
112
|
+
{:line_items => Quote::LineItem, :discounts => Quote::Discount, :line_item_discounts => Quote::LineItemDiscount, :taxes => Quote::Tax, :line_item_taxes => Quote::LineItemTax, :shipping_address => Quote::ShippingAddress, :billing_address => Quote::BillingAddress});
|
113
|
+
return quote;
|
114
|
+
end
|
115
|
+
|
116
|
+
def plan()
|
117
|
+
plan = get(:plan, Plan,
|
118
|
+
{:tiers => Plan::Tier, :applicable_addons => Plan::ApplicableAddon, :attached_addons => Plan::AttachedAddon, :event_based_addons => Plan::EventBasedAddon});
|
119
|
+
return plan;
|
120
|
+
end
|
121
|
+
|
122
|
+
def addon()
|
123
|
+
addon = get(:addon, Addon,
|
124
|
+
{:tiers => Addon::Tier});
|
125
|
+
return addon;
|
126
|
+
end
|
127
|
+
|
128
|
+
def coupon()
|
129
|
+
coupon = get(:coupon, Coupon);
|
130
|
+
return coupon;
|
131
|
+
end
|
132
|
+
|
133
|
+
def coupon_set()
|
134
|
+
coupon_set = get(:coupon_set, CouponSet);
|
135
|
+
return coupon_set;
|
136
|
+
end
|
137
|
+
|
138
|
+
def coupon_code()
|
139
|
+
coupon_code = get(:coupon_code, CouponCode);
|
140
|
+
return coupon_code;
|
141
|
+
end
|
142
|
+
|
143
|
+
def address()
|
144
|
+
address = get(:address, Address);
|
145
|
+
return address;
|
146
|
+
end
|
147
|
+
|
148
|
+
def event()
|
149
|
+
event = get(:event, Event,
|
150
|
+
{:webhooks => Event::Webhook});
|
151
|
+
return event;
|
152
|
+
end
|
153
|
+
|
154
|
+
def comment()
|
155
|
+
comment = get(:comment, Comment);
|
156
|
+
return comment;
|
157
|
+
end
|
158
|
+
|
159
|
+
def download()
|
160
|
+
download = get(:download, Download);
|
161
|
+
return download;
|
162
|
+
end
|
163
|
+
|
164
|
+
def portal_session()
|
165
|
+
portal_session = get(:portal_session, PortalSession,
|
166
|
+
{:linked_customers => PortalSession::LinkedCustomer});
|
167
|
+
return portal_session;
|
168
|
+
end
|
169
|
+
|
170
|
+
def site_migration_detail()
|
171
|
+
site_migration_detail = get(:site_migration_detail, SiteMigrationDetail);
|
172
|
+
return site_migration_detail;
|
173
|
+
end
|
174
|
+
|
175
|
+
def resource_migration()
|
176
|
+
resource_migration = get(:resource_migration, ResourceMigration);
|
177
|
+
return resource_migration;
|
178
|
+
end
|
179
|
+
|
180
|
+
def time_machine()
|
181
|
+
time_machine = get(:time_machine, TimeMachine);
|
182
|
+
return time_machine;
|
183
|
+
end
|
184
|
+
|
185
|
+
def export()
|
186
|
+
export = get(:export, Export,
|
187
|
+
{:download => Export::Download});
|
188
|
+
return export;
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
def unbilled_charges()
|
193
|
+
unbilled_charges = get_list(:unbilled_charges, UnbilledCharge,
|
194
|
+
{:tiers => UnbilledCharge::Tier});
|
195
|
+
return unbilled_charges;
|
196
|
+
end
|
197
|
+
|
198
|
+
def credit_notes()
|
199
|
+
credit_notes = get_list(:credit_notes, CreditNote,
|
200
|
+
{:line_items => CreditNote::LineItem, :discounts => CreditNote::Discount, :line_item_discounts => CreditNote::LineItemDiscount, :line_item_tiers => CreditNote::LineItemTier, :taxes => CreditNote::Tax, :line_item_taxes => CreditNote::LineItemTax, :linked_refunds => CreditNote::LinkedRefund, :allocations => CreditNote::Allocation});
|
201
|
+
return credit_notes;
|
202
|
+
end
|
203
|
+
|
204
|
+
def invoices()
|
205
|
+
invoices = get_list(:invoices, Invoice,
|
206
|
+
{:line_items => Invoice::LineItem, :discounts => Invoice::Discount, :line_item_discounts => Invoice::LineItemDiscount, :taxes => Invoice::Tax, :line_item_taxes => Invoice::LineItemTax, :line_item_tiers => Invoice::LineItemTier, :linked_payments => Invoice::LinkedPayment, :applied_credits => Invoice::AppliedCredit, :adjustment_credit_notes => Invoice::AdjustmentCreditNote, :issued_credit_notes => Invoice::IssuedCreditNote, :linked_orders => Invoice::LinkedOrder, :notes => Invoice::Note, :shipping_address => Invoice::ShippingAddress, :billing_address => Invoice::BillingAddress});
|
207
|
+
return invoices;
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
private
|
212
|
+
def get_list(type, klass, sub_types = {}, dependant_types = {}, dependant_sub_types = {})
|
213
|
+
if(@response[type] == nil)
|
214
|
+
return nil
|
215
|
+
end
|
216
|
+
set_val = Array.new
|
217
|
+
@response[type].each do |obj|
|
218
|
+
case obj
|
219
|
+
when Hash
|
220
|
+
model = klass.construct(obj, sub_types, dependant_types)
|
221
|
+
dependant_sub_types.each do |k,v|
|
222
|
+
model.init_dependant(obj, k, v);
|
223
|
+
end
|
224
|
+
set_val.push(model)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
return instance_variable_set("@#{type}", set_val)
|
228
|
+
end
|
229
|
+
|
230
|
+
private
|
231
|
+
def get(type, klass, sub_types = {}, dependant_types = {})
|
232
|
+
return klass.construct(@response[type], sub_types, dependant_types)
|
233
|
+
end
|
234
|
+
|
235
|
+
def to_s(*args)
|
236
|
+
JSON.pretty_generate(@response)
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
end
|