コード例 #1
0
            ///<summary>Takes a credit card number and returns the issuer id from it to match PaySimple's expected values</summary>
            public static int GetCardType(string ccNum)
            {
                int    retVal       = 0;
                string cardTypeName = CreditCardUtils.GetCardType(ccNum);

                if (cardTypeName == "VISA")
                {
                    retVal = 12;
                }
                else if (cardTypeName == "MASTERCARD")
                {
                    retVal = 13;
                }
                else if (cardTypeName == "AMEX")
                {
                    retVal = 14;
                }
                else if (cardTypeName == "DISCOVER")
                {
                    retVal = 15;
                }
                else
                {
                    throw new Exception("Unsupported Card Type");
                }
                return(retVal);
            }
コード例 #2
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);
        }
コード例 #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)));
 }
コード例 #4
0
            ///<summary>Builds the receipt string for a web service transaction.
            ///This method assumes ccExpYear is a 4 digit integer.</summary>
            public void BuildReceiptString(string ccNum, int ccExpMonth, int ccExpYear, string nameOnCard, long clinicNum, bool wasSwiped = false)
            {
                string result = "";
                int    xleft  = 0;
                int    xright = 15;

                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, '.') + this.TransType.ToString() + Environment.NewLine;
                result += Environment.NewLine;
                result += "Transaction #".PadRight(xright - xleft, '.') + this.RefNumber + Environment.NewLine;
                if (!string.IsNullOrWhiteSpace(nameOnCard))
                {
                    result += "Name".PadRight(xright - xleft, '.') + nameOnCard + Environment.NewLine;
                }
                result += "Account".PadRight(xright - xleft, '.');
                for (int i = 0; i < ccNum.Length - 4; i++)
                {
                    result += "*";
                }
                if (!string.IsNullOrWhiteSpace(ccNum))
                {
                    result += ccNum.Substring(ccNum.Length - 4) + Environment.NewLine;              //last 4 digits of card number only.
                }
                if (ccExpMonth >= 0 && ccExpYear >= 0)
                {
                    result += "Exp Date".PadRight(xright - xleft, '.') + ccExpMonth.ToString().PadLeft(2, '0') + (ccExpYear % 100) + Environment.NewLine;
                }
                result += "Entry".PadRight(xright - xleft, '.') + (wasSwiped ? "Swiped" : "Manual") + Environment.NewLine;
                result += "Auth Code".PadRight(xright - xleft, '.') + this.AuthCode + Environment.NewLine;
                result += "Result".PadRight(xright - xleft, '.') + this.Status + Environment.NewLine;
                result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
                if (this.TransType.In(PaySimple.TransType.RETURN, PaySimple.TransType.VOID))
                {
                    result += "Total Amt".PadRight(xright - xleft, '.') + (this.Amount * -1) + Environment.NewLine;
                }
                else
                {
                    result += "Total Amt".PadRight(xright - xleft, '.') + this.Amount + Environment.NewLine;
                }
                if (this.TransType == TransType.SALE)
                {
                    result += Environment.NewLine + Environment.NewLine + Environment.NewLine;
                    result += "I agree to pay the above total amount according to my card issuer/bank agreement.";
                }
                this.TransactionReceipt = result;
            }
コード例 #5
0
 ///<summary>For web services.</summary>
 public PayConnectResponse(PayConnectService.transResponse response, PayConnectService.creditCardRequest request)
 {
     if (response != null)
     {
         AuthCode  = response.AuthCode;
         RefNumber = response.RefNumber;
         if (response.Status != null)
         {
             Description = response.Status.description;
             StatusCode  = response.Status.code.ToString();
         }
         if (response.PaymentToken != null)
         {
             PaymentToken = response.PaymentToken.TokenId;
             if (response.PaymentToken.Expiration != null)
             {
                 TokenExpiration = new DateTime(response.PaymentToken.Expiration.year, response.PaymentToken.Expiration.month, 1);
             }
         }
         CardType = CreditCardUtils.GetCardType(request.CardNumber);
     }
 }
コード例 #6
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);
         }
     }
 }
コード例 #7
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);
        }
コード例 #8
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);
        }