示例#1
0
        public ShipmentCancellationResponse Cancel(string trackingNumber, CarrierAccount carrierAccount)
        {
            ShipmentCancellationResponse shipmentCancellationResponse = null;

            try
            {
                dynamic dataObject = new ExpandoObject();
                dynamic cancel     = new ExpandoObject();
                cancel.shipping_account = carrierAccount.id;
                cancel.carrier          = carrierAccount.carrier;
                cancel.tracking_number  = trackingNumber;
                cancel.test             = Test;

                dataObject.cancel = cancel;
                string payload      = JsonConvert.SerializeObject(dataObject);
                string jsonResponse = DataLayer.getResponseFromApi(ApiKey, DataLayer.WebMethod.POST, "/cancel", payload);
                shipmentCancellationResponse = convertCancellationResponse(jsonResponse);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(shipmentCancellationResponse);
        }
        public void CancelTest()
        {
            string         trackingNumber      = "794626099895";
            CarrierAccount fedexCarrierAccount = new CarrierAccount();

            fedexCarrierAccount.id      = fedexShippingAccountId;
            fedexCarrierAccount.carrier = "fedex";

            zkService.Test = true;
            ShipmentCancellationResponse cancellationResponse = zkService.Cancel(trackingNumber, fedexCarrierAccount);

            Assert.IsTrue(cancellationResponse != null);
        }
示例#3
0
        private ShipmentCancellationResponse convertCancellationResponse(string jsonResponse)
        {
            ShipmentCancellationResponse shipmentCancellationResponse = new ShipmentCancellationResponse();

            try
            {
                JObject responseObj = JObject.Parse(jsonResponse);


                if (responseObj["success"] != null)
                {
                    shipmentCancellationResponse.success = true;
                    JObject successObj     = JObject.Parse(responseObj["success"].ToString());
                    string  successMessage = successObj["message"].ToString();

                    shipmentCancellationResponse.message = successMessage;
                }
                else
                {
                    shipmentCancellationResponse.success = false;
                    string errorMessage = "API response is different than the one expected - " + responseObj.ToString();
                    if (responseObj["error"] != null)
                    {
                        JObject errorObj = JObject.Parse(responseObj["error"].ToString());
                        errorMessage = errorObj["message"].ToString();
                    }

                    shipmentCancellationResponse.message = errorMessage;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(shipmentCancellationResponse);
        }