Exemple #1
0
        private void butOK_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            int expYear;
            int expMonth;

            if (!VerifyData(out expYear, out expMonth))
            {
                Cursor = Cursors.Default;
                return;
            }
            string refNumber = "";

            if (trantype == PayConnectService.transType.VOID || trantype == PayConnectService.transType.RETURN)
            {
                refNumber = textRefNumber.Text;
            }
            PayConnectService.creditCardRequest request = Bridges.PayConnect.BuildSaleRequest(Convert.ToDecimal(textAmount.Text),
                                                                                              textCardNumber.Text, expYear, expMonth, textNameOnCard.Text, textSecurityCode.Text, textZipCode.Text, (parser != null?parser.Track2:null), trantype, refNumber);
            response = Bridges.PayConnect.ProcessCreditCard(request);
            if (trantype == PayConnectService.transType.SALE && response.Status.code == 0)         //Only print a receipt if transaction is an approved SALE.
            {
                receiptStr = BuildReceiptString(request, response);
                PrintReceipt(receiptStr);
            }
            if (response == null || response.Status.code != 0)         //error in transaction
            {
                Cursor       = Cursors.Default;
                DialogResult = DialogResult.Cancel;
                return;
            }
            Cursor       = Cursors.Default;
            DialogResult = DialogResult.OK;
        }
Exemple #2
0
        ///<summary>Builds a receipt string for a web service transaction.</summary>
        public static string BuildReceiptString(PayConnectService.creditCardRequest request, PayConnectService.transResponse response,
                                                PayConnectService.signatureResponse sigResponse, long clinicNum)
        {
            string result = "";
            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, '.') + request.TransType.ToString() + Environment.NewLine;
            result += Environment.NewLine;
            result += "Transaction #".PadRight(xright - xleft, '.') + response.RefNumber + Environment.NewLine;
            result += "Name".PadRight(xright - xleft, '.') + request.NameOnCard + Environment.NewLine;
            result += "Account".PadRight(xright - xleft, '.');
            for (int i = 0; i < request.CardNumber.Length - 4; i++)
            {
                result += "*";
            }
            result += request.CardNumber.Substring(request.CardNumber.Length - 4) + Environment.NewLine;      //last 4 digits of card number only.
            result += "Exp Date".PadRight(xright - xleft, '.') + request.Expiration.month.ToString().PadLeft(2, '0') + (request.Expiration.year % 100) + Environment.NewLine;
            result += "Card Type".PadRight(xright - xleft, '.') + CreditCardUtils.GetCardType(request.CardNumber) + Environment.NewLine;
            result += "Entry".PadRight(xright - xleft, '.') + (String.IsNullOrEmpty(request.MagData) ? "Manual" : "Swiped") + Environment.NewLine;
            result += "Auth Code".PadRight(xright - xleft, '.') + response.AuthCode + Environment.NewLine;
            result += "Result".PadRight(xright - xleft, '.') + response.Status.description + Environment.NewLine;
            if (response.Messages != null)
            {
                string label = "Message";
                foreach (string m in response.Messages)
                {
                    result += label.PadRight(xright - xleft, '.') + m + Environment.NewLine;
                    label   = "";
                }
            }
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
            if (request.TransType.In(PayConnectService.transType.RETURN, PayConnectService.transType.VOID))
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + (request.Amount * -1) + Environment.NewLine;
            }
            else
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + request.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 (sigResponse == null || sigResponse.Status == null || sigResponse.Status.code != 0)
            {
                result += "Signature X".PadRight(xmax - xleft, '_');
            }
            else
            {
                result += "Electronically signed";
            }
            return(result);
        }
Exemple #3
0
        private string BuildReceiptString(PayConnectService.creditCardRequest request, PayConnectService.transResponse response)
        {
            string result = "";
            int    xmin   = 0;
            int    xleft  = xmin;
            int    xright = 15;
            int    xmax   = 37;

            result += Environment.NewLine;
            //Print header/Practice information
            string practiceTitle = PrefC.GetString(PrefName.PracticeTitle);

            if (practiceTitle.Length > 0)
            {
                result += practiceTitle + Environment.NewLine;
            }
            string practiceAddress = PrefC.GetString(PrefName.PracticeAddress);

            if (practiceAddress.Length > 0)
            {
                result += practiceAddress + Environment.NewLine;
            }
            string practiceAddress2 = PrefC.GetString(PrefName.PracticeAddress2);

            if (practiceAddress2.Length > 0)
            {
                result += practiceAddress2 + Environment.NewLine;
            }
            string practiceCity  = PrefC.GetString(PrefName.PracticeCity);
            string practiceState = PrefC.GetString(PrefName.PracticeST);
            string practiceZip   = PrefC.GetString(PrefName.PracticeZip);

            if (practiceCity.Length > 0 || practiceState.Length > 0 || practiceZip.Length > 0)
            {
                string cityStateZip = practiceCity + " " + practiceState + " " + practiceZip;
                result += cityStateZip + Environment.NewLine;
            }
            string practicePhone = PrefC.GetString(PrefName.PracticePhone);

            if (practicePhone.Length == 10 &&
                (CultureInfo.CurrentCulture.Name == "en-US" ||
                 CultureInfo.CurrentCulture.Name.EndsWith("CA")))                 //Canadian. en-CA or fr-CA
            {
                result += "(" + practicePhone.Substring(0, 3) + ")" + practicePhone.Substring(3, 3) + "-" + practicePhone.Substring(6) + Environment.NewLine;
            }
            else if (practicePhone.Length > 0)
            {
                result += practicePhone + Environment.NewLine;
            }
            result += Environment.NewLine;
            //Print body
            result += "Date".PadRight(xright - xleft, '.') + DateTime.Now.ToString() + Environment.NewLine;
            result += Environment.NewLine;
            result += "Trans Type".PadRight(xright - xleft, '.') + request.TransType.ToString() + Environment.NewLine;
            result += Environment.NewLine;
            result += "Transaction #".PadRight(xright - xleft, '.') + response.RefNumber + Environment.NewLine;
            result += "Name".PadRight(xright - xleft, '.') + request.NameOnCard + Environment.NewLine;
            result += "Account".PadRight(xright - xleft, '.');
            for (int i = 0; i < request.CardNumber.Length - 4; i++)
            {
                result += "*";
            }
            result += request.CardNumber.Substring(request.CardNumber.Length - 4) + Environment.NewLine;      //last 4 digits of card number only.
            result += "Exp Date".PadRight(xright - xleft, '.') + request.Expiration.month.ToString().PadLeft(2, '0') + (request.Expiration.year % 100) + Environment.NewLine;
            result += "Card Type".PadRight(xright - xleft, '.') + CreditCardUtils.GetType(request.CardNumber) + Environment.NewLine;
            result += "Entry".PadRight(xright - xleft, '.') + (request.MagData == ""?"Manual":"Swiped") + Environment.NewLine;
            result += "Auth Code".PadRight(xright - xleft, '.') + response.AuthCode + Environment.NewLine;
            result += "Result".PadRight(xright - xleft, '.') + response.Status.description + Environment.NewLine;
            if (response.Messages != null)
            {
                string label = "Message";
                foreach (string m in response.Messages)
                {
                    result += label.PadRight(xright - xleft, '.') + m + Environment.NewLine;
                    label   = "";
                }
            }
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
            result += "Total Amt".PadRight(xright - xleft, '.') + request.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;
            result += "Signature X".PadRight(xmax - xleft, '_');
            return(result);
        }
Exemple #4
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);
        }