Exemple #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);
            }
            Action actionCloseProgress = null;

            try {
                actionCloseProgress = ODProgressOld.ShowProgressStatus("PayConnectProcessing", this, Lan.g(this, "Processing payment on terminal"));
                _posResponse        = DpsPos.ProcessCreditCard(posRequest);
            }
            catch (Exception ex) {
                actionCloseProgress?.Invoke();
                MessageBox.Show(Lan.g(this, "Error processing card:") + " " + ex.Message);
                return(false);
            }
            actionCloseProgress?.Invoke();
            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         = PayConnectUtils.BuildReceiptString(posRequest, _posResponse, sigResponse, _clinicNum);
            PrintReceipt(_receiptStr);
            return(true);
        }
Exemple #2
0
        ///<summary>Processes a PayConnect payment via the PayConnect web service.</summary>
        private bool ProcessPaymentWebService(int expYear, int expMonth)
        {
            string refNumber = "";

            if (_trantype == PayConnectService.transType.VOID || _trantype == PayConnectService.transType.RETURN)
            {
                refNumber = textRefNumber.Text;
            }
            string magData = null;

            if (_parser != null)
            {
                magData = _parser.Track2;
            }
            string cardNumber = textCardNumber.Text;

            //if using a stored CC and there is an X-Charge token saved for the CC and the user enters the whole card number to get a PayConnect token
            //and the number entered doesn't have the same last 4 digits and exp date, then assume it's not the same card and clear out the X-Charge token.
            if (_creditCardCur != null &&       //using a saved CC
                !string.IsNullOrEmpty(_creditCardCur.XChargeToken) &&                 //there is an X-Charge token saved
                (cardNumber.Right(4) != _creditCardCur.CCNumberMasked.Right(4) ||               //the card number entered doesn't have the same last 4 digits
                 expYear != _creditCardCur.CCExpiration.Year ||                      //the card exp date entered doesn't have the same year
                 expMonth != _creditCardCur.CCExpiration.Month))                         //the card exp date entered doesn't have the same month
            {
                if (MsgBox.Show(this, MsgBoxButtons.YesNo, "The card number or expiration date entered does not match the X-Charge card on file.  Do you wish "
                                + "to replace the X-Charge card with this one?"))
                {
                    _creditCardCur.XChargeToken = "";
                }
                else
                {
                    Cursor = Cursors.Default;
                    return(false);
                }
            }
            //if the user has chosen to store CC tokens and the stored CC has a token and the token is not expired,
            //then use it instead of the CC number and CC expiration.
            if (checkSaveToken.Checked &&
                _creditCardCur != null &&               //if the user selected a saved CC
                _creditCardCur.PayConnectToken != "" &&               //there is a stored token for this card
                _creditCardCur.PayConnectTokenExp.Date >= DateTime.Today.Date)                  //the token is not expired
            {
                cardNumber = _creditCardCur.PayConnectToken;
                expYear    = _creditCardCur.PayConnectTokenExp.Year;
                expMonth   = _creditCardCur.PayConnectTokenExp.Month;
            }
            string authCode = "";

            if (_trantype == PayConnectService.transType.FORCE)
            {
                authCode = textRefNumber.Text;
            }
            _request = Bridges.PayConnect.BuildSaleRequest(PIn.Decimal(textAmount.Text), cardNumber, expYear,
                                                           expMonth, textNameOnCard.Text, textSecurityCode.Text, textZipCode.Text, magData, _trantype, refNumber, checkSaveToken.Checked, authCode, checkForceDuplicate.Checked);
            _response = Bridges.PayConnect.ProcessCreditCard(_request, _clinicNum);
            if (_response == null || _response.Status.code != 0)         //error in transaction
            {
                return(false);
            }
            PayConnectService.signatureResponse sigResponse = SendSignature(_response.RefNumber);
            if ((_trantype.In(PayConnectService.transType.SALE, PayConnectService.transType.RETURN, PayConnectService.transType.VOID)) &&
                _response.Status.code == 0)                           //Only print a receipt if transaction is an approved SALE, RETURN, or VOID
            {
                _receiptStr = PayConnectUtils.BuildReceiptString(_request, _response, sigResponse, _clinicNum);
                PrintReceipt(_receiptStr);
            }
            if (!PrefC.GetBool(PrefName.StoreCCnumbers) && !checkSaveToken.Checked)             //not storing the card number or the token
            {
                return(true);
            }
            //response must be non-null and the status code must be 0=Approved
            //also, the user must have the pref StoreCCnumbers enabled or they have the checkSaveTokens checked
            if (_creditCardCur == null)           //user selected Add new card from the payment window, save it or its token depending on settings
            {
                _creditCardCur        = new CreditCard();
                _creditCardCur.IsNew  = true;
                _creditCardCur.PatNum = _patCur.PatNum;
                List <CreditCard> itemOrderCount = CreditCards.Refresh(_patCur.PatNum);
                _creditCardCur.ItemOrder = itemOrderCount.Count;
            }
            _creditCardCur.CCExpiration = new DateTime(expYear, expMonth, DateTime.DaysInMonth(expYear, expMonth));
            if (PrefC.GetBool(PrefName.StoreCCnumbers))
            {
                _creditCardCur.CCNumberMasked = textCardNumber.Text;
            }
            else
            {
                _creditCardCur.CCNumberMasked = textCardNumber.Text.Right(4).PadLeft(textCardNumber.Text.Length, 'X');
            }
            _creditCardCur.Zip                = textZipCode.Text;
            _creditCardCur.PayConnectToken    = "";
            _creditCardCur.PayConnectTokenExp = DateTime.MinValue;
            //Store the token and the masked CC number (only last four digits).
            if (checkSaveToken.Checked && _response.PaymentToken != null)
            {
                _creditCardCur.PayConnectToken    = _response.PaymentToken.TokenId;
                _creditCardCur.PayConnectTokenExp = new DateTime(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month,
                                                                 DateTime.DaysInMonth(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month));
            }
            _creditCardCur.CCSource = CreditCardSource.PayConnect;
            if (_creditCardCur.IsNew)
            {
                _creditCardCur.ClinicNum  = _clinicNum;
                _creditCardCur.Procedures = PrefC.GetString(PrefName.DefaultCCProcs);
                CreditCards.Insert(_creditCardCur);
            }
            else
            {
                if (_creditCardCur.CCSource == CreditCardSource.XServer)               //This card has also been added for XCharge.
                {
                    _creditCardCur.CCSource = CreditCardSource.XServerPayConnect;
                }
                CreditCards.Update(_creditCardCur);
            }
            return(true);
        }