From 299f48592a2d185f4e6b9f296f5b383b73dcdbc7 Mon Sep 17 00:00:00 2001 From: Wojciech Kula Date: Wed, 18 Dec 2024 09:59:20 +0100 Subject: [PATCH] Accept bank cards only for specific connectors Signed-off-by: Wojciech Kula --- modules/RsPaymentTerminal/manifest.yaml | 5 ++ modules/RsPaymentTerminal/src/main.rs | 82 +++++++++++++++++++------ 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/modules/RsPaymentTerminal/manifest.yaml b/modules/RsPaymentTerminal/manifest.yaml index 53e766e7a..e1a6c8770 100644 --- a/modules/RsPaymentTerminal/manifest.yaml +++ b/modules/RsPaymentTerminal/manifest.yaml @@ -40,6 +40,11 @@ config: password: description: Password for the Feig terminal. type: integer + accept_credit_cards_for_connectors: + description: Comma separated string with the connectors that should accept credit cards + type: string + default: "1,2" + requires: session: interface: session_cost diff --git a/modules/RsPaymentTerminal/src/main.rs b/modules/RsPaymentTerminal/src/main.rs index ed75f09e8..14339d44f 100644 --- a/modules/RsPaymentTerminal/src/main.rs +++ b/modules/RsPaymentTerminal/src/main.rs @@ -128,17 +128,21 @@ mod sync_feig { use sync_feig::SyncFeig; impl ProvidedIdToken { - fn new(id_token: String, authorization_type: AuthorizationType) -> Self { + fn new( + id_token: String, + authorization_type: AuthorizationType, + connectors: Option>, + ) -> Self { Self { parent_id_token: None, id_token: IdToken { value: id_token, r#type: IdTokenType::Local, - additional_info: None + additional_info: None, }, authorization_type, certificate: None, - connectors: None, + connectors: connectors, iso_15118_certificate_hash_data: None, prevalidated: None, request_id: None, @@ -154,6 +158,9 @@ pub struct PaymentTerminalModule { /// The Feig interface. feig: SyncFeig, + + /// For which connectors credit cards should be accepted + accept_credit_cards_for_connectors: Vec, } impl PaymentTerminalModule { @@ -188,26 +195,39 @@ impl PaymentTerminalModule { }; let card_info = read_card_loop()?; - let provided_token = match card_info { + if let Some(provided_token) = match card_info { CardInfo::Bank => { - self.feig.begin_transaction(&token)?; - - // Reuse the bank token as invoice token so we can use the - // invoice token later on to commit our transactions. - ProvidedIdToken::new(token, AuthorizationType::BankCard) - } - CardInfo::MembershipCard(id_token) => { - ProvidedIdToken::new(id_token, AuthorizationType::RFID) + if !self.accept_credit_cards_for_connectors.is_empty() { + self.feig.begin_transaction(&token)?; + + // Reuse the bank token as invoice token so we can use the + // invoice token later on to commit our transactions. + Some(ProvidedIdToken::new( + token, + AuthorizationType::BankCard, + Some(self.accept_credit_cards_for_connectors.clone()), + )) + } else { + None + } } - }; - publishers.token_provider.provided_token(provided_token)?; + CardInfo::MembershipCard(id_token) => Some(ProvidedIdToken::new( + id_token, + AuthorizationType::RFID, + None, + )), + } { + publishers.token_provider.provided_token(provided_token)?; + } Ok(()) } /// The implementation of the `SessionCostClientSubscriber::on_session_cost`, /// but here we can return errors. fn on_session_cost_impl(&self, context: &Context, value: SessionCost) -> Result<()> { - let Some(id_tag) = value.id_tag else { return Ok(()) }; + let Some(id_tag) = value.id_tag else { + return Ok(()); + }; // We only care about bank cards. match id_tag.authorization_type { @@ -289,9 +309,16 @@ fn main() -> Result<()> { let (tx, rx) = channel(); + let accept_credit_cards_for_connectors = config + .accept_credit_cards_for_connectors + .split(',') + .filter_map(|s| s.trim().parse::().ok()) + .collect(); + let pt_module = Arc::new(PaymentTerminalModule { tx, feig: SyncFeig::new(pt_config), + accept_credit_cards_for_connectors, }); let _module = Module::new( @@ -447,7 +474,10 @@ mod tests { code: Some(CurrencyCode::EUR), decimals: None, }, - id_tag: Some(ProvidedIdToken::new(String::new(), AuthorizationType::BankCard)), + id_tag: Some(ProvidedIdToken::new( + String::new(), + AuthorizationType::BankCard, + )), status: SessionStatus::Running, session_id: String::new(), idle_price: None, @@ -487,7 +517,10 @@ mod tests { code: Some(CurrencyCode::EUR), decimals: None, }, - id_tag: Some(ProvidedIdToken::new("token".to_string(), AuthorizationType::BankCard)), + id_tag: Some(ProvidedIdToken::new( + "token".to_string(), + AuthorizationType::BankCard, + )), status: SessionStatus::Finished, session_id: String::new(), idle_price: None, @@ -505,7 +538,10 @@ mod tests { code: Some(CurrencyCode::EUR), decimals: None, }, - id_tag: Some(ProvidedIdToken::new("token".to_string(), AuthorizationType::BankCard)), + id_tag: Some(ProvidedIdToken::new( + "token".to_string(), + AuthorizationType::BankCard, + )), status: SessionStatus::Finished, session_id: String::new(), idle_price: None, @@ -530,7 +566,10 @@ mod tests { code: Some(CurrencyCode::EUR), decimals: None, }, - id_tag: Some(ProvidedIdToken::new("token".to_string(), AuthorizationType::BankCard)), + id_tag: Some(ProvidedIdToken::new( + "token".to_string(), + AuthorizationType::BankCard, + )), status: SessionStatus::Finished, session_id: String::new(), idle_price: None, @@ -565,7 +604,10 @@ mod tests { code: Some(CurrencyCode::EUR), decimals: None, }, - id_tag: Some(ProvidedIdToken::new("token".to_string(), AuthorizationType::BankCard)), + id_tag: Some(ProvidedIdToken::new( + "token".to_string(), + AuthorizationType::BankCard, + )), status: SessionStatus::Finished, session_id: String::new(), idle_price: None,