private static void RunInternationalAddressValidationExample(APIResource resource)
        {
            Hashtable parameters = new Hashtable();

            parameters.Add("name", "Shippo Hippo");
            parameters.Add("company", "Shippo");
            parameters.Add("street_no", null);
            parameters.Add("street1", "40 Bay St");
            parameters.Add("street2", null);
            parameters.Add("city", "Toronto");
            parameters.Add("state", "ON");
            parameters.Add("zip", "M5J 2X2");
            parameters.Add("country", "CA");
            parameters.Add("phone", "+1 555 341 9393");
            parameters.Add("email", "*****@*****.**");
            parameters.Add("metadata", "Customer ID 123456");
            parameters.Add("validate", "true");
            Address address = resource.CreateAddress(parameters);

            Console.Out.WriteLine("Address IsValid: " + address.ValidationResults.IsValid);
            if (address.ValidationResults.Messages != null)
            {
                foreach (ValidationMessage message in address.ValidationResults.Messages)
                {
                    Console.Out.WriteLine("Address Message Code: " + message.Code);
                    Console.Out.WriteLine("Address Message Text: " + message.Text);
                    Console.Out.WriteLine();
                }
            }
            Console.Out.WriteLine("Address Latitude: " + address.Latitude);
            Console.Out.WriteLine("Address Longitude: " + address.Longitude);
        }
        public void Test()
        {
            var resource = new APIResource("shippo_live_c436088fca4e8ddee7df15da1c46458777e9d687");

            // Create address (from)
            var fromAdr = new Hashtable();

            fromAdr.Add("name", "Mr. Thierry Habart");
            fromAdr.Add("street1", "223 avenue des croix du feu");
            fromAdr.Add("city", "BRUXELLES");
            fromAdr.Add("zip", "1020");
            fromAdr.Add("country", "BE");
            fromAdr.Add("phone", "0485350536");
            fromAdr.Add("email", "*****@*****.**");

            var fromAddress = resource.CreateAddress(fromAdr);

            // Create address (to)
            var toAdr = new Hashtable();

            toAdr.Add("name", "Mr. Donabedian David");
            toAdr.Add("street1", "rue solleveld 20");
            toAdr.Add("city", "BRUXELLES");
            toAdr.Add("zip", "1200");
            toAdr.Add("country", "BE");
            toAdr.Add("phone", "0485350536");
            toAdr.Add("email", "*****@*****.**");

            var toAddress = resource.CreateAddress(toAdr);

            // Create a parcel (colis)
            var parcel = new Hashtable();

            parcel.Add("length", 5);
            parcel.Add("width", 5);
            parcel.Add("height", 5);
            parcel.Add("distance_unit", "cm");
            parcel.Add("weight", 2);
            parcel.Add("mass_unit", "kg");

            var p = resource.CreateParcel(parcel);

            // Create shippment.
            var shippment  = new Hashtable();
            var lstParcels = new List <string> {
                p.ObjectId
            };

            shippment.Add("address_to", toAddress.ObjectId);
            shippment.Add("address_from", fromAddress.ObjectId);
            shippment.Add("object_purpose", "PURCHASE");
            shippment.Add("parcels", lstParcels);
            shippment.Add("insurance_currency", "EUR");
            shippment.Add("insurance_amount", 0);
            shippment.Add("submission_type", "DROPOFF");
            shippment.Add("submission_date", "2017-09-04T23:59:50+00:00");
            var ship = resource.CreateShipment(shippment);

            // Get rates
            var    rates = resource.GetShippingRatesSync(ship.ObjectId);
            string s     = "";
        }
Beispiel #3
0
        public object Post(ShippmentDTO request)
        {
            //APIResource resource = new APIResource("shippo_test_5f00f661c1f2f19191bfba82cc8575fddb06c202");
            //APIResource resource = new APIResource("shippo_live_b248c98357917b42d991df307d6573359a901ea9");
            try {
                //to address
                Hashtable toAddressTable = new Hashtable();
                toAddressTable.Add("name", request.To.Name);
                toAddressTable.Add("company", request.To.Company);
                toAddressTable.Add("street_no", request.To.StreetNumber);
                toAddressTable.Add("street1", request.To.Street1);
                toAddressTable.Add("city", request.To.City);
                toAddressTable.Add("state", request.To.State);
                toAddressTable.Add("zip", request.To.Zip);
                toAddressTable.Add("country", request.To.Country);
                toAddressTable.Add("validate", "false");

                Address address = resource.CreateAddress(toAddressTable);

                // from address
                Hashtable fromAddressTable = new Hashtable();
                fromAddressTable.Add("name", request.From.Name);
                fromAddressTable.Add("company", request.From.Company);
                fromAddressTable.Add("street_no", request.From.StreetNumber);
                fromAddressTable.Add("street1", request.From.Street1);
                fromAddressTable.Add("city", request.From.City);
                fromAddressTable.Add("state", request.From.State);
                fromAddressTable.Add("zip", request.From.Zip);
                fromAddressTable.Add("country", request.From.Country);
                fromAddressTable.Add("validate", "false");

                List <Hashtable> parcels = new List <Hashtable>();

                foreach (var parcel in request.Parcels)
                {
                    Hashtable parcelTable = new Hashtable();
                    parcelTable.Add("length", parcel.Length);
                    parcelTable.Add("width", parcel.Width);
                    parcelTable.Add("height", parcel.Height);
                    parcelTable.Add("distance_unit", parcel.Distance_unit);
                    parcelTable.Add("weight", parcel.Weight);
                    parcelTable.Add("mass_unit", parcel.Mass_unit);
                    parcels.Add(parcelTable);
                }

                var apiResponse = resource.CreateShipment(new Hashtable()
                {
                    { "address_to", toAddressTable },
                    { "address_from", fromAddressTable },
                    { "parcels", parcels },
                    { "async", false }
                });

                var response = "{\"success\": \"success\" ," +
                               "\"shipment_id\" : \"" + apiResponse.ObjectId + "\"," +
                               "\"rates\" : " + JSON.stringify(apiResponse.Rates) + "}";

                return(response);
            }
            catch (Exception e)
            {
                var response = "{\"error\": \"exception caught by server\" ," +
                               "\"details\" : " + e.Message.ToString() + "}";
                return(response);
            }
        }