public RemovePaymentProfileResult RemovePaymentProfile(RemovePaymentProfileParameter parameter) { UserProfileDto userProfileDto = SiteContext.Current.UserProfileDto; UserProfile userProfile = this.UnitOfWork.GetRepository <UserProfile>().Get(SiteContext.Current.UserProfileDto.Id); if (userProfile == null) { return(this.CreateErrorServiceResult <RemovePaymentProfileResult>(SubCode.Forbidden, MessageProvider.Current.Forbidden)); } GetBillToResult billToResult = this.GetBillTo(parameter.BillToId); if (billToResult.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <RemovePaymentProfileResult>(billToResult.SubCode, billToResult.Message)); } Customer billTo = billToResult.BillTo; RemoveStoredPaymentProfileResult removeStoredPaymentProfileResult = this.GetPaymentGateway().RemoveStoredPaymentProfile(new RemoveStoredPaymentProfileParameter() { CustomerProfileId = userProfile.GetProperty("StoredCustomerProfileId", string.Empty), PaymentProfileId = parameter.PaymentProfileId, CustomerNumber = billTo.CustomerNumber }); if (!removeStoredPaymentProfileResult.Success) { return(this.CreateErrorServiceResult <RemovePaymentProfileResult>(SubCode.StorePaymentProfileFailed, string.Join(Environment.NewLine, removeStoredPaymentProfileResult.ResponseMessages))); } UserPaymentProfile userPaymentProfile = userProfile.UserPaymentProfiles.FirstOrDefault <UserPaymentProfile>((UserPaymentProfile u) => u.CardIdentifier.Equals(parameter.PaymentProfileId)); if (userPaymentProfile != null) { this.RemoveUserPaymentProfile(userProfile, userPaymentProfile); } return(new RemovePaymentProfileResult()); }
public override UpdateCartResult Execute(IUnitOfWork unitOfWork, UpdateCartParameter parameter, UpdateCartResult result) { if (!parameter.Status.EqualsIgnoreCase("Submitted")) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } if (parameter.PaymentProfileId != null) { UserPaymentProfile userPaymentProfile = unitOfWork.GetRepository <UserPaymentProfile>().GetTable().FirstOrDefault(p => p.CardIdentifier == parameter.PaymentProfileId); if (userPaymentProfile != null) { CreditCardDto cc = new CreditCardDto(); cc.CardNumber = userPaymentProfile.MaskedCardNumber; cc.CardType = userPaymentProfile.CardType; if (!string.IsNullOrEmpty(userPaymentProfile.ExpirationDate)) { cc.ExpirationMonth = Convert.ToInt32(userPaymentProfile.ExpirationDate.Substring(0, 2)); cc.ExpirationYear = Convert.ToInt32(userPaymentProfile.ExpirationDate.Substring(2, 2)); } parameter.CreditCard = cc; } } return(this.NextHandler.Execute(unitOfWork, parameter, result)); }
protected void AddUserPaymentProfile(UserProfile userProfile, UserPaymentProfile value) { UserProfile userProfileToUpdate = null; if (userProfile.Id != Guid.Empty) { userProfileToUpdate = this.UnitOfWork.GetTypedRepository <IUserProfileRepository>().GetTable().Expand <UserProfile, ICollection <UserPaymentProfile> >((UserProfile x) => x.UserPaymentProfiles).FirstOrDefault <UserProfile>((UserProfile x) => x.Id == userProfile.Id); } if (userProfileToUpdate == null) { userProfileToUpdate = userProfile; userProfileToUpdate.Id = Guid.Empty; } if (userProfileToUpdate.UserPaymentProfiles.Any <UserPaymentProfile>((UserPaymentProfile x) => x.Id == value.Id)) { return; } if (userProfileToUpdate.UserPaymentProfiles.Any <UserPaymentProfile>((UserPaymentProfile x) => x.CardIdentifier == value.CardIdentifier)) { return; } value.UserProfile = userProfileToUpdate; userProfileToUpdate.UserPaymentProfiles.Add(value); if (userProfileToUpdate.Id != Guid.Empty) { this.UnitOfWork.GetRepository <UserPaymentProfile>().Insert(value); } }
public override PatchUserPaymentProfileResult Execute(IUnitOfWork unitOfWork, PatchUserPaymentProfileParameter parameter, PatchUserPaymentProfileResult result) { IRepository <UserPaymentProfile> repository = unitOfWork.GetRepository <UserPaymentProfile>(); UserPaymentProfile updated = repository.Get(parameter.Id); updated.ExpirationDate = parameter.ExpirationDate; unitOfWork.Save(); ModifyRecurringSaleInformationRequest request = new ModifyRecurringSaleInformationRequest { UserId = this.UserId, Password = this.Password, MerchantId = this.MerchantId, RecurringSaleTokenIdToModify = parameter.CardIdentifier, CardExpirationDate = parameter.ExpirationDate, CustomerCode = SiteContext.Current.BillTo.CustomerNumber }; ModifyRecurringSaleInformationResponse modifyRecurringSaleInformationResponse = new AdministrationClient().ModifyRecurringSaleInformation(request); //BUSA-1122 Cenpos call to modify existing stored payment profile if (modifyRecurringSaleInformationResponse.Result == 0) { return(result); } else { return(this.CreateErrorServiceResult <PatchUserPaymentProfileResult>(result, SubCode.GeneralFailure, "Error occured while processing the card")); } }
public PaymentForm Create(UserPaymentProfile profile, Account account, PaymentTemplate template) { Argument.NotNull(profile, "profile"); Argument.NotNull(account, "account"); Argument.NotNull(template, "template"); var form = new JObject { { "payerTin", new JValue(profile.PayerTIN) }, { "payerName", new JValue(profile.PayerName) }, { "payerBankCode", new JValue(_bankSettings.VaBankCode) }, { "payerAccountNo", new JValue(account.AccountNo) } }; var fields = template.OrderTemplate.EnumerateNotTemplatedFields().ToList(); foreach (var field in fields) { form.Add(field.Key, new JValue(field.Value)); } return(new PaymentForm(form)); }
public override RemoveUserPaymentProfileResult Execute(IUnitOfWork unitOfWork, RemoveUserPaymentProfileParameter parameter, RemoveUserPaymentProfileResult result) { IRepository <UserPaymentProfile> repository = unitOfWork.GetRepository <UserPaymentProfile>(); string userPaymentProfileId = parameter.UserPaymentProfileId; UserPaymentProfile deleted = repository.Get(userPaymentProfileId); //BUSA-463 Subscription: Restrict to delete CC if its saved in Subscription Order var subscription = from sb in unitOfWork.GetRepository <SubscriptionBrasseler>().GetTable() join co in unitOfWork.GetRepository <CustomerOrder>().GetTable() on sb.ParentCustomerOrderId equals co.Id where co.Status != "SubscriptionCancelled" && sb.PaymentMethod == deleted.Id.ToString() && sb.CustomerOrderId == sb.ParentCustomerOrderId select sb; if (subscription.Count() > 0) { return(this.CreateErrorServiceResult <RemoveUserPaymentProfileResult>(result, SubCode.NotFound, MessageProvider.Current.Forbidden)); } this.RemoveStoredPaymentProfile(deleted.CardIdentifier); //BUSA-462 : Ability to save Credit Cards (in CenPos) and offer it to users repository.Delete(deleted); return(result); }
public UserPaymentProfile Create(User user, string address, string fullName) { Argument.NotNull(user, "user"); Argument.NotEmpty(address, "address"); Argument.NotEmpty(fullName, "fullName"); var payerTIN = Randomizer.NumericString(9); while (true) { var tin = payerTIN; var query = DbQuery.For <UserPaymentProfile>().FilterBy(x => x.PayerTIN == tin); if (_paymentProfileRepository.QueryOne(query) == null) { break; } payerTIN = Randomizer.NumericString(9); } var profile = new UserPaymentProfile(user, fullName, payerTIN, address); return(profile); }
private RemovePaymentProfileResult RemoveUserPaymentProfile(UserProfile userProfile, UserPaymentProfile value) { UserProfile userProfile1 = this.UnitOfWork.GetTypedRepository <IUserProfileRepository>().GetTable().Expand <UserProfile, ICollection <UserPaymentProfile> >(x => x.UserPaymentProfiles).FirstOrDefault <UserProfile>(x => x.Id == userProfile.Id); if (userProfile1 == null) { return(this.CreateErrorServiceResult <RemovePaymentProfileResult>(SubCode.NotFound, string.Format(MessageProvider.Current.Not_Found, (object)"UserProfile"))); } if (userProfile1.UserPaymentProfiles.All <UserPaymentProfile>(x => x.Id != value.Id)) { return(new RemovePaymentProfileResult()); } userProfile1.UserPaymentProfiles.Remove(userProfile1.UserPaymentProfiles.First <UserPaymentProfile>((Func <UserPaymentProfile, bool>)(x => x.Id == value.Id))); return(new RemovePaymentProfileResult()); }
protected UpdateCartResult ProcessInvoicePayment(IUnitOfWork unitOfWork, CustomerOrder cart, UpdateCartParameter parameter, UpdateCartResult result) { string orderTotalDue = "0"; string invoiceNumber = string.Empty; AddPaymentTransactionParameter parameter1 = new AddPaymentTransactionParameter(); parameter.Properties.TryGetValue("payAmount", out orderTotalDue); parameter.Properties.TryGetValue("invoiceList", out invoiceNumber); invoiceList = JsonConvert.DeserializeObject <List <InvoiceList> >(invoiceNumber); culture = CultureInfo.CreateSpecificCulture("en-US"); if (parameter.Properties.Count() > 0 && parameter.Properties.ContainsKey("payAmount")) { if (!invoiceList.Any()) { parameter1.ReferenceNumber = "OBAL"; } else if (invoiceList.Count == 1) { parameter1.ReferenceNumber = invoiceList.FirstOrDefault().InvoiceNo; } else { parameter1.ReferenceNumber = "INV" + "-" + invoiceList.FirstOrDefault().InvoiceNo; } //BUSA-1144 : Creating US culture as amount is not coming as "," separated from UI for french. parameter1.Amount = Math.Round(Convert.ToDecimal(orderTotalDue, culture), 2); if (parameter1.Amount <= 0) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, SubCode.Forbidden, "The amount should be greater than zero")); } CurrencyDto currency = SiteContext.Current.CurrencyDto; string str = (currency != null ? currency.CurrencyCode : (string)null) ?? string.Empty; parameter1.CurrencyCode = str; } parameter1.CreditCard = parameter.CreditCard; if (parameter.PaymentProfileId != null) { parameter1.PaymentProfileId = parameter.PaymentProfileId; UserPaymentProfile userPaymentProfile = unitOfWork.GetRepository <UserPaymentProfile>().GetTable().FirstOrDefault(p => p.CardIdentifier == parameter.PaymentProfileId); if (userPaymentProfile != null) { CreditCardDto cc = new CreditCardDto(); cc.CardNumber = userPaymentProfile.MaskedCardNumber; cc.CardType = userPaymentProfile.CardType; if (!string.IsNullOrEmpty(userPaymentProfile.ExpirationDate)) { cc.ExpirationMonth = Convert.ToInt32(userPaymentProfile.ExpirationDate.Substring(0, 2)); cc.ExpirationYear = Convert.ToInt32(userPaymentProfile.ExpirationDate.Substring(2, 2)); } parameter1.CreditCard = cc; } } parameter1.TransactionType = TransactionType.Capture; if (parameter.StorePaymentProfile) { transactionResult = this.paymentService.Value.AddPaymentTransaction(parameter1); if (transactionResult.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, transactionResult.SubCode, "The card transaction was declined. Please contact our customer support team.")); } this.paymentService.Value.AddPaymentProfile(new AddPaymentProfileParameter() { CurrencyCode = parameter1.CurrencyCode, BillToId = SiteContext.Current.BillTo.Id, CreditCard = parameter.CreditCard }); } else { //payment with saved card //if (parameter1.PaymentProfileId == null || parameter1.PaymentProfileId == "") //{ // parameter1.TransactionType = TransactionType.Sale; //only payment with new card. //} parameter1.TransactionType = TransactionType.Sale; transactionResult = this.paymentService.Value.AddPaymentTransaction(parameter1); if (transactionResult.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, transactionResult.SubCode, "The card transaction was declined. Please contact our customer support team.")); } } if (transactionResult.CreditCardTransaction != null) { transactionResult.CreditCardTransaction.CustomerOrderId = null; } if (result.ResultCode != ResultCode.Success) { return(result); } else { try { var response = PostPaymentToInfor(transactionResult, parameter1, invoiceNumber); if (!response) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, transactionResult.SubCode, "Your invoice payment failed")); } } catch (Exception ex) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, transactionResult.SubCode, "Your invoice payment failed" + ex)); } }
protected void ConvertCartToSubscriptionOrder(IUnitOfWork unitOfWork, CustomerOrder subscriptionOrder, UpdateCartParameter parameter, UpdateCartResult result) { SubscriptionBrasseler subscriptionBrasseler = new SubscriptionBrasseler(); subscriptionBrasseler.CustomerOrderId = subscriptionOrder.Id; subscriptionBrasseler.ActivationDate = subscriptionOrder.OrderDate; subscriptionBrasseler.DeActivationDate = DateTimeOffset.Parse(subscriptionOrder.OrderDate.AddYears(5).ToString()); subscriptionBrasseler.ParentCustomerOrderId = subscriptionOrder.Id;// BUSA-759 : SS- Unable to identify the parent order ID when user places multiple smart supply orders //save subscriptionOrder payment Method Starts if (parameter.TermsCode.EqualsIgnoreCase("CK")) { subscriptionBrasseler.PaymentMethod = "CK"; subscriptionOrder.TermsCode = "CK"; } else if (parameter.IsPaymentProfile && !string.IsNullOrEmpty(parameter.PaymentProfileId)) { UserPaymentProfile userPaymentProfile = unitOfWork.GetRepository <UserPaymentProfile>().GetTable().FirstOrDefault(p => p.CardIdentifier == parameter.PaymentProfileId); if (userPaymentProfile != null) { subscriptionBrasseler.PaymentMethod = userPaymentProfile.Id.ToString(); subscriptionOrder.TermsCode = "CC"; } } subscriptionOrder.ShippingCalculationNeededAsOf = (DateTimeOffset)DateTimeProvider.Current.Now; subscriptionOrder.RecalculateTax = true; this.PromotionEngine.Value.ClearPromotions(subscriptionOrder); subscriptionOrder.RecalculatePromotions = true; this.PricingPipeline.GetCartPricing(new Insite.Core.Plugins.Pipelines.Pricing.Parameters.GetCartPricingParameter(subscriptionOrder)); //this.CartHelper.Value.RecalculateCart(unitOfWork, subscriptionOrder, (OrderLine)null, true); if (subscriptionOrder.CustomProperties.Where(x => x.Name == "subscriptionFrequencyOpted").Count() > 0) { var Frequency = subscriptionOrder.CustomProperties.FirstOrDefault(x => x.Name == "subscriptionFrequencyOpted").Value; subscriptionBrasseler.Frequency = int.Parse(Frequency); //BUSA-781 logic to calculate next ship date when user selects date from calendar var isNextShipDate = subscriptionOrder.CustomProperties.FirstOrDefault(x => x.Name == "checkoutNextShipDate")?.Value; if (!string.IsNullOrEmpty(isNextShipDate)) { subscriptionBrasseler.NextDelieveryDate = new DateTimeOffset(Convert.ToDateTime(isNextShipDate), TimeSpan.Zero); } else { //subscriptionBrasseler.NextDelieveryDate = new DateTimeOffset(DateTimeProvider.Current.Now.AddDays(double.Parse(Frequency)), TimeSpan.Zero); kkk subscriptionBrasseler.NextDelieveryDate = (DateTimeOffset)DateTimeProvider.Current.Now.AddDays(double.Parse(Frequency)); //(DateTimeOffset.Now.AddDays(double.Parse(Frequency))); } //BUSA-781 end } if (subscriptionBrasseler != null) { unitOfWork.GetRepository <SubscriptionBrasseler>().Insert(subscriptionBrasseler); } CustomerOrder cart = result.GetCartResult.Cart; this.SetCustomerOrderNumber(unitOfWork, cart); SendSubscriptionCreationEmail(unitOfWork, subscriptionOrder); }
protected void CreateSubscriptionOrderLine(IUnitOfWork unitOfWork, CustomerOrder cart, UpdateCartParameter parameter, UpdateCartResult result) { if (cart == null || cart.OrderLines.Count <= 0) { return; } CustomerOrder subscriptionOrder = this.CreateSubscriptionOrder(unitOfWork, cart); SubscriptionBrasseler subscriptionBrasseler = new SubscriptionBrasseler(); subscriptionBrasseler.CustomerOrderId = subscriptionOrder.Id; subscriptionBrasseler.ActivationDate = subscriptionOrder.OrderDate; subscriptionBrasseler.DeActivationDate = DateTimeOffset.Parse(subscriptionOrder.OrderDate.AddYears(5).ToString()); subscriptionBrasseler.ParentCustomerOrderId = subscriptionOrder.Id;// BUSA-759 : SS- Unable to identify the parent order ID when user places multiple smart supply orders foreach (var ol in cart.OrderLines) { //BUSA-463 Subscription - Exclude subscription promotional product in susbcription order if (!ol.IsPromotionItem) { var isSubscriptionOpted = ol.GetProperty("IsSubscriptionOpted", "false"); if (!isSubscriptionOpted.EqualsIgnoreCase("true")) { continue; } //save subscriptionOrder payment Method Starts if (parameter.TermsCode.EqualsIgnoreCase("CK")) { subscriptionBrasseler.PaymentMethod = "CK"; subscriptionOrder.TermsCode = "CK"; } else if (parameter.IsPaymentProfile && !string.IsNullOrEmpty(parameter.PaymentProfileId)) { UserPaymentProfile userPaymentProfile = unitOfWork.GetRepository <UserPaymentProfile>().GetTable().FirstOrDefault(p => p.CardIdentifier == parameter.PaymentProfileId); if (userPaymentProfile != null) { subscriptionBrasseler.PaymentMethod = userPaymentProfile.Id.ToString(); subscriptionOrder.TermsCode = "CC"; } } else if (parameter.StorePaymentProfile) { var CCResponse = result.GetCartResult.Cart.CreditCardTransactions.FirstOrDefault(); if (CCResponse != null) { var CCidentifier = CCResponse.PNRef.ToString().Split('|').FirstOrDefault(); var userPaymentProfile = unitOfWork.GetRepository <UserPaymentProfile>().GetTable().FirstOrDefault(x => x.CardIdentifier == CCidentifier); if (userPaymentProfile != null) { subscriptionBrasseler.PaymentMethod = userPaymentProfile.Id.ToString(); } } subscriptionOrder.TermsCode = cart.TermsCode; } //else //{ // subscriptionBrasseler.PaymentMethod = "CK"; //} //save subscriptionOrder payment Method Ends //this.CustomerOrderUtilities.AddOrderLine(subscriptionOrder, this.OrderLineUtilities.Copy(ol)); Insite.Cart.Services.Pipelines.Results.AddCartLineResult addCartLineResult = this.CartPipeline.AddCartLine(new Insite.Cart.Services.Pipelines.Parameters.AddCartLineParameter() { Cart = subscriptionOrder, Product = ol.Product, QtyOrdered = ol.QtyOrdered, UnitOfMeasure = ol.UnitOfMeasure, CostCode = ol.CostCode, Notes = ol.Notes, CustomProperties = ol.CustomProperties.ToList() }); addCartLineResult.CartLine.SmartPart = ol.SmartPart; for (int index = subscriptionOrder.OrderLines.Count - 1; index >= 0; --index) { OrderLine orderLine = subscriptionOrder.OrderLines.ElementAt <OrderLine>(index); if (!this.ProductUtilities.Value.IsQuoteRequired(orderLine.Product) || cart.Status == "QuoteProposed") { this.ProcessInventory(orderLine); } orderLine.PromotionResultId = null; } } } subscriptionOrder.ShippingCalculationNeededAsOf = (DateTimeOffset)DateTimeProvider.Current.Now; subscriptionOrder.RecalculateTax = true; this.PromotionEngine.Value.ClearPromotions(subscriptionOrder); subscriptionOrder.RecalculatePromotions = true; PricingPipeline.GetCartPricing(new GetCartPricingParameter(subscriptionOrder)); //this.CartHelper.Value.RecalculateCart(unitOfWork, subscriptionOrder, (OrderLine)null, true); kkk if (subscriptionOrder.CustomProperties.Where(x => x.Name == "subscriptionFrequencyOpted").Count() > 0) { var Frequency = subscriptionOrder.CustomProperties.FirstOrDefault(x => x.Name == "subscriptionFrequencyOpted").Value; subscriptionBrasseler.Frequency = int.Parse(Frequency); //BUSA-871 : Shipping SS order on future date provided by user //subscriptionBrasseler.NextDelieveryDate = new DateTimeOffset(DateTimeProvider.Current.Now.AddDays(double.Parse(Frequency)), TimeSpan.Zero); subscriptionBrasseler.NextDelieveryDate = (DateTimeOffset.Now.AddDays(double.Parse(Frequency))); } if (subscriptionBrasseler != null) { unitOfWork.GetRepository <SubscriptionBrasseler>().Insert(subscriptionBrasseler); } SendSubscriptionCreationEmail(unitOfWork, subscriptionOrder); }