Exemple #1
0
        private void LineItemReturned(ulong merchantId, string orderId,
                                      OrdersReturnRefundLineItemRequest req)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Returned {0} of item {1}", req.Quantity,
                              req.LineItemId);
            Console.WriteLine("=================================================================");

            var resp = sandboxService.Orders.Returnrefundlineitem(req, merchantId, orderId).Execute();

            Console.WriteLine("Finished with status {0}.", resp.ExecutionStatus);
            Console.WriteLine();
        }
Exemple #2
0
        internal override void runCalls()
        {
            var merchantId = config.MerchantId.Value;

            // First, we create a new test order using the template1 template.  Normally, orders
            // would be automatically populated by Google in the non-sandbox version, and we'd
            // skip ahead to find out what orders are currently waiting for our acknowledgment.
            Console.WriteLine("=================================================================");
            Console.WriteLine("Creating Test Order for {0}", merchantId);
            Console.WriteLine("=================================================================");

            string orderId;

            {
                var req = new OrdersCreateTestOrderRequest();
                req.TemplateName = "template1";
                var resp = sandboxService.Orders.Createtestorder(req, merchantId).Execute();
                orderId = resp.OrderId;
            }

            Console.WriteLine("Order created with ID {0}", orderId);
            Console.WriteLine();

            // List all unacknowledged orders.  In normal usage, this is where we'd get new
            // order IDs to operate on.  We should see the new test order show up here.
            //ListAllUnacknowledgedOrders(merchantId);

            // Acknowledge the newly created order.  The assumption in doing so is that we've
            // collected the information for this order into our own internal system, and
            // acknowledging it allows us to skip it when searching for new orders (see
            // ListAllUnacknowledgedOrders()).
            Acknowledge(merchantId, orderId);

            // We'll use random numbers for a few things that would normally be supplied by
            // various systems, like the order IDs for the merchant's internal systems, the
            // shipping IDs for the merchant's internal systems, and the tracking ID we'd get
            // from the shipping carriers.
            string merchantOrderId = prng.Next().ToString();

            UpdateMerchantOrderId(merchantId, orderId, merchantOrderId);

            // Print out the current status of the order (and store a reference to the resource
            // so we can pull stuff out of it shortly).
            var currentOrder = GetOrderByMerchantOrderId(merchantId, merchantOrderId);

            PrintOrder(currentOrder);
            Console.WriteLine();

            // Oops, not enough stock for all the Chromecasts ordered, so we cancel one of them.
            {
                var req = new OrdersCancelLineItemRequest();
                req.LineItemId  = currentOrder.LineItems[0].Id;
                req.Quantity    = 1;
                req.Reason      = "noInventory";
                req.ReasonText  = "Ran out of inventory while fulfilling request.";
                req.OperationId = NewOperationId();

                CancelLineItem(merchantId, orderId, req);
            }

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // At this point we'll advance the test order, which simulates the point at which
            // an order is no longer cancelable by the customer and the order information reflects
            // that the order is ready for shipping.
            Console.WriteLine("=================================================================");
            Console.WriteLine("Advancing Test Order {0}", orderId);
            Console.WriteLine("=================================================================");
            sandboxService.Orders.Advancetestorder(merchantId, orderId).Execute();
            Console.WriteLine();

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // To simulate partial fulfillment, we'll pick the first line item and ship the
            // still-pending amount. (Remember, we cancelled one already.)
            var shipItem1Req = ShipAllLineItem(merchantId, orderId, currentOrder.LineItems[0]);

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // Now we ship the rest.
            var shipItem2Req = ShipAllLineItem(merchantId, orderId, currentOrder.LineItems[1]);

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // Customer receives the first item, so we notify Google that it was delivered.
            LineItemDelivered(merchantId, orderId, shipItem1Req);

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // Customer receives second item.
            LineItemDelivered(merchantId, orderId, shipItem2Req);

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();

            // Turns out one of the first items was broken when the customer received it, so
            // they returned it.  Let's make sure Google knows about it and why.
            {
                var req = new OrdersReturnRefundLineItemRequest();
                req.LineItemId  = currentOrder.LineItems[0].Id;
                req.Quantity    = 1;
                req.Reason      = "productArrivedDamaged";
                req.ReasonText  = "Item broken at receipt.";
                req.OperationId = NewOperationId();

                LineItemReturned(merchantId, orderId, req);
            }

            currentOrder = GetOrder(merchantId, orderId);
            PrintOrder(currentOrder);
            Console.WriteLine();
        }