Exemplo n.º 1
0
        ///<summary>Processes a PayConnect payment via a credit card terminal.</summary>
        private bool ProcessPaymentTerminal()
        {
            PosRequest posRequest = null;

            try {
                if (radioSale.Checked)
                {
                    posRequest = PosRequest.CreateSale(PIn.Decimal(textAmount.Text));
                }
                else if (radioAuthorization.Checked)
                {
                    posRequest = PosRequest.CreateAuth(PIn.Decimal(textAmount.Text));
                }
                else if (radioVoid.Checked)
                {
                    posRequest = PosRequest.CreateVoidByReference(textRefNumber.Text);
                }
                else if (radioReturn.Checked)
                {
                    if (textRefNumber.Text == "")
                    {
                        posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text));
                    }
                    else
                    {
                        posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text), textRefNumber.Text);
                    }
                }
                else                  //Shouldn't happen
                {
                    MsgBox.Show(this, "Please select a transaction type");
                    return(false);
                }
                posRequest.ForceDuplicate = checkForceDuplicate.Checked;
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g(this, "Error creating request:") + " " + ex.Message);
                return(false);
            }
            bool result = true;

            ODProgress.ShowAction(() => {
                _posResponse = DpsPos.ProcessCreditCard(posRequest);
            },
                                  startingMessage: Lan.g(this, "Processing payment on terminal"),
                                  actionException: ex => {
                this.Invoke(() => {
                    MessageBox.Show(Lan.g(this, "Error processing card:") + " " + ex.Message);
                    result = false;
                });
            });
            if (!result)
            {
                return(false);
            }
            if (_posResponse == null)
            {
                MessageBox.Show(Lan.g(this, "Error processing card"));
                return(false);
            }
            if (_posResponse.ResponseCode != "0")           //"0" indicates success. May need to check the AuthCode field too to determine if this was a success.
            {
                MessageBox.Show(Lan.g(this, "Error message from Pay Connect:") + "\r\n" + _posResponse.ResponseDescription);
                return(false);
            }
            PayConnectService.signatureResponse sigResponse = null;
            try {
                Cursor      = Cursors.WaitCursor;
                sigResponse = SendSignature(_posResponse.ReferenceNumber.ToString());
                Cursor      = Cursors.Default;
            }
            catch (Exception ex) {
                Cursor = Cursors.Default;
                MessageBox.Show(Lan.g(this, "Card successfully charged. Error processing signature:") + " " + ex.Message);
            }
            textCardNumber.Text = _posResponse.CardNumber;
            textAmount.Text     = _posResponse.Amount.ToString("f");
            _receiptStr         = PayConnectTerminal.BuildReceiptString(posRequest, _posResponse, sigResponse, _clinicNum);
            PrintReceipt(_receiptStr);
            return(true);
        }