public CreditCardPayment(IChargable chargable, long charged, CreditCardType creditCardType, string cardNumber, CardIssuer cardIssuer, long basePoint) : base(chargable, charged, charged, basePoint) { _creditCardType = creditCardType; _cardIssuer = cardIssuer; _cardNumber = cardNumber; }
/// <see cref="https://developer.payeezy.com/payeezy-api/apis/post/transactions-4"/> public Response TokenPurchase(string token, string cardType, string expirationMonth, string expirationYear, string dollarAmount, string cardHoldersName, string referenceNumber) { DateTime parsedExpirationDate = ParseDateTime(expirationMonth, expirationYear); CreditCardType ccType = CardTypeByString[cardType]; dollarAmount = GetUsDollarAmountAsCents(dollarAmount); dynamic payload = new { merchant_ref = referenceNumber, transaction_type = TransactionTypeToString[TransactionType.Purchase], method = MethodTypeToString[MethodType.Token], amount = dollarAmount, currency_code = CurrencyCode, token = new { token_type = "FDToken", token_data = new { type = CardTypeToString[ccType], value = token, cardholder_name = cardHoldersName, exp_date = FormatCardExpirationDate(parsedExpirationDate) } } }; return(ProcessRequest(payload, TransactionsController)); }
public abstract void CreateAccount(out Int32 id , String name , int? maxNumberOfUser , int? maxNumberOfDomainUser , int? maxNumberOfProjects , String companyName , String companyAddress1 , String companyAddress2 , String companyCity , String companyState , String companyZip , String creditCardNumber , CreditCardType creditCardType , String creditCardAddress1 , String creditCardAddress2 , String creditCardCity , String creditCardZip , bool? recurringBill , DateTime? accountExpirationDate , DateTime? creditCardExpiration , Account owner , String creditCardEmail , int? creditCardIdCountry , String creditCardState , String creditCardCardholder , String promoCode , Int32? companyIdCountry , String creditCardCvs , String companyPhone , String creditCardPhone , int? subscriptionLevelId , long? subscriptionId);
/// <summary> /// Initializes a new instance of the CreditCardValidator class /// </summary> /// <param name="cardNo">Card Number</param> /// <param name="cardType">Type of Card</param> /// <param name="cardMonth">Month when card expires</param> /// <param name="cardYear">Year when card expires</param> public CreditCardValidator(string cardNo, string cardType, string cardMonth, string cardYear) { this._cardNo = cardNo; this._cardType = (CreditCardType)Enum.Parse(typeof(CreditCardType), cardType); this._cardMonth = Convert.ToInt32(cardMonth); this._cardYear = Convert.ToInt32(cardYear); }
public bool ContainScheme(CreditCardType cardScheme, CardType cardType, string bank = null) { var scheme = string.Empty; if (cardScheme == CreditCardType.Visa) { scheme = "visa"; } else if (cardScheme == CreditCardType.Mcrd) { scheme = "master card"; } else if (cardScheme == CreditCardType.Amex) { scheme = "amex"; } if (cardType == CardType.Credit) { return(CreditCardSchemes.Any(sch => sch.ToLower() == scheme)); } if (cardType == CardType.Debit) { return(CreditCardSchemes.Any(sch => sch.ToLower() == scheme)); } if (cardType == CardType.UnKnown && !string.IsNullOrEmpty(bank)) { return(NetBankingOptions.Any(sch => sch.BankName.ToLower() == bank.ToLower())); } return(false); }
/// <summary> /// Initializes a new instance of the CreditCardValidator class /// </summary> /// <param name="cardNo">Card Number</param> /// <param name="cardType">Type of Card</param> /// <param name="cardMonth">Month when card expires</param> /// <param name="cardYear">Year when card expires</param> public CreditCardValidator(string cardNo, int cardType, int cardMonth, int cardYear) { this._cardNo = cardNo; this._cardType = (CreditCardType)Enum.Parse(typeof(CreditCardType), cardType.ToString()); this._cardMonth = cardMonth; this._cardYear = cardYear; }
public static void DeleteCustomerCreditCard(int customerID, CreditCardType type) { // If this is a new credit card, don't delete it - we have nothing to delete if (type == CreditCardType.New) return; // Save the a blank copy of the credit card // Passing a blank token will do the trick var request = new SetAccountCreditCardTokenRequest { CustomerID = customerID, CreditCardAccountType = (type == CreditCardType.Primary) ? AccountCreditCardType.Primary : AccountCreditCardType.Secondary, CreditCardToken = string.Empty, ExpirationMonth = 1, ExpirationYear = DateTime.Now.Year + 1, BillingName = string.Empty, BillingAddress = string.Empty, BillingCity = string.Empty, BillingState = string.Empty, BillingZip = string.Empty, BillingCountry = string.Empty }; var response = Exigo.WebService().SetAccountCreditCardToken(request); }
private void TestCommunityNewOrder(string contactProductName, CreditCardType creditCardType, bool useDiscount) { var products = GetProducts(contactProductName); var data = TestCommunity.Vecci.GetCommunityTestData(); var community = data.CreateTestCommunity(_communitiesCommand, _verticalsCommand, _contentEngine); var price = (from p in products select p.Price).Sum(); var adjustments = GetAdjustments(products, price, creditCardType); var discountedAdjustments = GetDiscountedAdjustments(price, creditCardType); var employer = LogIn(false); // Hit the landing page. var url = _verticalsCommand.GetCommunityPathUrl(community, "employers/Employer.aspx"); Get(url); // Choose. var instanceId = Choose(contactProductName); AssertPaymentPage(instanceId, products, adjustments, true); // Pay. Pay(instanceId, null, creditCardType, true, useDiscount); AssertReceiptPage(instanceId, products, useDiscount ? discountedAdjustments : adjustments); AssertOrdersPage(useDiscount ? discountedAdjustments : adjustments); AssertEmail(products, useDiscount ? discountedAdjustments : adjustments); AssertOrder(employer.Id, useDiscount ? discountedAdjustments : adjustments); }
/// <summary> /// The next. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public override string Next(IGenerationContext context) { CreditCardType cardType = this.preferred; if (this.preferred == CreditCardType.Random) { cardType = (CreditCardType)RandomNumberGenerator.Current.Next(1, 4); } // TODO: Actually generate numbers switch (cardType) { case CreditCardType.AmericanExpress: return("3782 822463 10005"); case CreditCardType.Discover: return("6011 1111 1111 1117"); case CreditCardType.MasterCard: return("5105 1051 0510 5100"); case CreditCardType.Visa: return("4111 1111 1111 1111"); default: return(null); } }
public async Task <ICommandHandlerAggregateAnswer> Update(Guid personId, CreditCardDto dto) { var command = Mapper.Map(dto).ToANew <CreditCardUpdateCommand> (cfg => cfg.Map((p, d) => CreditCardType.FromName(p.CreditCardType)).To(d => d.CreditCardType)); return(await dispatcher.Send <CreditCardUpdateCommand, Person>(command)); }
public static string UpdateCreditCardType(CreditCardType value) { // VI VISA AX AMERICAN EXPRESS DI DISCOVER MC MASTER CARD //AMEX //Discover //MasterCard //VISA string returnValue = ""; if (value == CreditCardType.Visa) { returnValue = "VI"; } if (value == CreditCardType.AmericanExpress) { returnValue = "AX"; } if (value == CreditCardType.Discover) { returnValue = "DI"; } if (value == CreditCardType.Mastercard) { returnValue = "MC"; } return(returnValue); }
public static ICreditCard GetCreditCard(CreditCardType type) { // Pripravimo si novo spremenljivko ICreditCard card = null; // Ustvarimo instanco glede na izbrani tip switch (type) { case CreditCardType.Student: card = new Student(); break; case CreditCardType.Silver: card = new Silver(); break; case CreditCardType.Gold: card = new Gold(); break; case CreditCardType.Platinum: card = new Platinum(); break; } return(card); }
// ***************************************************************************************** // GetCardTestNumber Method // /// <summary> /// TODO: Gets the card test number. /// </summary> /// <param name="cardType"> /// Type of the card.</param> /// <returns> /// System.String.</returns> // // 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 // MasterCard 2221001234567896 // 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 // // ***************************************************************************************** public static String GetCardTestNumber(CreditCardType cardType) { //Return bogus CC number that passes Luhn and format tests switch (cardType) { case CreditCardType.AmericanExpress: { return("3782 822463 10005"); } case CreditCardType.Discover: { return("6011 1111 1111 1117"); } case CreditCardType.MasterCard: { return("5105 1051 0510 5100"); } case CreditCardType.Visa: { return("4111 1111 1111 1111"); } default: { return(null); } } }
//Many thanks to Paul Ingles for this Code //http://www.codeproject.com/aspnet/creditcardvalidator.asp //Modified by Spook, 3/2006 /// <summary> /// Determines whether <see cref="cardNumber"/> is a valid for the <see cref="cardType"/>. /// </summary> /// <param name="cardNumber">The card number.</param> /// <param name="cardType">Type of the card.</param> /// <returns> /// <c>true</c> if [is valid card type] [the specified card number]; otherwise, <c>false</c>. /// </returns> public static bool IsValidCardType(string cardNumber, CreditCardType cardType) { bool validCardType = true; // AMEX -- 34 or 37 -- 15 length if (Regex.IsMatch(cardNumber, "^(34|37)") && (cardType == CreditCardType.Amex)) { validCardType = 15 == cardNumber.Length; } // MasterCard -- 51 through 55 -- 16 length else if (Regex.IsMatch(cardNumber, "^(51|52|53|54|55)") && (cardType == CreditCardType.MasterCard)) { validCardType = 16 == cardNumber.Length; } // VISA -- 4 -- 13 and 16 length else if (Regex.IsMatch(cardNumber, "^(4)") && (cardType == CreditCardType.VISA)) { validCardType = 13 == cardNumber.Length || 16 == cardNumber.Length; } // Discover -- 6011 -- 16 length else if (Regex.IsMatch(cardNumber, "^(6011)") && (cardType == CreditCardType.Discover)) { validCardType = 16 == cardNumber.Length; } return(validCardType); }
public static void DeleteCustomerCreditCard(int customerID, CreditCardType type) { // If this is a new credit card, don't delete it - we have nothing to delete if (type == CreditCardType.New) { return; } // Save the a blank copy of the credit card // Passing a blank token will do the trick var request = new SetAccountCreditCardTokenRequest { CustomerID = customerID, CreditCardAccountType = (type == CreditCardType.Primary) ? AccountCreditCardType.Primary : AccountCreditCardType.Secondary, CreditCardToken = string.Empty, ExpirationMonth = 1, ExpirationYear = DateTime.Now.Year + 1, BillingName = string.Empty, BillingAddress = string.Empty, BillingCity = string.Empty, BillingState = string.Empty, BillingZip = string.Empty, BillingCountry = string.Empty }; var response = Exigo.WebService().SetAccountCreditCardToken(request); }
/// <see cref="https://developer.payeezy.com/capturereversepayment/apis/post/transactions/%7Bid%7D"/> public Response CreditCardRefund(string transactionId, string cardNumber, string expirationMonth, string expirationYear, string dollarAmount, string cardHoldersName, string cardVerificationValue, string referenceNumber) { DateTime parsedExpirationDate; CreditCardType cardType = ValidateAndParseCardDetails(cardNumber, expirationMonth, expirationYear, out parsedExpirationDate); cardVerificationValue = ValidateCardSecurityCode(cardType, cardVerificationValue); dollarAmount = GetUsDollarAmountAsCents(dollarAmount); dynamic payload = new { merchant_ref = referenceNumber, transaction_type = TransactionTypeToString[TransactionType.Refund], method = MethodTypeToString[MethodType.CreditCard], amount = dollarAmount, currency_code = CurrencyCode, credit_card = new { type = CardTypeToString[cardType], cardholder_name = cardHoldersName, card_number = cardNumber, exp_date = FormatCardExpirationDate(parsedExpirationDate), cvv = cardVerificationValue } }; return(ProcessRequest(payload, string.Format("{0}/{1}", TransactionsController, transactionId))); }
/// <summary> /// Valida si una entidad de tipo CreditCardType coincide con los filtros /// </summary> /// <param name="newCreditCard">Objeto a validar</param> /// <returns>true. Si se muestra | false. Nose muestra</returns> /// <history> /// [emoguel] created 18/03/2016 /// </history> private bool ValidateFilters(CreditCardType newCreditCard) { if (_nStatus != -1) { if (newCreditCard.ccA != Convert.ToBoolean(_nStatus)) { return(false); } } if (!string.IsNullOrWhiteSpace(_creditCardTypeFilter.ccID)) { if (_creditCardTypeFilter.ccID != newCreditCard.ccID) { return(false); } } if (!string.IsNullOrWhiteSpace(_creditCardTypeFilter.ccN)) { if (!newCreditCard.ccN.Contains(_creditCardTypeFilter.ccN, StringComparison.OrdinalIgnoreCase)) { return(false); } } return(true); }
/// <summary> /// Initializes a new instance of the CreditCard structure. /// </summary> /// <param name="type">Type of Credit Card (VISA etc.)</param> /// <param name="number">Credit Card number</param> /// <param name="validThru">A string with date in ISO "yyyy-MM" format</param> /// public CreditCard(CreditCardType type, string number, string validThru) : this() { string notValidInfo = Validate(type, number); if (notValidInfo != null) { throw new ArgumentException(notValidInfo); } if (string.IsNullOrEmpty(validThru)) { throw new ArgumentException("Valid Thru must not be null"); } this.Type = type; this.Number = number; try { this.ValidThru = DateTime.ParseExact(validThru, "yyyy-M", System.Globalization.CultureInfo.InvariantCulture); } catch (Exception) { throw new ArgumentException( "Valid Thru must be a date in 'yyyy-MM' format"); } }
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); } }
/// <summary> /// Muestra la ventada detalle en modo ReadOnly /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [Emoguel] created 03/03/2016 /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { CreditCardType creditCardType = (CreditCardType)dgrCreditCard.SelectedItem; frmCreditCardTypesDetail frmCrediCard = new frmCreditCardTypesDetail(); frmCrediCard.Owner = this; frmCrediCard.mode = ((_blnEdit == true) ? EnumMode.Edit : EnumMode.ReadOnly); frmCrediCard.oldCreditCard = creditCardType; if (frmCrediCard.ShowDialog() == true) { int nIndex = 0; List <CreditCardType> lstCreditCradTypes = (List <CreditCardType>)dgrCreditCard.ItemsSource; if (!ValidateFilters(frmCrediCard.creditCardType)) //Validamos si cumple con los registros { lstCreditCradTypes.Remove(creditCardType); //Quitamos el registro de la lista } else { ObjectHelper.CopyProperties(creditCardType, frmCrediCard.creditCardType); lstCreditCradTypes.Sort((x, y) => string.Compare(x.ccN, y.ccN));//Ordenamos la lista nIndex = lstCreditCradTypes.IndexOf(creditCardType); } dgrCreditCard.Items.Refresh();//refrescamos la lista GridHelper.SelectRow(dgrCreditCard, nIndex); StatusBarReg.Content = lstCreditCradTypes.Count + " Credit Card Types."; } }
public CreditCard(CreditCardType type) { this.Type = type; this.BillingAddress = new Address(); this.ExpirationMonth = DateTime.Now.Month; this.ExpirationYear = DateTime.Now.Year; }
private void TestCoupon(Guid employerId, Coupon coupon, string contactProductName) { const CreditCardType creditCardType = CreditCardType.MasterCard; var products = GetProducts(contactProductName); var adjustments = GetAdjustments(products, null, creditCardType); // Choose. var instanceId = Choose(contactProductName, coupon.Code); AssertPaymentPage(instanceId, products, adjustments, false); // Pay. Pay(instanceId, coupon.Id, coupon.Code, creditCardType, false, null); // Now the coupon has been applied. adjustments = GetAdjustments(products, coupon, creditCardType); AssertReceiptPage(instanceId, products, adjustments); AssertOrdersPage(adjustments); AssertOrderPage(employerId, products, adjustments); AssertEmail(products, adjustments); AssertOrder(employerId, adjustments); }
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(); }
public void TestData_Has_Only1_(CreditCardType cardType, int walletId) { var wallet = GetWallet(Person1, walletId); Assert.IsNotNull(wallet); Assert.AreEqual(wallet.Cards.Count(c => c.Type == cardType), 1); }
public async Task <ICommandHandlerAggregateAnswer> Create(Guid personId, CreditCardDto dto) { var command = Mapper.Map(dto).OnTo(new CreditCardCreateCommand()); command.CreditCardType = CreditCardType.FromName(dto.CreditCardType); return(await dispatcher.Send <CreditCardCreateCommand, Person>(command)); }
public virtual CreditCardType UpdateCreditCardType(CreditCardType entity) { if (entity.IsTransient()) { return(entity); } CreditCardType other = GetCreditCardType(entity.CardTypeId); if (entity.Equals(other)) { return(entity); } string sql = @"Update CreditCardType set [CardTypeGUID]=@CardTypeGUID , [CardType]=@CardType , [Accepted]=@Accepted , [CreatedOn]=@CreatedOn where CardTypeID=@CardTypeID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CardTypeID", entity.CardTypeId) , new SqlParameter("@CardTypeGUID", entity.CardTypeGuid) , new SqlParameter("@CardType", entity.CardType) , new SqlParameter("@Accepted", entity.Accepted) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetCreditCardType(entity.CardTypeId)); }
public virtual CreditCardType InsertCreditCardType(CreditCardType entity) { CreditCardType other = new CreditCardType(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into CreditCardType ( [CardTypeGUID] ,[CardType] ,[Accepted] ,[CreatedOn] ) Values ( @CardTypeGUID , @CardType , @Accepted , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CardTypeID", entity.CardTypeId) , new SqlParameter("@CardTypeGUID", entity.CardTypeGuid) , new SqlParameter("@CardType", entity.CardType) , new SqlParameter("@Accepted", entity.Accepted) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetCreditCardType(Convert.ToInt32(identity))); } return(entity); }
public CreditCard(CreditCardType type) { Type = type; BillingAddress = new Address(); ExpirationMonth = DateTime.Now.Month; ExpirationYear = DateTime.Now.Year; }
/// <summary> /// Sirve para obetener una lista de Credit Crad Types /// </summary> /// <param name="creditCardType">Objeto con los filtros adicionales</param> /// <param name="nStatus">-1. Devuelve todos los registros | 0. devuelve registros inactivos | 1. devuelve registros activos</param> /// <returns>lista de credit card types</returns> /// <history> /// [Emoguel] created 07/03/2016 /// [emoguel] modified 17/03/2016--->Se agregó la validacion null del objeto y se cambió el filtro por descripcion a "contains" /// [erosado] 19/05/2016 Modified. Se agregó asincronÃa /// [erosado] 04/08/2016 Modified. Se estandarizó el valor que retorna. /// </history> public async static Task <List <CreditCardType> > GetCreditCardTypes(CreditCardType creditCardType = null, int nStatus = -1) { return(await Task.Run(() => { using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString())) { var query = from cct in dbContext.CreditCardTypes select cct; if (nStatus != -1)//Validación por estatus { bool blnEstatus = Convert.ToBoolean(nStatus); query = query.Where(cct => cct.ccA == blnEstatus); } if (creditCardType != null) //Valida si se tiene un obejto { if (!string.IsNullOrWhiteSpace(creditCardType.ccID)) //Validación por ID { query = query.Where(cct => cct.ccID == creditCardType.ccID); } if (!string.IsNullOrWhiteSpace(creditCardType.ccN))//Validación por nombre/Descripción { query = query.Where(cct => cct.ccN.Contains(creditCardType.ccN)); } } return query.OrderBy(cct => cct.ccN).ToList(); } })); }
private static bool LengthIsValidateWithType(int length, CreditCardType cardType) { switch (length) { case 12: return(cardType == CreditCardType.Maestro); case 13: return(cardType == CreditCardType.Maestro); case 14: return(cardType == CreditCardType.DinersClub || cardType == CreditCardType.Maestro); case 15: return(cardType == CreditCardType.AmericanExpress //|| cardType == CreditCardType.Maestro || cardType == CreditCardType.DinersClub); case 16: return(cardType == CreditCardType.ChinaUnionPay || cardType == CreditCardType.DinersClub || cardType == CreditCardType.DiscoverCard || cardType == CreditCardType.UkrCard || cardType == CreditCardType.RuPay || cardType == CreditCardType.InterPayment || cardType == CreditCardType.InstaPayment || cardType == CreditCardType.JCB || cardType == CreditCardType.Maestro || cardType == CreditCardType.Dankort || cardType == CreditCardType.MIR || cardType == CreditCardType.NPSPridnestrovie || cardType == CreditCardType.MasterCard || cardType == CreditCardType.Troy || cardType == CreditCardType.Visa || cardType == CreditCardType.Verve || cardType == CreditCardType.LankaPay); case 17: case 18: return(cardType == CreditCardType.ChinaUnionPay || cardType == CreditCardType.DinersClub || cardType == CreditCardType.DiscoverCard || cardType == CreditCardType.InterPayment || cardType == CreditCardType.JCB || cardType == CreditCardType.Maestro); case 19: return(cardType == CreditCardType.ChinaTUnion || cardType == CreditCardType.ChinaUnionPay || cardType == CreditCardType.DinersClub || cardType == CreditCardType.DiscoverCard || cardType == CreditCardType.InterPayment || cardType == CreditCardType.JCB || cardType == CreditCardType.Maestro || cardType == CreditCardType.Verve); } return(false); }
protected CreditCardType ValidateCreditCard(string cardNumber, string expirationMonth, string expirationYear, out DateTime parsedExpirationDate) { if (string.IsNullOrWhiteSpace(cardNumber)) { throw new CardNumberNullException("Card number is null / empty"); } if (string.IsNullOrWhiteSpace(expirationMonth)) { throw new ExpirationNullException("Expiration month is null / empty"); } if (string.IsNullOrWhiteSpace(expirationYear)) { throw new ExpirationNullException("Expiration year is null / empty"); } CreditCardType cardType = CreditCard.GetCardType(cardNumber); if (cardType == CreditCardType.Invalid) { throw new CardTypeNotSupportedException("Card type is unsupported or card number is invalid"); } if (!CreditCard.HasValidLuhnChecksum(cardNumber)) { throw new CardNumberInvalidException("Card number is invalid"); } /* * int parsedExpirationMonth; * if (!int.TryParse(expirationMonth, out parsedExpirationMonth)) { * throw new ExpirationFormatException("Expiration month must be a number"); * } * * if (parsedExpirationMonth < 1 || parsedExpirationMonth > 12) { * throw new ExpirationOutOfRangeException("Expiration month must be between 1 and 12"); * } * * int parsedExpirationYear; * if (!int.TryParse(expirationYear, out parsedExpirationYear)) { * throw new ExpirationFormatException("Expiration year must be a number"); * } * * int fourDigitYear; * try { * fourDigitYear = UsCulture.Calendar.ToFourDigitYear(parsedExpirationYear); * } catch (Exception ex) { * throw new ExpirationFormatException("Error converting expiration year to a four digit year", ex); * } * * int daysInMonth = DateTime.DaysInMonth(fourDigitYear, parsedExpirationMonth); * parsedExpirationDate = new DateTime(fourDigitYear, parsedExpirationMonth, daysInMonth, 23, 59, 59); */ parsedExpirationDate = ParseDateTime(expirationMonth, expirationYear); return(cardType); }
/// <summary> /// Handles the Click event of the btnPaymentMethod control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnPaymentMethod_Click(object sender, EventArgs e) { //Loadup the cpe and validate the CC if possible int creditCardType; string maskedCreditCardNumber = string.Empty; DateTime expirationDate = DateTime.MinValue; int.TryParse(ddlCreditCardType.SelectedValue, out creditCardType); CreditCardType cardType = (CreditCardType)Enum.Parse(typeof(CreditCardType), ddlCreditCardType.SelectedValue); order.PaymentMethod = Enum.GetName(typeof(CreditCardType), creditCardType); order.Save(WebUtility.GetUserName()); if (cardType == CreditCardType.PayPal) { if (Page.Request["token"] == null) { pnlCreditCardInfo.Visible = false; string returnUrl = Utility.GetSiteRoot() + "/checkout.aspx"; string cancelUrl = Utility.GetSiteRoot() + "/default.aspx"; string url = OrderController.SetExpressCheckout(order, returnUrl, cancelUrl, false); Response.Redirect(url, true); } } else { #if RELEASE if (!WebUtility.IsValidCardType(txtCreditCardNumber.Text.Trim(), cardType)) { throw new InvalidOperationException("Credit card number does not validate."); } #endif int creditCardLength = txtCreditCardNumber.Text.Trim().Length; if (creditCardLength > 4) { for (int i = 1; i <= creditCardLength - 4; i++) { maskedCreditCardNumber += "X"; } maskedCreditCardNumber += txtCreditCardNumber.Text.Trim().Substring(creditCardLength - 4, 4); } int month, year; int.TryParse(ddlCreditCardExpirationYear.SelectedValue, out year); int.TryParse(ddlCreditCardExpirationMonth.SelectedValue, out month); expirationDate = new DateTime(year, month, DateTime.DaysInMonth(year, month)); if (!shippingService.ShippingServiceSettings.UseShipping && !hasCoupons) { //Then we get thru without calculating tax. //re-calculate the tax OrderController.CalculateTax(WebUtility.GetUserName()); //reload the order orderSummary.Order = new OrderController().FetchOrder(WebUtility.GetUserName()); orderSummary.LoadOrder(); } } SetPaymentMethodDisplay(creditCardType, maskedCreditCardNumber, expirationDate); acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1; this.btnProcessOrder.Enabled = true; }
private List <CreditCardType> GetCreditCardsTypeMock() { List <CreditCardType> creditCardTypes = new List <CreditCardType>(); #region Adding Mastercard CreditCardType mastercard = new CreditCardType { Id = (int)CreditCardTypeEnum.Mastercard, Description = "Mastercard", CardNumberLength = 16, CardNumberPrefixes = new string[] { "5" }, ValidateWithLuhnAlgorithm = true }; creditCardTypes.Add(mastercard); #endregion #region Adding Visa CreditCardType visa = new CreditCardType { Id = (int)CreditCardTypeEnum.Visa, Description = "Visa", CardNumberLength = 16, CardNumberPrefixes = new string[] { "4" }, ValidateWithLuhnAlgorithm = true }; creditCardTypes.Add(visa); #endregion #region Adding American Express CreditCardType amex = new CreditCardType { Id = (int)CreditCardTypeEnum.Amex, Description = "American Express", CardNumberLength = 15, CardNumberPrefixes = new string[] { "34", "37" }, ValidateWithLuhnAlgorithm = true }; creditCardTypes.Add(amex); #endregion #region Adding Cabal CreditCardType cabal = new CreditCardType { Id = (int)CreditCardTypeEnum.Cabal, Description = "CABAL", CardNumberLength = 16, CardNumberPrefixes = new string[] { "604", "589657", "603522" }, ValidateWithLuhnAlgorithm = false }; creditCardTypes.Add(cabal); #endregion return(creditCardTypes); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="shortName"></param> /// <param name="type"></param> /// <param name="prefix"></param> /// <param name="length"></param> public CreditCard(string name, string shortName, CreditCardType type, string prefix, int length) { Name = name; ShortName = shortName; Type = type; Prefix = prefix; Length = length; }
public static CreditCard Create(CreditCardType type, string number, string owner, ExpiryDate expiration) { var card = new CreditCard { Type = type, Owner = owner, Number = number, Expires = expiration }; return(card); }
public void Update(int id, string description) { CreditCardType obj = context.CreditCardTypes.Single(row => row.ID == id); obj.Description = description; EntityHelper.SetAuditFieldForUpdate(obj, principal.Identity.Name); context.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { CreditCardType creditCardType = this.StoreAccountManager.GetById <CreditCardType>(id); this.StoreAccountManager.Delete(creditCardType); this.StoreAccountManager.Save(); return(RedirectToAction("Index")); }
/// <summary> Full constructor. </summary> public CreditCard(string ownerName, User user, string number, CreditCardType type, string expMonth, string expYear) : base(ownerName, user) { this.type = type; this.number = number; this.expMonth = expMonth; this.expYear = expYear; }
public void CreditCard_ShouldReturnValidNumber(CreditCardType type) { // Arrange // Act var result = _sut.CreditCard(type); // Assert Assert.IsNotNull(result); result.Type.ShouldBe(type); }
public int CreateCreditCardType(CreditCardType A) { try { db.CreditCardTypes.Add(A); return db.SaveChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
public Card(bool scanned, string redactedCardNumber, string postalCode, int expiryYear, int expiryMonth, string cvv, CreditCardType cardType, string cardNumber, ImageSource cardImage) { this.Scaned = scanned; this.RedactedCardNumber = redactedCardNumber; this.PostalCode = postalCode; this.ExpiryYear = expiryYear; this.ExpiryMonth = expiryMonth; this.Cvv = cvv; this.CardType = cardType; this.CardNumber = cardNumber; this.CardImage = cardImage; }
/// <summary> /// Initializes a new instance of the <see cref="CreditCard"/> class. /// </summary> /// <param name="expectedType">The expected type.</param> /// <param name="accountNumber">The account number.</param> /// <param name="cardholderName">The name of the cardholder.</param> /// <param name="verificationCode">The verification code.</param> /// <param name="expiryMonth">The expiry month.</param> /// <param name="expiryYear">The expiry year.</param> public CreditCard(CreditCardType expectedType, string accountNumber, string cardholderName, string verificationCode, int expiryMonth, int expiryYear) : this(expectedType, accountNumber, cardholderName, expiryMonth, expiryYear) { VerificationCode = verificationCode .Replace("-", "").Replace(" ", "") .Secure(); }
public int UpdateCreditCardType(CreditCardType A) { try { db.Entry(A).State = EntityState.Modified; return db.SaveChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="CreditCard"/> class. /// </summary> /// <param name="expectedType">The expected type.</param> /// <param name="accountNumber">The account number.</param> /// <param name="cardholderName">The name of the cardholder.</param> /// <param name="expiryMonth">The expiry month.</param> /// <param name="expiryYear">The expiry year.</param> public CreditCard(CreditCardType expectedType, string accountNumber, string cardholderName, int expiryMonth, int expiryYear) { SetInitialValues(accountNumber, cardholderName, expiryMonth, expiryYear); Type = expectedType; IsValid = this.IsValid(Type); IsExpired = ExpiryDate >= DateTime.Today; }
/// <summary> /// Generate a random credit card number. This card number will pass the Luhn algorithm so it looks like a legit card. /// </summary> /// <param name="ccType"></param> /// <returns></returns> public string CreditCardNumber(CreditCardType? ccType = null) { var card = ccType.HasValue ? CreditCard(ccType) : CreditCard(); var toGenerate = card.Length - card.Prefix.Length - 1; // Generates n - 1 digits var number = Enumerable.Concat(card.Prefix, Integer(toGenerate, toGenerate).ToString(CultureInfo.InvariantCulture)); // Generates the last digit according to Luhn algorithm number = string.Format("{0}{1}", number, LuhnAlgorithm(number.ToString())); return number.ToString(); }
protected string ValidateCardSecurityCode(CreditCardType cardType, string cardVerificationValue) { if (string.IsNullOrWhiteSpace(cardVerificationValue)) { throw new CardSecurityCodeNullException("Card security code is null / empty"); } cardVerificationValue = cardVerificationValue.Trim(); switch (cardType) { case CreditCardType.AmericanExpress: // American Express cards have a four-digit code printed on the front side of the card above the number. if (cardVerificationValue.Length != 4) { throw new CardSecurityCodeFormatException("Card security code must be 4 digits"); } break; case CreditCardType.Diners: case CreditCardType.Discover: case CreditCardType.MasterCard: case CreditCardType.Visa: // Diners Club, Discover, JCB, MasterCard, and Visa credit and debit cards have a three-digit card security code. // The code is the final group of numbers printed on the back signature panel of the card. if (cardVerificationValue.Length != 3) { throw new CardSecurityCodeFormatException("Card security code must be 3 digits"); } break; default: throw new CardTypeNotSupportedException("Card type does not support card security code"); } int parsedCardSecurityCode; if (!int.TryParse(cardVerificationValue, out parsedCardSecurityCode)) { throw new CardSecurityCodeFormatException("Card security code must be numeric"); } return cardVerificationValue; }
/// <summary> /// Determines if a given credit card is valid based on the specified type. /// </summary> /// <param name="card">The card to validate</param> /// <param name="type">The expected card type; if Unknown, the type is not considered</param> /// <returns>Whether the credit card is valid or invalid</returns> public static bool IsValid(this CreditCard card, CreditCardType type) { var result = card.IsValid(); switch (type) { case CreditCardType.Visa: return result && card.Satisfies<VisaSpecification>(); case CreditCardType.MasterCard: return result && card.Satisfies<MasterCardSpecification>(); case CreditCardType.Amex: return result && card.Satisfies<AmexSpecification>(); case CreditCardType.Discover: return result && card.Satisfies<DiscoverSpecification>(); case CreditCardType.DinersClub: return result && card.Satisfies<DinersClubSpecification>(); case CreditCardType.Jcb: return result && card.Satisfies<JcbSpecification>(); case CreditCardType.Unknown: return result; default: throw new ArgumentException("A credit card type is required", "type"); } }
public CreditCardNumberAttribute(CreditCardType[] types) { this.types = types; }
/// <summary> /// Uses Luhn credit card validation algorithm. Rule determines whether the specified string is valid credit card. /// See: http://en.wikipedia.org/wiki/Luhn_algorithm /// </summary> /// <param name="creditCard">The input as credit card string.</param> /// <param name="cardtype">The credit card type.</param> /// <returns> /// <c>true</c> if valid; otherwise, <c>false</c>. /// </returns> public static bool IsValidCreditCardNumber(this string creditCard, CreditCardType cardtype) { bool success = false; if (!string.IsNullOrEmpty(creditCard) && Extensions.IsValidCreditCardFormatValid(creditCard)) { creditCard = Extensions.CleanCreditCardInputString(creditCard); switch (cardtype) { case CreditCardType.Visa: success = Regex.IsMatch(creditCard, Extensions.RegexPatternCreditCardVisa); break; case CreditCardType.Master: success = Regex.IsMatch(creditCard, Extensions.RegexPatternCreditCardMasterCard); break; case CreditCardType.AmericanExpress: success = Regex.IsMatch(creditCard, Extensions.RegexPatternCreditCardAmericanExpress); break; case CreditCardType.Discover: success = Regex.IsMatch(creditCard, Extensions.RegexPatternCreditCardDiscover); break; case CreditCardType.DinersClub: success = Regex.IsMatch(creditCard, Extensions.RegexPatternCreditCardDinersClub); break; } } return success; }
public static bool IsCCNumberValid(string number, CreditCardType type, out string error) { return CreditCardDesc.Validate(type, number, out error); }
CreditCardDesc(CreditCardType type, int length, params InnRange[] ranges) { _type = type; _length = length; _ranges = ranges; }
public static ReqCreditCardType GetGomsCreditCardType(CreditCardType cardType) { ReqCreditCardType GomsCreditCardType; switch (cardType) { case CreditCardType.American_Express: GomsCreditCardType = ReqCreditCardType.AmericanExpress; break; case CreditCardType.Discover: GomsCreditCardType = ReqCreditCardType.Discover; break; case CreditCardType.JCB: GomsCreditCardType = ReqCreditCardType.JCB; break; case CreditCardType.Master_Card: GomsCreditCardType = ReqCreditCardType.MasterCard; break; case CreditCardType.Visa: GomsCreditCardType = ReqCreditCardType.Visa; break; default: GomsCreditCardType = ReqCreditCardType.NotSpecified; break; } return GomsCreditCardType; }
/// <summary> /// Generates a random credit card number. /// </summary> /// <param name="cardType">Type of the credit card.</param> /// <returns></returns> public static string GenerateNumber(CreditCardType cardType) { int pos = 0; int[] number = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int sum = 0; int finalDigit = 0; int lenOffset = 0; int len = 0; // Fill in the first values of the string based with the specified bank's prefix. switch (cardType) { case CreditCardType.Visa: number[0] = 4; pos = 1; len = 16; break; case CreditCardType.Mastercard: number[0] = 5; number[1] = _random.Next(1, 5); // Between 1 and 5. pos = 2; len = 16; break; case CreditCardType.AmericanExpress: number[0] = 3; number[1] = _random.Next(4, 7); // Between 4 and 7. pos = 2; len = 15; break; case CreditCardType.Discover: number[0] = 6; number[1] = 0; number[2] = 1; number[3] = 1; pos = 4; len = 16; break; } // Fill all the remaining numbers except for the last one with random values. while (pos < len - 1) number[pos++] = _random.Next(0, 9); // Calculate the Luhn checksum of the values thus far. lenOffset = (len + 1) % 2; for (pos = 0; pos < len - 1; pos++) { if ((pos + lenOffset) % 2 != 0) { var t = number[pos] * 2; if (t > 9) t -= 9; sum += t; } else { sum += number[pos]; } } // Choose the last digit so that it causes the entire string to pass the checksum. finalDigit = (10 - (sum % 10)) % 10; number[len - 1] = finalDigit; var buffer = new StringBuilder(); foreach (var n in number) buffer.Append(n); return buffer.ToString(); }
//Many thanks to Paul Ingles for this Code //http://www.codeproject.com/aspnet/creditcardvalidator.asp //Modified by Spook, 3/2006 /// <summary> /// Determines whether <see cref="cardNumber"/> is a valid for the <see cref="cardType"/>. /// </summary> /// <param name="cardNumber">The card number.</param> /// <param name="cardType">Type of the card.</param> /// <returns> /// <c>true</c> if [is valid card type] [the specified card number]; otherwise, <c>false</c>. /// </returns> public static bool IsValidCardType(string cardNumber, CreditCardType cardType) { bool validCardType = true; // AMEX -- 34 or 37 -- 15 length if (Regex.IsMatch(cardNumber, "^(34|37)") && (cardType == CreditCardType.Amex)) validCardType = 15 == cardNumber.Length; // MasterCard -- 51 through 55 -- 16 length else if (Regex.IsMatch(cardNumber, "^(51|52|53|54|55)") && (cardType == CreditCardType.MasterCard)) validCardType = 16 == cardNumber.Length; // VISA -- 4 -- 13 and 16 length else if (Regex.IsMatch(cardNumber, "^(4)") && (cardType == CreditCardType.VISA)) validCardType = 13 == cardNumber.Length || 16 == cardNumber.Length; // Discover -- 6011 -- 16 length else if (Regex.IsMatch(cardNumber, "^(6011)") && (cardType == CreditCardType.Discover)) validCardType = 16 == cardNumber.Length; return validCardType; }
public static bool CreditCard(string value, CreditCardType type) { return false; }
public CreditCard(CreditCardType creditCardType, string number) { this.CreditCardType = creditCardType; this.Number = number; }
public static bool Validate(CreditCardType type, string number, out string error) { error = ""; var desc = _table.FirstOrDefault(d => d.Type == type); if (desc == null) { error = "No information to validate card of such type."; return false; } if (!number.IsAllNumeric()) { error = "Number contains wrong characters."; return false; } return desc.Validate(number, ref error); }
/// <summary> /// Determines if a given credit card is valid, detecting its type. /// </summary> /// <param name="card">The card to validate</param> /// <param name="type">The type of the card, if identified</param> /// <returns>Whether the card is valid, and the card's type</returns> public static bool IsValid(this CreditCard card, out CreditCardType type) { var result = card.IsValid(); type = CreditCardType.Unknown; if (card.Satisfies<VisaSpecification>()) { type = CreditCardType.Visa; } else if (card.Satisfies<MasterCardSpecification>()) { type = CreditCardType.MasterCard; } else if (card.Satisfies<AmexSpecification>()) { type = CreditCardType.Amex; } else if (card.Satisfies<DiscoverSpecification>()) { type = CreditCardType.Discover; } else if (card.Satisfies<DinersClubSpecification>()) { type = CreditCardType.DinersClub; } else if (card.Satisfies<JcbSpecification>()) { type = CreditCardType.Jcb; } return result; }
public ActionResult DeleteCreditCard(CreditCardType type) { Exigo.DeleteCustomerCreditCard(Identity.Customer.CustomerID, type); return RedirectToAction("PaymentMethods"); }
public ActionResult ManageCreditCard(CreditCardType type) { var model = Exigo.GetCustomerPaymentMethods(Identity.Customer.CustomerID) .Where(c => c is CreditCard && ((CreditCard)c).Type == type) .FirstOrDefault(); // Clear out the card number ((CreditCard)model).CardNumber = ""; return View("ManageCreditCard", model); }