Example #1
0
        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     = "";
        }
Example #2
0
        static void Main(string[] args)
        {
            // replace with your Shippo Token
            // don't have one? get more info here
            // (https://goshippo.com/docs/#overview)
            APIResource resource = new APIResource("<Shippo Token>");

            // to address
            Hashtable toAddressTable = new Hashtable();

            toAddressTable.Add("object_purpose", "PURCHASE");
            toAddressTable.Add("name", "Shippo Itle");
            toAddressTable.Add("company", "Shippo");
            toAddressTable.Add("street1", "215 Clayton St.");
            toAddressTable.Add("city", "San Francisco");
            toAddressTable.Add("state", "CA");
            toAddressTable.Add("zip", "94117");
            toAddressTable.Add("country", "US");
            toAddressTable.Add("phone", "+1 555 341 9393");
            toAddressTable.Add("email", "*****@*****.**");

            // from address
            Hashtable fromAddressTable = new Hashtable();

            fromAddressTable.Add("object_purpose", "PURCHASE");
            fromAddressTable.Add("name", "Mr Hippo");
            fromAddressTable.Add("company", "San Diego Zoo");
            fromAddressTable.Add("street1", "2920 Zoo Drive");
            fromAddressTable.Add("city", "San Diego");
            fromAddressTable.Add("state", "CA");
            fromAddressTable.Add("zip", "92101");
            fromAddressTable.Add("country", "US");
            fromAddressTable.Add("email", "*****@*****.**");
            fromAddressTable.Add("phone", "+1 619 231 1515");
            fromAddressTable.Add("metadata", "Customer ID 123456");

            // parcel
            Hashtable parcelTable = new Hashtable();

            parcelTable.Add("length", "5");
            parcelTable.Add("width", "5");
            parcelTable.Add("height", "5");
            parcelTable.Add("distance_unit", "in");
            parcelTable.Add("weight", "2");
            parcelTable.Add("mass_unit", "lb");

            // shipment
            Hashtable shipmentTable = new Hashtable();

            shipmentTable.Add("address_to", toAddressTable);
            shipmentTable.Add("address_from", fromAddressTable);
            shipmentTable.Add("parcel", parcelTable);
            shipmentTable.Add("object_purpose", "PURCHASE");

            // create Shipment object
            Console.WriteLine("Creating Shipment object..");
            Shipment shipment = resource.CreateShipment(shipmentTable);

            // get shipping rates
            Console.WriteLine("Generating rates for shipment " + shipment.ObjectId);
            ShippoCollection <Rate> rates = resource.GetShippingRatesSync((String)shipment.ObjectId);

            Console.WriteLine(String.Format("Obtained " + rates.Data.Count + " rates for shipment " + shipment.ObjectId));
            Rate rate = rates.Data [0];

            Console.WriteLine("Getting shipping label..");
            Hashtable transactionParameters = new Hashtable();

            transactionParameters.Add("rate", rate.ObjectId);
            Transaction transaction = resource.CreateTransactionSync(transactionParameters);


            if (((String)transaction.ObjectStatus).Equals("SUCCESS", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Label url : " + transaction.LabelURL);
                Console.WriteLine("Tracking number : " + transaction.TrackingNumber);
            }
            else
            {
                Console.WriteLine("An Error has occured while generating your label. Messages : " + transaction.Messages);
            }
        }
        static void Main(string[] args)
        {
            // replace with your Shippo Token
            // don't have one? get more info here
            // (https://goshippo.com/docs/#overview)
            APIResource resource = new APIResource ("<Shippo Token>");

            // to address
            Hashtable toAddressTable = new Hashtable ();
            toAddressTable.Add ("object_purpose", "PURCHASE");
            toAddressTable.Add ("name", "Shippo Itle");
            toAddressTable.Add ("company", "Shippo");
            toAddressTable.Add ("street1", "215 Clayton St.");
            toAddressTable.Add ("city", "San Francisco");
            toAddressTable.Add ("state", "CA");
            toAddressTable.Add ("zip", "94117");
            toAddressTable.Add ("country", "US");
            toAddressTable.Add ("phone", "+1 555 341 9393");
            toAddressTable.Add ("email", "*****@*****.**");

            // from address
            Hashtable fromAddressTable = new Hashtable ();
            fromAddressTable.Add ("object_purpose", "PURCHASE");
            fromAddressTable.Add ("name", "Mr Hippo");
            fromAddressTable.Add ("company", "San Diego Zoo");
            fromAddressTable.Add ("street1", "2920 Zoo Drive");
            fromAddressTable.Add ("city", "San Diego");
            fromAddressTable.Add ("state", "CA");
            fromAddressTable.Add ("zip", "92101");
            fromAddressTable.Add ("country", "US");
            fromAddressTable.Add ("email", "*****@*****.**");
            fromAddressTable.Add ("phone", "+1 619 231 1515");
            fromAddressTable.Add ("metadata", "Customer ID 123456");

            // parcel
            Hashtable parcelTable = new Hashtable ();
            parcelTable.Add ("length", "5");
            parcelTable.Add ("width", "5");
            parcelTable.Add ("height", "5");
            parcelTable.Add ("distance_unit", "in");
            parcelTable.Add ("weight", "2");
            parcelTable.Add ("mass_unit", "lb");

            // shipment
            Hashtable shipmentTable = new Hashtable ();
            shipmentTable.Add ("address_to", toAddressTable);
            shipmentTable.Add ("address_from", fromAddressTable);
            shipmentTable.Add ("parcel", parcelTable);
            shipmentTable.Add ("object_purpose", "PURCHASE");

            // create Shipment object
            Console.WriteLine ("Creating Shipment object..");
            Shipment shipment = resource.CreateShipment (shipmentTable);

            // get shipping rates
            Console.WriteLine ("Generating rates for shipment " + shipment.ObjectId);
            ShippoCollection<Rate> rates = resource.GetShippingRatesSync ((String) shipment.ObjectId);

            Console.WriteLine (String.Format ("Obtained " + rates.Data.Count + " rates for shipment " + shipment.ObjectId));
            Rate rate = rates.Data [0];

            Console.WriteLine ("Getting shipping label..");
            Hashtable transactionParameters = new Hashtable ();
            transactionParameters.Add ("rate", rate.ObjectId);
            Transaction transaction = resource.CreateTransactionSync (transactionParameters);

            if (((String) transaction.ObjectStatus).Equals ("SUCCESS", StringComparison.OrdinalIgnoreCase)) {
                Console.WriteLine ("Label url : " + transaction.LabelURL);
                Console.WriteLine ("Tracking number : " + transaction.TrackingNumber);
            } else {
                Console.WriteLine ("An Error has occured while generating your label. Messages : " + transaction.Messages);
            }
        }