bill_forward 1.2014.296 → 1.2015.183

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -27
  3. data/.idea/compiler.xml +23 -23
  4. data/.idea/copyright/profiles_settings.xml +2 -2
  5. data/.idea/encodings.xml +5 -5
  6. data/.idea/inspectionProfiles/Project_Default.xml +10 -10
  7. data/.idea/inspectionProfiles/profiles_settings.xml +6 -6
  8. data/.idea/misc.xml +23 -23
  9. data/.idea/modules.xml +9 -9
  10. data/.idea/scopes/scope_settings.xml +4 -4
  11. data/.idea/vcs.xml +7 -7
  12. data/.rspec +1 -1
  13. data/Gemfile +13 -9
  14. data/LICENSE.md +22 -22
  15. data/README.md +285 -227
  16. data/Rakefile +73 -73
  17. data/bill_forward.gemspec +28 -29
  18. data/bill_forward.iml +28 -28
  19. data/lib/bill_forward/billing_entity.rb +295 -262
  20. data/lib/bill_forward/client.rb +350 -355
  21. data/lib/bill_forward/entities/account.rb +18 -18
  22. data/lib/bill_forward/entities/amendments/issue_invoice_amendment.rb +10 -0
  23. data/lib/bill_forward/entities/amendments/product_rate_plan_migration_amendment.rb +18 -0
  24. data/lib/bill_forward/entities/api_configuration.rb +12 -0
  25. data/lib/bill_forward/entities/invoice.rb +29 -3
  26. data/lib/bill_forward/entities/invoice_parts/taxation_link.rb +5 -5
  27. data/lib/bill_forward/entities/organisation.rb +36 -36
  28. data/lib/bill_forward/entities/payment_method.rb +4 -4
  29. data/lib/bill_forward/entities/payment_method_subscription_link.rb +5 -5
  30. data/lib/bill_forward/entities/pricing_component.rb +21 -21
  31. data/lib/bill_forward/entities/pricing_component_tier.rb +5 -5
  32. data/lib/bill_forward/entities/pricing_component_value.rb +5 -5
  33. data/lib/bill_forward/entities/pricing_component_value_migration_amendment_mapping.rb +31 -0
  34. data/lib/bill_forward/entities/product.rb +5 -5
  35. data/lib/bill_forward/entities/product_rate_plan.rb +43 -19
  36. data/lib/bill_forward/entities/profile.rb +14 -14
  37. data/lib/bill_forward/entities/refund.rb +5 -0
  38. data/lib/bill_forward/entities/role.rb +3 -3
  39. data/lib/bill_forward/entities/stripe_ach_token.rb +9 -0
  40. data/lib/bill_forward/entities/subscription.rb +83 -53
  41. data/lib/bill_forward/entities/subscription_charge.rb +14 -0
  42. data/lib/bill_forward/insertable_entity.rb +21 -31
  43. data/lib/bill_forward/mutable_entity.rb +26 -46
  44. data/lib/bill_forward/resource_path.rb +10 -10
  45. data/lib/bill_forward/type_check.rb +20 -20
  46. data/lib/bill_forward/version.rb +4 -4
  47. data/lib/bill_forward.rb +17 -17
  48. data/scratch/Gemfile +9 -0
  49. data/scratch/scratch.example.rb +8 -0
  50. data/spec/component/account_spec.rb +199 -199
  51. data/spec/component/billing_entity_spec.rb +152 -152
  52. data/spec/functional/account_spec.rb +24 -24
  53. data/spec/functional/bad_citizen/account_spec.rb +102 -102
  54. data/spec/functional/bad_citizen/credit_note_spec.rb +14 -13
  55. data/spec/functional/bad_citizen/payment_method_spec.rb +1 -1
  56. data/spec/functional/bad_citizen/product_rate_plan_migration_amendment_spec.rb +379 -0
  57. data/spec/functional/bad_citizen/product_rate_plan_spec.rb +103 -47
  58. data/spec/functional/bad_citizen/product_spec.rb +16 -9
  59. data/spec/functional/bad_citizen/situational/authorize_net_token_spec.rb +4 -0
  60. data/spec/functional/bad_citizen/situational/malordered_entity_spec.rb +1 -1
  61. data/spec/functional/bad_citizen/situational/payment_method_spec.rb +6 -1
  62. data/spec/functional/bad_citizen/situational/subscription_chargeable_spec.rb +96 -65
  63. data/spec/functional/bad_citizen/subscription_spec.rb +99 -60
  64. data/spec/functional/bad_citizen/subscription_with_credit_spec.rb +121 -91
  65. data/spec/functional/bad_citizen/unit_of_measure_spec.rb +14 -7
  66. data/spec/functional/client_spec.rb +23 -23
  67. data/spec/functional/organisation_spec.rb +27 -27
  68. data/spec/setup_test_constants.rb +72 -72
  69. data/spec/spec_helper.rb +10 -10
  70. data/spec/syntax/account_spec.rb +23 -23
  71. data/spec/syntax/billing_entity_spec.rb +92 -92
  72. data/tools/RSpec hardcoded.sublime-build +16 -0
  73. data/tools/RSpec.sublime-build +13 -0
  74. data/tools/Ruby legacy.sublime-build +7 -0
  75. data/tools/local_bundle_build.sh +8 -0
  76. data/tools/local_bundle_install.sh +9 -0
  77. metadata +30 -85
@@ -1,19 +1,19 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # Role[] .roles
5
- # PaymentMethod[] .paymentMethods
6
- # Profile .profile
7
- class Account < MutableEntity
8
- @resource_path = BillForward::ResourcePath.new("accounts", "account")
9
-
10
- protected
11
- def unserialize_all(hash)
12
- super
13
- unserialize_entity('profile', Profile, hash)
14
-
15
- unserialize_array_of_entities('roles', Role, hash)
16
- unserialize_array_of_entities('paymentMethods', PaymentMethod, hash)
17
- end
18
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # Role[] .roles
5
+ # PaymentMethod[] .paymentMethods
6
+ # Profile .profile
7
+ class Account < MutableEntity
8
+ @resource_path = BillForward::ResourcePath.new("accounts", "account")
9
+
10
+ protected
11
+ def unserialize_all(hash)
12
+ super
13
+ unserialize_entity('profile', Profile, hash)
14
+
15
+ unserialize_array_of_entities('roles', Role, hash)
16
+ unserialize_array_of_entities('paymentMethods', PaymentMethod, hash)
17
+ end
18
+ end
19
19
  end
@@ -0,0 +1,10 @@
1
+ module BillForward
2
+ class IssueInvoiceAmendment < Amendment
3
+ @resource_path = BillForward::ResourcePath.new("amendments", "amendment")
4
+
5
+ def initialize(*args)
6
+ super
7
+ set_state_param('@type', 'IssueInvoiceAmendment')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # PricingComponentValueMigrationAmendmentMapping[] .mappings
5
+ class ProductRatePlanMigrationAmendment < Amendment
6
+ @resource_path = BillForward::ResourcePath.new("amendments", "amendment")
7
+
8
+ def initialize(*args)
9
+ super
10
+ set_state_param('@type', 'ProductRatePlanMigrationAmendment')
11
+ end
12
+ protected
13
+ def unserialize_all(hash)
14
+ super
15
+ unserialize_array_of_entities('mappings', PricingComponentValueMigrationAmendmentMapping, hash)
16
+ end
17
+ end
18
+ end
@@ -1,11 +1,23 @@
1
1
  module BillForward
2
2
  class APIConfiguration < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new('configurations', 'APIConfiguration')
4
+
3
5
  class << self
4
6
  def create(entity = nil)
5
7
  raise DenyMethod.new 'Create support is denied for this entity; '+
6
8
  'at the time of writing, no API endpoint exists to support it. '+
7
9
  'The entity can be created through cascade only (i.e. instantiated within another entity).'
8
10
  end
11
+
12
+ def get_by_type(type, query_params = {}, custom_client = nil)
13
+ raise ArgumentError.new("type cannot be nil") if type.nil?
14
+
15
+ endpoint = sprintf('type/%s',
16
+ ERB::Util.url_encode(type)
17
+ )
18
+
19
+ self.request_many('get', endpoint, query_params, custom_client)
20
+ end
9
21
  end
10
22
  end
11
23
  end
@@ -1,9 +1,12 @@
1
1
  module BillForward
2
2
  # This entity exposes the following child entities via method_missing:
3
3
  #
4
- # InvoiceLine[] .invoiceLines
5
- # TaxLine[] .taxLines
6
- # InvoicePayment[] .invoicePayments
4
+ # InvoiceLine[] .invoiceLines
5
+ # TaxLine[] .taxLines
6
+ # InvoicePayment[] .invoicePayments
7
+ # Refund[] .invoiceRefunds
8
+ # CreditNote[] .invoiceCreditNotes
9
+ # SubscriptionCharge[] .charges
7
10
  class Invoice < MutableEntity
8
11
  @resource_path = BillForward::ResourcePath.new('invoices', 'invoice')
9
12
 
@@ -12,6 +15,26 @@ module BillForward
12
15
  raise DenyMethod.new 'Create support is denied for this entity; '+
13
16
  'Invoices are generated instead by the BillForward Engines.'
14
17
  end
18
+
19
+ def get_by_subscription_id(id, query_params = {}, custom_client = nil)
20
+ raise ArgumentError.new("id cannot be nil") if id.nil?
21
+
22
+ endpoint = sprintf('subscription/%s',
23
+ ERB::Util.url_encode(id)
24
+ )
25
+
26
+ self.request_many('get', endpoint, query_params, custom_client)
27
+ end
28
+
29
+ def get_by_account_id(id, query_params = {}, custom_client = nil)
30
+ raise ArgumentError.new("id cannot be nil") if id.nil?
31
+
32
+ endpoint = sprintf('account/%s',
33
+ ERB::Util.url_encode(id)
34
+ )
35
+
36
+ self.request_many('get', endpoint, query_params, custom_client)
37
+ end
15
38
  end
16
39
 
17
40
  protected
@@ -20,6 +43,9 @@ module BillForward
20
43
  unserialize_array_of_entities('invoiceLines', InvoiceLine, hash)
21
44
  unserialize_array_of_entities('taxLines', TaxLine, hash)
22
45
  unserialize_array_of_entities('invoicePayments', InvoicePayment, hash)
46
+ unserialize_array_of_entities('invoiceRefunds', Refund, hash)
47
+ unserialize_array_of_entities('invoiceCreditNotes', CreditNote, hash)
48
+ unserialize_array_of_entities('charges', SubscriptionCharge, hash)
23
49
  end
24
50
  end
25
51
  end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class TaxationLink < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("taxation-links", "TaxationLink")
4
- end
5
- end
1
+ module BillForward
2
+ class TaxationLink < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("taxation-links", "TaxationLink")
4
+ end
5
+ end
@@ -1,37 +1,37 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # APIConfiguration[] .apiConfigurations
5
- class Organisation < MutableEntity
6
- @resource_path = BillForward::ResourcePath.new("organizations", "organization")
7
-
8
- class << self
9
- def get_mine(options = {}, customClient = nil)
10
- client = customClient
11
- client = singleton_client if client.nil?
12
-
13
- route = resource_path.path
14
- endpoint = 'mine'
15
- url_full = "#{route}/#{endpoint}"
16
-
17
- response = client.get(url_full)
18
- results = response["results"]
19
-
20
- # maybe use build_entity_array here for consistency
21
- entity_array = Array.new
22
- # maybe it's an empty array, but that's okay too.
23
- results.each do |value|
24
- entity = self.new(value, client)
25
- entity_array.push(entity)
26
- end
27
- entity_array
28
- end
29
- end
30
-
31
- protected
32
- def unserialize_all(hash)
33
- super
34
- unserialize_array_of_entities('apiConfigurations', APIConfiguration, hash)
35
- end
36
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # APIConfiguration[] .apiConfigurations
5
+ class Organisation < MutableEntity
6
+ @resource_path = BillForward::ResourcePath.new("organizations", "organization")
7
+
8
+ class << self
9
+ def get_mine(options = {}, customClient = nil)
10
+ client = customClient
11
+ client = singleton_client if client.nil?
12
+
13
+ route = resource_path.path
14
+ endpoint = 'mine'
15
+ url_full = "#{route}/#{endpoint}"
16
+
17
+ response = client.get(url_full)
18
+ results = response["results"]
19
+
20
+ # maybe use build_entity_array here for consistency
21
+ entity_array = Array.new
22
+ # maybe it's an empty array, but that's okay too.
23
+ results.each do |value|
24
+ entity = self.new(value, client)
25
+ entity_array.push(entity)
26
+ end
27
+ entity_array
28
+ end
29
+ end
30
+
31
+ protected
32
+ def unserialize_all(hash)
33
+ super
34
+ unserialize_array_of_entities('apiConfigurations', APIConfiguration, hash)
35
+ end
36
+ end
37
37
  end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class PaymentMethod < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("payment-methods", "paymentMethod")
4
- end
1
+ module BillForward
2
+ class PaymentMethod < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("payment-methods", "paymentMethod")
4
+ end
5
5
  end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class PaymentMethodSubscriptionLink < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("payment-method-subcription-links", "PaymentMethodSubscriptionLink")
4
- end
5
- end
1
+ module BillForward
2
+ class PaymentMethodSubscriptionLink < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("payment-method-subcription-links", "PaymentMethodSubscriptionLink")
4
+ end
5
+ end
@@ -1,21 +1,21 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # PricingComponentTier[] .tiers
5
- class PricingComponent < MutableEntity
6
- @resource_path = BillForward::ResourcePath.new("pricing-components", "PricingComponent")
7
-
8
- def self.get_all(options=nil, customClient=nil)
9
- raise ArgumentError.new('Get All support is denied for this entity;
10
- at the time of writing, no working API endpoint exists to support it.
11
- The entity can be GETted through cascade (i.e. GET a related entity), or by ID only.'
12
- )
13
- end
14
-
15
- protected
16
- def unserialize_all(hash)
17
- super
18
- unserialize_array_of_entities('tiers', PricingComponentTier, hash)
19
- end
20
- end
21
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # PricingComponentTier[] .tiers
5
+ class PricingComponent < MutableEntity
6
+ @resource_path = BillForward::ResourcePath.new("pricing-components", "PricingComponent")
7
+
8
+ def self.get_all(options=nil, customClient=nil)
9
+ raise ArgumentError.new('Get All support is denied for this entity;
10
+ at the time of writing, no working API endpoint exists to support it.
11
+ The entity can be GETted through cascade (i.e. GET a related entity), or by ID only.'
12
+ )
13
+ end
14
+
15
+ protected
16
+ def unserialize_all(hash)
17
+ super
18
+ unserialize_array_of_entities('tiers', PricingComponentTier, hash)
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class PricingComponentTier < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("pricing-component-tiers", "pricingComponentTier")
4
- end
5
- end
1
+ module BillForward
2
+ class PricingComponentTier < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("pricing-component-tiers", "pricingComponentTier")
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class PricingComponentValue < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("pricing-component-values", "PricingComponentValue")
4
- end
5
- end
1
+ module BillForward
2
+ class PricingComponentValue < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("pricing-component-values", "PricingComponentValue")
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module BillForward
2
+ class PricingComponentValueMigrationAmendmentMapping < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new('', 'PricingComponentValueMigrationAmendmentMapping')
4
+
5
+ class << self
6
+ def create(entity = nil)
7
+ raise DenyMethod.new 'Create support is denied for this entity; '+
8
+ 'at the time of writing, no API endpoint exists to support it. '+
9
+ 'The entity can be created through cascade only (i.e. instantiated within another entity).'
10
+ end
11
+
12
+ def get_by_id(id, query_params = {}, customClient = nil)
13
+ raise DenyMethod.new 'Get by ID support is denied for this entity; '+
14
+ 'at the time of writing, no API endpoint exists to support it.'+
15
+ 'The entity can be GETted through cascade only (i.e. GET a related entity).'
16
+ end
17
+
18
+ def get_all(query_params = {}, customClient = nil)
19
+ raise DenyMethod.new 'Get All support is denied for this entity; '+
20
+ 'at the time of writing, no API endpoint exists to support it.'+
21
+ 'The entity can be GETted through cascade only (i.e. GET a related entity).'
22
+ end
23
+ end
24
+
25
+ def save()
26
+ raise DenyMethod.new 'Save support is denied for this entity; '+
27
+ 'at the time of writing, the provided API endpoint is not functioning.'+
28
+ 'The entity can be saved through cascade only (i.e. save a related entity).'
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
- module BillForward
2
- class Product < MutableEntity
3
- @resource_path = BillForward::ResourcePath.new("products", "product")
4
- end
5
- end
1
+ module BillForward
2
+ class Product < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("products", "product")
4
+ end
5
+ end
@@ -1,19 +1,43 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # Product .product
5
- # TaxationLink[] .taxation
6
- # PricingComponent[] .pricingComponents
7
- class ProductRatePlan < MutableEntity
8
- @resource_path = BillForward::ResourcePath.new("product-rate-plans", "productRatePlan")
9
-
10
- protected
11
- def unserialize_all(hash)
12
- super
13
- unserialize_entity('product', Product, hash)
14
-
15
- unserialize_array_of_entities('taxation', TaxationLink, hash)
16
- unserialize_array_of_entities('pricingComponents', PricingComponent, hash)
17
- end
18
- end
19
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # Product .product
5
+ # TaxationLink[] .taxation
6
+ # PricingComponent[] .pricingComponents
7
+ class ProductRatePlan < MutableEntity
8
+ @resource_path = BillForward::ResourcePath.new("product-rate-plans", "productRatePlan")
9
+
10
+ class << self
11
+ def get_by_product_id(id, query_params = {}, custom_client = nil)
12
+ raise ArgumentError.new("id cannot be nil") if id.nil?
13
+
14
+ endpoint = sprintf('product/%s',
15
+ ERB::Util.url_encode(id)
16
+ )
17
+
18
+ self.request_many('get', endpoint, query_params, custom_client)
19
+ end
20
+
21
+ def get_by_product_and_plan_id(product_id, plan_id, query_params = {}, custom_client = nil)
22
+ raise ArgumentError.new("id cannot be nil") if product_id.nil?
23
+ raise ArgumentError.new("id cannot be nil") if plan_id.nil?
24
+
25
+ endpoint = sprintf('product/%s/rate-plan/%s',
26
+ ERB::Util.url_encode(product_id),
27
+ ERB::Util.url_encode(plan_id)
28
+ )
29
+
30
+ self.request_first('get', endpoint, query_params, custom_client)
31
+ end
32
+ end
33
+
34
+ protected
35
+ def unserialize_all(hash)
36
+ super
37
+ unserialize_entity('product', Product, hash)
38
+
39
+ unserialize_array_of_entities('taxation', TaxationLink, hash)
40
+ unserialize_array_of_entities('pricingComponents', PricingComponent, hash)
41
+ end
42
+ end
43
+ end
@@ -1,15 +1,15 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # Address[] .addresses
5
- class Profile < MutableEntity
6
- @resource_path = BillForward::ResourcePath.new("profiles", "profile")
7
-
8
- protected
9
- def unserialize_all(hash)
10
- super
11
-
12
- unserialize_array_of_entities('addresses', Address, hash)
13
- end
14
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # Address[] .addresses
5
+ class Profile < MutableEntity
6
+ @resource_path = BillForward::ResourcePath.new("profiles", "profile")
7
+
8
+ protected
9
+ def unserialize_all(hash)
10
+ super
11
+
12
+ unserialize_array_of_entities('addresses', Address, hash)
13
+ end
14
+ end
15
15
  end
@@ -0,0 +1,5 @@
1
+ module BillForward
2
+ class Refund < MutableEntity
3
+ @resource_path = BillForward::ResourcePath.new("refunds", "refund")
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- module BillForward
2
- class Role < InsertableEntity
3
- end
1
+ module BillForward
2
+ class Role < InsertableEntity
3
+ end
4
4
  end
@@ -0,0 +1,9 @@
1
+ module BillForward
2
+ class StripeACHToken < MutableEntity
3
+ # WARNING: resource paths for StripeACHTokens do not follow the usual pattern;
4
+ # instead of posting to 'root' of a URL root reserved for AuthorizeNetTokens,
5
+ # this routing is a bit less standard; for example we can't GET from the same
6
+ # place we POST to.
7
+ @resource_path = BillForward::ResourcePath.new('vaulted-gateways/stripe-ACH', 'stripe_ach_token')
8
+ end
9
+ end
@@ -1,53 +1,83 @@
1
- module BillForward
2
- # This entity exposes the following child entities via method_missing:
3
- #
4
- # PricingComponentValue[] .pricingComponentValues
5
- # PricingComponentValueChange[] .pricingComponentValueChanges
6
- class Subscription < MutableEntity
7
- @resource_path = BillForward::ResourcePath.new("subscriptions", "subscription")
8
-
9
- class << self
10
- def get_by_account_id(id, query_params = {}, customClient = nil)
11
- client = customClient
12
- client = singleton_client if client.nil?
13
-
14
- raise ArgumentError.new("id cannot be nil") if id.nil?
15
- TypeCheck.verifyObj(Hash, query_params, 'query_params')
16
-
17
- route = resource_path.path
18
- endpoint = 'account'
19
- url_full = "#{route}/#{endpoint}/#{id}"
20
-
21
- response = client.get(url_full, query_params)
22
- results = response["results"]
23
-
24
- # maybe use build_entity_array here for consistency
25
- entity_array = Array.new
26
- # maybe it's an empty array, but that's okay too.
27
- results.each do |value|
28
- entity = self.new(value, client)
29
- entity_array.push(entity)
30
- end
31
- entity_array
32
- end
33
- end
34
-
35
- def activate
36
- set_state_param('state', 'AwaitingPayment')
37
- response = save
38
- response
39
- end
40
-
41
- protected
42
- def unserialize_all(hash)
43
- super
44
- # always has these:
45
- unserialize_array_of_entities('pricingComponentValues', PricingComponentValue, hash)
46
- unserialize_array_of_entities('pricingComponentValueChanges', PricingComponentValueChange, hash)
47
-
48
-
49
- # think about the other entities later..
50
- # unserialize_array_of_entities('paymentMethodSubscriptionLinks', PaymentMethodSubscriptionLink, hash)
51
- end
52
- end
53
- end
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # PricingComponentValue[] .pricingComponentValues
5
+ # PricingComponentValueChange[] .pricingComponentValueChanges
6
+ class Subscription < MutableEntity
7
+ @resource_path = BillForward::ResourcePath.new("subscriptions", "subscription")
8
+
9
+ class << self
10
+ def get_by_account_id(id, query_params = {}, custom_client = nil)
11
+ raise ArgumentError.new("id cannot be nil") if id.nil?
12
+
13
+ endpoint = sprintf('account/%s',
14
+ ERB::Util.url_encode(id)
15
+ )
16
+
17
+ self.request_many('get', endpoint, query_params, custom_client)
18
+ end
19
+ end
20
+
21
+ def activate
22
+ set_state_param('state', 'AwaitingPayment')
23
+ response = save
24
+ response
25
+ end
26
+
27
+ #### MIGRATE PLAN VIA AMENDMENT
28
+
29
+
30
+
31
+ # Migrates subscription to new plan, with PricingComponentValue values corresponding to named PricingComponents.
32
+ # This works only for 'arrears' or 'in advance' pricing components.
33
+ #
34
+ # Note: pricing component mapping is not yet implemented, so currently the 'names_to_values' parameter is ignored.
35
+ #
36
+ # @param names_to_values [hash] The map of pricing component names to numerical values ('Bandwidth usage' => 102)
37
+ # @param new_plan_id [string] ID of the plan to migrate to.
38
+ # @param invoicing_type [ENUM{'Immediate', 'Aggregated'}] (Default: 'Aggregated') Subscription-charge invoicing type <Immediate>: Generate invoice straight away with this charge applied, <Aggregated>: Add this charge to next invoice
39
+ # @param new_plan [ProductRatePlan] (Alternative parameter to avoid extra API request) The plan to migrate to.
40
+ #
41
+ # @return [self] The created Entity
42
+ def migrate_plan(names_to_values = Hash.new, new_plan_id = nil, invoicing_type = 'Aggregated', new_plan = nil)
43
+ # Until pricing component mapping is implemented, we don't to fetch the full plan
44
+ # if new_plan.nil? do
45
+ # new_plan = BillForward::ProductRatePlan::get_by_id(new_plan_id)
46
+ # end
47
+
48
+ migrate_plan_simple(new_plan_id, invoicing_type)
49
+ end
50
+
51
+ protected
52
+ def unserialize_all(hash)
53
+ super
54
+ # always has these:
55
+ unserialize_array_of_entities('pricingComponentValues', PricingComponentValue, hash)
56
+ unserialize_array_of_entities('pricingComponentValueChanges', PricingComponentValueChange, hash)
57
+
58
+
59
+ # think about the other entities later..
60
+ # unserialize_array_of_entities('paymentMethodSubscriptionLinks', PaymentMethodSubscriptionLink, hash)
61
+ end
62
+
63
+ # Migrates subscription to new plan, with PricingComponentValue values corresponding to named PricingComponents.
64
+ #
65
+ # Note: this simple invocation will be deprecated when full support for mapping component values is introduced. The public 'migrate_plan' interface is not expected to change though.
66
+ #
67
+ # @param new_plan_id [string] ID of the plan to migrate to.
68
+ # @param invoicing_type [ENUM{'Immediate', 'Aggregated'}] (Default: 'Aggregated') Subscription-charge invoicing type <Immediate>: Generate invoice straight away with this charge applied, <Aggregated>: Add this charge to next invoice
69
+ #
70
+ # @return [self] The created Entity
71
+ def migrate_plan_simple(new_plan_id, invoicing_type)
72
+ amendment = BillForward::ProductRatePlanMigrationAmendment.new({
73
+ 'subscriptionID' => id,
74
+ 'productRatePlanID' => new_plan_id,
75
+ 'mappings' => Array.new,
76
+ 'invoicingType' => invoicing_type
77
+ });
78
+
79
+ created_amendment = BillForward::ProductRatePlanMigrationAmendment.create(amendment)
80
+ created_amendment
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,14 @@
1
+ module BillForward
2
+ # This entity exposes the following child entities via method_missing:
3
+ #
4
+ # Invoice .invoice
5
+ class SubscriptionCharge < MutableEntity
6
+ @resource_path = BillForward::ResourcePath.new('charges', 'subscriptionCharge')
7
+
8
+ protected
9
+ def unserialize_all(hash)
10
+ super
11
+ unserialize_entity('invoice', Invoice, hash)
12
+ end
13
+ end
14
+ end