Esempio n. 1
0
        private void ParseTrack1()
        {
            if (String.IsNullOrEmpty(_track1Data))
            {
                throw new MagstripCardParseException("Track 1 data is empty.");
            }
            string[] parts = _track1Data.Split(new char[] { FIELD_SEPARATOR }, StringSplitOptions.None);
            if (parts.Length != 3)
            {
                throw new MagstripCardParseException("Missing last field separator (^) in track 1 data.");
            }
            _accountNumber = CreditCardUtils.StripNonDigits(parts[0]);
            if (!String.IsNullOrEmpty(parts[1]))
            {
                _accountHolder = parts[1].Trim();
            }
            if (!String.IsNullOrEmpty(_accountHolder))
            {
                int nameDelim = _accountHolder.IndexOf("/");
                if (nameDelim > -1)
                {
                    _lastName  = _accountHolder.Substring(0, nameDelim);
                    _firstName = _accountHolder.Substring(nameDelim + 1);
                }
            }
            //date format: YYMM
            string expDate = parts[2].Substring(0, 4);

            _expYear  = ParseExpireYear(expDate);
            _expMonth = ParseExpireMonth(expDate);
        }
Esempio n. 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);
        }
Esempio n. 3
0
 private int ParseExpireMonth(string s)
 {
     s = CreditCardUtils.StripNonDigits(s);
     if (!ValidateExpiration(s))
     {
         return(0);
     }
     if (s.Length > 4)
     {
         s = s.Substring(0, 4);
     }
     return(int.Parse(s.Substring(2, 2)));
 }
Esempio n. 4
0
 private void ParseTrack2()
 {
     if (String.IsNullOrEmpty(_track2Data))
     {
         throw new MagstripCardParseException("Track 2 data is empty.");
     }
     if (_track2Data.StartsWith(";"))
     {
         _track2Data = _track2Data.Substring(1);
     }
     //may have already parsed this info out if track 1 data present
     if (String.IsNullOrEmpty(_accountNumber) || (_expMonth == 0 || _expYear == 0))
     {
         //Track 2 only cards
         //Ex: ;1234123412341234=0305101193010877?
         int sepIndex = _track2Data.IndexOf('=');
         if (sepIndex < 0)
         {
             throw new MagstripCardParseException("Invalid track 2 data.");
         }
         string[] parts = _track2Data.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
         if (parts.Length != 2)
         {
             throw new MagstripCardParseException("Missing field separator (=) in track 2 data.");
         }
         if (String.IsNullOrEmpty(_accountNumber))
         {
             _accountNumber = CreditCardUtils.StripNonDigits(parts[0]);
         }
         if (_expMonth == 0 || _expYear == 0)
         {
             //date format: YYMM
             string expDate = parts[1].Substring(0, 4);
             _expYear  = ParseExpireYear(expDate);
             _expMonth = ParseExpireMonth(expDate);
         }
     }
 }
Esempio n. 5
0
        private int ParseExpireYear(string s)
        {
            s = CreditCardUtils.StripNonDigits(s);
            if (!ValidateExpiration(s))
            {
                return(0);
            }
            if (s.Length > 4)
            {
                s = s.Substring(0, 4);
            }
            int y = int.Parse(s.Substring(0, 2));

            if (y > 80)
            {
                y += 1900;
            }
            else
            {
                y += 2000;
            }
            return(y);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        ///<summary>Builds a receipt string for a terminal transaction.</summary>
        public static string BuildReceiptString(PosRequest posRequest, PosResponse posResponse, PayConnectService.signatureResponse sigResponse,
                                                long clinicNum)
        {
            string result = "";
            int    xleft  = 0;
            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 += AddReceiptField("Trans Type", posResponse.TransactionType.ToString());
            result += Environment.NewLine;
            result += AddReceiptField("Transaction #", posResponse.ReferenceNumber.ToString());
            result += AddReceiptField("Account", posResponse.CardNumber);
            result += AddReceiptField("Card Type", posResponse.CardBrand);
            result += AddReceiptField("Entry", posResponse.EntryMode);
            result += AddReceiptField("Auth Code", posResponse.AuthCode);
            result += AddReceiptField("Result", posResponse.ResponseDescription);
            result += AddReceiptField("MerchantId", posResponse.MerchantId);
            result += AddReceiptField("TerminalId", posResponse.TerminalId);
            result += AddReceiptField("Mode", posResponse.Mode);
            result += AddReceiptField("CardVerifyMthd", posResponse.CardVerificationMethod);
            if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.AppId))
            {
                result += AddReceiptField("EMV AppId", posResponse.EMV.AppId);
            }
            if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.TermVerifResults))
            {
                result += AddReceiptField("EMV TermResult", posResponse.EMV.TermVerifResults);
            }
            if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.IssuerAppData))
            {
                result += AddReceiptField("EMV IssuerData", posResponse.EMV.IssuerAppData);
            }
            if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.TransStatusInfo))
            {
                result += AddReceiptField("EMV TransInfo", posResponse.EMV.TransStatusInfo);
            }
            if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.AuthResponseCode))
            {
                result += AddReceiptField("EMV AuthResp", posResponse.EMV.AuthResponseCode);
            }
            result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
            if (posResponse.TransactionType.In(TransactionType.Refund, TransactionType.Void))
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + (posResponse.Amount * -1) + Environment.NewLine;
            }
            else
            {
                result += "Total Amt".PadRight(xright - xleft, '.') + posResponse.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);
        }