public static bool IsValidNumber(string cardNumber, CreditCardType cardType) { cardNumber = cardNumber.Trim(); //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(cardNumber).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(cardNumber)) { return(true); } else { //The card fails Luhn's test return(false); } } else { //The card number does not match the card type return(false); } }
protected void Pay(Guid instanceId, Guid couponId, string couponCode, CreditCardType creditCardType, bool useDiscountVisible, bool?useDiscount) { // Payment. AssertUrl(GetPaymentUrl(instanceId)); Assert.AreEqual(couponCode, _couponCodeTextBox.Text); // Simulate applying the coupon. _couponIdTextBox.Text = couponId.ToString(); AssertUseDiscountVisibility(useDiscountVisible); if (useDiscount != null) { _useDiscountCheckBox.IsChecked = useDiscount.Value; } _cardNumberTextBox.Text = CreditCardNumber; var index = 0; for (; index < _cardTypeDropDownList.Items.Count; ++index) { if (_cardTypeDropDownList.Items[index].Value == creditCardType.ToString()) { break; } } _cardTypeDropDownList.SelectedIndex = index; _cvvTextBox.Text = Cvv; _cardHolderNameTextBox.Text = CardHolderName; _authoriseCreditCardCheckBox.IsChecked = true; _purchaseButton.Click(); }
private static string GetText(CreditCardType type) { switch (type) { case CreditCardType.Amex: return("American Express"); default: return(type.ToString()); } }
public decimal GetInterestRate(CreditCardType cardType) { var rates = GetCardRates(); if (rates.ContainsKey(cardType)) { return(rates[cardType]); } else { throw new Exception($"!Error!, Could not find interest rate for {cardType.ToString()}"); } }
/// <summary> /// Returns the type of card based on the first few numbers of the credit card. /// </summary> /// <param name="CreditCardNumber">The credit card number.</param> /// <param name="Valid">valid or not.</param> /// <returns>String.</returns> public String CreditCardType(String CreditCardNumber, Boolean Valid) { CreditCardType Type = (CreditCardType)0; try { char[] array = CreditCardNumber.Take(2).ToArray(); var LeadingTwoNumbers = array[0].ToString() + array[1].ToString(); if (Int32.Parse(LeadingTwoNumbers) == 34 | Int32.Parse(LeadingTwoNumbers) == 37 && Valid == true) { Type = CreditCardProject.CreditCardType.AMERICAN_EXPRESS; } else if (Int32.Parse(array[0].ToString()) == 4 && Valid == true) { Type = CreditCardProject.CreditCardType.VISA; } else if (Int32.Parse(LeadingTwoNumbers) >= 51 && Int32.Parse(LeadingTwoNumbers) <= 55 && Valid == true) { Type = CreditCardProject.CreditCardType.MASTERCARD; } else if (Int32.Parse(LeadingTwoNumbers) == 60 | Int32.Parse(LeadingTwoNumbers) == 64 | Int32.Parse(LeadingTwoNumbers) == 65 && Valid == true) { Type = CreditCardProject.CreditCardType.DISCOVER; } else if (Valid == true) { Type = CreditCardProject.CreditCardType.OTHER; } else { Type = CreditCardProject.CreditCardType.INVALID; } } catch (IndexOutOfRangeException) { Console.WriteLine("The Credit Card Value can not be Null"); } return(Type.ToString()); }
protected CreditCardType ValidateAndParseCardDetails(string cardNumber, string expirationMonth, string expirationYear, out DateTime parsedExpirationDate) { CreditCardType cardType = base.ValidateCreditCard(cardNumber, expirationMonth, expirationYear, out parsedExpirationDate); if (!CardTypeToString.ContainsKey(cardType)) { throw new CardTypeNotSupportedException(string.Format("Card type {0} is not supported", cardType.ToString())); } return(cardType); }
public Hashtable DoDirectPaymentCode() { NVPCallerServices caller = new NVPCallerServices(); IAPIProfile profile = ProfileFactory.createSignatureAPIProfile(); /* * WARNING: Do not embed plaintext credentials in your application code. * Doing so is insecure and against best practices. * Your API credentials must be handled securely. Please consider * encrypting them for use in any production environment, and ensure * that only authorized individuals may view or modify them. */ // Set up your API credentials, PayPal end point, API operation and version. profile.APIUsername = Constants.PayPal_Username; //"sdk-three_api1.sdk.com"; profile.APIPassword = Constants.PayPal_Password; //"QFZCWN5HZM8VBG7Q"; profile.APISignature = Constants.PayPal_Signature; //"AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ"; profile.Environment = Constants.PayPal_PaymentAccount; //"live";// "sandbox"; caller.APIProfile = profile; NVPCodec encoder = new NVPCodec(); encoder["VERSION"] = "51.0"; encoder["METHOD"] = "DoDirectPayment"; // Add request-specific fields to the request. encoder["PAYMENTACTION"] = "Sale"; //paymentAction; encoder["AMT"] = fPaymentOrderTotal.ToString(); encoder["CREDITCARDTYPE"] = (sCCType.Equals(CreditCardType.AmericanExpress)) ? "Amex" : sCCType.ToString(); encoder["ACCT"] = CCNumber; encoder["EXPDATE"] = sCCExpDate; encoder["CVV2"] = sCCVerificationCode; encoder["FIRSTNAME"] = sCCOwnerFirstName; encoder["LASTNAME"] = sCCOwnerLastName; encoder["STREET"] = (sCCOwnerStreet2.Trim().Length > 0) ? string.Concat(sCCOwnerStreet1, ", ", sCCOwnerStreet2) : sCCOwnerStreet1; encoder["CITY"] = sCCOwnerCityName; encoder["STATE"] = sCCOwnerStateOrProvince; encoder["ZIP"] = sCCOwnerPostalCode; encoder["COUNTRYCODE"] = sCCOwnerCountryCode; encoder["CURRENCYCODE"] = "USD"; // Execute the API operation and obtain the response. string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); Hashtable htResult = new Hashtable(); foreach (string st in decoder.AllKeys) { htResult.Add(st, decoder[st]); } return(htResult); }
public static bool IsValidNumber(string cardNum, CreditCardType? cardType) { return _cardRegex.Match(cardNum).Groups[cardType.ToString()].Success && PassesLuhnTest(cardNum); }