private void HashAndSignCallback(IAsyncResult ar) { try { PosEventSignResult result = c.EndHashAndSign(ar); if (result != null) { if (result.HasErrors == true) { foreach (Error e in result.Errors) { Debug.WriteLine(e.ToString()); } } else { // The hash and sign was successful, show a receipt like form. Debug.WriteLine("The hash and sign callback was successful!"); if (result.HasSignature) { Debug.WriteLine("Signature: {0}", result.Signature); } if (result.IsClocking) { Debug.WriteLine("Clocking event: {0}", result.ClockingType); } Debug.WriteLine("Receipt printing mode: {0}", result.VATReceiptPrintingMode); foreach (VATSplit s in result.VATSplit) { Debug.WriteLine(s.ToString()); } PrintReceipt(result); } // Start the next transaction. // We allow clocking in the middle of another transaction in this example, for a real-world POS // you need to beware of transaction numbers. Don't create gaps or duplicate numbers if you do this! //if(result.IsClocking == false) InitializeTransaction(); } } catch (HashAndSignException ex) { // The InnerException of the HashAndSignException might contain information to help troubleshoot the issue. Debug.WriteLine("Error: " + ex.Message + ": " + (ex.InnerException != null ? ex.InnerException.Message : "")); // We just start a new transaction in this example. // Real world POS solutions should probably retain state and allow to try again. //InitializeTransaction(); } }
private void HashAndSignCallback(IAsyncResult ar) { PosEventSignResult result = FDMClient.EndHashAndSign(ar); if (result != null) { if (result.HasErrors) { foreach (Error e in result.Errors) { MessageBox.Show(e.ToString()); } } else { /* * string result_message = "Hash and sign result:\n"; * result_message = string.Concat( * result_message, string.Format( * "\tIsCLocking: {0}\n" + * "\tClockingType: {1}\n" + * "\tVATReceiptPrintingMode: {2}\n" + * "\tVATSplits:\n", * result.IsClocking, * result.ClockingType, * result.VATReceiptPrintingMode * ) * ); * * if(result.VATSplit != null) { * foreach(VATSplit s in result.VATSplit) { * result_message = string.Concat( * result_message, string.Format( * "\t\tPrintVatRateId: {0}\n" + * "\t\tTaxableAmount: {1}\n" + * "\t\tVATAmount: {2}\n" + * "\t\tVATRate: {3}\n" + * "\t\tVatRateId: {4}\n" + * "\n", * s.PrintVatRateId, * s.TaxableAmount, * s.VATAmount, * s.VATRate, * s.VatRateId * ) * ); * } * } * * MessageBox.Show(result_message); * * string event_message = "Event:\n"; * event_message = string.Concat( * event_message, string.Format( * "\tDrawerId: {0}\n" + * "\tDrawerName: {1}\n" + * "\tDrawerOpen: {2}\n" + * "\tInvoiceNumber: {3}\n" + * "\tIsFinalized: {4}\n" + * "\tIsRefund: {5}\n" + * "\tIsSimplifiedReceipt: {6}\n" + * "\tIsTrainingMode: {7}\n" + * "\tOperatorId: {8}\n" + * "\tOperatorName: {9}\n" + * "\tPayments:\n", * result.Event.DrawerId, * result.Event.DrawerName, * result.Event.DrawerOpen, * result.Event.InvoiceNumber, * result.Event.IsFinalized, * result.Event.IsRefund, * result.Event.IsSimplifiedReceipt, * result.Event.IsTrainingMode, * result.Event.OperatorId, * result.Event.OperatorName * ) * ); * * foreach(PaymentLine p in result.Event.Payments) { * event_message = string.Concat( * event_message, string.Format( * "\t\tForeignCurrencyAmount: {0}\n" + * "\t\tForeignCurrencyISO: {1}\n" + * "\t\tPayAmount: {2}\n" + * "\t\tPaymentId: {3}\n" + * "\t\tPaymentName: {4}\n" + * "\t\tPaymentType: {5}\n" + * "\t\tQuantity: {6}\n" + * "\t\tReference: {7}\n" + * "\n", * p.ForeignCurrencyAmount, * p.ForeignCurrencyISO, * p.PayAmount, * p.PaymentId, * p.PaymentName, * p.PaymentType, * p.Quantity, * p.Reference * ) * ); * } * * event_message = string.Concat( * event_message, string.Format( * "\tPOSSerialNumber: {0}\n" + * "\tProducts:\n", * result.Event.POSSerialNumber * ) * ); * * foreach(ProductLine p in result.Event.Products) { * event_message = string.Concat( * event_message, string.Format( * "\t\tDiscounts: {0}\n" + * "\t\tPrintVatRateId: {1}\n" + * "\t\tProductGroupId: {2}\n" + * "\t\tProductGroupName: {3}\n" + * "\t\tProductId: {4}\n" + * "\t\tProductName: {5}\n" + * "\t\tQuantity: {6}\n" + * "\t\tQuantityUnit: {7}\n" + * "\t\tSellingPrice: {8}\n" + * "\t\tVatRateId: {9}\n" + * "\n", * p.Discounts, * p.PrintVatRateId, * p.ProductGroupId, * p.ProductGroupName, * p.ProductId, * p.ProductName, * p.Quantity, * p.QuantityUnit, * p.SellingPrice, * p.VatRateId * ) * ); * } * * event_message = string.Concat( * event_message, string.Format( * "\tReference: {0}\n" + * "\tTerminalId: {1}\n" + * "\tTerminalName: {2}\n" + * "\tTransactionDateTime: {3}\n" + * "\tTransactionNumber: {4}\n" + * "\tVatRateA: {5}\n" + * "\tVatRateB: {6}\n" + * "\tVatRateC: {7}\n" + * "\tVatRateD: {8}\n", * result.Event.Reference, * result.Event.TerminalId, * result.Event.TerminalName, * result.Event.TransactionDateTime, * result.Event.TransactionNumber, * result.Event.VatRateA, * result.Event.VatRateB, * result.Event.VatRateC, * result.Event.VatRateD * ) * ); * MessageBox.Show(event_message); * * if(result.HasSignature) { * string signature_message = "Signature:\n"; * signature_message = string.Concat( * signature_message, string.Format( * "\tEventType: {0}\n" + * "\tFDMSerialNumber: {1}\n" + * "\tFullPluHash: {2}\n" + * "\tPrintEventType: {3}\n" + * "\tPrintPluHash: {4}\n" + * "\tSignature: {5}\n" + * "\tSignDateTime: {6}\n" + * "\tTicketCount: {7}\n" + * "\tTicketNumber: {8}\n" + * "\tVSCIdentificationNumber: {9}\n", * result.Signature.EventType, * result.Signature.FDMSerialNumber, * result.Signature.FullPluHash, * result.Signature.PrintEventType, * result.Signature.PrintPluHash, * result.Signature.Signature, * result.Signature.SignDateTime, * result.Signature.TicketCount, * result.Signature.TicketNumber, * result.Signature.VSCIdentificationNumber * ) * ); * MessageBox.Show(signature_message); * } */ PrintReceipt(result); } // Start the next transaction. // We allow clocking in the middle of another transaction in this example, for a real-world POS // you need to beware of transaction numbers. Don't create gaps or duplicate numbers if you do this! //if(result.IsClocking == false) InitializeTransaction(); } }