private AddPaymentTransactionResult SubmitNewTransaction(AddPaymentTransactionParameter parameter) { Customer billTo1; Customer shipTo1; if (parameter.IsAdmin) { ICustomerRepository typedRepository = this.UnitOfWork.GetTypedRepository <ICustomerRepository>(); if (!parameter.BillToId.HasValue) { return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.NotFound, "BillToId is empty")); } Guid?nullable = parameter.ShipToId; if (!nullable.HasValue) { return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.NotFound, "ShipToId is empty")); } ICustomerRepository customerRepository1 = typedRepository; nullable = parameter.BillToId; Guid id1 = nullable.Value; billTo1 = customerRepository1.Get(id1); ICustomerRepository customerRepository2 = typedRepository; nullable = parameter.ShipToId; Guid id2 = nullable.Value; shipTo1 = customerRepository2.Get(id2); } else { GetBillToResult billTo2 = this.GetBillTo(parameter.BillToId); if (billTo2.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(billTo2.SubCode, billTo2.Message)); } billTo1 = billTo2.BillTo; GetShipToResult shipTo2 = this.GetShipTo(parameter.BillToId, parameter.ShipToId); if (shipTo2.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(shipTo2.SubCode, shipTo2.Message)); } shipTo1 = shipTo2.ShipTo; } SubmitTransactionParameter transactionParameter = new SubmitTransactionParameter() { TransactionType = parameter.TransactionType, CustomerNumber = billTo1.CustomerNumber, ReferenceNumber = parameter.ReferenceNumber, CurrencyCode = parameter.CurrencyCode, BillToAddress = CreateCreditCardAddress(billTo1, parameter.CreditCard), ShipToAddress = CreateCreditCardAddress(shipTo1, (CreditCardDto)null), PaymentProfileId = parameter.PaymentProfileId, CreditCard = parameter.CreditCard, Amount = parameter.Amount, WebsiteId = parameter.WebsiteId }; if (!parameter.PaymentProfileId.IsBlank()) { UserProfile userProfile = this.UnitOfWork.GetRepository <UserProfile>().Get(SiteContext.Current.UserProfileDto.Id); transactionParameter.CustomerProfileId = userProfile.GetProperty("StoredCustomerProfileId", string.Empty); } CreditCardTransaction creditCardTransaction = this.CreateCreditCardTransaction(transactionParameter); transactionParameter.CreditCardTransactionId = new Guid?(creditCardTransaction.Id); SubmitTransactionResult submitTransactionResult = (parameter.CreditCard.CardType == "PayPal" ? this.paymentGatewayFactory.GetPaymentGateway("PaypalExpress") : this.GetPaymentGateway()).SubmitTransaction(transactionParameter); if (submitTransactionResult.ResponseMessages.Count > 0) { LogHelper.For(this).Error(transactionParameter.CustomerNumber + submitTransactionResult.ResponseMessages.FirstOrDefault() + submitTransactionResult.Success, "CenposResponse"); } if (!submitTransactionResult.Success) { this.UnitOfWork.RollbackTransaction(); this.UnitOfWork.Clear(true); this.UnitOfWork.BeginTransaction(); this.ResetContext(); this.UpdateCreditCardTransaction(creditCardTransaction, transactionParameter, submitTransactionResult); if (submitTransactionResult.IsConnectionError) { this.SubmitReversalTransaction(transactionParameter, submitTransactionResult); } return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.CreditCardFailed, string.Join(Environment.NewLine, (IEnumerable <string>)submitTransactionResult.ResponseMessages))); } return(new AddPaymentTransactionResult() { CreditCardTransaction = this.UpdateCreditCardTransaction(creditCardTransaction, transactionParameter, submitTransactionResult) }); }
public override GetCartResult Execute(IUnitOfWork unitOfWork, GetCartParameter parameter, GetCartResult result) { if (!parameter.CartId.HasValue) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } UserProfileDto userProfile = SiteContext.Current.UserProfileDto ?? SiteContext.Current.RememberedUserProfileDto; if (userProfile == null) { return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } if (!result.Cart.PlacedByUserName.IsBlank() && result.Cart.PlacedByUserName.Equals(userProfile.UserName)) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } Guid?nullable = result.Cart.PlacedByUserProfileId; if (!result.Cart.Status.EqualsIgnoreCase("Return Requested")) { if (!nullable.HasValue) { return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } nullable = result.Cart.PlacedByUserProfileId; if (nullable.Equals((object)userProfile.Id)) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } nullable = result.Cart.PlacedByUserProfile.ApproverUserProfileId; if (nullable.HasValue) { nullable = result.Cart.PlacedByUserProfile.ApproverUserProfileId; if (nullable.Equals((object)userProfile.Id)) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } } } if ((result.Cart.Status.EqualsIgnoreCase("AwaitingApproval") || result.Cart.Status.EqualsIgnoreCase("Submitted")) && this.authenticationService.IsUserInRole(userProfile.UserName, "Administrator")) { if (!result.Cart.Customer.UserProfiles.Any <UserProfile>((Func <UserProfile, bool>)(up => up.Id.Equals(userProfile.Id)))) { return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } ICustomerService customerService = this.customerService.Value; GetShipToCollectionParameter parameter1 = new GetShipToCollectionParameter(); parameter1.BillToId = new Guid?(result.Cart.Customer.Id); parameter1.AssignedOnly = true; parameter1.ExcludeBillTo = true; parameter1.ExcludeShowAll = true; parameter1.Page = new int?(1); parameter1.PageSize = new int?(1); GetShipToCollectionResult shipToCollection = customerService.GetShipToCollection(parameter1); if (shipToCollection.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <GetCartResult>(result, shipToCollection.SubCode, shipToCollection.Message)); } if (shipToCollection.TotalCount == 0) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } GetShipToResult shipTo = this.customerService.Value.GetShipTo(new GetShipToParameter() { BillToId = new Guid?(result.Cart.Customer.Id), ShipToId = new Guid?(result.Cart.ShipTo.Id) }); if (shipTo.ResultCode == ResultCode.Success) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } if (shipTo.SubCode != SubCode.NotFound) { return(this.CreateErrorServiceResult <GetCartResult>(result, shipTo.SubCode, shipTo.Message)); } return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } // BUSA-463 : To allow other user see subscription order. // Added "Retur Requested" condition for RMA. if (result.Cart.Status.EqualsIgnoreCase("SubscriptionOrder") || result.Cart.Status.EqualsIgnoreCase("Return Requested")) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } if (result.Cart.Type == "Order") { return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } nullable = (Guid?)result.Cart.Salesperson?.UserProfileId; Guid id1 = userProfile.Id; if ((nullable.HasValue ? (nullable.HasValue ? (nullable.GetValueOrDefault() != id1 ? 1 : 0) : 0) : 1) != 0) { nullable = (Guid?)result.Cart.Salesperson?.SalesManager?.UserProfileId; Guid id2 = userProfile.Id; if ((nullable.HasValue ? (nullable.HasValue ? (nullable.GetValueOrDefault() != id2 ? 1 : 0) : 0) : 1) != 0) { return(this.CreateErrorServiceResult <GetCartResult>(result, SubCode.Forbidden, MessageProvider.Current.Forbidden)); } } return(this.NextHandler.Execute(unitOfWork, parameter, result)); }