async fn create_or_get_invoice(
    client: &Client,
    invoice_path: &PathBuf,
) -> Result<crate::InvoiceCreateResponse> {
    // Load the invoice into memory so we can have access to its ID for fetching if needed
    let inv: crate::Invoice = crate::client::load::toml(invoice_path).await?;
    let id = inv.bindle.id.clone();
    match client.create_invoice(inv).await {
        Ok(resp) => Ok(resp),
        Err(e) if matches!(e, crate::client::ClientError::InvoiceAlreadyExists) => {
            info!("Invoice {} already exists on the bindle server. Fetching existing invoice and missing parcels list", id);
            let invoice = client.get_invoice(&id).await?;
            let missing = client.get_missing_parcels(id).await?;
            let missing = if missing.is_empty() {
                None
            } else {
                Some(missing)
            };
            Ok(crate::InvoiceCreateResponse { invoice, missing })
        }
        Err(e) => Err(e),
    }
}
/// Helper function for creating an invoice or fetching it if it already exists. For security
/// reasons, we need to fetch the invoice (and its missing parcels) if it already exists as the user
/// submitted one could be incorrect (intentionally or unintentionally)
Helper function for creating an invoice or fetching it if it already exists. For security
reasons, we need to fetch the invoice (and its missing parcels) if it already exists as the user
submitted one could be incorrect (intentionally or unintentionally)
Helper function for creating an invoice or fetching it if it already exists . For security reasons we need to fetch the invoice ( and its missing parcels ) if it already exists as the user submitted one could be incorrect ( intentionally or unintentionally )
async fn create_or_get_invoice(
    client: &Client,
    invoice_path: &PathBuf,
) -> Result<crate::InvoiceCreateResponse> {
    // Load the invoice into memory so we can have access to its ID for fetching if needed
    let inv: crate::Invoice = crate::client::load::toml(invoice_path).await?;
    let id = inv.bindle.id.clone();
    match client.create_invoice(inv).await {
        Ok(resp) => Ok(resp),
        Err(e) if matches!(e, crate::client::ClientError::InvoiceAlreadyExists) => {
            info!("Invoice {} already exists on the bindle server. Fetching existing invoice and missing parcels list", id);
            let invoice = client.get_invoice(&id).await?;
            let missing = client.get_missing_parcels(id).await?;
            let missing = if missing.is_empty() {
                None
            } else {
                Some(missing)
            };
            Ok(crate::InvoiceCreateResponse { invoice, missing })
        }
        Err(e) => Err(e),
    }
}
async fn create_or_get_invoice ( client : & Client , invoice_path : & PathBuf , ) -> Result < crate :: InvoiceCreateResponse > { // Load the invoice into memory so we can have access to its ID for fetching if needed let inv : crate :: Invoice = crate :: client :: load :: toml ( invoice_path ) . await ? ; let id = inv . bindle . id . clone ( ) ; match client . create_invoice ( inv ) . await { Ok ( resp ) => Ok ( resp ) , Err ( e ) if matches ! ( e crate client ClientError InvoiceAlreadyExists ) => { info ! ( " " id ) ; let invoice = client . get_invoice ( & id ) . await ? ; let missing = client . get_missing_parcels ( id ) . await ? ; let missing = if missing . is_empty ( ) { None } else { Some ( missing ) } ; Ok ( crate :: InvoiceCreateResponse { invoice , missing } ) } Err ( e ) => Err ( e ) , } }
Helper function for creating an invoice or fetching it if it already exists.
Helper function for creating an invoice or fetching it if it already exists .
client
&Client
invoice_path
&PathBuf
client
&Client
invoice_path
&PathBuf