示例#1
0
        public Payment PreProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            if (!ValidateData())
            {
                return(null);
            }

            var orderAddress = form.Parent.OrderAddresses.FirstOrDefault();

            var payment = new OtherPayment
            {
                PaymentMethodId   = PaymentMethodId,
                PaymentMethodName = "VerifoneHostedPages",
                OrderFormId       = form.OrderFormId,
                OrderGroupId      = form.OrderGroupId,
                Amount            = form.Total,
                Status            = PaymentStatus.Pending.ToString(),
                PaymentType       = PaymentType.Other,
                TransactionType   = TransactionType.Authorization.ToString(),
                BillingAddressId  = form.BillingAddressId,
                CustomerName      = orderAddress != null
                    ? string.Format("{0} {1}", orderAddress.FirstName, orderAddress.LastName)
                    : form.Parent.CustomerName
            };

            return(payment);
        }
示例#2
0
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="form"></param>
        /// <returns>bool</returns>
        public Payment PreProcess(OrderForm form)
        {
            OtherPayment otherPayment = new OtherPayment();

            otherPayment.BillingAddressId = form.BillingAddressId;
            return((Payment)otherPayment);
        }
        public Payment PreProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            if (!ValidateData())
            {
                return(null);
            }

            var payment = new OtherPayment
            {
                PaymentMethodId   = PaymentMethodId,
                PaymentMethodName = "VerifoneHostedPages",
                OrderFormId       = form.OrderFormId,
                OrderGroupId      = form.OrderGroupId,
                Amount            = form.Total,
                Status            = PaymentStatus.Pending.ToString(),
                PaymentType       = PaymentType.Other,
                BillingAddressId  = form.BillingAddressId,
                CustomerName      = form.Name
            };

            return(payment);
        }
示例#4
0
        public void Setup()
        {
            InitializeMocks();
            DbContextMock.ShouldThrowException = false;

            _person = new Person
            {
                Id = 1
            };
            _dbContext.People.Add(_person);

            _otherPayment1 = new OtherPayment
            {
                Id        = 1,
                Value     = 123.45,
                Comment   = "Test",
                CreatedOn = _dateTimeUtil.GetCurrentDateTime(),
                PersonId  = _person.Id
            };

            _otherPayment2 = new OtherPayment
            {
                Id        = 1,
                Value     = 123.45,
                Comment   = "Test",
                CreatedOn = _dateTimeUtil.GetCurrentDateTime().AddMonths(1),
                PersonId  = _person.Id
            };
            _dbContext.OtherPayments.Add(_otherPayment1);
            _dbContext.OtherPayments.Add(_otherPayment2);

            _otherPaymentsRepository = new DAL.Repositories.OtherPaymentsRepository(_dbContext, _dateTimeUtil);
        }
示例#5
0
        public void Setup()
        {
            InitializeMocks();
            InitializeLoggerMock(new OtherPaymentsService(null, null, null));

            _otherPayment1 = new OtherPayment
            {
                Id        = 1,
                CreatedOn = _dateTimeUtil.GetCurrentDateTime(),
                Value     = 10,
                Comment   = "test1",
                PersonId  = 1
            };
            _otherPayment2 = new OtherPayment
            {
                Id        = 2,
                CreatedOn = _dateTimeUtil.GetCurrentDateTime().AddDays(20),
                Value     = 10,
                Comment   = "test2",
                PersonId  = 1
            };
            _dbContext.OtherPayments.Add(_otherPayment1);
            _dbContext.OtherPayments.Add(_otherPayment2);
            _otherPaymentsService = new OtherPaymentsService(_otherPaymentsRepository, _logger, _dateTimeUtil);
        }
示例#6
0
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="form"></param>
        /// <returns>bool</returns>
        public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
        {
            OtherPayment otherPayment = new OtherPayment {
                TransactionType = TransactionType.Authorization.ToString()
            };

            return((Mediachase.Commerce.Orders.Payment)otherPayment);
        }
示例#7
0
        /// <summary>
        /// Creates the other payment.
        /// </summary>
        /// <returns></returns>
        public static Payment CreateOtherPayment()
        {
            OtherPayment payment = new OtherPayment();

            UpdatePaymentMethodInfo(payment);

            payment.Amount = 10;
            return(payment);
        }
示例#8
0
        /// <summary>
        /// 新增其他收支项实体
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool AddOtherPayment(OtherPayment item)
        {
            var obj = DatabaseProvider.Insert(item);

            if (obj != null)
            {
                return(Convert.ToInt32(obj) > 0);
            }
            return(false);
        }
示例#9
0
 private static OtherPaymentData ToRpcModel(OtherPayment otherPayment)
 {
     return(new OtherPaymentData
     {
         Id = otherPayment.Id,
         Comment = otherPayment.Comment,
         CreatedOn = Timestamp.FromDateTime(otherPayment.CreatedOn),
         PersonId = otherPayment.PersonId,
         Value = otherPayment.Value
     });
 }
示例#10
0
        public IPayment CreatePayment(decimal amount, IOrderGroup orderGroup)
        {
            var payment = new OtherPayment
            {
                PaymentMethodId   = _paymentMethod.PaymentMethodId,
                PaymentMethodName = _paymentMethod.Name,
                Amount            = amount,
                Status            = PaymentStatus.Pending.ToString(),
                TransactionType   = TransactionType.Authorization.ToString()
            };

            return(payment);
        }
示例#11
0
        public void AddSecondPaymentToOrder(ICart cart)
        {
            // ToDo: get the first payment added
            IPayment oldPayment = cart.GetFirstForm().Payments.First();

            // ToDo: Add a second payment
            OtherPayment giftCardPayment = null;

            this.TheGiftCard = GetTheGiftCard();

            oldPayment.Amount = oldPayment.Amount - decimal.Parse(this.TheGiftCard["Balance"].ToString());
            //decimal d = (decimal)this.theGiftCard["Balance"];

            // Add "GiftCard" payment to the Cart
            giftCardPayment = new OtherPayment
            {
                // this and balance management (at the end) can be improved with more creative logic
                Amount = decimal.Parse(this.TheGiftCard["Balance"].ToString()),

                // Note: the below payment method doesn´t exist, we do like this for lab/demo
                PaymentMethodName = "GiftCard"
            };

            // Comment: we should have a "true" payment type (and method), gets an eror with an empty/not stored Guid
            // Could transform the GiftCard to a "true" payment ...in the same way as "PayMe" or the demo/exercise in 2840
            // So, we´re cheating... "borrowing" a payment guid (saves time, but would like to have a "real type" & a guid)
            PaymentMethodDto payDto = PaymentManager.GetPaymentMethodBySystemName
                                          ("Generic", ContentLanguage.PreferredCulture.Name);

            giftCardPayment.PaymentMethodId = payDto.PaymentMethod[0].PaymentMethodId;
            // ...allmost okay for this demo/lab

            giftCardPayment.TransactionType = TransactionType.Sale.ToString();

            // could wrap a lot of what´s done here in a transaction scope...
            cart.GetFirstForm().Payments.Add(giftCardPayment);

            // ToDo: Maybe add identification of the card in the Order

            // Can have more finesse here, the exercise just buys for more than the card balance...
            // Reset and deactivate the giftcard if it´s now empty (in the exercise it is)
            this.TheGiftCard["IsActive"] = false;
            this.TheGiftCard["Balance"]  = 0M;

            // persist the card new details
            BusinessManager.Update(this.TheGiftCard);

            giftCardPayment.Status = PaymentStatus.Processed.ToString();
        }
示例#12
0
        public T CreateCreditPayment <T>(OrderForm returnForm, OrderGroup order, Guid paymentMethodId) where T : OtherPayment
        {
            OtherPayment otherPayment = new OtherPayment
            {
                PaymentMethodId   = paymentMethodId,
                PaymentMethodName = ((PaymentMethodDto.PaymentMethodRow)PaymentManager.GetPaymentMethod(paymentMethodId).PaymentMethod.Rows[0]).Name,
                BillingAddressId  = returnForm.BillingAddressId,
                TransactionType   = TransactionType.Credit.ToString(),
                Amount            = returnForm.Total
            };

            returnForm.Payments.Add(otherPayment);

            return((T)otherPayment);
        }
示例#13
0
        public virtual async Task <int> DeleteAsync(OtherPayment otherPayment)
        {
            if (otherPayment is null)
            {
                throw new NullReferenceException("Other payment cannot be empty");
            }
            DateTime currentDate  = _dateTimeUtil.GetCurrentDateTime();
            DateTime currentMonth = new DateTime(currentDate.Year, currentDate.Month + 1, 1);

            if (otherPayment.CreatedOn < currentMonth)
            {
                throw new InvalidOperationException("Cannot delete history record");
            }
            _context.OtherPayments.Remove(otherPayment);
            return(await _context.SaveChangesAsync());
        }
示例#14
0
        public void AddAsync_should_add_other_payment_to_db()
        {
            // Arrange
            OtherPayment otherPayment = new()
            {
                Value     = 10,
                Comment   = "Test",
                CreatedOn = _dateTimeUtil.GetCurrentDateTime(),
                PersonId  = _person.Id
            };

            // Act
            int          result = _otherPaymentsRepository.AddAsync(otherPayment).Result;
            OtherPayment actual = _dbContext.OtherPayments.FirstOrDefault(e => e.Id == otherPayment.Id);

            // Assert
            Assert.AreEqual(otherPayment, actual, "Other payment added succesfully");
            _dbContextMock.Verify(a => a.SaveChangesAsync(true, new CancellationToken()), Times.Once);
        }
        public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            var payment = new OtherPayment
            {
                PaymentMethodId = PaymentMethodId,
                PaymentMethodName = "CashOnDelivery",
                OrderFormId = form.OrderFormId,
                OrderGroupId = form.OrderGroupId,
                Amount = form.Total,
                Status = PaymentStatus.Pending.ToString(),
                TransactionType = TransactionType.Authorization.ToString()
            };

            return payment;
        }
        public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            var payment = new OtherPayment
            {
                PaymentMethodId   = PaymentMethodId,
                PaymentMethodName = "CashOnDelivery",
                OrderFormId       = form.OrderFormId,
                OrderGroupId      = form.OrderGroupId,
                Amount            = form.Total,
                Status            = PaymentStatus.Pending.ToString(),
                TransactionType   = TransactionType.Authorization.ToString()
            };

            return(payment);
        }
示例#17
0
 private static void ValidateData(OtherPayment otherPayment)
 {
     if (otherPayment is null)
     {
         throw new NullReferenceException("Other payment data cannot be empty");
     }
     if (otherPayment.Value == 0)
     {
         throw new ArgumentException("Summ of payment cannot be equal to zero");
     }
     if (string.IsNullOrWhiteSpace(otherPayment.Comment))
     {
         throw new ArgumentException("Comment cannot be empty");
     }
     if (otherPayment.CreatedOn == DateTime.MinValue)
     {
         throw new ArgumentException("Date of payment must be specified");
     }
     if (otherPayment.PersonId == 0)
     {
         throw new ArgumentException("Person identifier cannot be empty");
     }
 }
示例#18
0
 public virtual async Task <int> UpdateAsync(OtherPayment otherPayment)
 {
     ValidateData(otherPayment);
     _context.OtherPayments.Update(otherPayment);
     return(await _context.SaveChangesAsync());
 }
示例#19
0
        /// <summary>
        /// 修改其他收支项实体
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool UpdateOtherPayment(OtherPayment item)
        {
            var obj = DatabaseProvider.Update(item);

            return(Convert.ToInt32(obj) > 0);
        }
示例#20
0
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="form"></param>
        /// <returns>bool</returns>
        public Payment PreProcess(OrderForm form)
        {
            OtherPayment otherPayment = new OtherPayment();

            return((Payment)otherPayment);
        }
 /// <summary>
 /// This method is called before the order is completed. This method should check all the parameters
 /// and validate the credit card or other parameters accepted.
 /// </summary>
 /// <param name="form"></param>
 /// <returns>bool</returns>
 public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
 {
     OtherPayment otherPayment = new OtherPayment { TransactionType = TransactionType.Authorization.ToString() };
     return (Mediachase.Commerce.Orders.Payment)otherPayment;
 }
 /// <summary>
 /// This method is called before the order is completed. This method should check all the parameters
 /// and validate the credit card or other parameters accepted.
 /// </summary>
 /// <param name="form"></param>
 /// <returns>bool</returns>
 public Payment PreProcess(OrderForm form)
 {
     OtherPayment otherPayment = new OtherPayment();
     otherPayment.BillingAddressId = form.BillingAddressId;
     return (Payment)otherPayment;
 }
示例#23
0
        /// <summary>
        /// Paypal IPN callback
        /// </summary>
        /// <param name="token"></param>
        /// <param name="payerId"></param>
        /// <param name="cancel"></param>
        /// <returns></returns>
        public ActionResult PaypalExpressSuccess(string token, string payerId, bool? cancel)
        {
            var model = PrepareCheckoutModel(new CheckoutModel());
            Payment payment = null;

            var order = _orderClient.GetOrderByAuthCode(token);

            if (order == null)
            {
                ModelState.AddModelError("", "Order cannot be found for current payment!".Localize());
            }
            else
            {
                payment = order.OrderForms.SelectMany(f => f.Payments).First(p => p.AuthorizationCode == token);

                //If payment not cancelled proceed
                if (!cancel.HasValue || !cancel.Value)
                {

                    var paymentMethod = _paymentClient.GetPaymentMethod(payment.PaymentMethodName ?? "Paypal");

                    var configMap = paymentMethod.CreateSettings();

                    var service = new PayPalAPIInterfaceServiceService(configMap);

                    var getEcWrapper = new GetExpressCheckoutDetailsReq
                    {
                        GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
                    };

                    GetExpressCheckoutDetailsResponseType getEcResponse = null;

                    try
                    {
                        getEcResponse = service.GetExpressCheckoutDetails(getEcWrapper);
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", @"Paypal failure".Localize());
                        ModelState.AddModelError("", ex.Message);
                    }

                    if (getEcResponse != null)
                    {
                        if (getEcResponse.Ack.Equals(AckCodeType.FAILURE) ||
                            (getEcResponse.Errors != null && getEcResponse.Errors.Count > 0))
                        {
                            ModelState.AddModelError("", @"Paypal failure".Localize());
                            foreach (var error in getEcResponse.Errors)
                            {
                                ModelState.AddModelError("", error.LongMessage);
                            }
                        }
                        else
                        {
                            var details = getEcResponse.GetExpressCheckoutDetailsResponseDetails;

                            if (details.CheckoutStatus.Equals("PaymentActionCompleted",
                                StringComparison.OrdinalIgnoreCase))
                            {
                                return RedirectToAction("ProcessCheckout", "Checkout", new {id = order.OrderGroupId});
                            }

                            model.PaymentMethod = paymentMethod.Name;
                            model.ShippingMethod = details.UserSelectedOptions.ShippingOptionName;

                            if (!string.IsNullOrEmpty(details.UserSelectedOptions.ShippingOptionName))
                            {
                                foreach (var lineItem in order.OrderForms.SelectMany(f => f.LineItems))
                                {
                                    var shippingMethod =
                                        Ch.GetShippingMethods(new List<string> {model.ShippingMethod}).First();
                                    lineItem.ShippingMethodName = shippingMethod.DisplayName;
                                    lineItem.ShippingMethodId = shippingMethod.Id;
                                }
                            }

                            var paymentDetails = details.PaymentDetails[0];

                            model.BillingAddress.Address = ConvertFromPaypalAddress(paymentDetails.ShipToAddress,
                                "Billing");
                            model.BillingAddress.Address.Email = details.PayerInfo.Payer;
                            model.ShippingAddress.Address = ConvertFromPaypalAddress(paymentDetails.ShipToAddress,
                                "Shipping");
                            model.ShippingAddress.Address.Email = details.PayerInfo.Payer;

                            #region Process billing address

                            var billingAddress = OrderClient.FindAddressByName(order, "Billing");
                            if (billingAddress == null)
                            {
                                billingAddress = new OrderAddress();
                                order.OrderAddresses.Add(billingAddress);

                                var orderAddressId = billingAddress.OrderAddressId;
                                billingAddress.InjectFrom(
                                    new IgnorePropertiesInjection("OrderGroupId", "OrderGroup", "OrderAddressId",
                                        "Created"), model.BillingAddress.Address);
                                billingAddress.Name = "Billing";
                                billingAddress.OrderAddressId = orderAddressId;
                                order.AddressId = orderAddressId;
                                order.OrderForms[0].BillingAddressId = orderAddressId;
                            }

                            #endregion

                            #region Process shipping address

                            var shippingAddress = OrderClient.FindAddressByName(order, "Shipping");
                            if (shippingAddress == null)
                            {
                                shippingAddress = new OrderAddress();
                                order.OrderAddresses.Add(shippingAddress);
                            }

                            shippingAddress.InjectFrom(
                                new IgnorePropertiesInjection("OrderGroupId", "OrderGroup", "OrderAddressId", "Created"),
                                model.ShippingAddress.Address);
                            shippingAddress.Name = "Shipping";
                            shippingAddress.OrderAddressId = shippingAddress.OrderAddressId;

                            //Update shipping address id
                            foreach (var shipment in order.OrderForms.SelectMany(f => f.Shipments))
                            {
                                shipment.ShippingAddressId = shippingAddress.OrderAddressId;
                            }
                            foreach (var lineItem in order.OrderForms.SelectMany(f => f.LineItems))
                            {
                                lineItem.ShippingAddressId = shippingAddress.OrderAddressId;
                            }

                            #endregion

                            //Recalcualte totals (User could have changed shipping method in paypal).
                            Ch.RunWorkflow("ShoppingCartPrepareWorkflow", order);


                            if (ModelState.IsValid)
                            {
                                payment.ContractId = payerId;
                                payment.AuthorizationCode = token;
                                payment.Amount = order.Total;

                                //Normally this message should be shown to user when. This happens because address changes and Tax is recalculated
                                if (decimal.Parse(paymentDetails.OrderTotal.value, CultureInfo.InvariantCulture) !=
                                    order.Total)
                                {
                                    ModelState.AddModelError("",
                                        "Paypal payment total does not match order total! Check the totals and try to pay again."
                                            .Localize());
                                }
                                else
                                {
                                    try
                                    {
                                        Ch.RunWorkflow("ShoppingCartCheckoutWorkflow", order);
                                        Ch.OrderRepository.UnitOfWork.Commit();
                                        return RedirectToAction("ProcessCheckout", "Checkout",
                                            new {id = order.OrderGroupId});
                                    }
                                    catch (Exception ex)
                                    {
                                        ModelState.AddModelError("", ex.Message);
                                    }
                                }

                            }

                        }
                    }
                }
            }

            if (order != null)
            {
                //Cancel old order
                order.Status = OrderStatus.Cancelled.ToString();
                payment.Status = PaymentStatus.Canceled.ToString();

                //Restore cart if order fails
                Ch.ToCart(order);

                //Add paypal payment to make it selected in UI
                var paypalPayment = new OtherPayment
                {
                    PaymentMethodId = payment.PaymentMethodId,
                    PaymentMethodName = payment.PaymentMethodName,
                    Amount = payment.Amount
                };
                Ch.OrderForm.Payments.Add(paypalPayment);
                Ch.SaveChanges();
            }

            return View("Index", model);

        }
示例#24
0
        public override async Task <BaseResponse> AddAsync(OtherPaymentData request, ServerCallContext context)
        {
            try
            {
                if (request is null)
                {
                    await _otherPaymentsRepository.AddAsync(null);
                }
                OtherPayment otherPayment = FromRpcModel(request);
                int          result       = await _otherPaymentsRepository.AddAsync(otherPayment);

                if (result == 0)
                {
                    throw new Exception("Other payment has not been saved");
                }
                BaseResponse response = new()
                {
                    Code         = Code.Success,
                    ErrorMessage = string.Empty,
                    DataId       = otherPayment.Id
                };

                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(AddAsync),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };
                _logger.AddLog(logData);
                return(response);
            }
            catch (NullReferenceException nrex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(AddAsync),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = nrex
                };
                _logger.AddErrorLog(logData);
                return(new BaseResponse
                {
                    Code = Code.DataError,
                    ErrorMessage = nrex.Message
                });
            }
            catch (ArgumentException aex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(AddAsync),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = aex
                };
                _logger.AddErrorLog(logData);
                return(new BaseResponse
                {
                    Code = Code.DataError,
                    ErrorMessage = aex.Message
                });
            }
            catch (DbUpdateException duex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(AddAsync),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = duex
                };
                _logger.AddErrorLog(logData);
                return(new BaseResponse
                {
                    Code = Code.DbError,
                    ErrorMessage = "An error occured while saving other payment"
                });
            }
            catch (Exception ex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(OtherPaymentsService),
                    CallerMethodName = nameof(AddAsync),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };
                _logger.AddErrorLog(logData);
                return(new BaseResponse
                {
                    Code = Code.UnknownError,
                    ErrorMessage = ex.Message
                });
            }
        }
        /// <summary>
        /// Creates the payment.
        /// </summary>
        /// <param name="form">The order form.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="model">The payment  model.</param>
        /// <returns>Payment.</returns>
        private Payment CreatePayment(OrderForm form, string methodName, PaymentModel model)
        {
            var paymentOption =
                (from o in _paymentOptions where o.Key.Equals(methodName, StringComparison.OrdinalIgnoreCase) select o)
                    .SingleOrDefault();

            Payment payment;

            if (paymentOption != null)
            {
                payment = paymentOption.PreProcess(form, model);
            }
            else
            {
                payment = new OtherPayment
                    {
                        PaymentType = PaymentType.Other.GetHashCode(),
                        BillingAddressId = form.BillingAddressId,
                        PaymentMethodName = model.DisplayName,
                        PaymentMethodId = model.Id,
                    };
            }
            //Common Properties
            payment.Status = PaymentStatus.Pending.ToString();
            payment.OrderForm = form;
            payment.TransactionType = TransactionType.Sale.ToString();
            payment.Amount = form.OrderGroup.Total;

            return payment;
        }
示例#26
0
        public void Checkout(CheckoutVM checkoutVM)
        {
            PurchaseOrder purchaseOrder = _cartHelper.Cart.SaveAsPurchaseOrder();
            purchaseOrder.AcceptChanges();
            OrderForm orderForm = purchaseOrder.OrderForms[0];
            Shipment shipment = purchaseOrder.OrderForms[0].Shipments[0];
            shipment.ShippingMethodId = GetGuidShippingMethod(checkoutVM.ShippingMethod);

            CustomerContact contact = CustomerContext.Current.GetContactForUser(SecurityContext.Current.CurrentUser);
            IEnumerable<CustomerAddress> addresses = contact.ContactAddresses;

            foreach (CustomerAddress ca in addresses)
            {
                var name = ca.Name;
                if (ca.Name == "ShippingAddress1")
                {
                    purchaseOrder.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(ca));
                }
                if (ca.Name == "BillingAddress1")
                {
                    purchaseOrder.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(ca));

                }
            }

            purchaseOrder.OrderForms[0].BillingAddressId = "BillingAddress1";
            purchaseOrder.CustomerName = CustomerContext.Current.CurrentContactName;

            purchaseOrder.OrderAddresses.AcceptChanges();
            purchaseOrder.OrderForms[0].Shipments.AcceptChanges();
            purchaseOrder.OrderForms.AcceptChanges();
            purchaseOrder.AcceptChanges();

            Payment ThePayment = null;
            OtherPayment otherPayment = new OtherPayment();
            ThePayment = (Payment)otherPayment;
            ThePayment.TransactionType = TransactionType.Sale.ToString();
            ThePayment.Status = PaymentStatus.Pending.ToString();
            ThePayment.SetParent(orderForm);
            ThePayment.PaymentMethodId = GetGuidPaymentMethod(checkoutVM.PaymentMethod);
            ThePayment.Amount = _cartHelper.Cart.Total;
            ThePayment.AcceptChanges();
            orderForm.Payments.Add(ThePayment);
            orderForm.AcceptChanges();
        }
示例#27
0
        //Convert all the items from the cart into purchaseOrder items in order to ship them.
        //Send a notification email to user afer the order was placed.
        public void Checkout(CheckoutVM checkoutVM)
        {
            PurchaseOrder purchaseOrder = _cartHelper.Cart.SaveAsPurchaseOrder();
            purchaseOrder.ShippingTotal = checkoutVM.Cart.TotalPrice;
            purchaseOrder.HandlingTotal = checkoutVM.Cart.ListOfItems.Count;
            purchaseOrder.AcceptChanges();
            OrderForm orderForm = purchaseOrder.OrderForms[0];
            Shipment shipment = purchaseOrder.OrderForms[0].Shipments[0];

            IEnumerable<LineItem> lineItems = GetCartItems();
            foreach (var x in lineItems)
            {
                orderForm.LineItems.Add(x);
            }

            foreach (LineItem y in orderForm.LineItems)
            {
                PurchaseOrderManager.AddLineItemToShipment(purchaseOrder, y.LineItemId, shipment, y.Quantity);
            }

            orderForm.AcceptChanges();
            purchaseOrder.OrderForms[0].Shipments.AcceptChanges();

            Payment ThePayment = null;
            OtherPayment otherPayment = new OtherPayment();
            ThePayment = otherPayment;
            ThePayment.TransactionType = TransactionType.Sale.ToString();
            ThePayment.Status = PaymentStatus.Pending.ToString();
            ThePayment.SetParent(orderForm);
            ThePayment.AcceptChanges();
            orderForm.Payments.Add(ThePayment);

            MailSender mailSender = new MailSender();
            mailSender.SendMailToSpecificUser();
        }