protected UpdateCartResult ProcessCreditCardTransaction(IUnitOfWork unitOfWork, CustomerOrder cart, UpdateCartParameter parameter, UpdateCartResult result) { AddPaymentTransactionParameter parameter1 = new AddPaymentTransactionParameter(); if (parameter.Properties.Count() > 0 && parameter.Properties.ContainsKey("AddNewCard") && parameter.Status.EqualsIgnoreCase("SaveNewCard")) { parameter1.ReferenceNumber = string.Empty; parameter1.Amount = 0; CurrencyDto currency = SiteContext.Current.CurrencyDto; string str = (currency != null ? currency.CurrencyCode : (string)null) ?? string.Empty; parameter1.CurrencyCode = str; } parameter1.TransactionType = this.paymentSettings.SubmitSaleTransaction ? TransactionType.Sale : TransactionType.Authorization; parameter1.CreditCard = parameter.CreditCard; string paymentProfileId = parameter.PaymentProfileId; parameter1.PaymentProfileId = paymentProfileId; AddPaymentTransactionResult transactionResult = this.paymentService.Value.AddPaymentTransaction(parameter1); if (transactionResult.CreditCardTransaction != null) { if (parameter.Properties.Count() > 0 && parameter.Properties.ContainsKey("AddNewCard")) { transactionResult.CreditCardTransaction.CustomerOrderId = null; } else { transactionResult.CreditCardTransaction.CustomerOrderId = new Guid?(cart.Id); } } if (transactionResult.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <UpdateCartResult>(result, transactionResult.SubCode, transactionResult.Message)); } if (parameter.StorePaymentProfile) { if (parameter.Properties.Count() > 0 && parameter.Properties.ContainsKey("AddNewCard")) { this.paymentService.Value.AddPaymentProfile(new AddPaymentProfileParameter() { CurrencyCode = parameter1.CurrencyCode, BillToId = SiteContext.Current.BillTo.Id, CreditCard = parameter.CreditCard }); } else { this.paymentService.Value.AddPaymentProfile(new AddPaymentProfileParameter() { CurrencyCode = cart.Currency.CurrencyCode, BillToId = new Guid?(cart.Customer.Id), CreditCard = parameter.CreditCard }); } } return(result); }
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)); } }