chargebee 2.6.2 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1483 -1473
  3. data/LICENSE +24 -24
  4. data/README.rdoc +41 -41
  5. data/Rakefile +150 -150
  6. data/chargebee.gemspec +2 -2
  7. data/lib/.DS_Store +0 -0
  8. data/lib/chargebee.rb +85 -85
  9. data/lib/chargebee/environment.rb +28 -28
  10. data/lib/chargebee/errors.rb +43 -43
  11. data/lib/chargebee/list_result.rb +28 -28
  12. data/lib/chargebee/models/addon.rb +45 -45
  13. data/lib/chargebee/models/address.rb +18 -18
  14. data/lib/chargebee/models/card.rb +32 -32
  15. data/lib/chargebee/models/comment.rb +25 -25
  16. data/lib/chargebee/models/contact.rb +10 -10
  17. data/lib/chargebee/models/coupon.rb +40 -40
  18. data/lib/chargebee/models/coupon_code.rb +25 -25
  19. data/lib/chargebee/models/coupon_set.rb +37 -37
  20. data/lib/chargebee/models/credit_note.rb +77 -77
  21. data/lib/chargebee/models/credit_note_estimate.rb +35 -35
  22. data/lib/chargebee/models/customer.rb +120 -120
  23. data/lib/chargebee/models/download.rb +9 -9
  24. data/lib/chargebee/models/estimate.rb +46 -46
  25. data/lib/chargebee/models/event.rb +45 -45
  26. data/lib/chargebee/models/export.rb +86 -82
  27. data/lib/chargebee/models/gift.rb +42 -42
  28. data/lib/chargebee/models/hosted_page.rb +77 -73
  29. data/lib/chargebee/models/invoice.rb +172 -172
  30. data/lib/chargebee/models/invoice_estimate.rb +35 -35
  31. data/lib/chargebee/models/model.rb +101 -101
  32. data/lib/chargebee/models/order.rb +76 -76
  33. data/lib/chargebee/models/payment_source.rb +71 -70
  34. data/lib/chargebee/models/plan.rb +59 -59
  35. data/lib/chargebee/models/portal_session.rb +30 -30
  36. data/lib/chargebee/models/promotional_credit.rb +30 -30
  37. data/lib/chargebee/models/quote.rb +72 -72
  38. data/lib/chargebee/models/resource_migration.rb +13 -13
  39. data/lib/chargebee/models/site_migration_detail.rb +14 -14
  40. data/lib/chargebee/models/subscription.rb +137 -137
  41. data/lib/chargebee/models/subscription_estimate.rb +13 -13
  42. data/lib/chargebee/models/third_party_payment_method.rb +9 -9
  43. data/lib/chargebee/models/time_machine.rb +46 -46
  44. data/lib/chargebee/models/transaction.rb +62 -58
  45. data/lib/chargebee/models/unbilled_charge.rb +31 -31
  46. data/lib/chargebee/models/virtual_bank_account.rb +26 -26
  47. data/lib/chargebee/request.rb +27 -27
  48. data/lib/chargebee/rest.rb +92 -90
  49. data/lib/chargebee/result.rb +240 -240
  50. data/lib/chargebee/util.rb +56 -56
  51. data/lib/ssl/ca-certs.crt +3385 -3385
  52. data/spec/chargebee/list_result_spec.rb +53 -53
  53. data/spec/chargebee_spec.rb +99 -99
  54. data/spec/errors_spec.rb +23 -23
  55. data/spec/sample_response.rb +73 -73
  56. data/spec/spec_helper.rb +24 -24
  57. metadata +2 -2
@@ -1,121 +1,121 @@
1
- module ChargeBee
2
- class Customer < Model
3
-
4
- class BillingAddress < Model
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
10
- end
11
-
12
- class Contact < Model
13
- attr_accessor :id, :first_name, :last_name, :email, :phone, :label, :enabled, :send_account_email, :send_billing_email
14
- end
15
-
16
- class PaymentMethod < Model
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
- attr_accessor :id, :first_name, :last_name, :email, :phone, :company, :vat_number, :auto_collection,
25
- :net_term_days, :vat_number_validated_time, :vat_number_status, :allow_direct_debit, :is_location_valid,
26
- :created_at, :created_from_ip, :taxability, :entity_code, :exempt_number, :resource_version,
27
- :updated_at, :locale, :consolidated_invoicing, :billing_date, :billing_date_mode, :billing_day_of_week,
28
- :billing_day_of_week_mode, :pii_cleared, :card_status, :fraud_flag, :primary_payment_source_id,
29
- :backup_payment_source_id, :billing_address, :referral_urls, :contacts, :payment_method, :invoice_notes,
30
- :preferred_currency_code, :promotional_credits, :unbilled_charges, :refundable_credits, :excess_payments,
31
- :balances, :meta_data, :deleted, :registered_for_gst
32
-
33
- # OPERATIONS
34
- #-----------
35
-
36
- def self.create(params={}, env=nil, headers={})
37
- Request.send('post', uri_path("customers"), params, env, headers)
38
- end
39
-
40
- def self.list(params={}, env=nil, headers={})
41
- Request.send_list_request('get', uri_path("customers"), params, env, headers)
42
- end
43
-
44
- def self.retrieve(id, env=nil, headers={})
45
- Request.send('get', uri_path("customers",id.to_s), {}, env, headers)
46
- end
47
-
48
- def self.update(id, params={}, env=nil, headers={})
49
- Request.send('post', uri_path("customers",id.to_s), params, env, headers)
50
- end
51
-
52
- def self.update_payment_method(id, params, env=nil, headers={})
53
- Request.send('post', uri_path("customers",id.to_s,"update_payment_method"), params, env, headers)
54
- end
55
-
56
- def self.update_billing_info(id, params={}, env=nil, headers={})
57
- Request.send('post', uri_path("customers",id.to_s,"update_billing_info"), params, env, headers)
58
- end
59
-
60
- def self.contacts_for_customer(id, params={}, env=nil, headers={})
61
- Request.send('get', uri_path("customers",id.to_s,"contacts"), params, env, headers)
62
- end
63
-
64
- def self.assign_payment_role(id, params, env=nil, headers={})
65
- Request.send('post', uri_path("customers",id.to_s,"assign_payment_role"), params, env, headers)
66
- end
67
-
68
- def self.add_contact(id, params, env=nil, headers={})
69
- Request.send('post', uri_path("customers",id.to_s,"add_contact"), params, env, headers)
70
- end
71
-
72
- def self.update_contact(id, params, env=nil, headers={})
73
- Request.send('post', uri_path("customers",id.to_s,"update_contact"), params, env, headers)
74
- end
75
-
76
- def self.delete_contact(id, params, env=nil, headers={})
77
- Request.send('post', uri_path("customers",id.to_s,"delete_contact"), params, env, headers)
78
- end
79
-
80
- def self.add_promotional_credits(id, params, env=nil, headers={})
81
- Request.send('post', uri_path("customers",id.to_s,"add_promotional_credits"), params, env, headers)
82
- end
83
-
84
- def self.deduct_promotional_credits(id, params, env=nil, headers={})
85
- Request.send('post', uri_path("customers",id.to_s,"deduct_promotional_credits"), params, env, headers)
86
- end
87
-
88
- def self.set_promotional_credits(id, params, env=nil, headers={})
89
- Request.send('post', uri_path("customers",id.to_s,"set_promotional_credits"), params, env, headers)
90
- end
91
-
92
- def self.record_excess_payment(id, params, env=nil, headers={})
93
- Request.send('post', uri_path("customers",id.to_s,"record_excess_payment"), params, env, headers)
94
- end
95
-
96
- def self.collect_payment(id, params={}, env=nil, headers={})
97
- Request.send('post', uri_path("customers",id.to_s,"collect_payment"), params, env, headers)
98
- end
99
-
100
- def self.delete(id, params={}, env=nil, headers={})
101
- Request.send('post', uri_path("customers",id.to_s,"delete"), params, env, headers)
102
- end
103
-
104
- def self.move(params, env=nil, headers={})
105
- Request.send('post', uri_path("customers","move"), params, env, headers)
106
- end
107
-
108
- def self.change_billing_date(id, params={}, env=nil, headers={})
109
- Request.send('post', uri_path("customers",id.to_s,"change_billing_date"), params, env, headers)
110
- end
111
-
112
- def self.merge(params, env=nil, headers={})
113
- Request.send('post', uri_path("customers","merge"), params, env, headers)
114
- end
115
-
116
- def self.clear_personal_data(id, env=nil, headers={})
117
- Request.send('post', uri_path("customers",id.to_s,"clear_personal_data"), {}, env, headers)
118
- end
119
-
120
- end # ~Customer
1
+ module ChargeBee
2
+ class Customer < Model
3
+
4
+ class BillingAddress < Model
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
10
+ end
11
+
12
+ class Contact < Model
13
+ attr_accessor :id, :first_name, :last_name, :email, :phone, :label, :enabled, :send_account_email, :send_billing_email
14
+ end
15
+
16
+ class PaymentMethod < Model
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
+ attr_accessor :id, :first_name, :last_name, :email, :phone, :company, :vat_number, :auto_collection,
25
+ :net_term_days, :vat_number_validated_time, :vat_number_status, :allow_direct_debit, :is_location_valid,
26
+ :created_at, :created_from_ip, :taxability, :entity_code, :exempt_number, :resource_version,
27
+ :updated_at, :locale, :consolidated_invoicing, :billing_date, :billing_date_mode, :billing_day_of_week,
28
+ :billing_day_of_week_mode, :pii_cleared, :card_status, :fraud_flag, :primary_payment_source_id,
29
+ :backup_payment_source_id, :billing_address, :referral_urls, :contacts, :payment_method, :invoice_notes,
30
+ :preferred_currency_code, :promotional_credits, :unbilled_charges, :refundable_credits, :excess_payments,
31
+ :balances, :meta_data, :deleted, :registered_for_gst
32
+
33
+ # OPERATIONS
34
+ #-----------
35
+
36
+ def self.create(params={}, env=nil, headers={})
37
+ Request.send('post', uri_path("customers"), params, env, headers)
38
+ end
39
+
40
+ def self.list(params={}, env=nil, headers={})
41
+ Request.send_list_request('get', uri_path("customers"), params, env, headers)
42
+ end
43
+
44
+ def self.retrieve(id, env=nil, headers={})
45
+ Request.send('get', uri_path("customers",id.to_s), {}, env, headers)
46
+ end
47
+
48
+ def self.update(id, params={}, env=nil, headers={})
49
+ Request.send('post', uri_path("customers",id.to_s), params, env, headers)
50
+ end
51
+
52
+ def self.update_payment_method(id, params, env=nil, headers={})
53
+ Request.send('post', uri_path("customers",id.to_s,"update_payment_method"), params, env, headers)
54
+ end
55
+
56
+ def self.update_billing_info(id, params={}, env=nil, headers={})
57
+ Request.send('post', uri_path("customers",id.to_s,"update_billing_info"), params, env, headers)
58
+ end
59
+
60
+ def self.contacts_for_customer(id, params={}, env=nil, headers={})
61
+ Request.send('get', uri_path("customers",id.to_s,"contacts"), params, env, headers)
62
+ end
63
+
64
+ def self.assign_payment_role(id, params, env=nil, headers={})
65
+ Request.send('post', uri_path("customers",id.to_s,"assign_payment_role"), params, env, headers)
66
+ end
67
+
68
+ def self.add_contact(id, params, env=nil, headers={})
69
+ Request.send('post', uri_path("customers",id.to_s,"add_contact"), params, env, headers)
70
+ end
71
+
72
+ def self.update_contact(id, params, env=nil, headers={})
73
+ Request.send('post', uri_path("customers",id.to_s,"update_contact"), params, env, headers)
74
+ end
75
+
76
+ def self.delete_contact(id, params, env=nil, headers={})
77
+ Request.send('post', uri_path("customers",id.to_s,"delete_contact"), params, env, headers)
78
+ end
79
+
80
+ def self.add_promotional_credits(id, params, env=nil, headers={})
81
+ Request.send('post', uri_path("customers",id.to_s,"add_promotional_credits"), params, env, headers)
82
+ end
83
+
84
+ def self.deduct_promotional_credits(id, params, env=nil, headers={})
85
+ Request.send('post', uri_path("customers",id.to_s,"deduct_promotional_credits"), params, env, headers)
86
+ end
87
+
88
+ def self.set_promotional_credits(id, params, env=nil, headers={})
89
+ Request.send('post', uri_path("customers",id.to_s,"set_promotional_credits"), params, env, headers)
90
+ end
91
+
92
+ def self.record_excess_payment(id, params, env=nil, headers={})
93
+ Request.send('post', uri_path("customers",id.to_s,"record_excess_payment"), params, env, headers)
94
+ end
95
+
96
+ def self.collect_payment(id, params={}, env=nil, headers={})
97
+ Request.send('post', uri_path("customers",id.to_s,"collect_payment"), params, env, headers)
98
+ end
99
+
100
+ def self.delete(id, params={}, env=nil, headers={})
101
+ Request.send('post', uri_path("customers",id.to_s,"delete"), params, env, headers)
102
+ end
103
+
104
+ def self.move(params, env=nil, headers={})
105
+ Request.send('post', uri_path("customers","move"), params, env, headers)
106
+ end
107
+
108
+ def self.change_billing_date(id, params={}, env=nil, headers={})
109
+ Request.send('post', uri_path("customers",id.to_s,"change_billing_date"), params, env, headers)
110
+ end
111
+
112
+ def self.merge(params, env=nil, headers={})
113
+ Request.send('post', uri_path("customers","merge"), params, env, headers)
114
+ end
115
+
116
+ def self.clear_personal_data(id, env=nil, headers={})
117
+ Request.send('post', uri_path("customers",id.to_s,"clear_personal_data"), {}, env, headers)
118
+ end
119
+
120
+ end # ~Customer
121
121
  end # ~ChargeBee
@@ -1,10 +1,10 @@
1
- module ChargeBee
2
- class Download < Model
3
-
4
- attr_accessor :download_url, :valid_till
5
-
6
- # OPERATIONS
7
- #-----------
8
-
9
- end # ~Download
1
+ module ChargeBee
2
+ class Download < Model
3
+
4
+ attr_accessor :download_url, :valid_till
5
+
6
+ # OPERATIONS
7
+ #-----------
8
+
9
+ end # ~Download
10
10
  end # ~ChargeBee
@@ -1,47 +1,47 @@
1
- module ChargeBee
2
- class Estimate < Model
3
-
4
- attr_accessor :created_at, :subscription_estimate, :invoice_estimate, :invoice_estimates, :next_invoice_estimate,
5
- :credit_note_estimates, :unbilled_charge_estimates
6
-
7
- # OPERATIONS
8
- #-----------
9
-
10
- def self.create_subscription(params, env=nil, headers={})
11
- Request.send('post', uri_path("estimates","create_subscription"), params, env, headers)
12
- end
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
-
18
- def self.update_subscription(params, env=nil, headers={})
19
- Request.send('post', uri_path("estimates","update_subscription"), params, env, headers)
20
- end
21
-
22
- def self.renewal_estimate(id, params={}, env=nil, headers={})
23
- Request.send('get', uri_path("subscriptions",id.to_s,"renewal_estimate"), params, env, headers)
24
- end
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
-
46
- end # ~Estimate
1
+ module ChargeBee
2
+ class Estimate < Model
3
+
4
+ attr_accessor :created_at, :subscription_estimate, :invoice_estimate, :invoice_estimates, :next_invoice_estimate,
5
+ :credit_note_estimates, :unbilled_charge_estimates
6
+
7
+ # OPERATIONS
8
+ #-----------
9
+
10
+ def self.create_subscription(params, env=nil, headers={})
11
+ Request.send('post', uri_path("estimates","create_subscription"), params, env, headers)
12
+ end
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
+
18
+ def self.update_subscription(params, env=nil, headers={})
19
+ Request.send('post', uri_path("estimates","update_subscription"), params, env, headers)
20
+ end
21
+
22
+ def self.renewal_estimate(id, params={}, env=nil, headers={})
23
+ Request.send('get', uri_path("subscriptions",id.to_s,"renewal_estimate"), params, env, headers)
24
+ end
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
+
46
+ end # ~Estimate
47
47
  end # ~ChargeBee
@@ -1,46 +1,46 @@
1
- module ChargeBee
2
- class Event < Model
3
-
4
- class Webhook < Model
5
- attr_accessor :id, :webhook_status
6
- end
7
-
8
- attr_accessor :id, :occurred_at, :source, :user, :webhook_status, :webhook_failure_reason, :webhooks,
9
- :event_type, :api_version
10
-
11
- class Content < Result
12
- end
13
-
14
- def content
15
- Content.new(@values[:content])
16
- end
17
-
18
- def self.deserialize(json)
19
- begin
20
- webhook_data = JSON.parse(json)
21
- rescue JSON::ParserError => e
22
- raise Error.new("Invalid webhook object to deserialize. #{e}",e)
23
- end
24
-
25
- api_version = webhook_data["api_version"]
26
- if api_version != nil && api_version.casecmp(Environment::API_VERSION) != 0
27
- raise Error.new("API version [#{api_version.upcase}] in response does not match with client library API version [#{Environment::API_VERSION.upcase}]")
28
- end
29
-
30
- webhook_data = Util.symbolize_keys(webhook_data)
31
- Event.construct(webhook_data)
32
- end
33
-
34
- # OPERATIONS
35
- #-----------
36
-
37
- def self.list(params={}, env=nil, headers={})
38
- Request.send_list_request('get', uri_path("events"), params, env, headers)
39
- end
40
-
41
- def self.retrieve(id, env=nil, headers={})
42
- Request.send('get', uri_path("events",id.to_s), {}, env, headers)
43
- end
44
-
45
- end # ~Event
1
+ module ChargeBee
2
+ class Event < Model
3
+
4
+ class Webhook < Model
5
+ attr_accessor :id, :webhook_status
6
+ end
7
+
8
+ attr_accessor :id, :occurred_at, :source, :user, :webhook_status, :webhook_failure_reason, :webhooks,
9
+ :event_type, :api_version
10
+
11
+ class Content < Result
12
+ end
13
+
14
+ def content
15
+ Content.new(@values[:content])
16
+ end
17
+
18
+ def self.deserialize(json)
19
+ begin
20
+ webhook_data = JSON.parse(json)
21
+ rescue JSON::ParserError => e
22
+ raise Error.new("Invalid webhook object to deserialize. #{e}",e)
23
+ end
24
+
25
+ api_version = webhook_data["api_version"]
26
+ if api_version != nil && api_version.casecmp(Environment::API_VERSION) != 0
27
+ raise Error.new("API version [#{api_version.upcase}] in response does not match with client library API version [#{Environment::API_VERSION.upcase}]")
28
+ end
29
+
30
+ webhook_data = Util.symbolize_keys(webhook_data)
31
+ Event.construct(webhook_data)
32
+ end
33
+
34
+ # OPERATIONS
35
+ #-----------
36
+
37
+ def self.list(params={}, env=nil, headers={})
38
+ Request.send_list_request('get', uri_path("events"), params, env, headers)
39
+ end
40
+
41
+ def self.retrieve(id, env=nil, headers={})
42
+ Request.send('get', uri_path("events",id.to_s), {}, env, headers)
43
+ end
44
+
45
+ end # ~Event
46
46
  end # ~ChargeBee
@@ -1,83 +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
- end # ~Export
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
83
87
  end # ~ChargeBee