Skip to content

Commit

Permalink
RsPaymentTerminal: make all interfaces optional (EVerest#1047)
Browse files Browse the repository at this point in the history
Signed-off-by: Dima Dorezyuk <[email protected]>
Co-authored-by: Dima Dorezyuk <[email protected]>
  • Loading branch information
dorezyuk and Dima Dorezyuk authored Feb 11, 2025
1 parent d4dc560 commit e694b8d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions modules/RsPaymentTerminal/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ config:
requires:
session:
interface: session_cost
min_connections: 0
max_connections: 1
bank_session_token:
interface: bank_session_token_provider
min_connections: 0
max_connections: 1
provides:
token_provider:
interface: auth_token_provider
Expand Down
45 changes: 32 additions & 13 deletions modules/RsPaymentTerminal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,19 @@ impl PaymentTerminalModule {
/// custom validation steps on top.
fn begin_transaction(&self, publishers: &ModulePublisher) -> Result<()> {
// Get a valid invoice token.
let invoice_token = publishers.bank_session_token.get_bank_session_token()?;
let token = invoice_token
.token
.ok_or(anyhow::anyhow!("No token received"))?;
log::info!("Received the BankSessionToken {token}");
let token = {
match publishers.bank_session_token_slots.get(0) {
None => None,
Some(publisher) => {
let invoice_token = publisher.get_bank_session_token()?;
if invoice_token.token.is_none() {
anyhow::bail!("No token received")
}
invoice_token.token
}
}
};
log::info!("Received the BankSessionToken {token:?}");

// Wait for the card.
let read_card_loop = || -> Result<CardInfo> {
Expand All @@ -206,10 +214,10 @@ impl PaymentTerminalModule {

if let Some(provided_token) = match card_info {
CardInfo::Bank => {
if !self.accept_credit_cards {
if !self.accept_credit_cards || token.is_none() {
None
} else {
self.feig.begin_transaction(&token)?;
self.feig.begin_transaction(token.as_ref().unwrap())?;
let credit_cards_connectors = if self.credit_cards_connectors.is_empty() {
None
} else {
Expand All @@ -218,7 +226,7 @@ impl PaymentTerminalModule {
// Reuse the bank token as invoice token so we can use the
// invoice token later on to commit our transactions.
Some(ProvidedIdToken::new(
token,
token.unwrap(),
AuthorizationType::BankCard,
credit_cards_connectors,
))
Expand Down Expand Up @@ -333,8 +341,8 @@ fn main() -> Result<()> {
pt_module.clone(),
pt_module.clone(),
pt_module.clone(),
pt_module.clone(),
pt_module.clone(),
|_index| pt_module.clone(),
|_index| pt_module.clone(),
);

let read_card_debounce = Duration::from_secs(config.read_card_debounce as u64);
Expand All @@ -357,6 +365,7 @@ mod tests {
use self::generated::types::money::Currency;
use self::generated::types::money::CurrencyCode;
use self::generated::types::session_cost::SessionCostChunk;
use self::generated::BankSessionTokenProviderClientPublisher;

use super::*;
use mockall::predicate::eq;
Expand All @@ -374,7 +383,9 @@ mod tests {
for input in parameters {
let mut everest_mock = ModulePublisher::default();
everest_mock
.bank_session_token
.bank_session_token_slots
.push(BankSessionTokenProviderClientPublisher::default());
everest_mock.bank_session_token_slots[0]
.expect_get_bank_session_token()
.times(1)
.return_once(|| input);
Expand Down Expand Up @@ -407,7 +418,9 @@ mod tests {
let mut feig_mock = SyncFeig::default();

everest_mock
.bank_session_token
.bank_session_token_slots
.push(BankSessionTokenProviderClientPublisher::default());
everest_mock.bank_session_token_slots[0]
.expect_get_bank_session_token()
.times(1)
.return_once(|| {
Expand Down Expand Up @@ -508,7 +521,13 @@ mod tests {
let mut feig_mock = SyncFeig::default();

everest_mock
.bank_session_token
.bank_session_token_slots
.push(BankSessionTokenProviderClientPublisher::default());
everest_mock
.bank_session_token_slots
.push(BankSessionTokenProviderClientPublisher::default());

everest_mock.bank_session_token_slots[0]
.expect_get_bank_session_token()
.times(1)
.return_once(|| {
Expand Down

0 comments on commit e694b8d

Please sign in to comment.