1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//! `ProductOfferingPrice` and the terms attached to an offering.
use rust_decimal::Decimal;
use crate::core::macros::{tmf_entity, tmf_patch_body, tmf_struct};
use crate::core::{
CharacteristicValueUse, Duration, ExternalIdentifier, Money, Place, Policy, Quantity, Ref,
TaxItem, TimePeriod, Timestamp,
};
tmf_struct! {
@name = "ProductOfferingPrice", @ref = "ProductOfferingPriceRef";
/// A price at which an offering is sold.
///
/// This is the **read model**. Use [`ProductOfferingPriceCreate`] for `POST`
/// and [`ProductOfferingPriceUpdate`] for `PATCH`.
pub struct ProductOfferingPrice {
/// Server-assigned identifier.
id: String,
/// Canonical URI of this price.
href: String,
/// Name of the price.
name: String,
/// Narrative description.
description: String,
/// Version of the price.
version: String,
/// When the price was last changed.
last_update: Timestamp,
/// Lifecycle status, e.g. `Active`.
lifecycle_status: String,
/// Kind of price, e.g. `recurring`, `oneTime`, `usage`.
price_type: String,
/// For recurring prices, the billing frequency, e.g. `monthly`.
recurring_charge_period_type: String,
/// For recurring prices, the number of periods per charge.
recurring_charge_period_length: i64,
/// Whether this price bundles others.
is_bundle: bool,
/// The amount charged.
price: Money,
/// Period during which the price is valid.
valid_for: TimePeriod,
/// Unit of measure the price applies to.
unit_of_measure: Quantity,
/// Places where the price applies.
place: Vec<Ref<Place>>,
/// Policies constraining the price.
policy: Vec<Ref<Policy>>,
/// Prices bundled by this one.
bundled_pop_relationship: Vec<BundledPriceRelationship>,
/// Prices that alter this one, e.g. discounts.
pop_relationship: Vec<PriceRelationship>,
/// Characteristic uses narrowing when the price applies.
prod_spec_char_value_use: Vec<CharacteristicValueUse>,
/// Terms attached to this price.
product_offering_term: Vec<ProductOfferingTerm>,
/// Algorithms computing the price where a fixed amount will not do.
pricing_logic_algorithm: Vec<PricingLogicAlgorithm>,
/// Tax applied to the price.
tax: Vec<TaxItem>,
/// Identifiers for this price in external systems.
external_identifier: Vec<ExternalIdentifier>,
@decimal {
/// Percentage applied instead of an absolute amount.
percentage: Decimal,
}
}
}
tmf_entity!(ProductOfferingPrice);
tmf_struct! {
@name = "ProductOfferingPrice";
/// Body of a `POST /productOfferingPrice` — the v5 `ProductOfferingPrice_FVO`.
///
/// `name`, `lifecycleStatus`, `lastUpdate` and `priceType` are required on
/// create, so they are non-optional here.
pub struct ProductOfferingPriceCreate {
@required {
/// Name of the price. **Required on create.**
name: String,
/// Lifecycle status. **Required on create.**
lifecycle_status: String,
/// Kind of price. **Required on create.**
price_type: String,
/// When the price was last changed. **Required on create.**
last_update: Timestamp,
}
/// Client-supplied identifier, where the server permits one.
id: String,
/// Narrative description.
description: String,
/// Version of the price.
version: String,
/// For recurring prices, the billing frequency.
recurring_charge_period_type: String,
/// For recurring prices, the number of periods per charge.
recurring_charge_period_length: i64,
/// Whether this price bundles others.
is_bundle: bool,
/// The amount charged.
price: Money,
/// Period during which the price is valid.
valid_for: TimePeriod,
/// Unit of measure the price applies to.
unit_of_measure: Quantity,
/// Places where the price applies.
place: Vec<Ref<Place>>,
/// Policies constraining the price.
policy: Vec<Ref<Policy>>,
/// Prices bundled by this one.
bundled_pop_relationship: Vec<BundledPriceRelationship>,
/// Prices that alter this one.
pop_relationship: Vec<PriceRelationship>,
/// Characteristic uses narrowing when the price applies.
prod_spec_char_value_use: Vec<CharacteristicValueUse>,
/// Terms attached to this price.
product_offering_term: Vec<ProductOfferingTerm>,
/// Algorithms computing the price.
pricing_logic_algorithm: Vec<PricingLogicAlgorithm>,
/// Tax applied to the price.
tax: Vec<TaxItem>,
/// Identifiers for this price in external systems.
external_identifier: Vec<ExternalIdentifier>,
@decimal {
/// Percentage applied instead of an absolute amount.
percentage: Decimal,
}
}
}
tmf_struct! {
@name = "ProductOfferingPrice";
/// Body of a `PATCH /productOfferingPrice/{id}` — the v5 `_MVO` schema.
pub struct ProductOfferingPriceUpdate {
/// New name.
name: String,
/// New description.
description: String,
/// New version.
version: String,
/// New lifecycle status.
lifecycle_status: String,
/// New price type.
price_type: String,
/// New recurring billing frequency.
recurring_charge_period_type: String,
/// New number of periods per charge.
recurring_charge_period_length: i64,
/// New bundle flag.
is_bundle: bool,
/// New amount.
price: Money,
/// New validity period.
valid_for: TimePeriod,
/// New unit of measure.
unit_of_measure: Quantity,
/// Replacement place list.
place: Vec<Ref<Place>>,
/// Replacement policy list.
policy: Vec<Ref<Policy>>,
/// Replacement bundled prices.
bundled_pop_relationship: Vec<BundledPriceRelationship>,
/// Replacement price relationships.
pop_relationship: Vec<PriceRelationship>,
/// Replacement characteristic value uses.
prod_spec_char_value_use: Vec<CharacteristicValueUse>,
/// Replacement terms.
product_offering_term: Vec<ProductOfferingTerm>,
/// Replacement pricing algorithms.
pricing_logic_algorithm: Vec<PricingLogicAlgorithm>,
/// Replacement tax items.
tax: Vec<TaxItem>,
/// Replacement external identifiers.
external_identifier: Vec<ExternalIdentifier>,
@decimal {
/// New percentage.
percentage: Decimal,
}
}
}
tmf_struct! {
@name = "ProductOfferingPriceRelationship";
/// A relationship between two offering prices, e.g. a discount that alters
/// another price.
pub struct PriceRelationship {
/// Identifier of the related price.
id: String,
/// URI of the related price.
href: String,
/// Name of the related price.
name: String,
/// The role the related price plays.
role: String,
/// Kind of relationship, e.g. `discount`, `alteration`.
relationship_type: String,
/// Version of the related price.
version: String,
@renamed {
/// The concrete class of the related price.
"@referredType" referred_type: String,
}
}
}
tmf_struct! {
@name = "BundledProductOfferingPriceRelationship";
/// A price included in a bundled price.
pub struct BundledPriceRelationship {
/// Identifier of the bundled price.
id: String,
/// URI of the bundled price.
href: String,
/// Name of the bundled price.
name: String,
/// Version of the bundled price.
version: String,
@renamed {
/// The concrete class of the bundled price.
"@referredType" referred_type: String,
}
}
}
tmf_struct! {
@name = "PricingLogicAlgorithm";
/// An algorithm that computes a price where a fixed amount will not do —
/// tiered usage rating, for example.
pub struct PricingLogicAlgorithm {
/// Identifier of the algorithm instance.
id: String,
/// URI of the algorithm instance.
href: String,
/// Name of the algorithm.
name: String,
/// Narrative description.
description: String,
/// Identifier of the algorithm specification in the rating engine.
pla_spec_id: String,
/// Period during which the algorithm applies.
valid_for: TimePeriod,
}
}
tmf_struct! {
@name = "ProductOfferingTerm";
/// A contractual term attached to an offering, e.g. a 24-month commitment.
pub struct ProductOfferingTerm {
/// Name of the term.
name: String,
/// Narrative description.
description: String,
/// How long the term runs.
duration: Duration,
/// Period during which the term is valid.
valid_for: TimePeriod,
}
}
tmf_patch_body!(ProductOfferingPriceUpdate);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_v5_relationship_member_is_pop_not_popr() {
// v4 spelled it `poprRelationship`; carrying that name into a v5 type
// silently dropped every price relationship a v5 server sent.
let json = r#"{"@type":"ProductOfferingPrice","popRelationship":[{"id":"1","@type":"ProductOfferingPriceRelationship"}]}"#;
let price: ProductOfferingPrice = serde_json::from_str(json).unwrap();
assert_eq!(price.pop_relationship.as_ref().unwrap().len(), 1);
assert!(price.extensions.is_empty());
}
}