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
@@ -72,6 +72,7 @@ describe BillForward::Subscription do
72
72
  'customerProfileID' => @authorize_net_customer_profile_id,
73
73
  'customerPaymentProfileID' => @authorize_net_customer_payment_profile_id,
74
74
  'lastFourDigits' => @authorize_net_card_last_4_digits,
75
+ 'organizationID' => first_org.id
75
76
  })
76
77
  created_token = BillForward::AuthorizeNetToken.create(authorize_net_token)
77
78
 
@@ -90,25 +91,50 @@ describe BillForward::Subscription do
90
91
  created_payment_method = BillForward::PaymentMethod::create(payment_method)
91
92
 
92
93
 
93
- # create a unit of measure
94
- unit_of_measure = BillForward::UnitOfMeasure.new({
95
- 'name' => 'Devices',
96
- 'displayedAs' => 'Devices',
97
- 'roundingScheme' => 'UP',
98
- })
99
- created_uom = BillForward::UnitOfMeasure.create(unit_of_measure)
94
+ uom_1_name = 'CPU'
95
+ created_uom_1 = nil
96
+ begin
97
+ created_uom_1 = BillForward::UnitOfMeasure.get_by_id uom_1_name
98
+ rescue IndexError=>e
99
+ # create a unit of measure
100
+ unit_of_measure_1 = BillForward::UnitOfMeasure.new({
101
+ 'name' => uom_1_name,
102
+ 'displayedAs' => 'Cycles',
103
+ 'roundingScheme' => 'UP',
104
+ })
105
+ created_uom_1 = BillForward::UnitOfMeasure.create(unit_of_measure_1)
106
+ end
100
107
 
108
+ uom_2_name = 'Bandwidth'
109
+ created_uom_2 = nil
110
+ begin
111
+ created_uom_2 = BillForward::UnitOfMeasure.get_by_id uom_2_name
112
+ rescue IndexError=>e
113
+ # create another unit of measure
114
+ unit_of_measure_2 = BillForward::UnitOfMeasure.new({
115
+ 'name' => uom_2_name,
116
+ 'displayedAs' => 'Mbps',
117
+ 'roundingScheme' => 'UP',
118
+ })
119
+ created_uom_2 = BillForward::UnitOfMeasure.create(unit_of_measure_2)
120
+ end
101
121
 
102
- # create a product
103
- product = BillForward::Product.new({
104
- 'productType' => 'non-recurring',
105
- 'state' => 'prod',
106
- 'name' => 'Month of Paracetamoxyfrusebendroneomycin',
107
- 'description' => 'It can cure the common cold and being struck by lightning',
108
- 'durationPeriod' => 'days',
109
- 'duration' => 28,
110
- })
111
- created_product = BillForward::Product::create(product)
122
+ product_name = 'Monthly recurring'
123
+ created_product = nil
124
+ begin
125
+ created_product = BillForward::Product.get_by_id product_name
126
+ rescue IndexError=>e
127
+ # create a product
128
+ product = BillForward::Product.new({
129
+ 'productType' => 'recurring',
130
+ 'state' => 'prod',
131
+ 'name' => product_name,
132
+ 'description' => 'Purchaseables to which customer has a non-renewing, monthly entitlement',
133
+ 'durationPeriod' => 'months',
134
+ 'duration' => 1,
135
+ })
136
+ created_product = BillForward::Product::create(product)
137
+ end
112
138
 
113
139
 
114
140
  # make product rate plan..
@@ -117,77 +143,93 @@ describe BillForward::Subscription do
117
143
  # - pricing components..
118
144
  # .. - which require pricing component tiers
119
145
 
120
- # create tiers..
121
- # for a flat pricing component:
122
- tiers_for_flat_component_1 = Array.new()
123
- tiers_for_flat_component_1.push(
146
+ # for a tiered pricing component:
147
+ tiers_for_tiered_component_1 = Array.new()
148
+ tiers_for_tiered_component_1.push(
149
+ BillForward::PricingComponentTier.new({
150
+ 'lowerThreshold' => 0,
151
+ 'upperThreshold' => 0,
152
+ 'pricingType' => 'unit',
153
+ 'price' => 0,
154
+ }),
124
155
  BillForward::PricingComponentTier.new({
125
156
  'lowerThreshold' => 1,
126
- 'upperThreshold' => 1,
127
- 'pricingType' => 'fixed',
157
+ 'upperThreshold' => 10,
158
+ 'pricingType' => 'unit',
128
159
  'price' => 1,
160
+ }),
161
+ BillForward::PricingComponentTier.new({
162
+ 'lowerThreshold' => 11,
163
+ 'upperThreshold' => 1000,
164
+ 'pricingType' => 'unit',
165
+ 'price' => 0.50
129
166
  }))
130
167
 
131
- # for a tiered pricing component:
132
- tiers_for_tiered_component_1 = Array.new()
133
- tiers_for_tiered_component_1.push(
168
+ # for another tiered pricing component:
169
+ tiers_for_tiered_component_2 = Array.new()
170
+ tiers_for_tiered_component_2.push(
134
171
  BillForward::PricingComponentTier.new({
135
- 'lowerThreshold' => 1,
136
- 'upperThreshold' => 1,
137
- 'pricingType' => 'fixed',
138
- 'price' => 10,
172
+ 'lowerThreshold' => 0,
173
+ 'upperThreshold' => 0,
174
+ 'pricingType' => 'unit',
175
+ 'price' => 0,
139
176
  }),
140
177
  BillForward::PricingComponentTier.new({
141
- 'lowerThreshold' => 2,
178
+ 'lowerThreshold' => 1,
142
179
  'upperThreshold' => 10,
143
180
  'pricingType' => 'unit',
144
- 'price' => 5
181
+ 'price' => 0.10,
145
182
  }),
146
183
  BillForward::PricingComponentTier.new({
147
184
  'lowerThreshold' => 11,
148
- 'upperThreshold' => 100,
185
+ 'upperThreshold' => 1000,
149
186
  'pricingType' => 'unit',
150
- 'price' => 2
187
+ 'price' => 0.05
151
188
  }))
152
189
 
153
190
 
154
- # create pricing components, based on these tiers
191
+ # create 'in advance' ('subscription') pricing components, based on these tiers
155
192
  pricing_components = Array.new()
156
193
  pricing_components.push(
157
194
  BillForward::PricingComponent.new({
158
- '@type' => 'flatPricingComponent',
159
- 'chargeModel' => 'flat',
160
- 'name' => 'Devices used, fixed',
161
- 'description' => 'How many devices you use, I guess',
162
- 'unitOfMeasureID' => created_uom.id,
195
+ '@type' => 'tieredPricingComponent',
196
+ 'chargeModel' => 'tiered',
197
+ 'name' => 'CPU',
198
+ 'description' => 'CPU consumed',
199
+ 'unitOfMeasureID' => created_uom_1.id,
163
200
  'chargeType' => 'subscription',
164
201
  'upgradeMode' => 'immediate',
165
202
  'downgradeMode' => 'immediate',
166
203
  'defaultQuantity' => 1,
167
- 'tiers' => tiers_for_flat_component_1
204
+ 'tiers' => tiers_for_tiered_component_1
168
205
  }),
169
206
  BillForward::PricingComponent.new({
170
207
  '@type' => 'tieredPricingComponent',
171
208
  'chargeModel' => 'tiered',
172
- 'name' => 'Devices used, tiered',
173
- 'description' => 'How many devices you use, but with a tiering system',
174
- 'unitOfMeasureID' => created_uom.id,
209
+ 'name' => 'Bandwidth',
210
+ 'description' => 'Bandwidth consumed',
211
+ 'unitOfMeasureID' => created_uom_2.id,
175
212
  'chargeType' => 'subscription',
176
213
  'upgradeMode' => 'immediate',
177
214
  'downgradeMode' => 'immediate',
178
215
  'defaultQuantity' => 10,
179
- 'tiers' => tiers_for_tiered_component_1
216
+ 'tiers' => tiers_for_tiered_component_2
180
217
  }))
181
218
 
182
-
183
- # create product rate plan, using pricing components and product
184
- prp = BillForward::ProductRatePlan.new({
185
- 'currency' => 'USD',
186
- 'name' => 'A sound plan',
187
- 'pricingComponents' => pricing_components,
188
- 'productID' => created_product.id,
219
+ rate_plan_name = 'Sound Plan'
220
+ created_prp = nil
221
+ begin
222
+ created_prp = BillForward::ProductRatePlan.get_by_product_and_plan_id product_name, rate_plan_name
223
+ rescue IndexError=>e
224
+ # create product rate plan, using pricing components and product
225
+ prp = BillForward::ProductRatePlan.new({
226
+ 'currency' => 'USD',
227
+ 'name' => rate_plan_name,
228
+ 'pricingComponents' => pricing_components,
229
+ 'productID' => created_product.id,
189
230
  })
190
- created_prp = BillForward::ProductRatePlan.create(prp)
231
+ created_prp = BillForward::ProductRatePlan.create(prp)
232
+ end
191
233
 
192
234
 
193
235
  # create references for tests to use
@@ -207,16 +249,6 @@ describe BillForward::Subscription do
207
249
  # - account [we have this already]
208
250
  # - product rate plan [we have this already]
209
251
  # - pricing component value instances (for every pricing component on the PRP)
210
- # - payment method subscription links (for every payment method on the account)
211
-
212
- # create PaymentMethodSubscriptionLink from payment method and organisation
213
- payment_method_subscription_links = Array.new
214
- payment_method_subscription_links.push(
215
- BillForward::PaymentMethodSubscriptionLink.new({
216
- 'paymentMethodID' => payment_method.id,
217
- 'organizationID' => organisation.id,
218
- }))
219
-
220
252
 
221
253
  pricing_components = prp.pricingComponents
222
254
  # get references to each pricing component we made
@@ -242,8 +274,7 @@ describe BillForward::Subscription do
242
274
  'productRatePlanID' => prp.id,
243
275
  'accountID' => account.id,
244
276
  'name' => 'Memorable Subscription',
245
- 'description' => 'Memorable Subscription Description',
246
- 'paymentMethodSubscriptionLinks' => payment_method_subscription_links,
277
+ 'description' => "Customer acquired through 'Lazy Wednesdays' promotion",
247
278
  'pricingComponentValues' => pricing_component_values
248
279
  })
249
280
  created_sub = BillForward::Subscription.create(subscription)
@@ -18,106 +18,145 @@ describe BillForward::Subscription do
18
18
  end
19
19
  context 'all entities required for a subscription exist' do
20
20
  before :all do
21
- # create a unit of measure
22
- unit_of_measure = BillForward::UnitOfMeasure.new({
23
- 'name' => 'Devices',
24
- 'displayedAs' => 'Devices',
25
- 'roundingScheme' => 'UP',
26
- })
27
- created_uom = BillForward::UnitOfMeasure.create(unit_of_measure)
21
+ uom_1_name = 'CPU'
22
+ created_uom_1 = nil
23
+ begin
24
+ created_uom_1 = BillForward::UnitOfMeasure.get_by_id uom_1_name
25
+ rescue IndexError=>e
26
+ # create a unit of measure
27
+ unit_of_measure_1 = BillForward::UnitOfMeasure.new({
28
+ 'name' => uom_1_name,
29
+ 'displayedAs' => 'Cycles',
30
+ 'roundingScheme' => 'UP',
31
+ })
32
+ created_uom_1 = BillForward::UnitOfMeasure.create(unit_of_measure_1)
33
+ end
28
34
 
35
+ uom_2_name = 'Bandwidth'
36
+ created_uom_2 = nil
37
+ begin
38
+ created_uom_2 = BillForward::UnitOfMeasure.get_by_id uom_2_name
39
+ rescue IndexError=>e
40
+ # create another unit of measure
41
+ unit_of_measure_2 = BillForward::UnitOfMeasure.new({
42
+ 'name' => uom_2_name,
43
+ 'displayedAs' => 'Mbps',
44
+ 'roundingScheme' => 'UP',
45
+ })
46
+ created_uom_2 = BillForward::UnitOfMeasure.create(unit_of_measure_2)
47
+ end
29
48
 
30
- # create a product
31
- product = BillForward::Product.new({
32
- 'productType' => 'non-recurring',
33
- 'state' => 'prod',
34
- 'name' => 'Month of Paracetamoxyfrusebendroneomycin',
35
- 'description' => 'It can cure the common cold and being struck by lightning',
36
- 'durationPeriod' => 'minutes',
37
- 'duration' => 1,
38
- })
39
- created_product = BillForward::Product::create(product)
49
+ product_name = 'Monthly recurring'
50
+ created_product = nil
51
+ begin
52
+ created_product = BillForward::Product.get_by_id product_name
53
+ rescue IndexError=>e
54
+ # create a product
55
+ product = BillForward::Product.new({
56
+ 'productType' => 'recurring',
57
+ 'state' => 'prod',
58
+ 'name' => product_name,
59
+ 'description' => 'Purchaseables to which customer has a non-renewing, monthly entitlement',
60
+ 'durationPeriod' => 'months',
61
+ 'duration' => 1,
62
+ })
63
+ created_product = BillForward::Product::create(product)
64
+ end
40
65
 
41
66
 
42
67
  # make product rate plan..
43
68
  # requires:
44
69
  # - product,
45
- # - pricing components, which require..
46
- # .. - pricing component tiers
47
- # .. - and unit of measure
48
-
49
- # create tiers..
50
- # for a flat pricing component:
51
- tiers_for_flat_component_1 = Array.new()
52
- tiers_for_flat_component_1.push(
53
- BillForward::PricingComponentTier.new({
54
- 'lowerThreshold' => 1,
55
- 'upperThreshold' => 1,
56
- 'pricingType' => 'fixed',
57
- 'price' => 1,
58
- }))
70
+ # - pricing components..
71
+ # .. - which require pricing component tiers
59
72
 
60
73
  # for a tiered pricing component:
61
74
  tiers_for_tiered_component_1 = Array.new()
62
75
  tiers_for_tiered_component_1.push(
76
+ BillForward::PricingComponentTier.new({
77
+ 'lowerThreshold' => 0,
78
+ 'upperThreshold' => 0,
79
+ 'pricingType' => 'unit',
80
+ 'price' => 0,
81
+ }),
63
82
  BillForward::PricingComponentTier.new({
64
83
  'lowerThreshold' => 1,
65
- 'upperThreshold' => 1,
66
- 'pricingType' => 'fixed',
67
- 'price' => 10,
84
+ 'upperThreshold' => 10,
85
+ 'pricingType' => 'unit',
86
+ 'price' => 1,
68
87
  }),
69
88
  BillForward::PricingComponentTier.new({
70
- 'lowerThreshold' => 2,
89
+ 'lowerThreshold' => 11,
90
+ 'upperThreshold' => 1000,
91
+ 'pricingType' => 'unit',
92
+ 'price' => 0.50
93
+ }))
94
+
95
+ # for another tiered pricing component:
96
+ tiers_for_tiered_component_2 = Array.new()
97
+ tiers_for_tiered_component_2.push(
98
+ BillForward::PricingComponentTier.new({
99
+ 'lowerThreshold' => 0,
100
+ 'upperThreshold' => 0,
101
+ 'pricingType' => 'unit',
102
+ 'price' => 0,
103
+ }),
104
+ BillForward::PricingComponentTier.new({
105
+ 'lowerThreshold' => 1,
71
106
  'upperThreshold' => 10,
72
107
  'pricingType' => 'unit',
73
- 'price' => 5
108
+ 'price' => 0.10,
74
109
  }),
75
110
  BillForward::PricingComponentTier.new({
76
111
  'lowerThreshold' => 11,
77
- 'upperThreshold' => 100,
112
+ 'upperThreshold' => 1000,
78
113
  'pricingType' => 'unit',
79
- 'price' => 2
114
+ 'price' => 0.05
80
115
  }))
81
116
 
82
117
 
83
- # create pricing components, based on these tiers
118
+ # create 'in advance' ('subscription') pricing components, based on these tiers
84
119
  pricing_components = Array.new()
85
120
  pricing_components.push(
86
121
  BillForward::PricingComponent.new({
87
- '@type' => 'flatPricingComponent',
88
- 'chargeModel' => 'flat',
89
- 'name' => 'Devices used, fixed',
90
- 'description' => 'How many devices you use, I guess',
91
- 'unitOfMeasureID' => created_uom.id,
122
+ '@type' => 'tieredPricingComponent',
123
+ 'chargeModel' => 'tiered',
124
+ 'name' => 'CPU',
125
+ 'description' => 'CPU consumed',
126
+ 'unitOfMeasureID' => created_uom_1.id,
92
127
  'chargeType' => 'subscription',
93
128
  'upgradeMode' => 'immediate',
94
129
  'downgradeMode' => 'immediate',
95
130
  'defaultQuantity' => 1,
96
- 'tiers' => tiers_for_flat_component_1
131
+ 'tiers' => tiers_for_tiered_component_1
97
132
  }),
98
133
  BillForward::PricingComponent.new({
99
134
  '@type' => 'tieredPricingComponent',
100
135
  'chargeModel' => 'tiered',
101
- 'name' => 'Devices used, tiered',
102
- 'description' => 'How many devices you use, but with a tiering system',
103
- 'unitOfMeasureID' => created_uom.id,
104
- 'chargeType' => 'usage',
136
+ 'name' => 'Bandwidth',
137
+ 'description' => 'Bandwidth consumed',
138
+ 'unitOfMeasureID' => created_uom_2.id,
139
+ 'chargeType' => 'subscription',
105
140
  'upgradeMode' => 'immediate',
106
141
  'downgradeMode' => 'immediate',
107
142
  'defaultQuantity' => 10,
108
- 'tiers' => tiers_for_tiered_component_1
143
+ 'tiers' => tiers_for_tiered_component_2
109
144
  }))
110
145
 
111
-
112
- # create product rate plan, using pricing components and product
113
- prp = BillForward::ProductRatePlan.new({
114
- 'currency' => 'USD',
115
- 'name' => 'A sound plan',
116
- 'pricingComponents' => pricing_components,
117
- 'productID' => created_product.id,
146
+ rate_plan_name = 'Sound Plan'
147
+ created_prp = nil
148
+ begin
149
+ created_prp = BillForward::ProductRatePlan.get_by_product_and_plan_id product_name, rate_plan_name
150
+ rescue IndexError=>e
151
+ # create product rate plan, using pricing components and product
152
+ prp = BillForward::ProductRatePlan.new({
153
+ 'currency' => 'USD',
154
+ 'name' => rate_plan_name,
155
+ 'pricingComponents' => pricing_components,
156
+ 'productID' => created_product.id,
118
157
  })
119
- created_prp = BillForward::ProductRatePlan.create(prp)
120
-
158
+ created_prp = BillForward::ProductRatePlan.create(prp)
159
+ end
121
160
 
122
161
  # create references for tests to use
123
162
  @created_prp = created_prp
@@ -155,7 +194,7 @@ describe BillForward::Subscription do
155
194
  'productRatePlanID' => @created_prp.id,
156
195
  'accountID' => @created_account.id,
157
196
  'name' => 'Memorable Subscription',
158
- 'description' => 'Memorable Subscription Description',
197
+ 'description' => "Customer acquired through 'Lazy Wednesdays' promotion",
159
198
  'pricingComponentValues' => pricing_component_values
160
199
  })
161
200
  created_sub = BillForward::Subscription.create(subscription)