public static Batch getDefaultObject() { // Grab USPS carrier account to get the correct object ID for further testing. // This should be changed to be more generic in future versions of this test. In // other words, remove the depedence on a USPS carrier account to exist. ShippoCollection <CarrierAccount> carrierAccounts = getAPIResource().AllCarrierAccount(); string defaultCarrierAccount = ""; foreach (CarrierAccount account in carrierAccounts) { if (account.Carrier.ToString() == "usps") { defaultCarrierAccount = account.ObjectId; } } Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF", "CA", "94103", "US", "4151234567", "*****@*****.**"); Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF", "CA", "94103", "US", "4151234568", "*****@*****.**"); Parcel[] parcels = { Parcel.createForShipment(5, 5, 5, "in", 2, "oz") }; Shipment shipment = Shipment.createForBatch(addressFrom, addressTo, parcels); BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment); List <BatchShipment> batchShipments = new List <BatchShipment>(); batchShipments.Add(batchShipment); Batch batch = getAPIResource().CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6, "BATCH #170", batchShipments); Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status); return(batch); }
private static void RunBatchExample(APIResource resource) { ShippoCollection <CarrierAccount> carrierAccounts = resource.AllCarrierAccount(); string defaultCarrierAccount = ""; foreach (CarrierAccount account in carrierAccounts) { if (account.Carrier.ToString() == "usps") { defaultCarrierAccount = account.ObjectId; } } Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF", "CA", "94103", "US", "4151234567", "*****@*****.**"); Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF", "CA", "94103", "US", "4151234568", "*****@*****.**"); Parcel[] parcels = { Parcel.createForShipment(5, 5, 5, "in", 2, "oz") }; Shipment shipment = Shipment.createForBatch(addressFrom, addressTo, parcels); BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment); List <BatchShipment> batchShipments = new List <BatchShipment> (); batchShipments.Add(batchShipment); Batch batch = resource.CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6, "BATCH #170", batchShipments); Console.WriteLine("Batch Status = " + batch.Status); Console.WriteLine("Metadata = " + batch.Metadata); }
public static async Task <Manifest> GetDefaultObject(BaseAddress addressTo) { var parameters0 = new CreateShipment(); Address addressFrom = await AddressTest.GetDefaultObject(); Parcel parcel = await ParcelTest.GetDefaultObject(); parameters0.AddressFrom = addressFrom.ObjectId; parameters0.AddressTo = addressTo; parameters0.AddParcel(parcel.ObjectId); parameters0.ShipmentDate = DateTime.Now; parameters0.CustomsDeclaration = ""; parameters0.Extra = new ShipmentExtra { Insurance = new ShipmentExtraInsurance { Amount = 30, Currency = "USD" }, SignatureConfirmation = ShippoEnums.SignatureConfirmations.STANDARD }; parameters0.Metadata = "Customer ID 123456"; parameters0.Async = false; Shipment shipment = await GetShippoClient().CreateShipment(parameters0); ShippoCollection <Rate> rateCollection = await GetShippoClient().GetShippingRatesSync(shipment.ObjectId, "USD"); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); var createTransaction = new CreateTransaction { Rate = rateArray[0].ObjectId, Metadata = "Customer ID 123456" }; Transaction transaction = await GetShippoClient().CreateTransactionSync(createTransaction); var parameters2 = new CreateManifest { ShipmentDate = DateTime.Now, AddressFromObjectId = addressFrom.ObjectId, Provider = "usps" }; var transactions = new List <string>(); transactions.Add(transaction.ObjectId); parameters2.TransactionsIds = transactions.ToArray(); return(await GetShippoClient().CreateManifest(parameters2)); }
public static Transaction getDefaultObject() { Hashtable parameters = new Hashtable(); ShippoCollection <Rate> rateCollection = RateTest.getDefaultObject(); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); parameters.Add("rate", rateArray [0].ObjectId); parameters.Add("metadata", "Customer ID 123456"); return(getAPIResource().CreateTransactionSync(parameters)); }
public static async Task <Transaction> GetDefaultObject() { ShippoCollection <Rate> rateCollection = await RateTest.GetDefaultObject(); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); var parameters = new CreateTransaction { Rate = rateArray[0].ObjectId, Metadata = "Customer ID 123456" }; return(await GetShippoClient().CreateTransactionSync(parameters)); }
public static Manifest getDefaultObject() { Hashtable parameters0 = new Hashtable(); Address addressFrom = AddressTest.getDefaultObject(); Address addressTo = AddressTest.getDefaultObject_2(); Parcel parcel = ParcelTest.getDefaultObject(); parameters0.Add("address_from", addressFrom.ObjectId); parameters0.Add("address_to", addressTo.ObjectId); parameters0.Add("parcels", new String[] { parcel.ObjectId }); parameters0.Add("shipment_date", now); parameters0.Add("insurance_amount", "30"); parameters0.Add("insurance_currency", "USD"); parameters0.Add("extra", "{signature_confirmation: true}"); parameters0.Add("customs_declaration", ""); parameters0.Add("metadata", "Customer ID 123456"); parameters0.Add("async", false); Shipment shipment = getAPIResource().CreateShipment(parameters0); Hashtable parameters1 = new Hashtable(); parameters1.Add("id", shipment.ObjectId); parameters1.Add("currency_code", "USD"); ShippoCollection <Rate> rateCollection = getAPIResource().GetShippingRatesSync(parameters1); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); parameters1.Add("rate", rateArray [0].ObjectId); parameters1.Add("metadata", "Customer ID 123456"); Transaction transaction = getAPIResource().CreateTransactionSync(parameters1); Hashtable parameters2 = new Hashtable(); parameters2.Add("provider", "USPS"); parameters2.Add("shipment_date", now); parameters2.Add("address_from", addressFrom.ObjectId); List <String> transactions = new List <String>(); transactions.Add(transaction.ObjectId); parameters2.Add("transactions", transactions); return(getAPIResource().CreateManifest(parameters2)); }
public static Transaction getDefaultObject() { Hashtable parameters = new Hashtable(); ShippoCollection <Rate> rateCollection = RateTest.getDefaultObject(); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); parameters.Add("rate", rateArray [0].ObjectId); parameters.Add("notification_email_from", "true"); parameters.Add("notification_email_to", "false"); parameters.Add("notification_email_other", "*****@*****.**"); parameters.Add("metadata", "Customer ID 123456"); return(getAPIResource().CreateTransactionSync(parameters)); }
public static async Task <Batch> GetDefaultObject() { // Grab USPS carrier account to get the correct object ID for further testing. // This should be changed to be more generic in future versions of this test. In // other words, remove the depedence on a USPS carrier account to exist. ShippoCollection <CarrierAccount> carrierAccounts = await GetShippoClient().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 GetShippoClient().CreateBatch(new CreateBatch { DefaultCarrierAccount = defaultCarrierAccount, DefaultServicelevelToken = "usps_priority", LabelFiletype = ShippoEnums.LabelFiletypes.PDF_4x6, Metadata = "BATCH #170", BatchShipments = batchShipments }); Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status); return(batch); }
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); }
public void TestParametersRetreive() { ShippoCollection <CarrierAccount> testObject = CarrierAccountTest.getParameterObject(); Assert.AreEqual(1, testObject.Data.Count); }
public void TestValidRetrieve() { ShippoCollection <CarrierAccount> testObject = CarrierAccountTest.getDefaultObject(); Assert.Greater(testObject.Data.Count, 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); } }
public void TestValidCreate() { ShippoCollection <Rate> testObject = RateTest.getDefaultObject(); Assert.IsNotNull(testObject.Data); }
public async Task TestValidCreate() { ShippoCollection <Rate> testObject = await RateTest.GetDefaultObject(); Assert.IsNotNull(testObject.Data); }