Exemple #1
0
        public static string BuildReceiptString(PayConnectService.transType transType, string refNum, string nameOnCard, string cardNumber,
                                                string magData, string authCode, string statusDescription, List <string> messages, decimal amount, int sigResponseStatusCode, long clinicNum)
        {
            string result = "";

            cardNumber = cardNumber ?? "";         //Prevents null reference exceptions when PayConnectPortal transactions don't have an associated card number
            int xmin   = 0;
            int xleft  = xmin;
            int xright = 15;
            int xmax   = 37;

            result += Environment.NewLine;
            result += CreditCardUtils.AddClinicToReceipt(clinicNum);
            //Print body
            result += "Date".PadRight(xright - xleft, '.') + DateTime.Now.ToString() + Environment.NewLine;
            result += Environment.NewLine;
            result += "Trans Type".PadRight(xright - xleft, '.') + transType + Environment.NewLine;
            result += Environment.NewLine;
            result += "Transaction #".PadRight(xright - xleft, '.') + refNum + Environment.NewLine;
            result += "Name".PadRight(xright - xleft, '.') + nameOnCard + Environment.NewLine;
            result += "Account".PadRight(xright - xleft, '.');
            for (int i = 0; i < cardNumber.Length - 4; i++)
            {
                result += "*";
            }
            if (cardNumber.Length >= 4)
            {
                result += cardNumber.Substring(cardNumber.Length - 4) + Environment.NewLine;          //last 4 digits of card number only.
            }
            result += "Card Type".PadRight(xright - xleft, '.') + CreditCardUtils.GetCardType(cardNumber) + Environment.NewLine;
            result += "Entry".PadRight(xright - xleft, '.') + (String.IsNullOrEmpty(magData) ? "Manual" : "Swiped") + Environment.NewLine;
            result += "Auth Code".PadRight(xright - xleft, '.') + authCode + Environment.NewLine;
            result += "Result".PadRight(xright - xleft, '.') + statusDescription + Environment.NewLine;
            if (messages != null)
            {
                string label = "Message";
                foreach (string m in messages)
                {
                    result += label.PadRight(xright - xleft, '.') + m + Environment.NewLine;
                    label   = "";
                }
            }
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
            if (transType.In(PayConnectService.transType.RETURN, PayConnectService.transType.VOID))
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + (amount * -1) + Environment.NewLine;
            }
            else
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + amount + Environment.NewLine;
            }
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
            result += "I agree to pay the above total amount according to my card issuer/bank agreement." + Environment.NewLine;
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine;
            if (sigResponseStatusCode != 0)
            {
                result += "Signature X".PadRight(xmax - xleft, '_');
            }
            else
            {
                result += "Electronically signed";
            }
            return(result);
        }
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);
        }