예제 #1
0
        void BtnTender_Click(object sender, RoutedEventArgs e)
        {
            var r = new EFTTransactionRequest();

            // TxnType is required
            r.TxnType = GetTxnType();
            // Set ReferenceNumber to something unique
            r.TxnRef = DateTime.Now.ToString("YYMMddHHmmssfff");
            // Set AmountCash for cash out, and AmountPurchase for purchase/refund
            r.AmtPurchase = (r.TxnType == TransactionType.CashOut) ? 0 : decimal.Parse(txtAmount.Text);
            r.AmtCash     = (r.TxnType == TransactionType.CashOut) ? decimal.Parse(txtAmount.Text) : 0;
            // Set POS or pinpad printer
            r.ReceiptPrintMode = ReceiptPrintModeType.POSPrinter;
            // Set application. Used for gift card & 3rd party payment
            r.Application = TerminalApplication.EFTPOS;
            if (PLB_ComboBox.SelectedIndex == 1)
            {
                r.PurchaseAnalysisData = new PadField("PLB0011");
            }
            else if (PLB_ComboBox.SelectedIndex == 2)
            {
                r.PurchaseAnalysisData = new PadField("PLB0010");
            }
            if (!_eft.DoTransaction(r))
            {
                ShowNotification("FAILED TO SEND TXN", "", "", NotificationType.Error, true);
            }
        }
예제 #2
0
        public bool Refund(double dPurchase, string sRef)
        {
            Program.g_log.Info("Nitro refund start, amount = " + dPurchase.ToString("c"));
            m_nPrintCount    = 1;
            m_sResponseCode  = "";
            m_sResponseText1 = "";
            m_sResponseText2 = "";
            m_bError         = false;
            m_sReceipt       = "";
            m_sReceiptCust   = "";

            EFTTransactionRequest nitroRequest = new EFTTransactionRequest();

            //			nitroRequest.TrainingMode = true;
            nitroRequest.AmountPurchase  = (decimal)dPurchase;
            nitroRequest.AmountCash      = 0;
            nitroRequest.CardPANSource   = PANSource.Default;
            nitroRequest.ReferenceNumber = sRef;
            nitroRequest.Type            = TransactionType.Refund;

            if (!nitroClientIP.DoTransaction(nitroRequest))
            {
                MessageBox.Show("DoTransaction send to the Nitro Client IP interface failed.", "NITRO IP Interface", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            m_bPrint = false;
            Program.g_log.Info("Nitro refund done, amount = " + dPurchase.ToString("c"));
            return(true);
        }
예제 #3
0
        public async Task DoTransaction(EFTTransactionRequest request)
        {
            bool result = await SendRequest <EFTTransactionResponse>(request);

            if (result)
            {
                _data.TransactionReference = string.Empty;
            }
        }
예제 #4
0
        async void BtnTender_Click(object sender, RoutedEventArgs e)
        {
            {
                // Get an auth token
                // Basket data
                var basketId = System.Guid.NewGuid().ToString("N");
                var basket   = new EFTBasket()
                {
                    Id     = basketId,
                    Amount = 100,
                    Items  = new System.Collections.Generic.List <EFTBasketItem>()
                    {
                        new EFTBasketItem()
                        {
                            Id       = System.Guid.NewGuid().ToString("N"),
                            Amount   = 10,
                            Quantity = 5,
                            Name     = "Cat food",
                            TagList  = new List <string>()
                            {
                                "food", "pet"
                            }
                        },
                        new EFTBasketItem()
                        {
                            Id       = System.Guid.NewGuid().ToString("N"),
                            Amount   = 25,
                            Name     = "Dog food",
                            Quantity = 2
                        },
                        new EFTBasketItemCustom()
                        {
                            Id          = System.Guid.NewGuid().ToString("N"),
                            Amount      = 1,
                            Name        = "Custom",
                            Description = "This is the description of a custom item",
                            Quantity    = 1
                        }
                    }
                };
                try
                {
                    if (!await _eft.WriteRequestAsync(new EFTBasketDataRequest()
                    {
                        Command = new EFTBasketDataCommandCreate()
                        {
                            Basket = basket
                        }
                    }))
                    {
                        ShowNotification("FAILED TO SEND TXN", "", "", NotificationType.Error, true);
                    }
                    else
                    {
                        try
                        {
                            await _eft.ReadResponseAsync <EFTBasketDataResponse>(new CancellationTokenSource(new TimeSpan(0, 0, 10)).Token);
                        }
                        catch (TaskCanceledException)
                        {
                            // EFT-Client timeout waiting for response
                            ShowNotification("EFT-CLIENT TIMEOUT", null, null, NotificationType.Error, true);
                        }
                        catch (Exception exc)
                        {
                            // TODO: Handle failed EFTBasketDataRequest. Should still continue and attempt the transaction.
                            ShowNotification("FAILED TO SEND TXN", "", exc.Message, NotificationType.Error, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Format the error message so it can properly appear in the notification
                    ex.Message.Replace('\r', ' ');
                    ex.Message.Replace('\n', ' ');
                    ShowNotification("FAILED TO SEND TXN", ex.Message, null, NotificationType.Error, true);
                    return;
                }

                // Transaction request
                var r = new EFTTransactionRequest();
                // TxnType is required
                r.TxnType = GetTxnType();
                // Set ReferenceNumber to something unique
                r.TxnRef = DateTime.Now.ToString("YYMMddHHmmssfff");
                // Set AmountCash for cash out, and AmountPurchase for purchase/refund
                try
                {
                    r.AmtPurchase = (r.TxnType == TransactionType.CashOut) ? 0 : decimal.Parse(txtAmount.Text); //fix crash when amt has a letter in it
                    r.AmtCash     = (r.TxnType == TransactionType.CashOut) ? decimal.Parse(txtAmount.Text) : 0;
                    if (r.AmtPurchase < 0 || r.AmtCash < 0)
                    {
                        throw new Exception("Amount Cannot Be Less Than 0");
                    }
                }catch (Exception exc)
                {
                    ShowNotification("FAILED TO SEND TXN", "INVALID AMOUNT", exc.Message, NotificationType.Error, true);
                    return;
                }
                // Set POS or pinpad printer
                r.ReceiptPrintMode = ReceiptPrintModeType.POSPrinter;
                // Set application. Used for gift card & 3rd party payment
                r.Application = TerminalApplication.EFTPOS;
                // Set basket PAD tag
                r.PurchaseAnalysisData.SetTag("SKU", basketId);
                try
                {
                    if (!await _eft.WriteRequestAsync(r))
                    {
                        ShowNotification("FAILED TO SEND TXN", "", "", NotificationType.Error, true);
                    }
                    else
                    {
                        // Wait for response
                        var waitingForResponse = true;
                        do
                        {
                            EFTResponse eftResponse = null;
                            try
                            {
                                var timeoutToken = new CancellationTokenSource(new TimeSpan(0, 5, 0)).Token;
                                eftResponse = await _eft.ReadResponseAsync(timeoutToken);

                                // Handle response
                                if (eftResponse is null)
                                {
                                    // Error reading response
                                    waitingForResponse = false;
                                }
                                if (eftResponse is EFTReceiptResponse)
                                {
                                    OnReceipt(eftResponse as EFTReceiptResponse);
                                }
                                else if (eftResponse is EFTDisplayResponse)
                                {
                                    OnDisplay(eftResponse as EFTDisplayResponse);
                                }
                                else if (eftResponse is EFTTransactionResponse)
                                {
                                    waitingForResponse = false;
                                    OnTransaction(eftResponse as EFTTransactionResponse);
                                }

                                //// C#7
                                //switch (eftResponse)
                                //{
                                //    case EFTReceiptResponse resp:
                                //        OnReceipt(resp);
                                //        break;
                                //    case EFTDisplayResponse resp:
                                //        OnDisplay(resp);
                                //        break;
                                //    case EFTTransactionResponse resp:
                                //        waitingForResponse = false;
                                //        OnTransaction(resp);
                                //        break;
                                //    case null:
                                //        // Error reading response
                                //        waitingForResponse = false;
                                //        break;
                                //}
                            }
                            catch (TaskCanceledException)
                            {
                                // EFT-Client timeout waiting for response
                                ShowNotification("EFT-CLIENT TIMEOUT", null, null, NotificationType.Error, true);
                                OnTerminated();
                                waitingForResponse = false;
                            }
                            catch (ConnectionException)
                            {
                                // Socket closed
                                OnTerminated();
                                waitingForResponse = false;
                            }
                            catch (Exception)
                            {
                                // Unhandled exception
                                OnTerminated();
                                waitingForResponse = false;
                            }
                        }while (waitingForResponse);
                    }
                } catch (Exception exc)
                {
                    ShowNotification("FAILED TO SEND TXN", exc.Message, null, NotificationType.Error, true);
                }
            }
        }
예제 #5
0
    public void Run(CommandArgs args)
    {
        // Create new connection to EFT-Client
        var eft = new EFTClientIP()
        {
            HostName = args.Host,
            HostPort = args.Port,
            UseSSL   = args.Ssl
        };

        // Hook up events
        eft.OnDisplay += delegate(object sender, EFTEventArgs <EFTDisplayResponse> e) {
            foreach (var Str in e.Response.DisplayText)
            {
                var isApproved = Str.Trim() == "APPROVED";
                if (isApproved)
                {
                    // This automatically presses the OK button
                    // from the APPROVED popup produced by
                    // EftClntUI making a faster successful
                    // transaction,
                    eft.DoSendKey(new EFTSendKeyRequest()
                    {
                        Key = EFTPOSKey.OkCancel
                    });
                }
            }
        };
        eft.OnReceipt     += Eft_OnReceipt;;
        eft.OnTransaction += Eft_OnTransaction;
        eft.OnTerminated  += Eft_OnTerminated;
        // Connect
        if (!eft.Connect())
        {
            // Handle failed connection
            Console.Error.WriteLine("Connect failed");
            return;
        }

        // Build transaction request
        var r = new EFTTransactionRequest()
        {
            // TxnType is required
            TxnType = TransactionType.PurchaseCash,
            // Set TxnRef to something unique
            TxnRef = DateTime.Now.ToString("YYMMddHHmmsszzz"),
            // Set AmtCash for cash out, and AmtPurchase for purchase/refund
            AmtPurchase = args.Amount,
            AmtCash     = 0.00M,
            // Set POS or pinpad printer
            ReceiptPrintMode = ReceiptPrintModeType.POSPrinter,
            // Set application. Used for gift card & 3rd party payment
            Application = TerminalApplication.EFTPOS
        };

        // Send transaction
        if (!eft.DoTransaction(r))
        {
            // Handle failed send
            Console.Error.WriteLine("Send failed");
            return;
        }

        txnFired.WaitOne();
        eft.Disconnect();
        eft.Dispose();
    }