private void CancelLineItem(ulong merchantId, string orderId, OrdersCancelLineItemRequest req) { Console.WriteLine("================================================================="); Console.WriteLine("Canceling {0} of item {1}", req.Quantity, req.LineItemId); Console.WriteLine("================================================================="); var resp = sandboxService.Orders.Cancellineitem(req, merchantId, orderId).Execute(); Console.WriteLine("Finished with status {0}.", resp.ExecutionStatus); Console.WriteLine(); }
/// <summary> /// Cancels a line item. This method can only be called for non-multi-client accounts. /// Documentation https://developers.google.com/shoppingcontent/v2sandbox/reference/orders/cancellineitem /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated ShoppingContent service.</param> /// <param name="merchantId">The ID of the managing account.</param> /// <param name="orderId">The ID of the order.</param> /// <param name="body">A valid ShoppingContent v2sandbox body.</param> /// <returns>OrdersCancelLineItemResponseResponse</returns> public static OrdersCancelLineItemResponse Cancellineitem(ShoppingContentService service, string merchantId, string orderId, OrdersCancelLineItemRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (merchantId == null) { throw new ArgumentNullException(merchantId); } if (orderId == null) { throw new ArgumentNullException(orderId); } // Make the request. return(service.Orders.Cancellineitem(body, merchantId, orderId).Execute()); } catch (Exception ex) { throw new Exception("Request Orders.Cancellineitem failed.", ex); } }
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 OrdersReturnLineItemRequest(); 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(); }