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
@@ -0,0 +1,379 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "spec_helper")
2
+
3
+ describe BillForward::Subscription do
4
+ before :all do
5
+ @client = BillForwardTest::TEST_CLIENT
6
+ BillForward::Client.default_client = @client
7
+ end
8
+ context 'upon creating required entities for chargeable Subscription' do
9
+ before :all do
10
+ # get our organisation
11
+ # organisations = BillForward::Organisation.get_mine
12
+ # first_org = organisations.first
13
+
14
+
15
+ # create an account
16
+ # requires (optionally):
17
+ # - profile
18
+ # - - addresses
19
+ addresses = Array.new()
20
+ addresses.push(
21
+ BillForward::Address.new({
22
+ 'addressLine1' => 'address line 1',
23
+ 'addressLine2' => 'address line 2',
24
+ 'addressLine3' => 'address line 3',
25
+ 'city' => 'London',
26
+ 'province' => 'London',
27
+ 'country' => 'United Kingdom',
28
+ 'postcode' => 'SW1 1AS',
29
+ 'landline' => '02000000000',
30
+ 'primaryAddress' => true
31
+ }))
32
+ profile = BillForward::Profile.new({
33
+ 'email' => 'always@testing.is.moe',
34
+ 'firstName' => 'Ruby',
35
+ 'lastName' => 'Red',
36
+ 'addresses' => addresses
37
+ })
38
+ account = BillForward::Account.new({
39
+ 'profile' => profile
40
+ })
41
+ created_account = BillForward::Account.create account
42
+
43
+ ## Credit note payment method exists implicitly nowadays
44
+ # create for our account: a new payment method, using credit notes
45
+ # payment_method = BillForward::PaymentMethod.new({
46
+ # 'accountID' => created_account.id,
47
+ # 'name' => 'Credit Notes',
48
+ # 'description' => 'Pay using credit',
49
+ # # engines will link this to an invoice once paid, for the sake of refunds
50
+ # 'linkID' => '',
51
+ # 'gateway' => 'credit_note',
52
+ # 'userEditable' => 0,
53
+ # 'priority' => 100,
54
+ # 'reusable' => 1
55
+ # })
56
+ # created_payment_method = BillForward::PaymentMethod::create(payment_method)
57
+
58
+
59
+ # issue $100 credit to our account
60
+ credit_note = BillForward::CreditNote.new({
61
+ "accountID" => created_account.id,
62
+ "value" => 1000,
63
+ "currency" => "USD"
64
+ })
65
+ created_credit_note = BillForward::CreditNote.create(credit_note)
66
+
67
+ uom_1_name = 'CPU'
68
+ created_uom_1 = nil
69
+ begin
70
+ created_uom_1 = BillForward::UnitOfMeasure.get_by_id uom_1_name
71
+ rescue IndexError=>e
72
+ # create a unit of measure
73
+ unit_of_measure_1 = BillForward::UnitOfMeasure.new({
74
+ 'name' => uom_1_name,
75
+ 'displayedAs' => 'Cycles',
76
+ 'roundingScheme' => 'UP',
77
+ })
78
+ created_uom_1 = BillForward::UnitOfMeasure.create(unit_of_measure_1)
79
+ end
80
+
81
+ uom_2_name = 'Bandwidth'
82
+ created_uom_2 = nil
83
+ begin
84
+ created_uom_2 = BillForward::UnitOfMeasure.get_by_id uom_2_name
85
+ rescue IndexError=>e
86
+ # create another unit of measure
87
+ unit_of_measure_2 = BillForward::UnitOfMeasure.new({
88
+ 'name' => uom_2_name,
89
+ 'displayedAs' => 'Mbps',
90
+ 'roundingScheme' => 'UP',
91
+ })
92
+ created_uom_2 = BillForward::UnitOfMeasure.create(unit_of_measure_2)
93
+ end
94
+
95
+ product_name = 'Monthly recurring'
96
+ created_product = nil
97
+ begin
98
+ created_product = BillForward::Product.get_by_id product_name
99
+ rescue IndexError=>e
100
+ # create a product
101
+ product = BillForward::Product.new({
102
+ 'productType' => 'recurring',
103
+ 'state' => 'prod',
104
+ 'name' => product_name,
105
+ 'description' => 'Purchaseables to which customer has a non-renewing, monthly entitlement',
106
+ 'durationPeriod' => 'months',
107
+ 'duration' => 1,
108
+ })
109
+ created_product = BillForward::Product::create(product)
110
+ end
111
+
112
+
113
+ # make product rate plan..
114
+ # requires:
115
+ # - product,
116
+ # - pricing components..
117
+ # .. - which require pricing component tiers
118
+
119
+ # for a tiered pricing component:
120
+ tiers_for_tiered_component_1 = Array.new()
121
+ tiers_for_tiered_component_1.push(
122
+ BillForward::PricingComponentTier.new({
123
+ 'lowerThreshold' => 0,
124
+ 'upperThreshold' => 0,
125
+ 'pricingType' => 'unit',
126
+ 'price' => 0,
127
+ }),
128
+ BillForward::PricingComponentTier.new({
129
+ 'lowerThreshold' => 1,
130
+ 'upperThreshold' => 10,
131
+ 'pricingType' => 'unit',
132
+ 'price' => 1,
133
+ }),
134
+ BillForward::PricingComponentTier.new({
135
+ 'lowerThreshold' => 11,
136
+ 'upperThreshold' => 1000,
137
+ 'pricingType' => 'unit',
138
+ 'price' => 0.50
139
+ }))
140
+
141
+ # for another tiered pricing component:
142
+ tiers_for_tiered_component_2 = Array.new()
143
+ tiers_for_tiered_component_2.push(
144
+ BillForward::PricingComponentTier.new({
145
+ 'lowerThreshold' => 0,
146
+ 'upperThreshold' => 0,
147
+ 'pricingType' => 'unit',
148
+ 'price' => 0,
149
+ }),
150
+ BillForward::PricingComponentTier.new({
151
+ 'lowerThreshold' => 1,
152
+ 'upperThreshold' => 10,
153
+ 'pricingType' => 'unit',
154
+ 'price' => 0.10,
155
+ }),
156
+ BillForward::PricingComponentTier.new({
157
+ 'lowerThreshold' => 11,
158
+ 'upperThreshold' => 1000,
159
+ 'pricingType' => 'unit',
160
+ 'price' => 0.05
161
+ }))
162
+
163
+
164
+ # create 'in advance' ('subscription') pricing components, based on these tiers
165
+ pricing_components = Array.new()
166
+ pricing_components.push(
167
+ BillForward::PricingComponent.new({
168
+ '@type' => 'tieredPricingComponent',
169
+ 'chargeModel' => 'tiered',
170
+ 'name' => 'CPU',
171
+ 'description' => 'CPU consumed',
172
+ 'unitOfMeasureID' => created_uom_1.id,
173
+ 'chargeType' => 'subscription',
174
+ 'upgradeMode' => 'immediate',
175
+ 'downgradeMode' => 'immediate',
176
+ 'defaultQuantity' => 1,
177
+ 'tiers' => tiers_for_tiered_component_1
178
+ }),
179
+ BillForward::PricingComponent.new({
180
+ '@type' => 'tieredPricingComponent',
181
+ 'chargeModel' => 'tiered',
182
+ 'name' => 'Bandwidth',
183
+ 'description' => 'Bandwidth consumed',
184
+ 'unitOfMeasureID' => created_uom_2.id,
185
+ 'chargeType' => 'subscription',
186
+ 'upgradeMode' => 'immediate',
187
+ 'downgradeMode' => 'immediate',
188
+ 'defaultQuantity' => 10,
189
+ 'tiers' => tiers_for_tiered_component_2
190
+ }))
191
+
192
+ rate_plan_name = 'Sound Plan'
193
+ created_prp = nil
194
+ begin
195
+ created_prp = BillForward::ProductRatePlan.get_by_product_and_plan_id product_name, rate_plan_name
196
+ rescue IndexError=>e
197
+ # create product rate plan, using pricing components and product
198
+ prp = BillForward::ProductRatePlan.new({
199
+ 'currency' => 'USD',
200
+ 'name' => rate_plan_name,
201
+ 'pricingComponents' => pricing_components,
202
+ 'productID' => created_product.id,
203
+ })
204
+ created_prp = BillForward::ProductRatePlan.create(prp)
205
+ end
206
+
207
+ # create references for tests to use
208
+ @created_account = created_account
209
+ @created_prp = created_prp
210
+ # @created_payment_method = created_payment_method
211
+
212
+ @created_product = created_product
213
+ @created_uom_1 = created_uom_1
214
+ @created_uom_2 = created_uom_2
215
+ end
216
+ describe '::create' do
217
+ describe 'the subscription' do
218
+ before :all do
219
+ # make subscription..
220
+ # requires:
221
+ # - account [we have this already]
222
+ # - product rate plan [we have this already]
223
+ # - pricing component value instances (for every pricing component on the PRP)
224
+
225
+
226
+ pricing_components = @created_prp.pricingComponents
227
+ # get references to each pricing component we made
228
+ tiered_pricing_component_1 = pricing_components[0]
229
+ tiered_pricing_component_2 = pricing_components[1]
230
+
231
+ # create PricingComponentValue instances for every PricingComponent on the PRP
232
+ pricing_component_values = Array.new
233
+ pricing_component_values.push(
234
+ BillForward::PricingComponentValue.new({
235
+ 'pricingComponentID' => tiered_pricing_component_1.id,
236
+ 'value' => 1,
237
+ }),
238
+ BillForward::PricingComponentValue.new({
239
+ 'pricingComponentID' => tiered_pricing_component_2.id,
240
+ 'value' => 5,
241
+ }))
242
+
243
+
244
+ # create subscription
245
+ subscription = BillForward::Subscription.new({
246
+ 'type' => 'Subscription',
247
+ 'productRatePlanID' => @created_prp.id,
248
+ 'accountID' => @created_account.id,
249
+ 'name' => 'Memorable Subscription',
250
+ 'description' => "Customer acquired through 'Lazy Wednesdays' promotion",
251
+ 'pricingComponentValues' => pricing_component_values
252
+ })
253
+ created_sub = BillForward::Subscription.create(subscription)
254
+
255
+ # create references for tests to use
256
+ @created_sub = created_sub
257
+ end
258
+ subject(:subscription) { @created_sub }
259
+ it 'is created' do
260
+ expect(subscription['@type']).to eq(BillForward::Subscription.resource_path.entity_name)
261
+ end
262
+ it 'can be gotten' do
263
+ gotten_subscription = BillForward::Subscription.get_by_id(subscription.id)
264
+ expect(gotten_subscription['@type']).to eq(BillForward::Subscription.resource_path.entity_name)
265
+ end
266
+ it 'can be activated' do
267
+ expect(subscription['state']).to eq('Provisioned')
268
+ updated_subscription = subscription.activate
269
+
270
+ expect(updated_subscription['state']).to satisfy{|s| ['AwaitingPayment', 'Paid'].include?(s)}
271
+ end
272
+ describe 'ProductRatePlanMigrationAmendment' do
273
+ before :all do
274
+ # make product rate plan to migrate to..
275
+ # requires:
276
+ # - product,
277
+ # - pricing components..
278
+ # .. - which require pricing component tiers
279
+
280
+ # for a tiered pricing component:
281
+ tiers_for_tiered_component_1 = Array.new()
282
+ tiers_for_tiered_component_1.push(
283
+ BillForward::PricingComponentTier.new({
284
+ 'lowerThreshold' => 0,
285
+ 'upperThreshold' => 0,
286
+ 'pricingType' => 'unit',
287
+ 'price' => 0,
288
+ }),
289
+ BillForward::PricingComponentTier.new({
290
+ 'lowerThreshold' => 1,
291
+ 'upperThreshold' => 10,
292
+ 'pricingType' => 'unit',
293
+ 'price' => 10,
294
+ }),
295
+ BillForward::PricingComponentTier.new({
296
+ 'lowerThreshold' => 11,
297
+ 'upperThreshold' => 1000,
298
+ 'pricingType' => 'unit',
299
+ 'price' => 5
300
+ }))
301
+
302
+ # for another tiered pricing component:
303
+ tiers_for_tiered_component_2 = Array.new()
304
+ tiers_for_tiered_component_2.push(
305
+ BillForward::PricingComponentTier.new({
306
+ 'lowerThreshold' => 0,
307
+ 'upperThreshold' => 0,
308
+ 'pricingType' => 'unit',
309
+ 'price' => 0,
310
+ }),
311
+ BillForward::PricingComponentTier.new({
312
+ 'lowerThreshold' => 1,
313
+ 'upperThreshold' => 10,
314
+ 'pricingType' => 'unit',
315
+ 'price' => 1,
316
+ }),
317
+ BillForward::PricingComponentTier.new({
318
+ 'lowerThreshold' => 11,
319
+ 'upperThreshold' => 1000,
320
+ 'pricingType' => 'unit',
321
+ 'price' => 0.5
322
+ }))
323
+
324
+
325
+ # create 'in advance' ('subscription') pricing components, based on these tiers
326
+ pricing_components = Array.new()
327
+ pricing_components.push(
328
+ BillForward::PricingComponent.new({
329
+ '@type' => 'tieredPricingComponent',
330
+ 'chargeModel' => 'tiered',
331
+ 'name' => 'CPU',
332
+ 'description' => 'CPU consumed',
333
+ 'unitOfMeasureID' => @created_uom_1.id,
334
+ 'chargeType' => 'subscription',
335
+ 'upgradeMode' => 'immediate',
336
+ 'downgradeMode' => 'immediate',
337
+ 'defaultQuantity' => 2,
338
+ 'tiers' => tiers_for_tiered_component_1
339
+ }),
340
+ BillForward::PricingComponent.new({
341
+ '@type' => 'tieredPricingComponent',
342
+ 'chargeModel' => 'tiered',
343
+ 'name' => 'Bandwidth',
344
+ 'description' => 'Bandwidth consumed',
345
+ 'unitOfMeasureID' => @created_uom_2.id,
346
+ 'chargeType' => 'subscription',
347
+ 'upgradeMode' => 'immediate',
348
+ 'downgradeMode' => 'immediate',
349
+ 'defaultQuantity' => 20,
350
+ 'tiers' => tiers_for_tiered_component_2
351
+ }))
352
+
353
+ rate_plan_2_name = 'A Plan comes together'
354
+ created_prp = nil
355
+ begin
356
+ created_prp = BillForward::ProductRatePlan.get_by_product_and_plan_id @created_product.name, rate_plan_2_name
357
+ rescue IndexError=>e
358
+ # create product rate plan, using pricing components and product
359
+ prp = BillForward::ProductRatePlan.new({
360
+ 'currency' => 'USD',
361
+ 'name' => rate_plan_2_name,
362
+ 'pricingComponents' => pricing_components,
363
+ 'productID' => @created_product.id,
364
+ })
365
+ created_prp = BillForward::ProductRatePlan.create(prp)
366
+ end
367
+
368
+ @new_prp = created_prp
369
+ end
370
+ subject(:subscription) { @created_sub }
371
+ it 'can be migrated' do
372
+ migration_amendment = @created_sub.migrate_plan(Hash.new, @new_prp.id)
373
+ expect(migration_amendment.productRatePlanID).to eq(@new_prp.id)
374
+ end
375
+ end
376
+ end
377
+ end
378
+ end
379
+ end
@@ -8,95 +8,151 @@ describe BillForward::ProductRatePlan do
8
8
  describe '::create' do
9
9
  context 'product and pricing components already exist' do
10
10
  before :all do
11
- unit_of_measure = BillForward::UnitOfMeasure.new({
12
- 'name' => 'Devices',
13
- 'displayedAs' => 'Devices',
14
- 'roundingScheme' => 'UP',
15
- })
16
- created_uom = BillForward::UnitOfMeasure.create(unit_of_measure)
11
+ uom_1_name = 'CPU'
12
+ created_uom_1 = nil
13
+ begin
14
+ created_uom_1 = BillForward::UnitOfMeasure.get_by_id uom_1_name
15
+ rescue IndexError=>e
16
+ # create a unit of measure
17
+ unit_of_measure_1 = BillForward::UnitOfMeasure.new({
18
+ 'name' => uom_1_name,
19
+ 'displayedAs' => 'Cycles',
20
+ 'roundingScheme' => 'UP',
21
+ })
22
+ created_uom_1 = BillForward::UnitOfMeasure.create(unit_of_measure_1)
23
+ end
17
24
 
25
+ uom_2_name = 'Bandwidth'
26
+ created_uom_2 = nil
27
+ begin
28
+ created_uom_2 = BillForward::UnitOfMeasure.get_by_id uom_2_name
29
+ rescue IndexError=>e
30
+ # create another unit of measure
31
+ unit_of_measure_2 = BillForward::UnitOfMeasure.new({
32
+ 'name' => uom_2_name,
33
+ 'displayedAs' => 'Mbps',
34
+ 'roundingScheme' => 'UP',
35
+ })
36
+ created_uom_2 = BillForward::UnitOfMeasure.create(unit_of_measure_2)
37
+ end
38
+
39
+ product_name = 'Monthly recurring'
40
+ created_product = nil
41
+ begin
42
+ created_product = BillForward::Product.get_by_id product_name
43
+ rescue IndexError=>e
44
+ # create a product
45
+ product = BillForward::Product.new({
46
+ 'productType' => 'recurring',
47
+ 'state' => 'prod',
48
+ 'name' => product_name,
49
+ 'description' => 'Purchaseables to which customer has a non-renewing, monthly entitlement',
50
+ 'durationPeriod' => 'months',
51
+ 'duration' => 1,
52
+ })
53
+ created_product = BillForward::Product::create(product)
54
+ end
18
55
 
19
- product = BillForward::Product.new({
20
- 'productType' => 'non-recurring',
21
- 'state' => 'prod',
22
- 'name' => 'Month of Paracetamoxyfrusebendroneomycin',
23
- 'description' => 'It can cure the common cold and being struck by lightning',
24
- 'durationPeriod' => 'days',
25
- 'duration' => 28,
26
- })
27
- @created_product = BillForward::Product::create(product)
28
56
 
57
+ # make product rate plan..
58
+ # requires:
59
+ # - product,
60
+ # - pricing components..
61
+ # .. - which require pricing component tiers
29
62
 
30
- tiers_for_flat_component_1 = Array.new()
31
- tiers_for_flat_component_1.push(
63
+ # for a tiered pricing component:
64
+ tiers_for_tiered_component_1 = Array.new()
65
+ tiers_for_tiered_component_1.push(
66
+ BillForward::PricingComponentTier.new({
67
+ 'lowerThreshold' => 0,
68
+ 'upperThreshold' => 0,
69
+ 'pricingType' => 'unit',
70
+ 'price' => 0,
71
+ }),
32
72
  BillForward::PricingComponentTier.new({
33
73
  'lowerThreshold' => 1,
34
- 'upperThreshold' => 1,
35
- 'pricingType' => 'fixed',
74
+ 'upperThreshold' => 10,
75
+ 'pricingType' => 'unit',
36
76
  'price' => 1,
77
+ }),
78
+ BillForward::PricingComponentTier.new({
79
+ 'lowerThreshold' => 11,
80
+ 'upperThreshold' => 1000,
81
+ 'pricingType' => 'unit',
82
+ 'price' => 0.50
37
83
  }))
38
84
 
39
- tiers_for_tiered_component_1 = Array.new()
40
- tiers_for_tiered_component_1.push(
85
+ # for another tiered pricing component:
86
+ tiers_for_tiered_component_2 = Array.new()
87
+ tiers_for_tiered_component_2.push(
41
88
  BillForward::PricingComponentTier.new({
42
- 'lowerThreshold' => 1,
43
- 'upperThreshold' => 1,
44
- 'pricingType' => 'fixed',
45
- 'price' => 10,
89
+ 'lowerThreshold' => 0,
90
+ 'upperThreshold' => 0,
91
+ 'pricingType' => 'unit',
92
+ 'price' => 0,
46
93
  }),
47
94
  BillForward::PricingComponentTier.new({
48
- 'lowerThreshold' => 2,
95
+ 'lowerThreshold' => 1,
49
96
  'upperThreshold' => 10,
50
97
  'pricingType' => 'unit',
51
- 'price' => 5
98
+ 'price' => 0.10,
52
99
  }),
53
100
  BillForward::PricingComponentTier.new({
54
101
  'lowerThreshold' => 11,
55
- 'upperThreshold' => 100,
102
+ 'upperThreshold' => 1000,
56
103
  'pricingType' => 'unit',
57
- 'price' => 2
104
+ 'price' => 0.05
58
105
  }))
59
106
 
60
-
107
+
108
+ # create 'in advance' ('subscription') pricing components, based on these tiers
61
109
  pricing_components = Array.new()
62
110
  pricing_components.push(
63
111
  BillForward::PricingComponent.new({
64
- '@type' => 'flatPricingComponent',
65
- 'chargeModel' => 'flat',
66
- 'name' => 'Devices used, fixed',
67
- 'description' => 'How many devices you use, I guess',
68
- 'unitOfMeasureID' => created_uom.id,
112
+ '@type' => 'tieredPricingComponent',
113
+ 'chargeModel' => 'tiered',
114
+ 'name' => 'CPU',
115
+ 'description' => 'CPU consumed',
116
+ 'unitOfMeasureID' => created_uom_1.id,
69
117
  'chargeType' => 'subscription',
70
118
  'upgradeMode' => 'immediate',
71
119
  'downgradeMode' => 'immediate',
72
120
  'defaultQuantity' => 1,
73
- 'tiers' => tiers_for_flat_component_1
121
+ 'tiers' => tiers_for_tiered_component_1
74
122
  }),
75
123
  BillForward::PricingComponent.new({
76
124
  '@type' => 'tieredPricingComponent',
77
125
  'chargeModel' => 'tiered',
78
- 'name' => 'Devices used, tiered',
79
- 'description' => 'How many devices you use, but with a tiering system',
80
- 'unitOfMeasureID' => created_uom.id,
126
+ 'name' => 'Bandwidth',
127
+ 'description' => 'Bandwidth consumed',
128
+ 'unitOfMeasureID' => created_uom_2.id,
81
129
  'chargeType' => 'subscription',
82
130
  'upgradeMode' => 'immediate',
83
131
  'downgradeMode' => 'immediate',
84
132
  'defaultQuantity' => 10,
85
- 'tiers' => tiers_for_tiered_component_1
133
+ 'tiers' => tiers_for_tiered_component_2
86
134
  }))
87
135
 
136
+ @created_product = created_product
88
137
  @pricing_components = pricing_components
89
138
  end
90
139
  subject(:product) { @created_product }
91
140
  subject(:pricing_components) { @pricing_components }
92
- it 'creates a Product' do
93
- prp = BillForward::ProductRatePlan.new({
94
- 'currency' => 'USD',
95
- 'name' => 'A sound plan',
96
- 'pricingComponents' => pricing_components,
97
- 'productID' => product.id,
141
+ it 'creates a Rate Plan' do
142
+ rate_plan_name = 'Sound Plan'
143
+ created_prp = nil
144
+ begin
145
+ created_prp = BillForward::ProductRatePlan.get_by_product_and_plan_id product.name, rate_plan_name
146
+ rescue IndexError=>e
147
+ # create product rate plan, using pricing components and product
148
+ prp = BillForward::ProductRatePlan.new({
149
+ 'currency' => 'USD',
150
+ 'name' => rate_plan_name,
151
+ 'pricingComponents' => pricing_components,
152
+ 'productID' => product.id,
98
153
  })
99
- created_prp = BillForward::ProductRatePlan.create(prp)
154
+ created_prp = BillForward::ProductRatePlan.create(prp)
155
+ end
100
156
 
101
157
  expect(created_prp['@type']).to eq(BillForward::ProductRatePlan.resource_path.entity_name)
102
158
  end
@@ -7,15 +7,22 @@ describe BillForward::Product do
7
7
  end
8
8
  describe '::create' do
9
9
  it 'creates a Product' do
10
- product = BillForward::Product.new({
11
- 'productType' => 'non-recurring',
12
- 'state' => 'prod',
13
- 'name' => 'Month of Paracetamoxyfrusebendroneomycin',
14
- 'description' => 'It can cure the common cold and being struck by lightning',
15
- 'durationPeriod' => 'days',
16
- 'duration' => 28,
17
- })
18
- created_product = BillForward::Product::create(product)
10
+ product_name = 'Monthly recurring'
11
+ created_product = nil
12
+ begin
13
+ created_product = BillForward::Product.get_by_id product_name
14
+ rescue IndexError=>e
15
+ # create a product
16
+ product = BillForward::Product.new({
17
+ 'productType' => 'recurring',
18
+ 'state' => 'prod',
19
+ 'name' => product_name,
20
+ 'description' => 'Purchaseables to which customer has a non-renewing, monthly entitlement',
21
+ 'durationPeriod' => 'months',
22
+ 'duration' => 1,
23
+ })
24
+ created_product = BillForward::Product::create(product)
25
+ end
19
26
  expect(created_product['@type']).to eq(BillForward::Product.resource_path.entity_name)
20
27
  end
21
28
  end
@@ -14,11 +14,15 @@ describe BillForward::AuthorizeNetToken do
14
14
  it 'creates a token' do
15
15
  created_account = BillForward::Account.create
16
16
 
17
+ organisations = BillForward::Organisation.get_mine
18
+ first_org = organisations.first
19
+
17
20
  authorize_net_token = BillForward::AuthorizeNetToken.new({
18
21
  'accountID' => created_account.id,
19
22
  'customerProfileID' => @authorize_net_customer_profile_id,
20
23
  'customerPaymentProfileID' => @authorize_net_customer_payment_profile_id,
21
24
  'lastFourDigits' => @authorize_net_card_last_4_digits,
25
+ 'organizationID' => first_org.id
22
26
  })
23
27
 
24
28
  created_token = BillForward::AuthorizeNetToken.create(authorize_net_token)
@@ -29,7 +29,7 @@ describe BillForward::Amendment do
29
29
  allow(amendment.class).to receive(:resource_path).and_return(BillForward::InvoiceRecalculationAmendment.resource_path)
30
30
  allow(amendment).to receive(:serialize).and_return(malformed_serialize)
31
31
 
32
- expect{BillForward::InvoiceRecalculationAmendment.create(amendment)}.to raise_error(BillForward::ApiError, /400/)
32
+ expect{BillForward::InvoiceRecalculationAmendment.create(amendment)}.to raise_error(BillForward::ApiError, /500/)
33
33
  end
34
34
  end
35
35
  end
@@ -14,12 +14,16 @@ describe BillForward::PaymentMethod do
14
14
  context 'account exists' do
15
15
  context 'using Authorize.Net payment gateway' do
16
16
  before :all do
17
+ organisations = BillForward::Organisation.get_mine
18
+ first_org = organisations.first
19
+
17
20
  @created_account = BillForward::Account.create
18
21
  authorize_net_token = BillForward::AuthorizeNetToken.new({
19
22
  'accountID' => @created_account.id,
20
23
  'customerProfileID' => @authorize_net_customer_profile_id,
21
24
  'customerPaymentProfileID' => @authorize_net_customer_payment_profile_id,
22
25
  'lastFourDigits' => @authorize_net_card_last_4_digits,
26
+ 'organizationID' => first_org.id
23
27
  })
24
28
 
25
29
  @created_token = BillForward::AuthorizeNetToken.create(authorize_net_token)
@@ -27,6 +31,7 @@ describe BillForward::PaymentMethod do
27
31
  subject (:token) { @created_token }
28
32
  subject (:account) { @created_account }
29
33
  it 'creates a payment method' do
34
+
30
35
  payment_method = BillForward::PaymentMethod.new({
31
36
  'accountID' => account.id,
32
37
  'linkID' => token.id,
@@ -35,7 +40,7 @@ describe BillForward::PaymentMethod do
35
40
  'gateway' => 'authorizeNet',
36
41
  'userEditable' => 0,
37
42
  'priority' => 100,
38
- 'reusable' => 1,
43
+ 'reusable' => 1
39
44
  })
40
45
  created_payment_method = BillForward::PaymentMethod::create(payment_method)
41
46