Skip to content

Commit

Permalink
Cancel all pending transactions (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Wojciech Kula <[email protected]>
  • Loading branch information
wku12 authored Jan 28, 2025
1 parent 9c47655 commit 9922e83
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions zvt_feig_terminal/src/feig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ impl Feig {

/// Returns the pending transaction.
///
/// We return a vector of possible pending transactions. Right now we just
/// We return the first possible pending transactions. Right now we just
/// check for one.
async fn get_pending(&mut self) -> Result<Vec<usize>> {
async fn get_pending(&mut self) -> Result<Option<usize>> {
let request = packets::PartialReversal {
receipt_no: Some(0xFFFF),
..packets::PartialReversal::default()
Expand All @@ -239,13 +239,13 @@ impl Feig {
sequences::PartialReversalResponse::PartialReversalAbort(data) => {
// The 0xFFFF means no pending transactions.
let Some(receipt_no) = data.receipt_no else {
return Ok(vec![]);
return Ok(None);
};

if receipt_no == 0xFFFF {
return Ok(vec![]);
return Ok(None);
}
return Ok(vec![receipt_no]);
return Ok(Some(receipt_no));
}
_ => bail!(Error::UnexpectedPacket),
}
Expand All @@ -257,9 +257,9 @@ impl Feig {
/// Cancels all pending transactions.
async fn cancel_pending(&mut self) -> Result<()> {
self.transactions.clear();
let pending = self.get_pending().await?;
for p in pending {
self.cancel_transaction_by_receipt_no(p).await?

while let Some(receipt_no) = self.get_pending().await? {
self.cancel_transaction_by_receipt_no(receipt_no).await?;
}
Ok(())
}
Expand Down Expand Up @@ -311,7 +311,8 @@ impl Feig {
pub async fn configure(&mut self) -> Result<()> {
let tid_changed = self.set_terminal_id().await?;
if tid_changed {
self.run_diagnosis(packets::DiagnosisType::EmvConfiguration).await?;
self.run_diagnosis(packets::DiagnosisType::EmvConfiguration)
.await?;
}
self.initialize().await?;
self.end_of_day().await?;
Expand Down

0 comments on commit 9922e83

Please sign in to comment.