Ejemplo n.º 1
0
    private OrderNotifyService CreateOrder(CheckoutDetails checkout)
    {
        OrderCreateService orderCreateService = new OrderCreateService(
            StoreContext.ShoppingCart,
            checkout,
            StoreContext.Culture,
            StoreContext.Currency,
            AffiliateHelper.GetAffiliateCode(),
            WebUtilities.GetVisitorIP());

        OrderNotifyService orderBusiness;
        Order       order;
        OrderAmount orderAmount;

        if (!IsAnonymousCheckout())
        {
            order         = PlaceOrder(orderCreateService, out orderAmount);
            orderBusiness = new OrderNotifyService(order.OrderID);
        }
        else
        {
            order = PlaceOrderAnonymous(
                SystemConst.AnonymousUser, orderCreateService, checkout, out orderAmount);

            orderBusiness = new OrderNotifyService(order.OrderID);
        }

        AffiliateOrder affiliateorder = new AffiliateOrder();

        affiliateorder.AffiliateCode = AffiliateHelper.GetAffiliateCode();
        affiliateorder.CreateAffiliateOrder(order.OrderID, orderAmount.Subtotal, orderAmount.Discount);

        return(orderBusiness);
    }
Ejemplo n.º 2
0
    private OrderNotifyService CreateOrder(CheckoutDetails checkout)
    {
        OrderCreateService orderCreateService = new OrderCreateService(
            StoreContext.ShoppingCart,
            checkout,
            StoreContext.Culture,
            CurrenntCurrency,
            AffiliateHelper.GetAffiliateCode(),
            WebUtilities.GetVisitorIP());

        OrderNotifyService orderBusiness;
        OrderAmount        amount = orderCreateService.GetOrderAmount(StoreContext.Customer)
                                    .Add(CartItemPromotion.CalculatePromotionShippingAndTax(
                                             checkout,
                                             StoreContext.ShoppingCart.SeparateCartItemGroups(),
                                             StoreContext.Customer));

        Order order = orderCreateService.PlaceOrder(amount,
                                                    StoreContext.Customer, DataAccessContext.StoreRetriever, StoreContext.Culture);

        GiftRegistry.UpdateGiftRegistryQuantity(StoreContext.ShoppingCart, checkout);
        CustomerRewardPoint.UpdateRedeemPoint(checkout, StoreContext.Customer, order);

        orderBusiness = new OrderNotifyService(order.OrderID);

        return(orderBusiness);
    }
Ejemplo n.º 3
0
        public async Task CreateAsync_OrderValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var order    = new OrderUpdateModel();
            var expected = fixture.Create <string>();

            var bookGetService = new Mock <IBookGetService>();

            bookGetService
            .Setup(x => x.ValidateAsync(order))
            .Throws(new InvalidOperationException(expected));

            var clientGetService = new Mock <IClientGetService>();

            clientGetService.Setup(x => x.ValidateAsync(order)).Throws(new InvalidOperationException(expected));


            var orderDataAccess = new Mock <IOrderDataAccess>();

            var orderGetService = new OrderCreateService(orderDataAccess.Object, bookGetService.Object, clientGetService.Object);

            // Act
            var action = new Func <Task>(() => orderGetService.CreateAsync(order));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            orderDataAccess.Verify(x => x.InsertAsync(order), Times.Never);
        }
Ejemplo n.º 4
0
        public async Task CreateAsync_OrderValidationSucceed_CreateOrder()
        {
            // Arrange
            var order    = new OrderUpdateModel();
            var expected = new Order();

            var bookGetService = new Mock <IBookGetService>();

            bookGetService.Setup(x => x.ValidateAsync(order));

            var clientGetService = new Mock <IClientGetService>();

            clientGetService.Setup(x => x.ValidateAsync(order));

            var orderDataAccess = new Mock <IOrderDataAccess>();

            orderDataAccess.Setup(x => x.InsertAsync(order)).ReturnsAsync(expected);

            var orderGetService = new OrderCreateService(orderDataAccess.Object, bookGetService.Object, clientGetService.Object);

            // Act
            var result = await orderGetService.CreateAsync(order);

            // Assert
            result.Should().Be(expected);
        }
Ejemplo n.º 5
0
    private void ProcessOnPayPalProUSPayment(CheckoutDetails checkout)
    {
        PayPalProUSPaymentMethod paypalPayment = (PayPalProUSPaymentMethod)checkout.PaymentMethod;
        bool                   result          = false;
        PaymentAppResult       paymentResult;
        RecurringPaymentResult recurringPaymentResult;
        ProcessPaymentService  process = ProcessPaymentService.CreateNew(new HttpService(), StoreContext.ShoppingCart);

        result = process.ProcessPayPalProUSPayment(
            StoreContext.GetOrderAmount().Total,
            DataAccessContext.CurrencyRepository.GetOne(DataAccessContext.Configurations.GetValue("PaymentCurrency")),
            StoreContext.Culture,
            checkout,
            StoreContext.ShoppingCart,
            StoreContext.Customer,
            UrlPath.StorefrontUrl,
            WebUtilities.GetVisitorIP(),
            out paymentResult,
            out recurringPaymentResult);

        if (result)
        {
            OrderCreateService orderCreateService = new OrderCreateService(
                StoreContext.ShoppingCart,
                StoreContext.CheckoutDetails,
                StoreContext.Culture,
                CurrenntCurrency,
                AffiliateHelper.GetAffiliateCode(),
                WebUtilities.GetVisitorIP(),
                recurringPaymentResult
                );

            Order       order;
            OrderAmount amount = orderCreateService.GetOrderAmount(StoreContext.Customer)
                                 .Add(CartItemPromotion.CalculatePromotionShippingAndTax(
                                          StoreContext.CheckoutDetails,
                                          StoreContext.ShoppingCart.SeparateCartItemGroups(),
                                          StoreContext.Customer));
            order = orderCreateService.PlaceOrder(amount, StoreContext.Customer, DataAccessContext.StoreRetriever, StoreContext.Culture);
            GiftRegistry.UpdateGiftRegistryQuantity(StoreContext.ShoppingCart, StoreContext.CheckoutDetails);
            CustomerRewardPoint.UpdateRedeemPoint(StoreContext.CheckoutDetails, StoreContext.Customer, order);

            OrderNotifyService orderBusiness = new OrderNotifyService(order.OrderID);

            ProcessCreditCardPaymentSuccess(
                orderBusiness,
                paymentResult.GatewayOrderID,
                paymentResult.PaymentLog,
                paymentResult.CvvStatus,
                paymentResult.AvsAddrStatus,
                paymentResult.AvsZipStatus);
        }
        else
        {
            ProcessCreditCardPaymentFailure(paymentResult.ErrorMessage);
        }
    }
Ejemplo n.º 6
0
    private void ProcessAnonymousPayment(CheckoutDetails checkout)
    {
        AnonymousPaymentMethod payment = (AnonymousPaymentMethod)checkout.PaymentMethod;

        ProcessPaymentResult paymentResult;
        bool result = payment.ProcessPayment(
            StoreContext.GetOrderAmount().Total,
            DataAccessContext.Configurations.GetValue("PaymentCurrency"),
            checkout,
            out paymentResult);

        if (result)
        {
            OrderCreateService orderCreateService = new OrderCreateService(
                StoreContext.ShoppingCart,
                checkout,
                StoreContext.Culture,
                StoreContext.Currency,
                AffiliateHelper.GetAffiliateCode(),
                WebUtilities.GetVisitorIP());

            OrderAmount orderAmount;
            Order       order = PlaceOrderAnonymous(
                (Page.User.Identity.IsAuthenticated) ? Membership.GetUser().UserName : SystemConst.AnonymousUser,
                orderCreateService,
                checkout, out orderAmount);

            AffiliateOrder affiliateorder = new AffiliateOrder();
            affiliateorder.AffiliateCode = AffiliateHelper.GetAffiliateCode();
            affiliateorder.CreateAffiliateOrder(order.OrderID, orderAmount.Subtotal, orderAmount.Discount);

            OrderNotifyService orderBusiness = new OrderNotifyService(order.OrderID);
            ProcessCreditCardPaymentSuccess(
                orderBusiness,
                paymentResult.GatewayOrderID,
                paymentResult.PaymentLog,
                paymentResult.CvvStatus,
                paymentResult.AvsAddrStatus,
                paymentResult.AvsZipStatus);
        }
        else
        {
            CheckoutNotCompletePage.RedirectToPage(
                "Error Message",
                paymentResult.ErrorMessage,
                "ShoppingCart.aspx",
                "Return To Shopping Cart");
        }
    }
Ejemplo n.º 7
0
 public async Task <IActionResult> Create(OrderCreateDTO orderCreate)
 {
     try
     {
         var order =
             Mapper.Map <OrderDTO>(
                 await OrderCreateService.CreateAsync(Mapper.Map <OrderUpdateModel>(orderCreate)));
         return(Redirect($"/orders/{order.Id}"));
     }
     catch
     {
         ViewData["BookId"]     = new SelectList(Mapper.Map <IEnumerable <BookDTO> >(await BookGetService.GetAsync()), "Id", "Title");
         ViewData["CustomerId"] = new SelectList(Mapper.Map <IEnumerable <CustomerDTO> >(await CustomerGetService.GetAsync()), "Id", "FullName");
         return(View());
     }
 }
Ejemplo n.º 8
0
 public async Task <OrderDTO> Create(OrderCreateDTO orderCreate)
 {
     return(Mapper.Map <OrderDTO>(await OrderCreateService.CreateAsync(Mapper.Map <OrderUpdateModel>(orderCreate))));
 }
Ejemplo n.º 9
0
    private void ProcessOnPayPalProUSPayment(CheckoutDetails checkout)
    {
        PayPalProUSPaymentMethod paypalPayment = (PayPalProUSPaymentMethod)checkout.PaymentMethod;
        bool                   result          = false;
        PaymentAppResult       paymentResult;
        RecurringPaymentResult recurringPaymentResult;
        ProcessPaymentService  process = ProcessPaymentService.CreateNew(new HttpService(), StoreContext.ShoppingCart);

        result = process.ProcessPayPalProUSPayment(
            StoreContext.GetOrderAmount().Total,
            DataAccessContext.CurrencyRepository.GetOne(DataAccessContext.Configurations.GetValue("PaymentCurrency")),
            StoreContext.Culture,
            checkout,
            StoreContext.ShoppingCart,
            StoreContext.Customer,
            UrlPath.StorefrontUrl,
            WebUtilities.GetVisitorIP(),
            out paymentResult,
            out recurringPaymentResult);

        if (result)
        {
            OrderCreateService orderCreateService = new OrderCreateService(
                StoreContext.ShoppingCart,
                StoreContext.CheckoutDetails,
                StoreContext.Culture,
                StoreContext.Currency,
                AffiliateHelper.GetAffiliateCode(),
                WebUtilities.GetVisitorIP(),
                recurringPaymentResult
                );

            Order       order;
            OrderAmount orderAmount;
            if (!IsAnonymousCheckout())
            {
                order = PlaceOrder(orderCreateService, out orderAmount);
            }
            else
            {
                order = PlaceOrderAnonymous(SystemConst.UnknownUser, orderCreateService, checkout, out orderAmount);
            }

            AffiliateOrder affiliateorder = new AffiliateOrder();
            affiliateorder.AffiliateCode = AffiliateHelper.GetAffiliateCode();
            affiliateorder.CreateAffiliateOrder(order.OrderID, orderAmount.Subtotal, orderAmount.Discount);

            OrderNotifyService orderBusiness = new OrderNotifyService(order.OrderID);

            ProcessCreditCardPaymentSuccess(
                orderBusiness,
                paymentResult.GatewayOrderID,
                paymentResult.PaymentLog,
                paymentResult.CvvStatus,
                paymentResult.AvsAddrStatus,
                paymentResult.AvsZipStatus);
        }
        else
        {
            ProcessCreditCardPaymentFailure(paymentResult.ErrorMessage);
        }
    }
Ejemplo n.º 10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Extract the XML from the request.
        Stream       RequestStream       = Request.InputStream;
        StreamReader RequestStreamReader = new StreamReader(RequestStream);
        string       RequestXml          = RequestStreamReader.ReadToEnd();

        RequestStream.Close();
        Log.Debug("Request XML:\n" + RequestXml);

        string             gatewayOrderID = "";
        string             orderID;
        OrderNotifyService orderBusiness;

        try
        {
            // Act on the XML.
            switch (EncodeHelper.GetTopElement(RequestXml))
            {
            case "new-order-notification":
                Log.Debug("Start new-order-notification");
                NewOrderNotification N1 =
                    (NewOrderNotification)EncodeHelper.Deserialize(RequestXml,
                                                                   typeof(NewOrderNotification));
                string OrderNumber1 = N1.googleordernumber;

                PaymentLogUpdateNewOrderNotification(N1);
                _serialNumber = N1.serialnumber;
                Log.Debug("-********************- Check DataAccessContext.GetOrderIDByGateWayID Data -**********************-");
                Log.Debug("GetOrderIDByGateWayID ( "
                          + OrderNumber1 + " ) = " + DataAccessContext.OrderRepository.GetOrderIDByGatewayID(OrderNumber1));
                Log.Debug("-********************- END Check DataAccessContext.GetOrderIDByGateWayID Data -**********************-");
                if (DataAccessContext.OrderRepository.GetOrderIDByGatewayID(OrderNumber1) == "0")
                {
                    BuildShoppingCart(RequestXml, N1);

                    Log.Debug("Start converting to order");

                    OrderCreateService orderCreateService = new OrderCreateService(
                        StoreContext.ShoppingCart,
                        StoreContext.CheckoutDetails,
                        StoreContext.Culture,
                        StoreContext.Currency,
                        AffiliateHelper.GetAffiliateCode(),
                        WebUtilities.GetVisitorIP());

                    string storeID = EncodeHelper.GetElementValue(RequestXml, "StoreID");
                    DataAccessContext.SetStoreRetriever(new StoreRetriever(storeID));

                    OrderAmount orderAmount = orderCreateService.GetOrderAmount(Customer.Null)
                                              .Add(CartItemPromotion.CalculatePromotionShippingAndTax(
                                                       StoreContext.CheckoutDetails,
                                                       StoreContext.ShoppingCart.SeparateCartItemGroups(),
                                                       Customer.Null));

                    Order order = orderCreateService.PlaceOrderAnonymous(orderAmount,
                                                                         SystemConst.UnknownUser,
                                                                         CreateBuyerBillingAddress(N1),
                                                                         ConvertToString(N1.buyerbillingaddress.email), DataAccessContext.StoreRetriever, StoreContext.Culture);

                    AffiliateOrder affiliateorder = new AffiliateOrder();
                    affiliateorder.AffiliateCode = AffiliateHelper.GetAffiliateCode();
                    affiliateorder.CreateAffiliateOrder(order.OrderID, orderAmount.Subtotal, orderAmount.Discount);

                    orderBusiness = new OrderNotifyService(order.OrderID);

                    Log.Debug("End converting to order");

                    Log.Debug("Start sending order email");
                    orderBusiness.SendOrderEmail();
                    Log.Debug("End sending order email");

                    Order orderDetail = DataAccessContext.OrderRepository.GetOne(order.OrderID);
                    orderDetail.GatewayOrderID = OrderNumber1;
                    Log.Debug("OrderDetail.GatewayOrderID = " + OrderNumber1);
                    Log.Debug("Start Save Order Detail");
                    DataAccessContext.OrderRepository.Save(orderDetail);
                    Log.Debug("End Save Order Detail");

                    DataAccessContext.SetStoreRetriever(new StoreRetriever());
                }
                else
                {
                    Order orderDetail = DataAccessContext.OrderRepository.GetOne(
                        DataAccessContext.OrderRepository.GetOrderIDByGatewayID(OrderNumber1));

                    Log.Debug("-**************************- start Check Error -**************************-");
                    Log.Debug("N1.googleOrderNumber = " + N1.googleordernumber);
                    Log.Debug("OrderNumber1 = " + OrderNumber1);
                    Log.Debug("N1.buyerbillingaddress.contactname = " + ConvertToString(N1.buyerbillingaddress.contactname));
                    Log.Debug("N1.buyerbillingaddress.address1 = " + ConvertToString(N1.buyerbillingaddress.address1));
                    Log.Debug("N1.buyerbillingaddress.city = " + ConvertToString(N1.buyerbillingaddress.city));
                    Log.Debug("N1.buyerbillingaddress.region = " + ConvertToString(N1.buyerbillingaddress.contactname));
                    Log.Debug("N1.buyerbillingaddress.postalcode = " + ConvertToString(N1.buyerbillingaddress.postalcode));
                    Log.Debug("orderDetail.Billing.Company = " + orderDetail.Billing.Company);
                    Log.Debug("orderDetail.Billing.Country = " + orderDetail.Billing.Country);
                    Log.Debug("orderDetail.Billing.Phone = " + orderDetail.Billing.Phone);
                    Log.Debug("orderDetail.Billing.Fax = " + orderDetail.Billing.Fax);
                    Log.Debug("-**************************- End Check Error -**************************-");

                    orderDetail.Billing = new Vevo.Base.Domain.Address(ConvertToString(N1.buyerbillingaddress.contactname),
                                                                       String.Empty, orderDetail.Billing.Company,
                                                                       ConvertToString(N1.buyerbillingaddress.address1),
                                                                       ConvertToString(N1.buyerbillingaddress.address2),
                                                                       ConvertToString(N1.buyerbillingaddress.city),
                                                                       ConvertToString(N1.buyerbillingaddress.region),
                                                                       ConvertToString(N1.buyerbillingaddress.postalcode),
                                                                       orderDetail.Billing.Country, orderDetail.Billing.Phone,
                                                                       orderDetail.Billing.Fax);
                    orderDetail.Email = ConvertToString(N1.buyerbillingaddress.email);

                    DataAccessContext.OrderRepository.Save(orderDetail);
                }

                Log.Debug("End new-order-notification");
                break;

            case "risk-information-notification":
                Log.Debug("risk-information-notification");
                RiskInformationNotification N2 = (RiskInformationNotification)EncodeHelper.Deserialize(
                    RequestXml, typeof(RiskInformationNotification));
                // This notification tells us that Google has authorized the order
                // and it has passed the fraud check.
                // Use the data below to determine if you want to accept the order, then start processing it.
                gatewayOrderID = N2.googleordernumber;
                _serialNumber  = N2.serialnumber;

                PaymentLogUpdateRiskInformation(N2);
                VerifyAvsAndCvv(N2);
                break;

            case "order-state-change-notification":
                Log.Debug("Start order-state-change-notification");
                OrderStateChangeNotification N3 = (OrderStateChangeNotification)EncodeHelper.Deserialize(
                    RequestXml, typeof(OrderStateChangeNotification));

                _serialNumber = N3.serialnumber;

                PaymentLogUpdateOrderStateChange(N3);

                if (N3.newfinancialorderstate != N3.previousfinancialorderstate)
                {
                    Order orderDetail = DataAccessContext.OrderRepository.GetOne(
                        DataAccessContext.OrderRepository.GetOrderIDByGatewayID(N3.googleordernumber));
                    orderDetail.GatewayPaymentStatus = N3.newfinancialorderstate.ToString();

                    DataAccessContext.OrderRepository.Save(orderDetail);

                    switch (N3.newfinancialorderstate)
                    {
                    case FinancialOrderState.PAYMENT_DECLINED:
                    case FinancialOrderState.CANCELLED_BY_GOOGLE:
                        SendErrorEmail(N3);
                        break;

                    case FinancialOrderState.CHARGEABLE:
                        if (DataAccessContext.Configurations.GetBoolValueNoThrow("GCheckoutChargeAuto"))
                        {
                            GoogleChargeOrder(N3.googleordernumber);
                        }
                        break;
                    }
                }

                Log.Debug("End order-state-change-notification");
                break;

            case "charge-amount-notification":
                Log.Debug("Start charge-amount-notification");
                ChargeAmountNotification N4 = (ChargeAmountNotification)EncodeHelper.Deserialize(RequestXml,
                                                                                                 typeof(ChargeAmountNotification));
                // Google has successfully charged the customer's credit card.
                gatewayOrderID = N4.googleordernumber;
                _serialNumber  = N4.serialnumber;

                PaymentLogChargeAmountUpdate(N4);

                orderID       = DataAccessContext.OrderRepository.GetOrderIDByGatewayID(gatewayOrderID);
                orderBusiness = new OrderNotifyService(orderID);
                orderBusiness.ProcessPaymentComplete();
                Log.Debug("End charge-amount-notification");
                break;

            case "refund-amount-notification":
                Log.Debug("Start refund-amount-notification");

                RefundAmountNotification N5 =
                    (RefundAmountNotification)EncodeHelper.Deserialize(
                        RequestXml,
                        typeof(RefundAmountNotification));
                // Google has successfully refunded the customer's credit card.
                gatewayOrderID = N5.googleordernumber;
                _serialNumber  = N5.serialnumber;
                //decimal RefundedAmount = N5.latestrefundamount.Value;

                PaymentLogUpdateRefundAmount(N5);
                Order orderDetails = DataAccessContext.OrderRepository.GetOne(
                    DataAccessContext.OrderRepository.GetOrderIDByGatewayID(gatewayOrderID));
                orderDetails.PaymentComplete = false;
                DataAccessContext.OrderRepository.Save(orderDetails);

                Log.Debug("End refund-amount-notification");
                break;

            case "chargeback-amount-notification":
                Log.Debug("Start chargeback-amount-notification");

                ChargebackAmountNotification N6 = (ChargebackAmountNotification)EncodeHelper.Deserialize(
                    RequestXml, typeof(ChargebackAmountNotification));
                // A customer initiated a chargeback with his credit card company to get her money back.
                gatewayOrderID = N6.googleordernumber;
                _serialNumber  = N6.serialnumber;
                decimal ChargebackAmount = N6.latestchargebackamount.Value;

                PaymentLogUpdateChargeback(N6);

                orderDetails = DataAccessContext.OrderRepository.GetOne(
                    DataAccessContext.OrderRepository.GetOrderIDByGatewayID(gatewayOrderID));
                orderDetails.GatewayPaymentStatus = "ChargeBack";
                DataAccessContext.OrderRepository.Save(orderDetails);

                Log.Debug("End chargeback-amount-notification");
                break;

            default:
                break;
            }
        }
        catch (Exception ex)
        {
            DataAccessContext.SetStoreRetriever(new StoreRetriever());
            Log.Debug(ex.ToString());
        }
    }