bill_forward 1.2014.296
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +27 -0
- data/.idea/.name +1 -0
- data/.idea/compiler.xml +23 -0
- data/.idea/copyright/profiles_settings.xml +3 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +11 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
- data/.idea/misc.xml +23 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.rspec +2 -0
- data/Gemfile +9 -0
- data/LICENSE.md +22 -0
- data/README.md +227 -0
- data/Rakefile +73 -0
- data/bill_forward.gemspec +29 -0
- data/bill_forward.iml +28 -0
- data/lib/bill_forward.rb +18 -0
- data/lib/bill_forward/billing_entity.rb +263 -0
- data/lib/bill_forward/client.rb +355 -0
- data/lib/bill_forward/custom_hash.rb +14 -0
- data/lib/bill_forward/deny_method.rb +4 -0
- data/lib/bill_forward/entities/account.rb +19 -0
- data/lib/bill_forward/entities/address.rb +25 -0
- data/lib/bill_forward/entities/amendments/amendment.rb +11 -0
- data/lib/bill_forward/entities/amendments/invoice_recalculation_amendment.rb +10 -0
- data/lib/bill_forward/entities/api_configuration.rb +11 -0
- data/lib/bill_forward/entities/authorize_net_token.rb +9 -0
- data/lib/bill_forward/entities/credit_note.rb +13 -0
- data/lib/bill_forward/entities/invoice.rb +25 -0
- data/lib/bill_forward/entities/invoice_parts/invoice_line.rb +37 -0
- data/lib/bill_forward/entities/invoice_parts/invoice_payment.rb +29 -0
- data/lib/bill_forward/entities/invoice_parts/tax_line.rb +23 -0
- data/lib/bill_forward/entities/invoice_parts/taxation_link.rb +5 -0
- data/lib/bill_forward/entities/organisation.rb +37 -0
- data/lib/bill_forward/entities/payment_method.rb +5 -0
- data/lib/bill_forward/entities/payment_method_subscription_link.rb +5 -0
- data/lib/bill_forward/entities/pricing_component.rb +21 -0
- data/lib/bill_forward/entities/pricing_component_tier.rb +5 -0
- data/lib/bill_forward/entities/pricing_component_value.rb +5 -0
- data/lib/bill_forward/entities/pricing_component_value_change.rb +5 -0
- data/lib/bill_forward/entities/product.rb +5 -0
- data/lib/bill_forward/entities/product_rate_plan.rb +19 -0
- data/lib/bill_forward/entities/profile.rb +15 -0
- data/lib/bill_forward/entities/role.rb +4 -0
- data/lib/bill_forward/entities/subscription.rb +53 -0
- data/lib/bill_forward/entities/unit_of_measure.rb +5 -0
- data/lib/bill_forward/insertable_entity.rb +32 -0
- data/lib/bill_forward/mutable_entity.rb +47 -0
- data/lib/bill_forward/resource_path.rb +11 -0
- data/lib/bill_forward/type_check.rb +21 -0
- data/lib/bill_forward/version.rb +4 -0
- data/spec/component/account_spec.rb +200 -0
- data/spec/component/billing_entity_spec.rb +153 -0
- data/spec/component/invoice_spec.rb +155 -0
- data/spec/component/subscription_spec.rb +357 -0
- data/spec/functional/account_spec.rb +25 -0
- data/spec/functional/bad_citizen/account_spec.rb +103 -0
- data/spec/functional/bad_citizen/credit_note_spec.rb +41 -0
- data/spec/functional/bad_citizen/payment_method_spec.rb +34 -0
- data/spec/functional/bad_citizen/product_rate_plan_spec.rb +105 -0
- data/spec/functional/bad_citizen/product_spec.rb +22 -0
- data/spec/functional/bad_citizen/situational/authorize_net_token_spec.rb +27 -0
- data/spec/functional/bad_citizen/situational/invoice_recalculation_amendment_spec.rb +27 -0
- data/spec/functional/bad_citizen/situational/invoice_spec.rb +22 -0
- data/spec/functional/bad_citizen/situational/malordered_entity_spec.rb +43 -0
- data/spec/functional/bad_citizen/situational/organisation_spec.rb +39 -0
- data/spec/functional/bad_citizen/situational/payment_method_spec.rb +47 -0
- data/spec/functional/bad_citizen/situational/subscription_chargeable_spec.rb +255 -0
- data/spec/functional/bad_citizen/subscription_spec.rb +179 -0
- data/spec/functional/bad_citizen/subscription_with_credit_spec.rb +240 -0
- data/spec/functional/bad_citizen/unit_of_measure_spec.rb +20 -0
- data/spec/functional/billing_entity_spec.rb +22 -0
- data/spec/functional/client_spec.rb +24 -0
- data/spec/functional/organisation_spec.rb +28 -0
- data/spec/setup_test_constants.rb +73 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/syntax/account_spec.rb +24 -0
- data/spec/syntax/address_spec.rb +19 -0
- data/spec/syntax/api_configuration_spec.rb +13 -0
- data/spec/syntax/billing_entity_spec.rb +93 -0
- data/spec/syntax/client_spec.rb +8 -0
- metadata +287 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
describe BillForward::Organisation do
|
|
4
|
+
before :all do
|
|
5
|
+
@client = BillForwardTest::TEST_CLIENT
|
|
6
|
+
BillForward::Client.default_client = @client
|
|
7
|
+
|
|
8
|
+
# Authorize.Net credentials used to test adding a payment gateway
|
|
9
|
+
@authorize_net_login_id = BillForwardTest::AUTHORIZE_NET_LOGIN_ID
|
|
10
|
+
@authorize_net_transaction_key = BillForwardTest::AUTHORIZE_NET_TRANSACTION_KEY
|
|
11
|
+
end
|
|
12
|
+
describe '.api_configurations' do
|
|
13
|
+
it "can be updated" do
|
|
14
|
+
organisations = BillForward::Organisation.get_mine
|
|
15
|
+
first_org = organisations.first
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# remove all existing AuthorizeNetConfigurations (if any)
|
|
19
|
+
filtered = first_org.apiConfigurations.reject do |config|
|
|
20
|
+
config['@type'] == 'AuthorizeNetConfiguration'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
first_org.apiConfigurations = filtered
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#add a new AuthorizeNetConfiguration
|
|
27
|
+
first_org.apiConfigurations.push BillForward::APIConfiguration.new({
|
|
28
|
+
"@type" => "AuthorizeNetConfiguration",
|
|
29
|
+
"APILoginID" => @authorize_net_login_id,
|
|
30
|
+
"transactionKey" => @authorize_net_transaction_key,
|
|
31
|
+
"environment" => "Sandbox"
|
|
32
|
+
})
|
|
33
|
+
updated_org = first_org.save
|
|
34
|
+
|
|
35
|
+
added_config = updated_org.apiConfigurations.last
|
|
36
|
+
expect(added_config.APILoginID).to eq(@authorize_net_login_id)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
describe BillForward::PaymentMethod do
|
|
4
|
+
before :all do
|
|
5
|
+
@client = BillForwardTest::TEST_CLIENT
|
|
6
|
+
BillForward::Client.default_client = @client
|
|
7
|
+
|
|
8
|
+
# Authorize.Net credentials used to test tokenizing a card
|
|
9
|
+
@authorize_net_customer_profile_id = BillForwardTest::AUTHORIZE_NET_CUSTOMER_PROFILE_ID
|
|
10
|
+
@authorize_net_customer_payment_profile_id = BillForwardTest::AUTHORIZE_NET_CUSTOMER_PAYMENT_PROFILE_ID
|
|
11
|
+
@authorize_net_card_last_4_digits = BillForwardTest::AUTHORIZE_NET_CARD_LAST_4_DIGITS
|
|
12
|
+
end
|
|
13
|
+
describe '::create' do
|
|
14
|
+
context 'account exists' do
|
|
15
|
+
context 'using Authorize.Net payment gateway' do
|
|
16
|
+
before :all do
|
|
17
|
+
@created_account = BillForward::Account.create
|
|
18
|
+
authorize_net_token = BillForward::AuthorizeNetToken.new({
|
|
19
|
+
'accountID' => @created_account.id,
|
|
20
|
+
'customerProfileID' => @authorize_net_customer_profile_id,
|
|
21
|
+
'customerPaymentProfileID' => @authorize_net_customer_payment_profile_id,
|
|
22
|
+
'lastFourDigits' => @authorize_net_card_last_4_digits,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
@created_token = BillForward::AuthorizeNetToken.create(authorize_net_token)
|
|
26
|
+
end
|
|
27
|
+
subject (:token) { @created_token }
|
|
28
|
+
subject (:account) { @created_account }
|
|
29
|
+
it 'creates a payment method' do
|
|
30
|
+
payment_method = BillForward::PaymentMethod.new({
|
|
31
|
+
'accountID' => account.id,
|
|
32
|
+
'linkID' => token.id,
|
|
33
|
+
'name' => 'Authorize.Net',
|
|
34
|
+
'description' => 'Pay via Authorize.Net',
|
|
35
|
+
'gateway' => 'authorizeNet',
|
|
36
|
+
'userEditable' => 0,
|
|
37
|
+
'priority' => 100,
|
|
38
|
+
'reusable' => 1,
|
|
39
|
+
})
|
|
40
|
+
created_payment_method = BillForward::PaymentMethod::create(payment_method)
|
|
41
|
+
|
|
42
|
+
expect(created_payment_method['@type']).to eq(BillForward::PaymentMethod.resource_path.entity_name)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
|
|
8
|
+
# Authorize.Net credentials used to test adding a payment gateway
|
|
9
|
+
@authorize_net_login_id = BillForwardTest::AUTHORIZE_NET_LOGIN_ID
|
|
10
|
+
@authorize_net_transaction_key = BillForwardTest::AUTHORIZE_NET_TRANSACTION_KEY
|
|
11
|
+
|
|
12
|
+
# Authorize.Net credentials used to test adding a payment gateway
|
|
13
|
+
@authorize_net_customer_profile_id = BillForwardTest::AUTHORIZE_NET_CUSTOMER_PROFILE_ID
|
|
14
|
+
@authorize_net_customer_payment_profile_id = BillForwardTest::AUTHORIZE_NET_CUSTOMER_PAYMENT_PROFILE_ID
|
|
15
|
+
@authorize_net_card_last_4_digits = BillForwardTest::AUTHORIZE_NET_CARD_LAST_4_DIGITS
|
|
16
|
+
end
|
|
17
|
+
context 'upon creating required entities for chargeable Subscription' do
|
|
18
|
+
before :all do
|
|
19
|
+
# get our organisation
|
|
20
|
+
organisations = BillForward::Organisation.get_mine
|
|
21
|
+
first_org = organisations.first
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# remove from our organisation all existing AuthorizeNetConfigurations (if any)
|
|
25
|
+
filtered = first_org.apiConfigurations.reject do |config|
|
|
26
|
+
config['@type'] == 'AuthorizeNetConfiguration'
|
|
27
|
+
end
|
|
28
|
+
first_org.apiConfigurations = filtered
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# add to our organisation: a new AuthorizeNetConfiguration
|
|
32
|
+
first_org.apiConfigurations.push BillForward::APIConfiguration.new({
|
|
33
|
+
"@type" => "AuthorizeNetConfiguration",
|
|
34
|
+
"APILoginID" => @authorize_net_login_id,
|
|
35
|
+
"transactionKey" => @authorize_net_transaction_key,
|
|
36
|
+
"environment" => "Sandbox"
|
|
37
|
+
})
|
|
38
|
+
updated_org = first_org.save
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# create an account
|
|
42
|
+
# requires (optionally):
|
|
43
|
+
# - profile
|
|
44
|
+
# - - addresses
|
|
45
|
+
addresses = Array.new()
|
|
46
|
+
addresses.push(
|
|
47
|
+
BillForward::Address.new({
|
|
48
|
+
'addressLine1' => 'address line 1',
|
|
49
|
+
'addressLine2' => 'address line 2',
|
|
50
|
+
'addressLine3' => 'address line 3',
|
|
51
|
+
'city' => 'London',
|
|
52
|
+
'province' => 'London',
|
|
53
|
+
'country' => 'United Kingdom',
|
|
54
|
+
'postcode' => 'SW1 1AS',
|
|
55
|
+
'landline' => '02000000000',
|
|
56
|
+
'primaryAddress' => true
|
|
57
|
+
}))
|
|
58
|
+
profile = BillForward::Profile.new({
|
|
59
|
+
'email' => 'always@testing.is.moe',
|
|
60
|
+
'firstName' => 'Test',
|
|
61
|
+
'addresses' => addresses
|
|
62
|
+
})
|
|
63
|
+
account = BillForward::Account.new({
|
|
64
|
+
'profile' => profile
|
|
65
|
+
})
|
|
66
|
+
created_account = BillForward::Account.create account
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# create for our account: a tokenized card from Authorize.Net
|
|
70
|
+
authorize_net_token = BillForward::AuthorizeNetToken.new({
|
|
71
|
+
'accountID' => created_account.id,
|
|
72
|
+
'customerProfileID' => @authorize_net_customer_profile_id,
|
|
73
|
+
'customerPaymentProfileID' => @authorize_net_customer_payment_profile_id,
|
|
74
|
+
'lastFourDigits' => @authorize_net_card_last_4_digits,
|
|
75
|
+
})
|
|
76
|
+
created_token = BillForward::AuthorizeNetToken.create(authorize_net_token)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# create for our account: a new payment method, using Authorize.Net token
|
|
80
|
+
payment_method = BillForward::PaymentMethod.new({
|
|
81
|
+
'accountID' => created_account.id,
|
|
82
|
+
'linkID' => created_token.id,
|
|
83
|
+
'name' => 'Authorize.Net',
|
|
84
|
+
'description' => 'Pay via Authorize.Net',
|
|
85
|
+
'gateway' => 'authorizeNet',
|
|
86
|
+
'userEditable' => 0,
|
|
87
|
+
'priority' => 100,
|
|
88
|
+
'reusable' => 1,
|
|
89
|
+
})
|
|
90
|
+
created_payment_method = BillForward::PaymentMethod::create(payment_method)
|
|
91
|
+
|
|
92
|
+
|
|
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)
|
|
100
|
+
|
|
101
|
+
|
|
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)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# make product rate plan..
|
|
115
|
+
# requires:
|
|
116
|
+
# - product,
|
|
117
|
+
# - pricing components..
|
|
118
|
+
# .. - which require pricing component tiers
|
|
119
|
+
|
|
120
|
+
# create tiers..
|
|
121
|
+
# for a flat pricing component:
|
|
122
|
+
tiers_for_flat_component_1 = Array.new()
|
|
123
|
+
tiers_for_flat_component_1.push(
|
|
124
|
+
BillForward::PricingComponentTier.new({
|
|
125
|
+
'lowerThreshold' => 1,
|
|
126
|
+
'upperThreshold' => 1,
|
|
127
|
+
'pricingType' => 'fixed',
|
|
128
|
+
'price' => 1,
|
|
129
|
+
}))
|
|
130
|
+
|
|
131
|
+
# for a tiered pricing component:
|
|
132
|
+
tiers_for_tiered_component_1 = Array.new()
|
|
133
|
+
tiers_for_tiered_component_1.push(
|
|
134
|
+
BillForward::PricingComponentTier.new({
|
|
135
|
+
'lowerThreshold' => 1,
|
|
136
|
+
'upperThreshold' => 1,
|
|
137
|
+
'pricingType' => 'fixed',
|
|
138
|
+
'price' => 10,
|
|
139
|
+
}),
|
|
140
|
+
BillForward::PricingComponentTier.new({
|
|
141
|
+
'lowerThreshold' => 2,
|
|
142
|
+
'upperThreshold' => 10,
|
|
143
|
+
'pricingType' => 'unit',
|
|
144
|
+
'price' => 5
|
|
145
|
+
}),
|
|
146
|
+
BillForward::PricingComponentTier.new({
|
|
147
|
+
'lowerThreshold' => 11,
|
|
148
|
+
'upperThreshold' => 100,
|
|
149
|
+
'pricingType' => 'unit',
|
|
150
|
+
'price' => 2
|
|
151
|
+
}))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# create pricing components, based on these tiers
|
|
155
|
+
pricing_components = Array.new()
|
|
156
|
+
pricing_components.push(
|
|
157
|
+
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,
|
|
163
|
+
'chargeType' => 'subscription',
|
|
164
|
+
'upgradeMode' => 'immediate',
|
|
165
|
+
'downgradeMode' => 'immediate',
|
|
166
|
+
'defaultQuantity' => 1,
|
|
167
|
+
'tiers' => tiers_for_flat_component_1
|
|
168
|
+
}),
|
|
169
|
+
BillForward::PricingComponent.new({
|
|
170
|
+
'@type' => 'tieredPricingComponent',
|
|
171
|
+
'chargeModel' => 'tiered',
|
|
172
|
+
'name' => 'Devices used, tiered',
|
|
173
|
+
'description' => 'How many devices you use, but with a tiering system',
|
|
174
|
+
'unitOfMeasureID' => created_uom.id,
|
|
175
|
+
'chargeType' => 'subscription',
|
|
176
|
+
'upgradeMode' => 'immediate',
|
|
177
|
+
'downgradeMode' => 'immediate',
|
|
178
|
+
'defaultQuantity' => 10,
|
|
179
|
+
'tiers' => tiers_for_tiered_component_1
|
|
180
|
+
}))
|
|
181
|
+
|
|
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,
|
|
189
|
+
})
|
|
190
|
+
created_prp = BillForward::ProductRatePlan.create(prp)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# create references for tests to use
|
|
194
|
+
@created_account = created_account
|
|
195
|
+
@created_prp = created_prp
|
|
196
|
+
@created_payment_method = created_payment_method
|
|
197
|
+
@updated_org = updated_org
|
|
198
|
+
end
|
|
199
|
+
subject(:account) { @created_account }
|
|
200
|
+
subject(:prp) { @created_prp }
|
|
201
|
+
subject(:payment_method) { @created_payment_method }
|
|
202
|
+
subject(:organisation) { @updated_org }
|
|
203
|
+
describe '::create' do
|
|
204
|
+
it 'creates Subscription' do
|
|
205
|
+
# make subscription..
|
|
206
|
+
# requires:
|
|
207
|
+
# - account [we have this already]
|
|
208
|
+
# - product rate plan [we have this already]
|
|
209
|
+
# - 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
|
+
|
|
221
|
+
pricing_components = prp.pricingComponents
|
|
222
|
+
# get references to each pricing component we made
|
|
223
|
+
flat_pricing_component_1 = pricing_components[0]
|
|
224
|
+
tiered_pricing_component_1 = pricing_components[1]
|
|
225
|
+
|
|
226
|
+
# create PricingComponentValue instances for every PricingComponent on the PRP
|
|
227
|
+
pricing_component_values = Array.new
|
|
228
|
+
pricing_component_values.push(
|
|
229
|
+
BillForward::PricingComponentValue.new({
|
|
230
|
+
'pricingComponentID' => flat_pricing_component_1.id,
|
|
231
|
+
'value' => 1,
|
|
232
|
+
}),
|
|
233
|
+
BillForward::PricingComponentValue.new({
|
|
234
|
+
'pricingComponentID' => tiered_pricing_component_1.id,
|
|
235
|
+
'value' => 5,
|
|
236
|
+
}))
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
# create subscription
|
|
240
|
+
subscription = BillForward::Subscription.new({
|
|
241
|
+
'type' => 'Subscription',
|
|
242
|
+
'productRatePlanID' => prp.id,
|
|
243
|
+
'accountID' => account.id,
|
|
244
|
+
'name' => 'Memorable Subscription',
|
|
245
|
+
'description' => 'Memorable Subscription Description',
|
|
246
|
+
'paymentMethodSubscriptionLinks' => payment_method_subscription_links,
|
|
247
|
+
'pricingComponentValues' => pricing_component_values
|
|
248
|
+
})
|
|
249
|
+
created_sub = BillForward::Subscription.create(subscription)
|
|
250
|
+
|
|
251
|
+
expect(created_sub['@type']).to eq(BillForward::Subscription.resource_path.entity_name)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "spec_helper")
|
|
2
|
+
# we want unique numbers to test updates with
|
|
3
|
+
require 'SecureRandom'
|
|
4
|
+
|
|
5
|
+
describe BillForward::Subscription do
|
|
6
|
+
before :all do
|
|
7
|
+
@client = BillForwardTest::TEST_CLIENT
|
|
8
|
+
BillForward::Client.default_client = @client
|
|
9
|
+
end
|
|
10
|
+
describe '::get_by_account_id' do
|
|
11
|
+
context 'an account exists' do
|
|
12
|
+
before :all do
|
|
13
|
+
created_account = BillForward::Account.create
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# create references for tests to use
|
|
17
|
+
@created_account = created_account
|
|
18
|
+
end
|
|
19
|
+
context 'all entities required for a subscription exist' do
|
|
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)
|
|
28
|
+
|
|
29
|
+
|
|
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)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# make product rate plan..
|
|
43
|
+
# requires:
|
|
44
|
+
# - 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
|
+
}))
|
|
59
|
+
|
|
60
|
+
# for a tiered pricing component:
|
|
61
|
+
tiers_for_tiered_component_1 = Array.new()
|
|
62
|
+
tiers_for_tiered_component_1.push(
|
|
63
|
+
BillForward::PricingComponentTier.new({
|
|
64
|
+
'lowerThreshold' => 1,
|
|
65
|
+
'upperThreshold' => 1,
|
|
66
|
+
'pricingType' => 'fixed',
|
|
67
|
+
'price' => 10,
|
|
68
|
+
}),
|
|
69
|
+
BillForward::PricingComponentTier.new({
|
|
70
|
+
'lowerThreshold' => 2,
|
|
71
|
+
'upperThreshold' => 10,
|
|
72
|
+
'pricingType' => 'unit',
|
|
73
|
+
'price' => 5
|
|
74
|
+
}),
|
|
75
|
+
BillForward::PricingComponentTier.new({
|
|
76
|
+
'lowerThreshold' => 11,
|
|
77
|
+
'upperThreshold' => 100,
|
|
78
|
+
'pricingType' => 'unit',
|
|
79
|
+
'price' => 2
|
|
80
|
+
}))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# create pricing components, based on these tiers
|
|
84
|
+
pricing_components = Array.new()
|
|
85
|
+
pricing_components.push(
|
|
86
|
+
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,
|
|
92
|
+
'chargeType' => 'subscription',
|
|
93
|
+
'upgradeMode' => 'immediate',
|
|
94
|
+
'downgradeMode' => 'immediate',
|
|
95
|
+
'defaultQuantity' => 1,
|
|
96
|
+
'tiers' => tiers_for_flat_component_1
|
|
97
|
+
}),
|
|
98
|
+
BillForward::PricingComponent.new({
|
|
99
|
+
'@type' => 'tieredPricingComponent',
|
|
100
|
+
'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',
|
|
105
|
+
'upgradeMode' => 'immediate',
|
|
106
|
+
'downgradeMode' => 'immediate',
|
|
107
|
+
'defaultQuantity' => 10,
|
|
108
|
+
'tiers' => tiers_for_tiered_component_1
|
|
109
|
+
}))
|
|
110
|
+
|
|
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,
|
|
118
|
+
})
|
|
119
|
+
created_prp = BillForward::ProductRatePlan.create(prp)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# create references for tests to use
|
|
123
|
+
@created_prp = created_prp
|
|
124
|
+
end
|
|
125
|
+
context 'a subscription exists for the account' do
|
|
126
|
+
before :all do
|
|
127
|
+
# make subscription..
|
|
128
|
+
# requires:
|
|
129
|
+
# - account [we have this already]
|
|
130
|
+
# - product rate plan [we have this already]
|
|
131
|
+
# - pricing component value instances (for every pricing component on the PRP)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
pricing_components = @created_prp.pricingComponents
|
|
135
|
+
# get references to each pricing component we made
|
|
136
|
+
flat_pricing_component_1 = pricing_components[0]
|
|
137
|
+
tiered_pricing_component_1 = pricing_components[1]
|
|
138
|
+
|
|
139
|
+
# create PricingComponentValue instances for every PricingComponent on the PRP
|
|
140
|
+
pricing_component_values = Array.new
|
|
141
|
+
pricing_component_values.push(
|
|
142
|
+
BillForward::PricingComponentValue.new({
|
|
143
|
+
'pricingComponentID' => flat_pricing_component_1.id,
|
|
144
|
+
'value' => 1,
|
|
145
|
+
}),
|
|
146
|
+
BillForward::PricingComponentValue.new({
|
|
147
|
+
'pricingComponentID' => tiered_pricing_component_1.id,
|
|
148
|
+
'value' => 5,
|
|
149
|
+
}))
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# create subscription
|
|
153
|
+
subscription = BillForward::Subscription.new({
|
|
154
|
+
'type' => 'Subscription',
|
|
155
|
+
'productRatePlanID' => @created_prp.id,
|
|
156
|
+
'accountID' => @created_account.id,
|
|
157
|
+
'name' => 'Memorable Subscription',
|
|
158
|
+
'description' => 'Memorable Subscription Description',
|
|
159
|
+
'pricingComponentValues' => pricing_component_values
|
|
160
|
+
})
|
|
161
|
+
created_sub = BillForward::Subscription.create(subscription)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# create references for tests to use
|
|
165
|
+
@created_sub = created_sub
|
|
166
|
+
end
|
|
167
|
+
subject (:account) { @created_account }
|
|
168
|
+
subject (:subscription) { @created_sub }
|
|
169
|
+
describe 'the subscription' do
|
|
170
|
+
it 'can be gotten' do
|
|
171
|
+
subscriptions = BillForward::Subscription.get_by_account_id(account.id)
|
|
172
|
+
expect(subscriptions.first.id).to eq(subscription.id)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|