Exemple #1
0
        private AddPaymentTransactionResult SubmitReferenceTransaction(AddPaymentTransactionParameter parameter)
        {
            if (parameter.OriginalRequestNumber.IsBlank() || parameter.OriginalRequestToken.IsBlank())
            {
                return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.CreditCardFailed, "Original Request Number and Original Reference Number required"));
            }
            SubmitTransactionParameter transactionParameter = new SubmitTransactionParameter()
            {
                TransactionType       = parameter.TransactionType,
                ReferenceNumber       = parameter.ReferenceNumber,
                OriginalRequestNumber = parameter.OriginalRequestNumber,
                OriginalRequestToken  = parameter.OriginalRequestToken,
                Amount    = parameter.Amount,
                WebsiteId = parameter.WebsiteId
            };
            CreditCardTransaction creditCardTransaction = this.CreateCreditCardTransaction(transactionParameter);

            transactionParameter.CreditCardTransactionId = new Guid?(creditCardTransaction.Id);
            SubmitTransactionResult submitTransactionResult = this.GetPaymentGateway().SubmitTransaction(transactionParameter);

            if (!submitTransactionResult.Success)
            {
                this.UpdateCreditCardTransaction(creditCardTransaction, transactionParameter, submitTransactionResult);
                if (submitTransactionResult.IsConnectionError)
                {
                    return(this.ResendTransaction(transactionParameter));
                }
                return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.CreditCardFailed, string.Join(Environment.NewLine, (IEnumerable <string>)submitTransactionResult.ResponseMessages)));
            }
            return(new AddPaymentTransactionResult()
            {
                CreditCardTransaction = this.UpdateCreditCardTransaction(creditCardTransaction, transactionParameter, submitTransactionResult)
            });
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public AddPaymentTransactionResult AddPaymentTransaction(AddPaymentTransactionParameter parameter)
 {
     if (SiteContext.Current.UserProfileDto == null)
     {
         return(this.CreateErrorServiceResult <AddPaymentTransactionResult>(SubCode.Forbidden, MessageProvider.Current.Forbidden));
     }
     if (parameter.TransactionType != TransactionType.Authorization && parameter.TransactionType != TransactionType.Sale && parameter.TransactionType != TransactionType.Capture)
     {
         return(this.SubmitReferenceTransaction(parameter));
     }
     return(this.SubmitNewTransaction(parameter));
 }
        protected UpdateCartResult ProcessInvoiceCredit(IUnitOfWork unitOfWork, CustomerOrder cart, UpdateCartParameter parameter, UpdateCartResult result)
        {
            string  orderTotalDue = "0";
            string  invoiceNumber = string.Empty;
            decimal Amount        = 0;

            culture = CultureInfo.CreateSpecificCulture("en-US");
            AddPaymentTransactionParameter parameter1 = new AddPaymentTransactionParameter();

            parameter.Properties.TryGetValue("creditAmount", out orderTotalDue);
            parameter.Properties.TryGetValue("creditInvoiceList", out invoiceNumber);
            invoiceList = JsonConvert.DeserializeObject <List <InvoiceList> >(invoiceNumber);

            if (parameter.Properties.Count() > 0 && parameter.Properties.ContainsKey("creditAmount"))
            {
                //BUSA-1152
                Amount = Math.Round(Convert.ToDecimal(orderTotalDue, culture), 2);
                if (Amount <= 0)
                {
                    return(this.CreateErrorServiceResult <UpdateCartResult>(result, SubCode.Forbidden, "The amount should be greater than zero"));
                }
            }

            try
            {
                var response = PostCreditToInfor(Amount, invoiceNumber);
                if (!response)
                {
                    return(this.CreateErrorServiceResult <UpdateCartResult>(result, SubCode.GetPaymentProfileFailed, "Your invoice payment failed"));
                }
            }
            catch (Exception ex)
            {
                return(this.CreateErrorServiceResult <UpdateCartResult>(result, SubCode.GeneralFailure, "Your invoice payment failed" + ex));
            }
            finally
            {
                unitOfWork.Save();
            }

            return(result);
        }
Exemple #5
0
        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)
            });
        }
Exemple #6
0
        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));
                }
            }