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
@@ -8,8 +8,8 @@ describe BillForward::Subscription do
8
8
  context 'upon creating required entities for chargeable Subscription' do
9
9
  before :all do
10
10
  # get our organisation
11
- organisations = BillForward::Organisation.get_mine
12
- first_org = organisations.first
11
+ # organisations = BillForward::Organisation.get_mine
12
+ # first_org = organisations.first
13
13
 
14
14
 
15
15
  # create an account
@@ -31,7 +31,8 @@ describe BillForward::Subscription do
31
31
  }))
32
32
  profile = BillForward::Profile.new({
33
33
  'email' => 'always@testing.is.moe',
34
- 'firstName' => 'Test',
34
+ 'firstName' => 'Ruby',
35
+ 'lastName' => 'Red',
35
36
  'addresses' => addresses
36
37
  })
37
38
  account = BillForward::Account.new({
@@ -39,50 +40,74 @@ describe BillForward::Subscription do
39
40
  })
40
41
  created_account = BillForward::Account.create account
41
42
 
42
-
43
+ ## Credit note payment method exists implicitly nowadays
43
44
  # create for our account: a new payment method, using credit notes
44
- payment_method = BillForward::PaymentMethod.new({
45
- 'accountID' => created_account.id,
46
- 'name' => 'Credit Notes',
47
- 'description' => 'Pay using credit',
48
- # engines will link this to an invoice once paid, for the sake of refunds
49
- 'linkID' => '',
50
- 'gateway' => 'credit_note',
51
- 'userEditable' => 0,
52
- 'priority' => 100,
53
- 'reusable' => 1
54
- })
55
- created_payment_method = BillForward::PaymentMethod::create(payment_method)
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)
56
57
 
57
58
 
58
59
  # issue $100 credit to our account
59
60
  credit_note = BillForward::CreditNote.new({
60
61
  "accountID" => created_account.id,
61
- "nominalValue" => 100,
62
+ "value" => 1000,
62
63
  "currency" => "USD"
63
64
  })
64
65
  created_credit_note = BillForward::CreditNote.create(credit_note)
65
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
66
80
 
67
- # create a unit of measure
68
- unit_of_measure = BillForward::UnitOfMeasure.new({
69
- 'name' => 'Devices',
70
- 'displayedAs' => 'Devices',
71
- 'roundingScheme' => 'UP',
72
- })
73
- created_uom = BillForward::UnitOfMeasure.create(unit_of_measure)
74
-
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
75
94
 
76
- # create a product
77
- product = BillForward::Product.new({
78
- 'productType' => 'non-recurring',
79
- 'state' => 'prod',
80
- 'name' => 'Month of Paracetamoxyfrusebendroneomycin',
81
- 'description' => 'It can cure the common cold and being struck by lightning',
82
- 'durationPeriod' => 'minutes',
83
- 'duration' => 1,
84
- })
85
- created_product = BillForward::Product::create(product)
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
86
111
 
87
112
 
88
113
  # make product rate plan..
@@ -91,83 +116,98 @@ describe BillForward::Subscription do
91
116
  # - pricing components..
92
117
  # .. - which require pricing component tiers
93
118
 
94
- # create tiers..
95
- # for a flat pricing component:
96
- tiers_for_flat_component_1 = Array.new()
97
- tiers_for_flat_component_1.push(
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
+ }),
98
128
  BillForward::PricingComponentTier.new({
99
129
  'lowerThreshold' => 1,
100
- 'upperThreshold' => 1,
101
- 'pricingType' => 'fixed',
130
+ 'upperThreshold' => 10,
131
+ 'pricingType' => 'unit',
102
132
  'price' => 1,
133
+ }),
134
+ BillForward::PricingComponentTier.new({
135
+ 'lowerThreshold' => 11,
136
+ 'upperThreshold' => 1000,
137
+ 'pricingType' => 'unit',
138
+ 'price' => 0.50
103
139
  }))
104
140
 
105
- # for a tiered pricing component:
106
- tiers_for_tiered_component_1 = Array.new()
107
- tiers_for_tiered_component_1.push(
141
+ # for another tiered pricing component:
142
+ tiers_for_tiered_component_2 = Array.new()
143
+ tiers_for_tiered_component_2.push(
108
144
  BillForward::PricingComponentTier.new({
109
- 'lowerThreshold' => 1,
110
- 'upperThreshold' => 1,
111
- 'pricingType' => 'fixed',
112
- 'price' => 10,
145
+ 'lowerThreshold' => 0,
146
+ 'upperThreshold' => 0,
147
+ 'pricingType' => 'unit',
148
+ 'price' => 0,
113
149
  }),
114
150
  BillForward::PricingComponentTier.new({
115
- 'lowerThreshold' => 2,
151
+ 'lowerThreshold' => 1,
116
152
  'upperThreshold' => 10,
117
153
  'pricingType' => 'unit',
118
- 'price' => 5
154
+ 'price' => 0.10,
119
155
  }),
120
156
  BillForward::PricingComponentTier.new({
121
157
  'lowerThreshold' => 11,
122
- 'upperThreshold' => 100,
158
+ 'upperThreshold' => 1000,
123
159
  'pricingType' => 'unit',
124
- 'price' => 2
160
+ 'price' => 0.05
125
161
  }))
126
162
 
127
163
 
128
- # create pricing components, based on these tiers
164
+ # create 'in advance' ('subscription') pricing components, based on these tiers
129
165
  pricing_components = Array.new()
130
166
  pricing_components.push(
131
167
  BillForward::PricingComponent.new({
132
- '@type' => 'flatPricingComponent',
133
- 'chargeModel' => 'flat',
134
- 'name' => 'Devices used, fixed',
135
- 'description' => 'How many devices you use, I guess',
136
- 'unitOfMeasureID' => created_uom.id,
168
+ '@type' => 'tieredPricingComponent',
169
+ 'chargeModel' => 'tiered',
170
+ 'name' => 'CPU',
171
+ 'description' => 'CPU consumed',
172
+ 'unitOfMeasureID' => created_uom_1.id,
137
173
  'chargeType' => 'subscription',
138
174
  'upgradeMode' => 'immediate',
139
175
  'downgradeMode' => 'immediate',
140
176
  'defaultQuantity' => 1,
141
- 'tiers' => tiers_for_flat_component_1
177
+ 'tiers' => tiers_for_tiered_component_1
142
178
  }),
143
179
  BillForward::PricingComponent.new({
144
180
  '@type' => 'tieredPricingComponent',
145
181
  'chargeModel' => 'tiered',
146
- 'name' => 'Devices used, tiered',
147
- 'description' => 'How many devices you use, but with a tiering system',
148
- 'unitOfMeasureID' => created_uom.id,
149
- 'chargeType' => 'usage',
182
+ 'name' => 'Bandwidth',
183
+ 'description' => 'Bandwidth consumed',
184
+ 'unitOfMeasureID' => created_uom_2.id,
185
+ 'chargeType' => 'subscription',
150
186
  'upgradeMode' => 'immediate',
151
187
  'downgradeMode' => 'immediate',
152
188
  'defaultQuantity' => 10,
153
- 'tiers' => tiers_for_tiered_component_1
189
+ 'tiers' => tiers_for_tiered_component_2
154
190
  }))
155
191
 
156
-
157
- # create product rate plan, using pricing components and product
158
- prp = BillForward::ProductRatePlan.new({
159
- 'currency' => 'USD',
160
- 'name' => 'A sound plan',
161
- 'pricingComponents' => pricing_components,
162
- 'productID' => created_product.id,
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,
163
203
  })
164
- created_prp = BillForward::ProductRatePlan.create(prp)
204
+ created_prp = BillForward::ProductRatePlan.create(prp)
205
+ end
165
206
 
166
207
 
167
208
  # create references for tests to use
168
209
  @created_account = created_account
169
210
  @created_prp = created_prp
170
- @created_payment_method = created_payment_method
171
211
  end
172
212
  describe '::create' do
173
213
  describe 'the subscription' do
@@ -177,31 +217,22 @@ describe BillForward::Subscription do
177
217
  # - account [we have this already]
178
218
  # - product rate plan [we have this already]
179
219
  # - pricing component value instances (for every pricing component on the PRP)
180
- # - payment method subscription links (for every payment method on the account)
181
-
182
- # create PaymentMethodSubscriptionLink from payment method and organisation
183
- payment_method_subscription_links = Array.new
184
- payment_method_subscription_links.push(
185
- BillForward::PaymentMethodSubscriptionLink.new({
186
- 'paymentMethodID' => @created_payment_method.id
187
- }))
188
-
189
220
 
190
221
  pricing_components = @created_prp.pricingComponents
191
222
  # get references to each pricing component we made
192
- flat_pricing_component_1 = pricing_components[0]
193
- tiered_pricing_component_1 = pricing_components[1]
223
+ tiered_pricing_component_1 = pricing_components[0]
224
+ tiered_pricing_component_2 = pricing_components[1]
194
225
 
195
226
  # create PricingComponentValue instances for every PricingComponent on the PRP
196
227
  pricing_component_values = Array.new
197
228
  pricing_component_values.push(
198
229
  BillForward::PricingComponentValue.new({
199
- 'pricingComponentID' => flat_pricing_component_1.id,
200
- 'value' => 1,
230
+ 'pricingComponentID' => tiered_pricing_component_1.id,
231
+ 'value' => 13,
201
232
  }),
202
233
  BillForward::PricingComponentValue.new({
203
- 'pricingComponentID' => tiered_pricing_component_1.id,
204
- 'value' => 5,
234
+ 'pricingComponentID' => tiered_pricing_component_2.id,
235
+ 'value' => 13,
205
236
  }))
206
237
 
207
238
 
@@ -211,8 +242,7 @@ describe BillForward::Subscription do
211
242
  'productRatePlanID' => @created_prp.id,
212
243
  'accountID' => @created_account.id,
213
244
  'name' => 'Memorable Subscription',
214
- 'description' => 'Memorable Subscription Description',
215
- 'paymentMethodSubscriptionLinks' => payment_method_subscription_links,
245
+ 'description' => "Customer acquired through 'Lazy Wednesdays' promotion",
216
246
  'pricingComponentValues' => pricing_component_values
217
247
  })
218
248
  created_sub = BillForward::Subscription.create(subscription)
@@ -232,7 +262,7 @@ describe BillForward::Subscription do
232
262
  expect(subscription['state']).to eq('Provisioned')
233
263
  updated_subscription = subscription.activate
234
264
 
235
- expect(updated_subscription['state']).to eq('AwaitingPayment')
265
+ expect(updated_subscription['state']).to satisfy{|s| ['AwaitingPayment', 'Paid'].include?(s)}
236
266
  end
237
267
  end
238
268
  end
@@ -7,14 +7,21 @@ describe BillForward::UnitOfMeasure do
7
7
  end
8
8
  describe '::create' do
9
9
  it 'creates a UnitOfMeasure' do
10
- unit_of_measure = BillForward::UnitOfMeasure.new({
11
- 'name' => 'Devices',
12
- 'displayedAs' => 'Devices',
13
- 'roundingScheme' => 'UP',
14
- })
15
- created_uom = BillForward::UnitOfMeasure.create(unit_of_measure)
10
+ uom_1_name = 'CPU'
11
+ created_uom_1 = nil
12
+ begin
13
+ created_uom_1 = BillForward::UnitOfMeasure.get_by_id uom_1_name
14
+ rescue IndexError=>e
15
+ # create a unit of measure
16
+ unit_of_measure_1 = BillForward::UnitOfMeasure.new({
17
+ 'name' => uom_1_name,
18
+ 'displayedAs' => 'Cycles',
19
+ 'roundingScheme' => 'UP',
20
+ })
21
+ created_uom_1 = BillForward::UnitOfMeasure.create(unit_of_measure_1)
22
+ end
16
23
 
17
- expect(created_uom['@type']).to eq(BillForward::UnitOfMeasure.resource_path.entity_name)
24
+ expect(created_uom_1['@type']).to eq(BillForward::UnitOfMeasure.resource_path.entity_name)
18
25
  end
19
26
  end
20
27
  end
@@ -1,24 +1,24 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
2
-
3
- describe BillForward::Client do
4
- describe '#new' do
5
- before :all do
6
- @client = BillForwardTest::TEST_CLIENT
7
- BillForward::Client.default_client = @client
8
- end
9
- it "should find empty results upon looking up non-existent ID" do
10
- account_id = "nonexist"
11
-
12
- expect{BillForward::Account.get_by_id account_id}.to raise_error(IndexError)
13
- end
14
- it "should raise upon bad token" do
15
- host=@client.host
16
- token="badtoken"
17
- dudclient = BillForward::Client.new(
18
- :host => host,
19
- :api_token => token
20
- )
21
- expect{BillForward::Organisation.get_mine(nil,dudclient)}.to raise_error(BillForward::ApiAuthorizationError)
22
- end
23
- end
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
2
+
3
+ describe BillForward::Client do
4
+ describe '#new' do
5
+ before :all do
6
+ @client = BillForwardTest::TEST_CLIENT
7
+ BillForward::Client.default_client = @client
8
+ end
9
+ it "should find empty results upon looking up non-existent ID" do
10
+ account_id = "nonexist"
11
+
12
+ expect{BillForward::Account.get_by_id account_id}.to raise_error(IndexError)
13
+ end
14
+ it "should raise upon bad token" do
15
+ host=@client.host
16
+ token="badtoken"
17
+ dudclient = BillForward::Client.new(
18
+ :host => host,
19
+ :api_token => token
20
+ )
21
+ expect{BillForward::Organisation.get_mine(nil,dudclient)}.to raise_error(BillForward::ApiAuthorizationError)
22
+ end
23
+ end
24
24
  end
@@ -1,28 +1,28 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
2
-
3
- describe BillForward::Account do
4
- before :all do
5
- @client = BillForwardTest::TEST_CLIENT
6
- BillForward::Client.default_client = @client
7
- end
8
- describe '::get_all' do
9
- it 'raises permissions error' do
10
- # 'admin' privilege is insufficient to see other organisations
11
- expect{BillForward::Organisation::get_all}.to raise_error(BillForward::ApiError, /415/)
12
- # TODO: consider that API v219 (at least) gives instead:
13
- # ====
14
- # 400 API Error.
15
- # Type: PermissionsError
16
- # Message: Access is denied
17
- # ====
18
- end
19
- end
20
- describe '::get_mine' do
21
- it "should find organisations" do
22
- organisations = BillForward::Organisation.get_mine
23
- organisations_first = organisations.first
24
-
25
- expect(organisations_first['@type']).to eq(BillForward::Organisation.resource_path.entity_name)
26
- end
27
- end
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
2
+
3
+ describe BillForward::Account do
4
+ before :all do
5
+ @client = BillForwardTest::TEST_CLIENT
6
+ BillForward::Client.default_client = @client
7
+ end
8
+ describe '::get_all' do
9
+ it 'raises permissions error' do
10
+ # 'admin' privilege is insufficient to see other organisations
11
+ expect{BillForward::Organisation::get_all}.to raise_error(BillForward::ApiError, /500/)
12
+ # Expected error:
13
+ # ====
14
+ # 500 API Error.
15
+ # Type: PermissionsError
16
+ # Message: Access is denied
17
+ # ====
18
+ end
19
+ end
20
+ describe '::get_mine' do
21
+ it "should find organisations" do
22
+ organisations = BillForward::Organisation.get_mine
23
+ organisations_first = organisations.first
24
+
25
+ expect(organisations_first['@type']).to eq(BillForward::Organisation.resource_path.entity_name)
26
+ end
27
+ end
28
28
  end
@@ -1,73 +1,73 @@
1
- # constants include BillForward credentials, required for running functional tests.
2
- # this file, ignored from version control, allows users to specify credentials for a test account
3
- test_constants_file = File.join(File.expand_path(File.dirname(__FILE__)), "test_constants.rb")
4
- if (File.exist?(test_constants_file))
5
- puts "using test constants from #{test_constants_file}"
6
- require test_constants_file
7
- else
8
- puts 'using default test constants'
9
- # The following is a template for what your 'test_constants.rb' should contain.
10
- # If used in this placeholder state, functional tests will not pass.
11
- module BillForwardTest
12
- BILLFORWARD_API_HOST='insert-API-URL-here'
13
- BILLFORWARD_API_TOKEN="insert-access-token-here OR leave-blank-for-OAUTH"
14
-
15
- ### alternatively:
16
- # (these values are used if you leave API token blank)
17
- # authenticate using OAUTH:
18
- BILLFORWARD_USERNAME="insert-username"
19
- BILLFORWARD_PASSWORD="insert-password"
20
- BILLFORWARD_CLIENT_ID="insert-client-id"
21
- BILLFORWARD_CLIENT_SECRET="insert-client-secret"
22
-
23
-
24
- # ---- Enable logging if you want (shows request and response bodies)
25
- USE_LOGGING=false
26
-
27
-
28
- # ---- Enable proxy if you want (for example to see requests in Fiddler)
29
- CLIENT_PROXY_ENABLED=false
30
- CLIENT_PROXY_URL="http://127.0.0.1:8888"
31
-
32
-
33
- ## These constants are required only for running situational tests (not in the main run):
34
- # ---- Required for Authorize.Net gateway tests only
35
- AUTHORIZE_NET_LOGIN_ID = 'FILL IN WITH AUTHORIZE NET LOGIN ID'
36
- AUTHORIZE_NET_TRANSACTION_KEY = 'FILL IN WITH AUTHORIZE NET TRANSACTION KEY'
37
- # ---- Required for Authorize.Net tokenization tests only
38
- AUTHORIZE_NET_CUSTOMER_PROFILE_ID = 12345678 # FILL IN WITH AUTHORIZE NET CUSTOMER PROFILE ID
39
- AUTHORIZE_NET_CUSTOMER_PAYMENT_PROFILE_ID = 12345678 # FILL IN WITH AUTHORIZE NET CUSTOMER PAYMENT PROFILE ID
40
- AUTHORIZE_NET_CARD_LAST_4_DIGITS = 1234
41
-
42
-
43
- # ---- Required for Invoice tests only
44
- USUAL_INVOICE_ID = 'FILL IN WITH EXISTING INVOICE ID'
45
- end
46
- end
47
-
48
- # create BillForward client for use in all tests
49
- # requires working credentials only when running functional tests
50
- module BillForwardTest
51
- if (BillForwardTest::BILLFORWARD_API_TOKEN == '')
52
- # Authenticate using OAuth; username and password
53
- TEST_CLIENT = BillForward::Client.new(
54
- :host => BillForwardTest::BILLFORWARD_API_HOST,
55
- :use_logging => BillForwardTest::USE_LOGGING,
56
- :username => BillForwardTest::BILLFORWARD_USERNAME,
57
- :password => BillForwardTest::BILLFORWARD_PASSWORD,
58
- :client_id => BillForwardTest::BILLFORWARD_CLIENT_ID,
59
- :client_secret => BillForwardTest::BILLFORWARD_CLIENT_SECRET,
60
- :use_proxy => BillForwardTest::CLIENT_PROXY_ENABLED,
61
- :proxy_url => BillForwardTest::CLIENT_PROXY_URL
62
- )
63
- else
64
- # Authenticate instead using access token
65
- TEST_CLIENT = BillForward::Client.new(
66
- :host => BillForwardTest::BILLFORWARD_API_HOST,
67
- :use_logging => BillForwardTest::USE_LOGGING,
68
- :api_token => BillForwardTest::BILLFORWARD_API_TOKEN,
69
- :use_proxy => BillForwardTest::CLIENT_PROXY_ENABLED,
70
- :proxy_url => BillForwardTest::CLIENT_PROXY_URL
71
- )
72
- end
1
+ # constants include BillForward credentials, required for running functional tests.
2
+ # this file, ignored from version control, allows users to specify credentials for a test account
3
+ test_constants_file = File.join(File.expand_path(File.dirname(__FILE__)), "test_constants.rb")
4
+ if (File.exist?(test_constants_file))
5
+ puts "using test constants from #{test_constants_file}"
6
+ require test_constants_file
7
+ else
8
+ puts 'using default test constants'
9
+ # The following is a template for what your 'test_constants.rb' should contain.
10
+ # If used in this placeholder state, functional tests will not pass.
11
+ module BillForwardTest
12
+ BILLFORWARD_API_HOST='insert-API-URL-here'
13
+ BILLFORWARD_API_TOKEN="insert-access-token-here OR leave-blank-for-OAUTH"
14
+
15
+ ### alternatively:
16
+ # (these values are used if you leave API token blank)
17
+ # authenticate using OAUTH:
18
+ BILLFORWARD_USERNAME="insert-username"
19
+ BILLFORWARD_PASSWORD="insert-password"
20
+ BILLFORWARD_CLIENT_ID="insert-client-id"
21
+ BILLFORWARD_CLIENT_SECRET="insert-client-secret"
22
+
23
+
24
+ # ---- Enable logging if you want (shows request and response bodies)
25
+ USE_LOGGING=false
26
+
27
+
28
+ # ---- Enable proxy if you want (for example to see requests in Fiddler)
29
+ CLIENT_PROXY_ENABLED=false
30
+ CLIENT_PROXY_URL="http://127.0.0.1:8888"
31
+
32
+
33
+ ## These constants are required only for running situational tests (not in the main run):
34
+ # ---- Required for Authorize.Net gateway tests only
35
+ AUTHORIZE_NET_LOGIN_ID = 'FILL IN WITH AUTHORIZE NET LOGIN ID'
36
+ AUTHORIZE_NET_TRANSACTION_KEY = 'FILL IN WITH AUTHORIZE NET TRANSACTION KEY'
37
+ # ---- Required for Authorize.Net tokenization tests only
38
+ AUTHORIZE_NET_CUSTOMER_PROFILE_ID = 12345678 # FILL IN WITH AUTHORIZE NET CUSTOMER PROFILE ID
39
+ AUTHORIZE_NET_CUSTOMER_PAYMENT_PROFILE_ID = 12345678 # FILL IN WITH AUTHORIZE NET CUSTOMER PAYMENT PROFILE ID
40
+ AUTHORIZE_NET_CARD_LAST_4_DIGITS = 1234
41
+
42
+
43
+ # ---- Required for Invoice tests only
44
+ USUAL_INVOICE_ID = 'FILL IN WITH EXISTING INVOICE ID'
45
+ end
46
+ end
47
+
48
+ # create BillForward client for use in all tests
49
+ # requires working credentials only when running functional tests
50
+ module BillForwardTest
51
+ if (BillForwardTest::BILLFORWARD_API_TOKEN == '')
52
+ # Authenticate using OAuth; username and password
53
+ TEST_CLIENT = BillForward::Client.new(
54
+ :host => BillForwardTest::BILLFORWARD_API_HOST,
55
+ :use_logging => BillForwardTest::USE_LOGGING,
56
+ :username => BillForwardTest::BILLFORWARD_USERNAME,
57
+ :password => BillForwardTest::BILLFORWARD_PASSWORD,
58
+ :client_id => BillForwardTest::BILLFORWARD_CLIENT_ID,
59
+ :client_secret => BillForwardTest::BILLFORWARD_CLIENT_SECRET,
60
+ :use_proxy => BillForwardTest::CLIENT_PROXY_ENABLED,
61
+ :proxy_url => BillForwardTest::CLIENT_PROXY_URL
62
+ )
63
+ else
64
+ # Authenticate instead using access token
65
+ TEST_CLIENT = BillForward::Client.new(
66
+ :host => BillForwardTest::BILLFORWARD_API_HOST,
67
+ :use_logging => BillForwardTest::USE_LOGGING,
68
+ :api_token => BillForwardTest::BILLFORWARD_API_TOKEN,
69
+ :use_proxy => BillForwardTest::CLIENT_PROXY_ENABLED,
70
+ :proxy_url => BillForwardTest::CLIENT_PROXY_URL
71
+ )
72
+ end
73
73
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'bundler/setup'
2
- Bundler.setup
3
-
4
- require 'bill_forward' # and any other gems you need
5
-
6
- # this file provides constants for tests to share
7
- require File.join(File.expand_path(File.dirname(__FILE__)), "setup_test_constants")
8
-
9
- RSpec.configure do |config|
10
- # some (optional) config here
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'bill_forward' # and any other gems you need
5
+
6
+ # this file provides constants for tests to share
7
+ require File.join(File.expand_path(File.dirname(__FILE__)), "setup_test_constants")
8
+
9
+ RSpec.configure do |config|
10
+ # some (optional) config here
11
11
  end