Ejemplo n.º 1
0
        public Order PlaceOrder(IECommerceConfiguration configuration, string cardNumber, string cardVerificationCode,
			DeliveryMethod deliveryMethod, decimal deliveryPrice, Address billingAddress,
			Address shippingAddress, PaymentCard paymentCard, string emailAddress,
			string telephoneNumber, string mobileTelephoneNumber,
			IEnumerable<OrderItem> items,
            decimal totalVatPrice, decimal totalPrice)
        {
            // Convert shopping basket into order, with unpaid status.
            Order order = new Order
            {
                User = (_webContext.User != null && (_webContext.User is WebPrincipal)) ? ((WebPrincipal) _webContext.User).MembershipUser : null,
                DeliveryMethod = deliveryMethod,
                BillingAddress = billingAddress,
                ShippingAddress = shippingAddress,
                PaymentCard = paymentCard,
                EmailAddress = emailAddress,
                TelephoneNumber = telephoneNumber,
                MobileTelephoneNumber = mobileTelephoneNumber,
                Status = OrderStatus.Unpaid,
                TotalDeliveryPrice = deliveryPrice,
                TotalVatPrice = totalVatPrice,
                TotalPrice = totalPrice
            };
            foreach (OrderItem orderItem in items)
                orderItem.AddTo(order);
            order.AddTo(configuration.Orders);
            _persister.Save(order);

            order.Title = "Order #" + order.ID;
            _persister.Save(order);

            // Process payment.
            PaymentRequest paymentRequest = new PaymentRequest(
                PaymentTransactionType.Payment, order.ID.ToString(), order.TotalPrice, order.Title,
                order.BillingAddress, order.ShippingAddress,
                order.PaymentCard, cardNumber, cardVerificationCode,
                order.TelephoneNumber, order.EmailAddress, _webContext.Request.UserHostAddress);

            PaymentResponse paymentResponse = _paymentGateway.TakePayment(paymentRequest);

            if (paymentResponse.Success)
            {
                // Update order status to Paid.
                order.Status = OrderStatus.Paid;
                _persister.Save(order);

                // Send email to customer and vendor.

                //commented out by Dave - why would this be a centralised library - like we don't need to change this for project to project?

                //_orderMailService.SendOrderConfirmationToCustomer(configuration, order);
                //_orderMailService.SendOrderConfirmationToVendor(configuration, order);
            }
            else
            {
                throw new ZeusECommerceException(paymentResponse.Message);
            }

            return order;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public PaymentRequest(PaymentTransactionType transactionType, string transactionCode, decimal amount, string description,
            Address billingAddress, Address shippingAddress,
            PaymentCard card, string cardNumber, string cardSecurityCode,
            string telephoneNumber, string emailAddress,
            string clientIpAddress)
        {
            TransactionType = transactionType;
            TransactionCode = transactionCode;
            Amount = amount;
            Description = description;

            BillingAddress = billingAddress;
            ShippingAddress = shippingAddress;

            Card = card;
            CardNumber = cardNumber;
            CardSecurityCode = cardSecurityCode;

            TelephoneNumber = telephoneNumber;
            EmailAddress = emailAddress;

            ClientIpAddress = clientIpAddress;
        }
Ejemplo n.º 3
0
        public Order PlaceOrderWithoutPayment(IECommerceConfiguration configuration, DeliveryMethod deliveryMethod, 
            decimal deliveryPrice, Address billingAddress,
            Address shippingAddress, PaymentCard paymentCard, string emailAddress,
            string telephoneNumber, string mobileTelephoneNumber,
            IEnumerable<OrderItem> items,
            decimal totalVatPrice, decimal totalPrice)
        {
            try
            {

                // Convert shopping basket into order, with unpaid status.
                Order order = new Order
                {
                    User = (_webContext.User != null && (_webContext.User is WebPrincipal)) ? ((WebPrincipal)_webContext.User).MembershipUser : null,
                    DeliveryMethod = deliveryMethod,
                    BillingAddress = billingAddress,
                    ShippingAddress = shippingAddress,
                    PaymentCard = paymentCard,
                    EmailAddress = emailAddress,
                    TelephoneNumber = telephoneNumber,
                    MobileTelephoneNumber = mobileTelephoneNumber,
                    Status = OrderStatus.Unpaid,
                    TotalDeliveryPrice = deliveryPrice,
                    TotalVatPrice = totalVatPrice,
                    TotalPrice = totalPrice
                };
                foreach (OrderItem orderItem in items)
                    orderItem.AddTo(order);

                order.AddTo(configuration.Orders);

                order.Status = OrderStatus.Unpaid;
                _persister.Save(order);

                if (_webContext.User != null && !string.IsNullOrEmpty(_webContext.User.Identity.Name))
                {
                    order.Title = _webContext.User.Identity.Name + " for " + items.First().Title;
                }
                else
                {
                    order.Title = "Order #" + order.ID;
                }

                _persister.Save(order);

                return order;
            }
            catch (System.Exception ex)
            {
                throw(new System.Exception("Error creating order: \n" + ex.Message + "\n" + ex.StackTrace));
            }
        }