chargebee 1.7.4 → 2.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1107 -94
  3. data/LICENSE +1 -1
  4. data/README.rdoc +22 -15
  5. data/chargebee.gemspec +27 -7
  6. data/lib/.DS_Store +0 -0
  7. data/lib/chargebee.rb +28 -2
  8. data/lib/chargebee/environment.rb +11 -6
  9. data/lib/chargebee/errors.rb +1 -1
  10. data/lib/chargebee/models/addon.rb +18 -3
  11. data/lib/chargebee/models/address.rb +1 -1
  12. data/lib/chargebee/models/card.rb +8 -7
  13. data/lib/chargebee/models/comment.rb +1 -1
  14. data/lib/chargebee/models/contact.rb +11 -0
  15. data/lib/chargebee/models/coupon.rb +20 -4
  16. data/lib/chargebee/models/coupon_code.rb +9 -1
  17. data/lib/chargebee/models/coupon_set.rb +38 -0
  18. data/lib/chargebee/models/credit_note.rb +78 -0
  19. data/lib/chargebee/models/credit_note_estimate.rb +36 -0
  20. data/lib/chargebee/models/customer.rb +73 -12
  21. data/lib/chargebee/models/estimate.rb +26 -15
  22. data/lib/chargebee/models/event.rb +1 -1
  23. data/lib/chargebee/models/export.rb +87 -0
  24. data/lib/chargebee/models/gift.rb +43 -0
  25. data/lib/chargebee/models/hierarchy.rb +10 -0
  26. data/lib/chargebee/models/hosted_page.rb +33 -5
  27. data/lib/chargebee/models/invoice.rb +82 -19
  28. data/lib/chargebee/models/invoice_estimate.rb +36 -0
  29. data/lib/chargebee/models/model.rb +34 -3
  30. data/lib/chargebee/models/order.rb +49 -3
  31. data/lib/chargebee/models/payment_source.rb +84 -0
  32. data/lib/chargebee/models/plan.rb +33 -5
  33. data/lib/chargebee/models/promotional_credit.rb +31 -0
  34. data/lib/chargebee/models/quote.rb +77 -0
  35. data/lib/chargebee/models/resource_migration.rb +14 -0
  36. data/lib/chargebee/models/site_migration_detail.rb +15 -0
  37. data/lib/chargebee/models/subscription.rb +60 -8
  38. data/lib/chargebee/models/subscription_estimate.rb +14 -0
  39. data/lib/chargebee/models/third_party_payment_method.rb +10 -0
  40. data/lib/chargebee/models/time_machine.rb +47 -0
  41. data/lib/chargebee/models/token.rb +11 -0
  42. data/lib/chargebee/models/transaction.rb +29 -10
  43. data/lib/chargebee/models/unbilled_charge.rb +32 -0
  44. data/lib/chargebee/models/virtual_bank_account.rb +32 -0
  45. data/lib/chargebee/request.rb +11 -0
  46. data/lib/chargebee/rest.rb +6 -4
  47. data/lib/chargebee/result.rb +183 -27
  48. data/spec/errors_spec.rb +23 -0
  49. data/spec/sample_response.rb +1 -1
  50. metadata +39 -11
  51. data/lib/chargebee/models/payment_intent.rb +0 -27
@@ -0,0 +1,78 @@
1
+ module ChargeBee
2
+ class CreditNote < Model
3
+
4
+ class LineItem < Model
5
+ attr_accessor :id, :subscription_id, :date_from, :date_to, :unit_amount, :quantity, :amount, :pricing_model, :is_taxed, :tax_amount, :tax_rate, :discount_amount, :item_level_discount_amount, :description, :entity_type, :tax_exempt_reason, :entity_id, :customer_id
6
+ end
7
+
8
+ class Discount < Model
9
+ attr_accessor :amount, :description, :entity_type, :entity_id
10
+ end
11
+
12
+ class LineItemDiscount < Model
13
+ attr_accessor :line_item_id, :discount_type, :coupon_id, :discount_amount
14
+ end
15
+
16
+ class LineItemTier < Model
17
+ attr_accessor :line_item_id, :starting_unit, :ending_unit, :quantity_used, :unit_amount
18
+ end
19
+
20
+ class Tax < Model
21
+ attr_accessor :name, :amount, :description
22
+ end
23
+
24
+ class LineItemTax < Model
25
+ attr_accessor :line_item_id, :tax_name, :tax_rate, :is_partial_tax_applied, :is_non_compliance_tax, :taxable_amount, :tax_amount, :tax_juris_type, :tax_juris_name, :tax_juris_code
26
+ end
27
+
28
+ class LinkedRefund < Model
29
+ attr_accessor :txn_id, :applied_amount, :applied_at, :txn_status, :txn_date, :txn_amount
30
+ end
31
+
32
+ class Allocation < Model
33
+ attr_accessor :invoice_id, :allocated_amount, :allocated_at, :invoice_date, :invoice_status
34
+ end
35
+
36
+ attr_accessor :id, :customer_id, :subscription_id, :reference_invoice_id, :type, :reason_code,
37
+ :status, :vat_number, :date, :price_type, :currency_code, :total, :amount_allocated, :amount_refunded,
38
+ :amount_available, :refunded_at, :voided_at, :resource_version, :updated_at, :sub_total, :round_off_amount,
39
+ :fractional_correction, :line_items, :discounts, :line_item_discounts, :line_item_tiers, :taxes,
40
+ :line_item_taxes, :linked_refunds, :allocations, :deleted
41
+
42
+ # OPERATIONS
43
+ #-----------
44
+
45
+ def self.create(params, env=nil, headers={})
46
+ Request.send('post', uri_path("credit_notes"), params, env, headers)
47
+ end
48
+
49
+ def self.retrieve(id, env=nil, headers={})
50
+ Request.send('get', uri_path("credit_notes",id.to_s), {}, env, headers)
51
+ end
52
+
53
+ def self.pdf(id, params={}, env=nil, headers={})
54
+ Request.send('post', uri_path("credit_notes",id.to_s,"pdf"), params, env, headers)
55
+ end
56
+
57
+ def self.record_refund(id, params, env=nil, headers={})
58
+ Request.send('post', uri_path("credit_notes",id.to_s,"record_refund"), params, env, headers)
59
+ end
60
+
61
+ def self.void_credit_note(id, params={}, env=nil, headers={})
62
+ Request.send('post', uri_path("credit_notes",id.to_s,"void"), params, env, headers)
63
+ end
64
+
65
+ def self.list(params={}, env=nil, headers={})
66
+ Request.send_list_request('get', uri_path("credit_notes"), params, env, headers)
67
+ end
68
+
69
+ def self.credit_notes_for_customer(id, params={}, env=nil, headers={})
70
+ Request.send('get', uri_path("customers",id.to_s,"credit_notes"), params, env, headers)
71
+ end
72
+
73
+ def self.delete(id, params={}, env=nil, headers={})
74
+ Request.send('post', uri_path("credit_notes",id.to_s,"delete"), params, env, headers)
75
+ end
76
+
77
+ end # ~CreditNote
78
+ end # ~ChargeBee
@@ -0,0 +1,36 @@
1
+ module ChargeBee
2
+ class CreditNoteEstimate < Model
3
+
4
+ class LineItem < Model
5
+ attr_accessor :id, :subscription_id, :date_from, :date_to, :unit_amount, :quantity, :amount, :pricing_model, :is_taxed, :tax_amount, :tax_rate, :discount_amount, :item_level_discount_amount, :description, :entity_type, :tax_exempt_reason, :entity_id, :customer_id
6
+ end
7
+
8
+ class Discount < Model
9
+ attr_accessor :amount, :description, :entity_type, :entity_id
10
+ end
11
+
12
+ class Tax < Model
13
+ attr_accessor :name, :amount, :description
14
+ end
15
+
16
+ class LineItemTax < Model
17
+ attr_accessor :line_item_id, :tax_name, :tax_rate, :is_partial_tax_applied, :is_non_compliance_tax, :taxable_amount, :tax_amount, :tax_juris_type, :tax_juris_name, :tax_juris_code
18
+ end
19
+
20
+ class LineItemDiscount < Model
21
+ attr_accessor :line_item_id, :discount_type, :coupon_id, :discount_amount
22
+ end
23
+
24
+ class LineItemTier < Model
25
+ attr_accessor :line_item_id, :starting_unit, :ending_unit, :quantity_used, :unit_amount
26
+ end
27
+
28
+ attr_accessor :reference_invoice_id, :type, :price_type, :currency_code, :sub_total, :total,
29
+ :amount_allocated, :amount_available, :line_items, :discounts, :taxes, :line_item_taxes, :line_item_discounts,
30
+ :line_item_tiers, :round_off_amount, :customer_id
31
+
32
+ # OPERATIONS
33
+ #-----------
34
+
35
+ end # ~CreditNoteEstimate
36
+ end # ~ChargeBee
@@ -2,7 +2,11 @@ module ChargeBee
2
2
  class Customer < Model
3
3
 
4
4
  class BillingAddress < Model
5
- attr_accessor :first_name, :last_name, :email, :company, :phone, :line1, :line2, :line3, :city, :state_code, :state, :country, :zip
5
+ attr_accessor :first_name, :last_name, :email, :company, :phone, :line1, :line2, :line3, :city, :state_code, :state, :country, :zip, :validation_status
6
+ end
7
+
8
+ class ReferralUrl < Model
9
+ attr_accessor :external_customer_id, :referral_sharing_url, :created_at, :updated_at, :referral_campaign_id, :referral_account_id, :referral_external_campaign_id, :referral_system
6
10
  end
7
11
 
8
12
  class Contact < Model
@@ -10,13 +14,26 @@ module ChargeBee
10
14
  end
11
15
 
12
16
  class PaymentMethod < Model
13
- attr_accessor :type, :gateway, :status, :reference_id
17
+ attr_accessor :type, :gateway, :gateway_account_id, :status, :reference_id
18
+ end
19
+
20
+ class Balance < Model
21
+ attr_accessor :promotional_credits, :excess_payments, :refundable_credits, :unbilled_charges, :currency_code, :balance_currency_code
22
+ end
23
+
24
+ class Relationship < Model
25
+ attr_accessor :parent_id, :payment_owner_id, :invoice_owner_id
14
26
  end
15
27
 
16
28
  attr_accessor :id, :first_name, :last_name, :email, :phone, :company, :vat_number, :auto_collection,
17
- :allow_direct_debit, :created_at, :created_from_ip, :taxability, :card_status, :billing_address,
18
- :contacts, :payment_method, :invoice_notes, :account_credits, :refundable_credits, :excess_payments,
19
- :meta_data
29
+ :net_term_days, :vat_number_validated_time, :vat_number_status, :allow_direct_debit, :is_location_valid,
30
+ :created_at, :created_from_ip, :exemption_details, :taxability, :entity_code, :exempt_number,
31
+ :resource_version, :updated_at, :locale, :consolidated_invoicing, :billing_date, :billing_date_mode,
32
+ :billing_day_of_week, :billing_day_of_week_mode, :pii_cleared, :card_status, :fraud_flag, :primary_payment_source_id,
33
+ :backup_payment_source_id, :billing_address, :referral_urls, :contacts, :payment_method, :invoice_notes,
34
+ :preferred_currency_code, :promotional_credits, :unbilled_charges, :refundable_credits, :excess_payments,
35
+ :balances, :meta_data, :deleted, :registered_for_gst, :business_customer_without_vat_number,
36
+ :customer_type, :relationship
20
37
 
21
38
  # OPERATIONS
22
39
  #-----------
@@ -26,7 +43,7 @@ module ChargeBee
26
43
  end
27
44
 
28
45
  def self.list(params={}, env=nil, headers={})
29
- Request.send('get', uri_path("customers"), params, env, headers)
46
+ Request.send_list_request('get', uri_path("customers"), params, env, headers)
30
47
  end
31
48
 
32
49
  def self.retrieve(id, env=nil, headers={})
@@ -45,6 +62,14 @@ module ChargeBee
45
62
  Request.send('post', uri_path("customers",id.to_s,"update_billing_info"), params, env, headers)
46
63
  end
47
64
 
65
+ def self.contacts_for_customer(id, params={}, env=nil, headers={})
66
+ Request.send('get', uri_path("customers",id.to_s,"contacts"), params, env, headers)
67
+ end
68
+
69
+ def self.assign_payment_role(id, params, env=nil, headers={})
70
+ Request.send('post', uri_path("customers",id.to_s,"assign_payment_role"), params, env, headers)
71
+ end
72
+
48
73
  def self.add_contact(id, params, env=nil, headers={})
49
74
  Request.send('post', uri_path("customers",id.to_s,"add_contact"), params, env, headers)
50
75
  end
@@ -57,21 +82,57 @@ module ChargeBee
57
82
  Request.send('post', uri_path("customers",id.to_s,"delete_contact"), params, env, headers)
58
83
  end
59
84
 
60
- def self.add_account_credits(id, params, env=nil, headers={})
61
- Request.send('post', uri_path("customers",id.to_s,"add_account_credits"), params, env, headers)
85
+ def self.add_promotional_credits(id, params, env=nil, headers={})
86
+ Request.send('post', uri_path("customers",id.to_s,"add_promotional_credits"), params, env, headers)
87
+ end
88
+
89
+ def self.deduct_promotional_credits(id, params, env=nil, headers={})
90
+ Request.send('post', uri_path("customers",id.to_s,"deduct_promotional_credits"), params, env, headers)
91
+ end
92
+
93
+ def self.set_promotional_credits(id, params, env=nil, headers={})
94
+ Request.send('post', uri_path("customers",id.to_s,"set_promotional_credits"), params, env, headers)
62
95
  end
63
96
 
64
- def self.deduct_account_credits(id, params, env=nil, headers={})
65
- Request.send('post', uri_path("customers",id.to_s,"deduct_account_credits"), params, env, headers)
97
+ def self.record_excess_payment(id, params, env=nil, headers={})
98
+ Request.send('post', uri_path("customers",id.to_s,"record_excess_payment"), params, env, headers)
66
99
  end
67
100
 
68
- def self.set_account_credits(id, params, env=nil, headers={})
69
- Request.send('post', uri_path("customers",id.to_s,"set_account_credits"), params, env, headers)
101
+ def self.collect_payment(id, params={}, env=nil, headers={})
102
+ Request.send('post', uri_path("customers",id.to_s,"collect_payment"), params, env, headers)
70
103
  end
71
104
 
72
105
  def self.delete(id, params={}, env=nil, headers={})
73
106
  Request.send('post', uri_path("customers",id.to_s,"delete"), params, env, headers)
74
107
  end
75
108
 
109
+ def self.move(params, env=nil, headers={})
110
+ Request.send('post', uri_path("customers","move"), params, env, headers)
111
+ end
112
+
113
+ def self.change_billing_date(id, params={}, env=nil, headers={})
114
+ Request.send('post', uri_path("customers",id.to_s,"change_billing_date"), params, env, headers)
115
+ end
116
+
117
+ def self.merge(params, env=nil, headers={})
118
+ Request.send('post', uri_path("customers","merge"), params, env, headers)
119
+ end
120
+
121
+ def self.clear_personal_data(id, env=nil, headers={})
122
+ Request.send('post', uri_path("customers",id.to_s,"clear_personal_data"), {}, env, headers)
123
+ end
124
+
125
+ def self.relationships(id, params={}, env=nil, headers={})
126
+ Request.send('post', uri_path("customers",id.to_s,"relationships"), params, env, headers)
127
+ end
128
+
129
+ def self.delete_relationship(id, env=nil, headers={})
130
+ Request.send('post', uri_path("customers",id.to_s,"delete_relationship"), {}, env, headers)
131
+ end
132
+
133
+ def self.hierarchy(id, params={}, env=nil, headers={})
134
+ Request.send('get', uri_path("customers",id.to_s,"hierarchy"), params, env, headers)
135
+ end
136
+
76
137
  end # ~Customer
77
138
  end # ~ChargeBee
@@ -1,21 +1,8 @@
1
1
  module ChargeBee
2
2
  class Estimate < Model
3
3
 
4
- class LineItem < Model
5
- attr_accessor :date_from, :date_to, :unit_amount, :quantity, :is_taxed, :tax, :tax_rate, :amount, :description, :type, :entity_type, :entity_id
6
- end
7
-
8
- class Discount < Model
9
- attr_accessor :amount, :description, :type, :entity_id
10
- end
11
-
12
- class Tax < Model
13
- attr_accessor :amount, :description
14
- end
15
-
16
- attr_accessor :created_at, :recurring, :subscription_id, :subscription_status, :term_ends_at,
17
- :collect_now, :price_type, :amount, :credits_applied, :amount_due, :sub_total, :line_items,
18
- :discounts, :taxes
4
+ attr_accessor :created_at, :subscription_estimate, :invoice_estimate, :invoice_estimates, :next_invoice_estimate,
5
+ :credit_note_estimates, :unbilled_charge_estimates
19
6
 
20
7
  # OPERATIONS
21
8
  #-----------
@@ -24,6 +11,10 @@ module ChargeBee
24
11
  Request.send('post', uri_path("estimates","create_subscription"), params, env, headers)
25
12
  end
26
13
 
14
+ def self.create_sub_for_customer_estimate(id, params, env=nil, headers={})
15
+ Request.send('get', uri_path("customers",id.to_s,"create_subscription_estimate"), params, env, headers)
16
+ end
17
+
27
18
  def self.update_subscription(params, env=nil, headers={})
28
19
  Request.send('post', uri_path("estimates","update_subscription"), params, env, headers)
29
20
  end
@@ -32,5 +23,25 @@ module ChargeBee
32
23
  Request.send('get', uri_path("subscriptions",id.to_s,"renewal_estimate"), params, env, headers)
33
24
  end
34
25
 
26
+ def self.upcoming_invoices_estimate(id, env=nil, headers={})
27
+ Request.send('get', uri_path("customers",id.to_s,"upcoming_invoices_estimate"), {}, env, headers)
28
+ end
29
+
30
+ def self.change_term_end(id, params={}, env=nil, headers={})
31
+ Request.send('post', uri_path("subscriptions",id.to_s,"change_term_end_estimate"), params, env, headers)
32
+ end
33
+
34
+ def self.cancel_subscription(id, params={}, env=nil, headers={})
35
+ Request.send('post', uri_path("subscriptions",id.to_s,"cancel_subscription_estimate"), params, env, headers)
36
+ end
37
+
38
+ def self.pause_subscription(id, params={}, env=nil, headers={})
39
+ Request.send('post', uri_path("subscriptions",id.to_s,"pause_subscription_estimate"), params, env, headers)
40
+ end
41
+
42
+ def self.resume_subscription(id, params={}, env=nil, headers={})
43
+ Request.send('post', uri_path("subscriptions",id.to_s,"resume_subscription_estimate"), params, env, headers)
44
+ end
45
+
35
46
  end # ~Estimate
36
47
  end # ~ChargeBee
@@ -35,7 +35,7 @@ module ChargeBee
35
35
  #-----------
36
36
 
37
37
  def self.list(params={}, env=nil, headers={})
38
- Request.send('get', uri_path("events"), params, env, headers)
38
+ Request.send_list_request('get', uri_path("events"), params, env, headers)
39
39
  end
40
40
 
41
41
  def self.retrieve(id, env=nil, headers={})
@@ -0,0 +1,87 @@
1
+ module ChargeBee
2
+ class Export < Model
3
+
4
+ class Download < Model
5
+ attr_accessor :download_url, :valid_till
6
+ end
7
+
8
+ attr_accessor :id, :operation_type, :mime_type, :status, :created_at, :download
9
+ def wait_for_export_completion(env = nil, headers={})
10
+ env = env || ChargeBee.default_env
11
+ sleeptime = env.export_sleeptime
12
+
13
+ export_final = (1..50).inject(self) do |export|
14
+ break export if export.status != "in_process"
15
+ sleep(sleeptime)
16
+ self.class.retrieve(self.id, env, headers).export
17
+ end
18
+
19
+ # sync last fetched one with the current instance
20
+ new_values = export_final.instance_variable_get("@values")
21
+ self.instance_variable_set("@values", new_values)
22
+ self.load(new_values)
23
+
24
+ case export_final.status
25
+ when "in_process"
26
+ raise Error.new('Export is taking too long')
27
+ when "failed"
28
+ json_obj = Util.symbolize_keys(JSON.parse(self.error_json))
29
+ raise OperationFailedError.new(json_obj[:http_code], json_obj)
30
+ when "not_enabled", "_unknown"
31
+ raise Error.new("Export status is in wrong state #{self.status}")
32
+ end
33
+ end
34
+
35
+ # OPERATIONS
36
+ #-----------
37
+
38
+ def self.retrieve(id, env=nil, headers={})
39
+ Request.send('get', uri_path("exports",id.to_s), {}, env, headers)
40
+ end
41
+
42
+ def self.revenue_recognition(params, env=nil, headers={})
43
+ Request.send('post', uri_path("exports","revenue_recognition"), params, env, headers)
44
+ end
45
+
46
+ def self.deferred_revenue(params, env=nil, headers={})
47
+ Request.send('post', uri_path("exports","deferred_revenue"), params, env, headers)
48
+ end
49
+
50
+ def self.plans(params={}, env=nil, headers={})
51
+ Request.send('post', uri_path("exports","plans"), params, env, headers)
52
+ end
53
+
54
+ def self.addons(params={}, env=nil, headers={})
55
+ Request.send('post', uri_path("exports","addons"), params, env, headers)
56
+ end
57
+
58
+ def self.coupons(params={}, env=nil, headers={})
59
+ Request.send('post', uri_path("exports","coupons"), params, env, headers)
60
+ end
61
+
62
+ def self.customers(params={}, env=nil, headers={})
63
+ Request.send('post', uri_path("exports","customers"), params, env, headers)
64
+ end
65
+
66
+ def self.subscriptions(params={}, env=nil, headers={})
67
+ Request.send('post', uri_path("exports","subscriptions"), params, env, headers)
68
+ end
69
+
70
+ def self.invoices(params={}, env=nil, headers={})
71
+ Request.send('post', uri_path("exports","invoices"), params, env, headers)
72
+ end
73
+
74
+ def self.credit_notes(params={}, env=nil, headers={})
75
+ Request.send('post', uri_path("exports","credit_notes"), params, env, headers)
76
+ end
77
+
78
+ def self.transactions(params={}, env=nil, headers={})
79
+ Request.send('post', uri_path("exports","transactions"), params, env, headers)
80
+ end
81
+
82
+ def self.orders(params={}, env=nil, headers={})
83
+ Request.send('post', uri_path("exports","orders"), params, env, headers)
84
+ end
85
+
86
+ end # ~Export
87
+ end # ~ChargeBee
@@ -0,0 +1,43 @@
1
+ module ChargeBee
2
+ class Gift < Model
3
+
4
+ class Gifter < Model
5
+ attr_accessor :customer_id, :invoice_id, :signature, :note
6
+ end
7
+
8
+ class GiftReceiver < Model
9
+ attr_accessor :customer_id, :subscription_id, :first_name, :last_name, :email
10
+ end
11
+
12
+ class GiftTimeline < Model
13
+ attr_accessor :status, :occurred_at
14
+ end
15
+
16
+ attr_accessor :id, :status, :scheduled_at, :auto_claim, :claim_expiry_date, :resource_version,
17
+ :updated_at, :gifter, :gift_receiver, :gift_timelines
18
+
19
+ # OPERATIONS
20
+ #-----------
21
+
22
+ def self.create(params, env=nil, headers={})
23
+ Request.send('post', uri_path("gifts"), params, env, headers)
24
+ end
25
+
26
+ def self.retrieve(id, env=nil, headers={})
27
+ Request.send('get', uri_path("gifts",id.to_s), {}, env, headers)
28
+ end
29
+
30
+ def self.list(params={}, env=nil, headers={})
31
+ Request.send_list_request('get', uri_path("gifts"), params, env, headers)
32
+ end
33
+
34
+ def self.claim(id, env=nil, headers={})
35
+ Request.send('post', uri_path("gifts",id.to_s,"claim"), {}, env, headers)
36
+ end
37
+
38
+ def self.cancel(id, env=nil, headers={})
39
+ Request.send('post', uri_path("gifts",id.to_s,"cancel"), {}, env, headers)
40
+ end
41
+
42
+ end # ~Gift
43
+ end # ~ChargeBee