refactor: Update Application layer for Codecrete Bill integration
- Change SwissQrCodeExtractionResult to use Bill + RawLines - Update ISwissQrCodeProcessor to return tuple (Bill, string[]) - Add Codecrete.SwissQRBill.Generator v3.4.0 package reference - Update ExtractSwissQrCodeQuery handler to use AutoMapper for Bill->DTO mapping - Remove References property from query (not needed for QR extraction)
This commit is contained in:
@@ -1,116 +1,37 @@
|
||||
namespace DocumentOperator.Application.Common.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// Response containing extracted Swiss QR Code data and passed-through references.
|
||||
/// Response containing extracted Swiss QR Code in dual format.
|
||||
/// </summary>
|
||||
/// <param name="References">Reference strings passed through from the request</param>
|
||||
/// <param name="QrCodeData">Parsed Swiss QR Code data from the last page of the PDF</param>
|
||||
/// <param name="Bill">Parsed Swiss QR Bill (structured format)</param>
|
||||
/// <param name="RawLines">Raw Swiss QR Code lines (original newline-separated format)</param>
|
||||
/// <example>
|
||||
/// {
|
||||
/// "references": ["REF-001", "REF-002"],
|
||||
/// "qrCodeData": {
|
||||
/// "qrType": "SPC",
|
||||
/// "version": "0200",
|
||||
/// "codingType": "1",
|
||||
/// "iban": "CH4431999123000889012",
|
||||
/// "creditor": {
|
||||
/// "addressType": "S",
|
||||
/// "name": "Robert Schneider AG",
|
||||
/// "street": "Rue du Lac",
|
||||
/// "buildingNumber": "1268",
|
||||
/// "postalCode": "2501",
|
||||
/// "city": "Biel",
|
||||
/// "country": "CH"
|
||||
/// },
|
||||
/// "amount": 1949.75,
|
||||
/// "bill": {
|
||||
/// "version": "V2_0",
|
||||
/// "amount": 630.20,
|
||||
/// "currency": "CHF",
|
||||
/// "account": "CH953000520280564701R",
|
||||
/// "creditor": {
|
||||
/// "type": "Structured",
|
||||
/// "name": "ALMAT AG",
|
||||
/// "town": "Tagelswangen"
|
||||
/// },
|
||||
/// "referenceType": "QRR",
|
||||
/// "reference": "210000000003139471430009017"
|
||||
/// }
|
||||
/// "reference": "000000000000000000252080824"
|
||||
/// },
|
||||
/// "rawLines": [
|
||||
/// "SPC",
|
||||
/// "0200",
|
||||
/// "1",
|
||||
/// "CH953000520280564701R",
|
||||
/// "S",
|
||||
/// "ALMAT AG",
|
||||
/// "..."
|
||||
/// ]
|
||||
/// }
|
||||
/// </example>
|
||||
public record SwissQrCodeExtractionResult(
|
||||
IReadOnlyList<string> References,
|
||||
SwissQrCodeDataDto QrCodeData
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Swiss QR Code data according to Swiss QR Bill Standard 2.0.
|
||||
/// Contains all fields defined in the Swiss Payment Standards.
|
||||
/// </summary>
|
||||
public record SwissQrCodeDataDto(
|
||||
/// <summary>QR type - always "SPC" for Swiss Payment Code</summary>
|
||||
string QrType,
|
||||
|
||||
/// <summary>Version of the Swiss QR Code standard (e.g., "0200" for version 2.0)</summary>
|
||||
string Version,
|
||||
|
||||
/// <summary>Character set code (always "1" for UTF-8)</summary>
|
||||
string CodingType,
|
||||
|
||||
/// <summary>IBAN of the creditor (payee)</summary>
|
||||
string Iban,
|
||||
|
||||
/// <summary>Creditor (payee) information</summary>
|
||||
AddressDataDto Creditor,
|
||||
|
||||
/// <summary>Ultimate creditor information (optional)</summary>
|
||||
AddressDataDto? UltimateCreditor,
|
||||
|
||||
/// <summary>Payment amount (null if not specified)</summary>
|
||||
decimal? Amount,
|
||||
|
||||
/// <summary>Currency code (CHF or EUR)</summary>
|
||||
string Currency,
|
||||
|
||||
/// <summary>Ultimate debtor (payer) information (optional)</summary>
|
||||
AddressDataDto? UltimateDebtor,
|
||||
|
||||
/// <summary>Reference type: "QRR" (QR Reference), "SCOR" (Creditor Reference ISO 11649), or "NON" (No Reference)</summary>
|
||||
string ReferenceType,
|
||||
|
||||
/// <summary>Payment reference (format depends on ReferenceType)</summary>
|
||||
string? Reference,
|
||||
|
||||
/// <summary>Unstructured message (max 140 characters)</summary>
|
||||
string? UnstructuredMessage,
|
||||
|
||||
/// <summary>Bill information (structured data for automated processing)</summary>
|
||||
string? BillInformation,
|
||||
|
||||
/// <summary>Alternative procedure parameters (up to 2 entries)</summary>
|
||||
IReadOnlyList<string>? AlternativeProcedureParameters
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Address data in Swiss QR Code (creditor or debtor).
|
||||
/// Can be either structured (S) or combined (K) format.
|
||||
/// </summary>
|
||||
public record AddressDataDto(
|
||||
/// <summary>Address type: "S" for structured, "K" for combined</summary>
|
||||
string AddressType,
|
||||
|
||||
/// <summary>Name of person or company</summary>
|
||||
string Name,
|
||||
|
||||
/// <summary>Street name (structured address only)</summary>
|
||||
string? Street,
|
||||
|
||||
/// <summary>Building number (structured address only)</summary>
|
||||
string? BuildingNumber,
|
||||
|
||||
/// <summary>Address line 1 (combined address only)</summary>
|
||||
string? AddressLine1,
|
||||
|
||||
/// <summary>Address line 2 (combined address only)</summary>
|
||||
string? AddressLine2,
|
||||
|
||||
/// <summary>Postal code</summary>
|
||||
string PostalCode,
|
||||
|
||||
/// <summary>City/town name</summary>
|
||||
string City,
|
||||
|
||||
/// <summary>Two-letter country code (ISO 3166-1 alpha-2)</summary>
|
||||
string Country
|
||||
SwissQrBillDto Bill,
|
||||
IReadOnlyList<string> RawLines
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DocumentOperator.Domain.ValueObjects;
|
||||
using Codecrete.SwissQRBill.Generator;
|
||||
|
||||
namespace DocumentOperator.Application.Common.Interfaces;
|
||||
|
||||
@@ -9,16 +9,21 @@ namespace DocumentOperator.Application.Common.Interfaces;
|
||||
public interface ISwissQrCodeProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts and parses Swiss QR Code from the last page of a PDF document.
|
||||
/// Extracts and parses Swiss QR Code from a PDF document.
|
||||
/// Returns both parsed Bill object and raw QR text lines.
|
||||
/// </summary>
|
||||
/// <param name="pdfBytes">PDF document as byte array</param>
|
||||
/// <param name="pageNumbers">Optional: Specific page numbers to scan (1-indexed). If null, scans all pages starting with last page.</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
/// <returns>Parsed Swiss QR Code data</returns>
|
||||
/// <returns>Tuple: (Parsed Codecrete Bill, Raw QR lines as string array)</returns>
|
||||
/// <exception cref="Domain.Exceptions.SwissQrCodeNotFoundException">
|
||||
/// Thrown when no Swiss QR Code is found on the last page
|
||||
/// Thrown when no Swiss QR Code is found in the specified pages
|
||||
/// </exception>
|
||||
/// <exception cref="Domain.Exceptions.PdfProcessingException">
|
||||
/// Thrown when PDF processing fails
|
||||
/// </exception>
|
||||
Task<SwissQrCodeData> ExtractSwissQrCodeAsync(byte[] pdfBytes, CancellationToken cancellationToken = default);
|
||||
Task<(Bill Bill, string[] RawLines)> ExtractSwissQrCodeAsync(
|
||||
byte[] pdfBytes,
|
||||
int[]? pageNumbers = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user