chargebee 2.6.4 → 2.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1524 -1488
  3. data/LICENSE +24 -24
  4. data/README.rdoc +41 -41
  5. data/chargebee.gemspec +4 -3
  6. data/lib/chargebee.rb +85 -85
  7. data/lib/chargebee/environment.rb +28 -28
  8. data/lib/chargebee/errors.rb +43 -43
  9. data/lib/chargebee/models/addon.rb +45 -45
  10. data/lib/chargebee/models/address.rb +18 -18
  11. data/lib/chargebee/models/card.rb +32 -32
  12. data/lib/chargebee/models/comment.rb +25 -25
  13. data/lib/chargebee/models/contact.rb +10 -10
  14. data/lib/chargebee/models/coupon.rb +40 -40
  15. data/lib/chargebee/models/coupon_code.rb +25 -25
  16. data/lib/chargebee/models/coupon_set.rb +37 -37
  17. data/lib/chargebee/models/credit_note.rb +77 -77
  18. data/lib/chargebee/models/credit_note_estimate.rb +35 -35
  19. data/lib/chargebee/models/customer.rb +137 -120
  20. data/lib/chargebee/models/download.rb +9 -9
  21. data/lib/chargebee/models/estimate.rb +46 -46
  22. data/lib/chargebee/models/event.rb +45 -45
  23. data/lib/chargebee/models/export.rb +86 -86
  24. data/lib/chargebee/models/gift.rb +42 -42
  25. data/lib/chargebee/models/hierarchy.rb +10 -0
  26. data/lib/chargebee/models/hosted_page.rb +77 -77
  27. data/lib/chargebee/models/invoice.rb +172 -172
  28. data/lib/chargebee/models/invoice_estimate.rb +35 -35
  29. data/lib/chargebee/models/model.rb +101 -101
  30. data/lib/chargebee/models/order.rb +76 -76
  31. data/lib/chargebee/models/payment_source.rb +79 -71
  32. data/lib/chargebee/models/plan.rb +60 -59
  33. data/lib/chargebee/models/portal_session.rb +30 -30
  34. data/lib/chargebee/models/promotional_credit.rb +30 -30
  35. data/lib/chargebee/models/quote.rb +72 -72
  36. data/lib/chargebee/models/resource_migration.rb +13 -13
  37. data/lib/chargebee/models/site_migration_detail.rb +14 -14
  38. data/lib/chargebee/models/subscription.rb +137 -137
  39. data/lib/chargebee/models/subscription_estimate.rb +13 -13
  40. data/lib/chargebee/models/third_party_payment_method.rb +9 -9
  41. data/lib/chargebee/models/time_machine.rb +46 -46
  42. data/lib/chargebee/models/token.rb +11 -0
  43. data/lib/chargebee/models/transaction.rb +62 -62
  44. data/lib/chargebee/models/unbilled_charge.rb +31 -31
  45. data/lib/chargebee/models/virtual_bank_account.rb +30 -26
  46. data/lib/chargebee/request.rb +27 -27
  47. data/lib/chargebee/rest.rb +92 -92
  48. data/lib/chargebee/result.rb +255 -240
  49. data/spec/errors_spec.rb +23 -23
  50. data/spec/sample_response.rb +73 -73
  51. metadata +5 -4
  52. data/lib/chargebee/.DS_Store +0 -0
@@ -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,31 @@
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
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
+ def self.delete_local(id, env=nil, headers={})
27
+ Request.send('post', uri_path("virtual_bank_accounts",id.to_s,"delete_local"), {}, env, headers)
28
+ end
29
+
30
+ end # ~VirtualBankAccount
27
31
  end # ~ChargeBee
@@ -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
@@ -1,92 +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
- "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
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
@@ -1,240 +1,255 @@
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
- def to_s(*args)
211
- JSON.pretty_generate(@response)
212
- end
213
-
214
-
215
- private
216
- def get_list(type, klass, sub_types = {}, dependant_types = {}, dependant_sub_types = {})
217
- if(@response[type] == nil)
218
- return nil
219
- end
220
- set_val = Array.new
221
- @response[type].each do |obj|
222
- case obj
223
- when Hash
224
- model = klass.construct(obj, sub_types, dependant_types)
225
- dependant_sub_types.each do |k,v|
226
- model.init_dependant(obj, k, v);
227
- end
228
- set_val.push(model)
229
- end
230
- end
231
- return instance_variable_set("@#{type}", set_val)
232
- end
233
-
234
- private
235
- def get(type, klass, sub_types = {}, dependant_types = {})
236
- return klass.construct(@response[type], sub_types, dependant_types)
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, :relationship => Customer::Relationship});
17
+ return customer;
18
+ end
19
+
20
+ def hierarchy()
21
+ hierarchy = get(:hierarchy, Hierarchy);
22
+ return hierarchy;
23
+ end
24
+
25
+ def contact()
26
+ contact = get(:contact, Contact);
27
+ return contact;
28
+ end
29
+
30
+ def token()
31
+ token = get(:token, Token);
32
+ return token;
33
+ end
34
+
35
+ def payment_source()
36
+ payment_source = get(:payment_source, PaymentSource,
37
+ {:card => PaymentSource::Card, :bank_account => PaymentSource::BankAccount, :amazon_payment => PaymentSource::AmazonPayment, :paypal => PaymentSource::Paypal});
38
+ return payment_source;
39
+ end
40
+
41
+ def third_party_payment_method()
42
+ third_party_payment_method = get(:third_party_payment_method, ThirdPartyPaymentMethod);
43
+ return third_party_payment_method;
44
+ end
45
+
46
+ def virtual_bank_account()
47
+ virtual_bank_account = get(:virtual_bank_account, VirtualBankAccount);
48
+ return virtual_bank_account;
49
+ end
50
+
51
+ def card()
52
+ card = get(:card, Card);
53
+ return card;
54
+ end
55
+
56
+ def promotional_credit()
57
+ promotional_credit = get(:promotional_credit, PromotionalCredit);
58
+ return promotional_credit;
59
+ end
60
+
61
+ def invoice()
62
+ invoice = get(:invoice, Invoice,
63
+ {: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});
64
+ return invoice;
65
+ end
66
+
67
+ def credit_note()
68
+ credit_note = get(:credit_note, CreditNote,
69
+ {: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});
70
+ return credit_note;
71
+ end
72
+
73
+ def unbilled_charge()
74
+ unbilled_charge = get(:unbilled_charge, UnbilledCharge,
75
+ {:tiers => UnbilledCharge::Tier});
76
+ return unbilled_charge;
77
+ end
78
+
79
+ def order()
80
+ order = get(:order, Order,
81
+ {: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});
82
+ return order;
83
+ end
84
+
85
+ def gift()
86
+ gift = get(:gift, Gift,
87
+ {:gifter => Gift::Gifter, :gift_receiver => Gift::GiftReceiver, :gift_timelines => Gift::GiftTimeline});
88
+ return gift;
89
+ end
90
+
91
+ def transaction()
92
+ transaction = get(:transaction, Transaction,
93
+ {:linked_invoices => Transaction::LinkedInvoice, :linked_credit_notes => Transaction::LinkedCreditNote, :linked_refunds => Transaction::LinkedRefund, :linked_payments => Transaction::LinkedPayment});
94
+ return transaction;
95
+ end
96
+
97
+ def hosted_page()
98
+ hosted_page = get(:hosted_page, HostedPage);
99
+ return hosted_page;
100
+ end
101
+
102
+ def estimate()
103
+ estimate = get(:estimate, Estimate, {},
104
+ {:subscription_estimate => SubscriptionEstimate, :invoice_estimate => InvoiceEstimate, :invoice_estimates => InvoiceEstimate, :next_invoice_estimate => InvoiceEstimate, :credit_note_estimates => CreditNoteEstimate, :unbilled_charge_estimates => UnbilledCharge});
105
+ estimate.init_dependant(@response[:estimate], :subscription_estimate,
106
+ {:shipping_address => SubscriptionEstimate::ShippingAddress});
107
+ estimate.init_dependant(@response[:estimate], :invoice_estimate,
108
+ {: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});
109
+ estimate.init_dependant(@response[:estimate], :next_invoice_estimate,
110
+ {: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});
111
+ estimate.init_dependant_list(@response[:estimate], :invoice_estimates,
112
+ {: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});
113
+ estimate.init_dependant_list(@response[:estimate], :credit_note_estimates,
114
+ {: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});
115
+ estimate.init_dependant_list(@response[:estimate], :unbilled_charge_estimates,
116
+ {:tiers => UnbilledCharge::Tier});
117
+ return estimate;
118
+ end
119
+
120
+ def quote()
121
+ quote = get(:quote, Quote,
122
+ {: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});
123
+ return quote;
124
+ end
125
+
126
+ def plan()
127
+ plan = get(:plan, Plan,
128
+ {:tiers => Plan::Tier, :applicable_addons => Plan::ApplicableAddon, :attached_addons => Plan::AttachedAddon, :event_based_addons => Plan::EventBasedAddon});
129
+ return plan;
130
+ end
131
+
132
+ def addon()
133
+ addon = get(:addon, Addon,
134
+ {:tiers => Addon::Tier});
135
+ return addon;
136
+ end
137
+
138
+ def coupon()
139
+ coupon = get(:coupon, Coupon);
140
+ return coupon;
141
+ end
142
+
143
+ def coupon_set()
144
+ coupon_set = get(:coupon_set, CouponSet);
145
+ return coupon_set;
146
+ end
147
+
148
+ def coupon_code()
149
+ coupon_code = get(:coupon_code, CouponCode);
150
+ return coupon_code;
151
+ end
152
+
153
+ def address()
154
+ address = get(:address, Address);
155
+ return address;
156
+ end
157
+
158
+ def event()
159
+ event = get(:event, Event,
160
+ {:webhooks => Event::Webhook});
161
+ return event;
162
+ end
163
+
164
+ def comment()
165
+ comment = get(:comment, Comment);
166
+ return comment;
167
+ end
168
+
169
+ def download()
170
+ download = get(:download, Download);
171
+ return download;
172
+ end
173
+
174
+ def portal_session()
175
+ portal_session = get(:portal_session, PortalSession,
176
+ {:linked_customers => PortalSession::LinkedCustomer});
177
+ return portal_session;
178
+ end
179
+
180
+ def site_migration_detail()
181
+ site_migration_detail = get(:site_migration_detail, SiteMigrationDetail);
182
+ return site_migration_detail;
183
+ end
184
+
185
+ def resource_migration()
186
+ resource_migration = get(:resource_migration, ResourceMigration);
187
+ return resource_migration;
188
+ end
189
+
190
+ def time_machine()
191
+ time_machine = get(:time_machine, TimeMachine);
192
+ return time_machine;
193
+ end
194
+
195
+ def export()
196
+ export = get(:export, Export,
197
+ {:download => Export::Download});
198
+ return export;
199
+ end
200
+
201
+
202
+ def unbilled_charges()
203
+ unbilled_charges = get_list(:unbilled_charges, UnbilledCharge,
204
+ {:tiers => UnbilledCharge::Tier});
205
+ return unbilled_charges;
206
+ end
207
+
208
+ def credit_notes()
209
+ credit_notes = get_list(:credit_notes, CreditNote,
210
+ {: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});
211
+ return credit_notes;
212
+ end
213
+
214
+ def hierarchies()
215
+ hierarchies = get_list(:hierarchies, Hierarchy,
216
+ {});
217
+ return hierarchies;
218
+ end
219
+
220
+ def invoices()
221
+ invoices = get_list(:invoices, Invoice,
222
+ {: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});
223
+ return invoices;
224
+ end
225
+
226
+ def to_s(*args)
227
+ JSON.pretty_generate(@response)
228
+ end
229
+
230
+ private
231
+ def get_list(type, klass, sub_types = {}, dependant_types = {}, dependant_sub_types = {})
232
+ if(@response[type] == nil)
233
+ return nil
234
+ end
235
+ set_val = Array.new
236
+ @response[type].each do |obj|
237
+ case obj
238
+ when Hash
239
+ model = klass.construct(obj, sub_types, dependant_types)
240
+ dependant_sub_types.each do |k,v|
241
+ model.init_dependant(obj, k, v);
242
+ end
243
+ set_val.push(model)
244
+ end
245
+ end
246
+ return instance_variable_set("@#{type}", set_val)
247
+ end
248
+
249
+ private
250
+ def get(type, klass, sub_types = {}, dependant_types = {})
251
+ return klass.construct(@response[type], sub_types, dependant_types)
252
+ end
253
+
254
+ end
255
+ end