pub struct Customer {
pub href: Option<String>,
pub id: Option<String>,
pub name: Option<String>,
pub status: Option<String>,
pub status_reason: Option<String>,
pub valid_for: Option<TimePeriod>,
/* private fields */
}
Expand description
Customer object
Fields§
§href: Option<String>
Html Reference to this object
id: Option<String>
Unique Id
name: Option<String>
Name of this
status: Option<String>
Customer status
status_reason: Option<String>
Reason for current status
valid_for: Option<TimePeriod>
Validity of this record
Implementations§
Source§impl Customer
impl Customer
Sourcepub fn new(org: Organization) -> Customer
pub fn new(org: Organization) -> Customer
Create new customer object against an Organization (legal entity)
#[cfg(all(feature = "tmf632", feature = "build-V4"))]
#[cfg(all(feature = "tmf632", feature = "build-V5"))]
let org = Organization::new("Legal Entity");
let cust = Customer::new(org);
Examples found in repository?
More examples
19fn main() {
20 #[cfg(all(feature = "tmf679", feature = "build-V4"))]
21 {
22 let org = Organization::new("ACustomer");
23 let customer = Customer::new(org);
24 let offering = ProductOffering::new("MyOffer");
25 let mut poq = ProductOfferingQualification::new(Some(ProductOfferingRef::from(offering)));
26 poq.add_party(RelatedParty::from(&customer));
27
28 dbg!(poq);
29 }
30}
28fn main() {
29 #[cfg(all(feature = "tmf622", feature = "build-V4"))]
30 {
31 // This example simple creates in memory structures without reference to any persistence
32 let offer = ProductOffering::new("Sample Offering");
33 let org = Organization::new("ACustomer");
34 let customer = Customer::new(org);
35 let mut person = Individual::new("John Smith");
36 person.add_contact(ContactMedium::email("John.Smith@example.com"));
37 let mut order = ProductOrder::new();
38 order.add_order_item(ProductOrderItem::from(offer));
39 order.add_party(RelatedParty::from(&customer));
40 order.add_party(RelatedParty::from(&person));
41 dbg!(order);
42 }
43}
Sourcepub fn generate_code(&mut self, offset: Option<u32>)
pub fn generate_code(&mut self, offset: Option<u32>)
Geneate a unique customer code via cryptographic functions Uses crate::gen_code.
Examples found in repository?
7fn main() {
8 // let org = Organization::new("ACustomer");
9 // let customer = Customer::new(org);
10
11 // dbg!(&customer);
12 let mut customer = Customer::default();
13 customer.set_id("1");
14 customer.generate_code(None);
15 customer.generate_href();
16 customer.set_market_segment("Health Industry");
17 dbg!(&customer);
18
19 customer.upgrade_to_code(None);
20 dbg!(customer);
21}
More examples
5fn main() -> Result<(), String> {
6 let mut cust1 = Customer::default();
7
8 cust1.set_name("NATIONAL BEVERAGE COMPANY LIMITED");
9 cust1.id = Some(String::from("123456"));
10 cust1.generate_code(None);
11
12 let code1 = cust1
13 .get_characteristic("code")
14 .ok_or(String::from("No Value"))?;
15 let hash = cust1
16 .get_characteristic("hash")
17 .ok_or(String::from("No Value"))?;
18
19 println!(
20 "Customer: {} + ID: {} Offset=0\t generates Code: {}",
21 cust1.get_name(),
22 cust1.get_id(),
23 code1.value
24 );
25 println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
26
27 cust1.generate_code(Some(1));
28
29 let code1 = cust1
30 .get_characteristic("code")
31 .ok_or(String::from("No Value"))?;
32 let hash = cust1
33 .get_characteristic("hash")
34 .ok_or(String::from("No Value"))?;
35
36 println!(
37 "Customer: {} + ID: {} Offset=1\t generates Code: {}",
38 cust1.get_name(),
39 cust1.get_id(),
40 code1.value
41 );
42 println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
43
44 Ok(())
45}
Sourcepub fn get_characteristic(&self, characteristic: &str) -> Option<Characteristic>
pub fn get_characteristic(&self, characteristic: &str) -> Option<Characteristic>
Try to find characteristic with given name
Examples found in repository?
5fn main() -> Result<(), String> {
6 let mut cust1 = Customer::default();
7
8 cust1.set_name("NATIONAL BEVERAGE COMPANY LIMITED");
9 cust1.id = Some(String::from("123456"));
10 cust1.generate_code(None);
11
12 let code1 = cust1
13 .get_characteristic("code")
14 .ok_or(String::from("No Value"))?;
15 let hash = cust1
16 .get_characteristic("hash")
17 .ok_or(String::from("No Value"))?;
18
19 println!(
20 "Customer: {} + ID: {} Offset=0\t generates Code: {}",
21 cust1.get_name(),
22 cust1.get_id(),
23 code1.value
24 );
25 println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
26
27 cust1.generate_code(Some(1));
28
29 let code1 = cust1
30 .get_characteristic("code")
31 .ok_or(String::from("No Value"))?;
32 let hash = cust1
33 .get_characteristic("hash")
34 .ok_or(String::from("No Value"))?;
35
36 println!(
37 "Customer: {} + ID: {} Offset=1\t generates Code: {}",
38 cust1.get_name(),
39 cust1.get_id(),
40 code1.value
41 );
42 println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
43
44 Ok(())
45}
Sourcepub fn replace_characteristic(
&mut self,
characteristic: Characteristic,
) -> Option<Characteristic>
pub fn replace_characteristic( &mut self, characteristic: Characteristic, ) -> Option<Characteristic>
Replace a characteristic returning the old value if found. Creates the characteristic array if it doesn’t exist. Creates the characteristic entry if it doesn’t exist. Replaces the characteristic entry if it does exist.
§Returns
Will return the previous value if it existed. This
§Example
let mut cust = Customer::default();
let char = Characteristic::from(("Validated","NotYet"));
let old_char = cust.replace_characteristic(char);
assert_eq!(old_char.is_none(),true);
Sourcepub fn set_market_segment(
&mut self,
segment: impl Into<String>,
) -> Option<Characteristic>
pub fn set_market_segment( &mut self, segment: impl Into<String>, ) -> Option<Characteristic>
Set the market segment
Examples found in repository?
7fn main() {
8 // let org = Organization::new("ACustomer");
9 // let customer = Customer::new(org);
10
11 // dbg!(&customer);
12 let mut customer = Customer::default();
13 customer.set_id("1");
14 customer.generate_code(None);
15 customer.generate_href();
16 customer.set_market_segment("Health Industry");
17 dbg!(&customer);
18
19 customer.upgrade_to_code(None);
20 dbg!(customer);
21}
Sourcepub fn get_market_segment(&self) -> Option<Characteristic>
pub fn get_market_segment(&self) -> Option<Characteristic>
Get the market segment
Sourcepub fn upgrade_to_code(&mut self, offset: Option<u32>) -> Option<Characteristic>
pub fn upgrade_to_code(&mut self, offset: Option<u32>) -> Option<Characteristic>
Upgrade the customer to a cryptographic code to replace a sequential Id. Will return the newly generated cryptographic code. Takes the following steps:
- Moves existing ID into characteristic of ‘Id’
- Generate cryptographic code via generate_code
- Replace Id, with newly genreated code.
- Returns new code.
§Returns
Will return the new code.
§Example
let mut cust = Customer::default();
cust.set_id("1");
let char = cust.upgrade_to_code(None);
Examples found in repository?
7fn main() {
8 // let org = Organization::new("ACustomer");
9 // let customer = Customer::new(org);
10
11 // dbg!(&customer);
12 let mut customer = Customer::default();
13 customer.set_id("1");
14 customer.generate_code(None);
15 customer.generate_href();
16 customer.set_market_segment("Health Industry");
17 dbg!(&customer);
18
19 customer.upgrade_to_code(None);
20 dbg!(customer);
21}
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Customer
impl<'de> Deserialize<'de> for Customer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EventPayload<CustomerEvent> for Customer
impl EventPayload<CustomerEvent> for Customer
Source§impl From<&Customer> for RelatedParty
impl From<&Customer> for RelatedParty
Source§impl From<&Organization> for Customer
impl From<&Organization> for Customer
Source§fn from(value: &Organization) -> Self
fn from(value: &Organization) -> Self
Source§impl HasId for Customer
impl HasId for Customer
Source§fn generate_id(&mut self)
fn generate_id(&mut self)
Source§fn generate_href(&mut self)
fn generate_href(&mut self)
Source§fn get_class() -> String
fn get_class() -> String
Source§fn get_class_href() -> String
fn get_class_href() -> String
Source§fn get_mod_path() -> String
fn get_mod_path() -> String
Source§fn set_id(&mut self, id: impl Into<String>)
fn set_id(&mut self, id: impl Into<String>)
Source§fn id(self, id: impl Into<String>) -> Self
fn id(self, id: impl Into<String>) -> Self
[create
]Source§impl HasName for Customer
impl HasName for Customer
Source§impl HasReference for Customer
impl HasReference for Customer
Source§type RefType = RelatedParty
type RefType = RelatedParty
Source§fn as_ref(&self) -> Option<Self::RefType>
fn as_ref(&self) -> Option<Self::RefType>
Source§fn as_entity_ref(&self) -> RelatedEntity
fn as_entity_ref(&self) -> RelatedEntity
Source§impl HasValidity for Customer
impl HasValidity for Customer
Source§fn get_validity(&self) -> Option<TimePeriod>
fn get_validity(&self) -> Option<TimePeriod>
Source§fn get_validity_end(&self) -> Option<TimeStamp>
fn get_validity_end(&self) -> Option<TimeStamp>
Source§fn get_validity_start(&self) -> Option<TimeStamp>
fn get_validity_start(&self) -> Option<TimeStamp>
Source§fn set_validity(&mut self, validity: TimePeriod)
fn set_validity(&mut self, validity: TimePeriod)
TimePeriod
Source§fn set_validity_end(&mut self, end: TimeStamp) -> TimePeriod
fn set_validity_end(&mut self, end: TimeStamp) -> TimePeriod
TimePeriod
Source§fn set_validity_start(&mut self, start: TimeStamp) -> TimePeriod
fn set_validity_start(&mut self, start: TimeStamp) -> TimePeriod
TimePeriod