Exemplo n.º 1
0
        private static async Task RunInternationalAddressValidationExample(ShippoClient resource)
        {
            var parameters = new CreateAddress
            {
                Name       = "Shippo Hippo",
                Company    = "Shippo",
                StreetNo   = null,
                Street1    = "40 Bay St",
                Street2    = null,
                City       = "Toronto",
                State      = "ON",
                PostalCode = "M5J 2X2",
                Country    = "CA",
                Phone      = "+1 555 341 9393",
                Email      = "*****@*****.**",
                Metadata   = "Customer ID 123456",
                Validate   = true
            };
            Address address = await 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();
                }
            }
        }
Exemplo n.º 2
0
        private static async Task RunTrackingExample(ShippoClient resource)
        {
            Track track = await resource.RetrieveTracking("usps", TRACKING_NO);

            Console.WriteLine("Carrier = " + track.Carrier.ToUpper());
            Console.WriteLine("Tracking number = " + track.TrackingNumber);
        }
Exemplo n.º 3
0
        private static async Task RunBatchExample(ShippoClient resource)
        {
            ShippoCollection <CarrierAccount> carrierAccounts = await resource.AllCarrierAccounts();

            string defaultCarrierAccount = "";

            foreach (CarrierAccount account in carrierAccounts)
            {
                if (account.Carrier.ToString() == "usps")
                {
                    defaultCarrierAccount = account.ObjectId;
                }
            }

            var addressFrom = CreateAddress.CreateForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF",
                                                              "CA", "94103", "US", "4151234567", "*****@*****.**");
            var addressTo = CreateAddress.CreateForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF",
                                                            "CA", "94103", "US", "4151234568", "*****@*****.**");

            CreateParcel[] parcels       = { CreateParcel.CreateForShipment(5, 5, 5, DistanceUnits.@in, 2, MassUnits.oz) };
            var            shipment      = CreateShipment.CreateForBatch(addressFrom, addressTo, parcels);
            var            batchShipment = CreateBatchShipment.CreateForBatchShipments(defaultCarrierAccount, "usps_priority", shipment);

            var batchShipments = new List <CreateBatchShipment>();

            batchShipments.Add(batchShipment);

            Batch batch = await resource.CreateBatch(new CreateBatch
            {
                DefaultCarrierAccount    = defaultCarrierAccount,
                DefaultServicelevelToken = "usps_priority",
                LabelFiletype            = ShippoEnums.LabelFiletypes.PDF_4x6,
                Metadata       = "BATCH #170",
                BatchShipments = batchShipments
            });

            Console.WriteLine("Batch Status = " + batch.Status);
            Console.WriteLine("Metadata = " + batch.Metadata);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            // replace with your Shippo Token
            // don't have one? get more info here
            // (https://goshippo.com/docs/#overview)
            var client = new ShippoClient("<YourShippoToken>");

            // to address
            var toAddressTable = new CreateAddress
            {
                Name       = "Mr. Hippo",
                Company    = "Shippo",
                Street1    = "215 Clayton St.",
                City       = "San Francisco",
                State      = "CA",
                PostalCode = "94117",
                Country    = "US",
                Phone      = "+1 555 341 9393",
                Email      = "*****@*****.**"
            };

            // from address
            var fromAddressTable = new CreateAddress
            {
                Name       = "Ms Hippo",
                Company    = "San Diego Zoo",
                Street1    = "2920 Zoo Drive",
                City       = "San Diego",
                State      = "CA",
                PostalCode = "92101",
                Country    = "US",
                Email      = "*****@*****.**",
                Phone      = "+1 619 231 1515",
                Metadata   = "Customer ID 123456"
            };

            // parcel
            var parcelTable = new CreateParcel
            {
                Length       = 5,
                Width        = 5,
                Height       = 5,
                DistanceUnit = DistanceUnits.@in,
                Weight       = 2,
                MassUnit     = MassUnits.lb
            };

            // shipment
            var shipmentTable = new CreateShipment
            {
                AddressTo   = toAddressTable,
                AddressFrom = fromAddressTable,
                Async       = false
            };

            shipmentTable.AddParcel(parcelTable);

            // create Shipment object
            Console.WriteLine("Creating Shipment object..");
            Task.Run(async() =>
            {
                Shipment shipment = await client.CreateShipment(shipmentTable);

                // select desired shipping rate according to your business logic
                // we simply select the first rate in this example
                Rate rate = shipment.Rates[0];

                Console.WriteLine("Getting shipping label..");
                var transactionParameters = new CreateTransaction
                {
                    Rate  = rate.ObjectId,
                    Async = false
                };
                Transaction transaction = await client.CreateTransaction(transactionParameters);

                if (transaction.Status == ShippoEnums.TransactionStatuses.SUCCESS)
                {
                    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);
                }

                Console.WriteLine("\nBatch\n");
                await RunBatchExample(client);

                Console.WriteLine("\nTrack\n");
                await RunTrackingExample(client);

                Console.WriteLine("\nValidating International Address\n");
                await RunInternationalAddressValidationExample(client);
            }).Wait();
        }
Exemplo n.º 5
0
 public void Init()
 {
     shippoClient = new ShippoClient("<YourShippoToken>");
 }