public static decimal PaymentCaliculation(CreditCardTypeType cardType, decimal totalPrice) { decimal finalPrice = 0; switch (cardType) { case CreditCardTypeType.Visa: case CreditCardTypeType.MasterCard: case CreditCardTypeType.Discover: { finalPrice = Math.Round((totalPrice * (8m / 100)), 2); break; } case CreditCardTypeType.Amex: { finalPrice = Math.Round((totalPrice * (10m / 100)), 2); break; } case CreditCardTypeType.eCheck: { finalPrice = Math.Round((totalPrice * (10.75m / 100)), 2); break; } default: { finalPrice = Math.Round((totalPrice * (8m / 100)), 2); break; } } return(finalPrice); }
/// <summary> /// Get Paypal credit card type /// </summary> /// <param name="CreditCardType">Credit card type</param> /// <returns>Paypal credit card type</returns> protected CreditCardTypeType GetPaypalCreditCardType(string CreditCardType) { CreditCardTypeType creditCardTypeType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), CreditCardType); return(creditCardTypeType); //if (CreditCardType.ToLower() == "visa") // return CreditCardTypeType.Visa; //if (CreditCardType.ToLower() == "mastercard") // return CreditCardTypeType.MasterCard; //if (CreditCardType.ToLower() == "americanexpress") // return CreditCardTypeType.Amex; //if (CreditCardType.ToLower() == "discover") // return CreditCardTypeType.Discover; //throw new NopException("Unknown credit card type"); }
public static bool IsValidNumber(string cardNum, CreditCardTypeType? cardType) { //Create new instance of Regex comparer with our //credit card regex pattern Regex cardTest = new Regex(cardRegex); //Make sure the supplied number matches the supplied //card type if (cardTest.Match(cardNum).Groups[cardType.ToString()].Success) { //If the card type matches the number, then run it //through Luhn's test to make sure the number appears correct if (PassesLuhnTest(cardNum)) return true; else //The card fails Luhn's test return false; } else //The card number does not match the card type return false; }
public static string GetCardTestNumber(CreditCardTypeType cardType) { //According to PayPal, the valid test numbers that should be used //for testing card transactions are: //Credit Card Type Credit Card Number //American Express 378282246310005 //American Express 371449635398431 //American Express Corporate 378734493671000 //Diners Club 30569309025904 //Diners Club 38520000023237 //Discover 6011111111111117 //Discover 6011000990139424 //MasterCard 5555555555554444 //MasterCard 5105105105105100 //Visa 4111111111111111 //Visa 4012888888881881 //Src: https://www.paypal.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm //Credit: Scott Dorman, http://www.geekswithblogs.net/sdorman //Return bogus CC number that passes Luhn and format tests switch (cardType) { case CreditCardTypeType.Amex: return("3782 822463 10005"); case CreditCardTypeType.Discover: return("6011 1111 1111 1117"); case CreditCardTypeType.MasterCard: return("5105 1051 0510 5100"); case CreditCardTypeType.Visa: return("4111 1111 1111 1111"); default: return(null); } }
private decimal TotalAmountToPay(CreditCardTypeType cardType, string paymentMethod) { CreditCardTypeType CardType = paymentMethod == "eCheck" ? CreditCardTypeType.eCheck : cardType; HttpCookie authCookie = Request.Cookies[".BGBCProducts"]; decimal total = 0; if (authCookie != null) { string[] ids = authCookie.Value.ToString().Split(','); IEnumerable <Product> list = _repository.Get(); foreach (var item in list) { if (Array.Exists(ids, e => e == item.ProductID.ToString())) { total = total + (decimal)item.Price; } } decimal fee = CreditCardUtility.PaymentCaliculation(CardType, total); decimal tax = Math.Round((total * (8.25m / 100)), 2); total = total + tax + fee; } return(total); }
/// <summary> /// Debugging Tool /// </summary> /// <param name="cardType"></param> /// <returns></returns> public static string GetCardTestNumber(CreditCardTypeType cardType) { //Test Numbers from PayPal //for testing card transactions are: //Credit Card Type Credit Card Number //*American Express 378282246310005 //*American Express 371449635398431 //American Express Corporate 378734493671000 //Diners Club 30569309025904 //Diners Club 38520000023237 //Discover 6011111111111117 //Discover 6011000990139424 //*MasterCard 5555555555554444 //*MasterCard 5105105105105100 //*Visa Credit 4111111111111111 //*Visa Debit 4012888888881881 //*Maestro (switch/solo) 6331101999990016 //Src: https://www.paypal.com/en_GB/vhelp/paypalmanager_help/credit_card_numbers.htm //Return bogus CC number that passes Luhn and format tests switch (cardType) { case CreditCardTypeType.Amex: return "3782 822463 10005"; case CreditCardTypeType.MasterCard: return "5105 1051 0510 5100"; case CreditCardTypeType.MasterCardDebit: return "5105 1051 0510 5100"; case CreditCardTypeType.Visa: return "4111 1111 1111 1111"; case CreditCardTypeType.VisaDebit: return "4917 4800 0000 0008"; case CreditCardTypeType.Maestro: return "6331 1019 9999 0016"; default: return null; } }
/// <summary> /// Test CVV Code /// </summary> /// <param name="cvvCode"></param> /// <param name="cardType"></param> /// <returns></returns> public static bool IsValidCvvCode(string cvvCode, CreditCardTypeType? cardType) { int digits = 0; switch (cardType) { case CreditCardTypeType.MasterCard: digits = 3; break; case CreditCardTypeType.MasterCardDebit: digits = 3; break; case CreditCardTypeType.VisaDebit: digits = 3; break; case CreditCardTypeType.Visa: digits = 3; break; //case "DISCOVER": //case "EUROCARD": case CreditCardTypeType.Maestro: case CreditCardTypeType.Amex: digits = 4; break; default: return false; } var regEx = new Regex("[0-9]{" + digits + "}"); return (cvvCode.Length == digits && regEx.Match(cvvCode).Success); }
static public OrderInfo Charge(string firstName, string lastName, string address1, string address2, string city, string state, string zip, string country, string ccType, string ccNumber, string ccAuthCode, int ccExpireYear, int ccExpireMonth, decimal priceFinal, decimal priceTax, decimal priceShipping) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; CreditCardTypeType cardType = CreditCardTypeType.Visa; switch (ccType) { case "Visa": case "MasterCard": case "Discover": cardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), ccType.ToString()); break; case "AMEX": cardType = CreditCardTypeType.Amex; break; default: cardType = CreditCardTypeType.Visa; break; } CountryCodeType countryCode = CountryCodeType.US; try { countryCode = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), country); } catch { countryCode = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), Robo.Country.NameToCode(country)); } finally { countryCode = CountryCodeType.US; } using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl))) { var credentials = new CustomSecurityHeaderType() { Credentials = new UserIdPasswordType() { Username = APIUserName, Password = APIPassword, Signature = APISignature } }; DoDirectPaymentReq req = new DoDirectPaymentReq() { DoDirectPaymentRequest = new DoDirectPaymentRequestType() { Version = "121.0", DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType() { CreditCard = new CreditCardDetailsType() { CardOwner = new PayerInfoType() { PayerName = new PersonNameType() { FirstName = firstName, LastName = lastName }, Address = new AddressType() { CityName = city, StateOrProvince = state, PostalCode = zip, Country = countryCode, Street1 = address1, Street2 = address2 } }, CreditCardNumber = ccNumber, CreditCardType = cardType, CreditCardTypeSpecified = true, CVV2 = ccAuthCode, ExpMonth = ccExpireMonth, ExpMonthSpecified = true, ExpYear = ccExpireYear, ExpYearSpecified = true }, PaymentAction = PaymentActionCodeType.Sale, PaymentDetails = new PaymentDetailsType() { OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceFinal.ToString("F2") }, ShippingTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceShipping.ToString("F2") }, TaxTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceTax.ToString("F2") } } } } }; var response = client.DoDirectPayment(ref credentials, req); // check errors string errors = CheckErrors(response); OrderInfo info = new OrderInfo(); if (errors == String.Empty) { info.Ack = response.Ack.ToString(); info.TransactionID = response.TransactionID; info.CVV2Code = response.CVV2Code; } else { info.Ack = errors; } return(info); } }
protected CreditCardTypeType GetPaypalCreditCardType(string creditCardType) { CreditCardTypeType creditCardTypeType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), creditCardType); return(creditCardTypeType); }
public Commerce.Common.Transaction DoDirectCheckout(Commerce.Common.Order order, bool AuthOnly) { PayPalSvc.DoDirectPaymentReq req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = PayPalServiceUtility.PayPalAPIVersionNumber; DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType(); details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.PaymentDetails = new PaymentDetailsType(); CountryCodeType payerCountry = CountryCodeType.US; if (order.BillingAddress.Country != "US") { try { payerCountry = (CountryCodeType)StringToEnum(typeof(CountryCodeType), order.BillingAddress.Country); } catch { } } details.CreditCard.CardOwner.Address.Country = payerCountry; details.CreditCard.CardOwner.PayerCountry = payerCountry; details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = order.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = order.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = order.BillingAddress.City; details.CreditCard.CardOwner.Address.StateOrProvince = order.BillingAddress.StateOrRegion; details.CreditCard.CardOwner.Address.PostalCode = order.BillingAddress.Zip; details.CreditCard.CardOwner.PayerName.FirstName = order.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = order.BillingAddress.LastName; //the basics int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits; decimal dTotal = Math.Round(order.CalculateSubTotal(), roundTo) + Math.Round(order.TaxAmount, roundTo) + Math.Round(order.ShippingAmount, roundTo); details.PaymentDetails.OrderTotal = GetBasicAmount(dTotal); details.PaymentDetails.ShippingTotal = this.GetBasicAmount(Math.Round(order.ShippingAmount, roundTo)); details.PaymentDetails.TaxTotal = this.GetBasicAmount(Math.Round(order.TaxAmount, roundTo)); details.PaymentDetails.Custom = order.OrderNumber; details.PaymentDetails.ItemTotal = GetBasicAmount(Math.Round(order.CalculateSubTotal(), roundTo)); details.PaymentDetails.ButtonSource = DP_BN_ID; //credit card details.CreditCard.CreditCardNumber = order.CreditCardNumber; CreditCardTypeType ccType = CreditCardTypeType.Visa; switch (order.CreditCardType) { case Commerce.Common.CreditCardType.MasterCard: ccType = CreditCardTypeType.MasterCard; break; case Commerce.Common.CreditCardType.Amex: ccType = CreditCardTypeType.Amex; break; } details.CreditCard.CreditCardType = ccType; details.CreditCard.ExpMonth = Convert.ToInt16(order.CreditCardExpireMonth); details.CreditCard.ExpYear = Convert.ToInt16(order.CreditCardExpireYear); details.CreditCard.CVV2 = order.CreditCardSecurityNumber; //set the IP - required details.IPAddress = order.UserIP; //set the req var to details req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; //sale type if (AuthOnly) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } //send the request DoDirectPaymentResponseType response = service2.DoDirectPayment(req); string errors = this.CheckErrors(response); Commerce.Common.Transaction trans = new Commerce.Common.Transaction(); trans.OrderID = order.OrderID; string sOut = ""; if (errors == string.Empty) { trans.GatewayResponse = response.Ack.ToString(); trans.AuthorizationCode = response.TransactionID; trans.CVV2Code = response.CVV2Code; } else { trans.GatewayResponse = errors; throw new Exception(errors); } return(trans); }
public static string GetCardTestNumber(CreditCardTypeType cardType) { //According to PayPal, the valid test numbers that should be used //for testing card transactions are: //Credit Card Type Credit Card Number //American Express 378282246310005 //American Express 371449635398431 //American Express Corporate 378734493671000 //Diners Club 30569309025904 //Diners Club 38520000023237 //Discover 6011111111111117 //Discover 6011000990139424 //MasterCard 5555555555554444 //MasterCard 5105105105105100 //Visa 4111111111111111 //Visa 4012888888881881 //Src: https://www.paypal.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm //Credit: Scott Dorman, http://www.geekswithblogs.net/sdorman //Return bogus CC number that passes Luhn and format tests switch (cardType) { case CreditCardTypeType.Amex: return "3782 822463 10005"; case CreditCardTypeType.Discover: return "6011 1111 1111 1117"; case CreditCardTypeType.MasterCard: return "5105 1051 0510 5100"; case CreditCardTypeType.Visa: return "4111 1111 1111 1111"; default: return null; } }