Beispiel #1
0
        public async Task InvalidParamsAsync()
        {
            var manifestItems = new List<PostmatesManifestItem>();
            manifestItems.Add(new PostmatesManifestItem()
            {
                Name = "Loopie Laundry bag",
                Quantity = 1,
                Size = PostmatesItemSizes.Medium
            });

            var delivery = new PostmatesCreateDeliveryArgs()
            {
                Manifest = "Laundry in a Loopie bag.",
                ManifestItems = manifestItems,
                PickupName = "Marcus",
                PickupAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "229 1st AVE N",
                    City = "Seattle",
                    State = UsStates.WA,
                    Country = Countries.US,
                    ZipCode = "98109"
                },
                PickupPhoneNumber = "3155140118",
                PickupNotes = "Ring doorbell",
                DropoffName = "Loopie HQ",
                DropoffAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "3958 6th AVE NW",
                    StreetAddress2 = "",
                    City = "Seattle",
                    State = UsStates.WA,
                    Country = Countries.US,
                    ZipCode = "98107"
                },
                DropoffPhoneNumber = "31asdfg118",
                DropoffNotes = "Ring doorbell/Call"
            };

            try
            {
                var result = await PostmatesClient.CreateDeliveryAsync(delivery);
            }
            catch (Exception e)
            {
                Assert.IsType<InvalidParamsException>(e);
                var containsParam = ((InvalidParamsException)e).PostmatesParams.TryGetValue("dropoff_phone_number", out string paramMessage);
                Assert.True(containsParam);
            }
        }
Beispiel #2
0
        public async Task ListOngoingDeliveriesAsync()
        {

            var deliveryCreateArgs = new PostmatesCreateDeliveryArgs()
            {
                Manifest = "Laundry in a Loopie bag.",
                PickupName = "Marcus",
                PickupAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "229 1st AVE N",
                    City = "Seattle",
                    State = UsStates.WA,
                    Country = Countries.US,
                    ZipCode = "98109"
                },
                PickupPhoneNumber = "3155140118",
                PickupNotes = "Ring doorbell",
                DropoffName = "Loopie HQ",
                DropoffAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "3958 6th AVE NW",
                    StreetAddress2 = "",
                    City = "Seattle",
                    State = UsStates.WA,
                    Country = Countries.US,
                    ZipCode = "98107"
                },
                DropoffPhoneNumber = "3155140118",
                DropoffNotes = "Ring doorbell/Call",
                PickupReady = DateTime.UtcNow.AddMinutes(10),
                PickupDeadline = DateTime.UtcNow.AddMinutes(25),
                DropoffReady = DateTime.UtcNow.AddMinutes(20),
                DropoffDeadline = DateTime.UtcNow.AddMinutes(60)
            };

            var ongoingDelivery = await PostmatesClient.CreateDeliveryAsync(deliveryCreateArgs);

            var result = await PostmatesClient.GetOngoingDeliveriesAsync();
            
            /// $todo(marcus.bowyer)
            ///     figure out how to make this actually return something
            
        }
        public async Task CreateDeliveryAsync()
        {
            var manifestItems = new List <PostmatesManifestItem>();

            manifestItems.Add(new PostmatesManifestItem()
            {
                Name     = "Loopie Laundry bag",
                Quantity = 1,
                Size     = PostmatesItemSizes.Medium
            });

            var delivery = new PostmatesCreateDeliveryArgs()
            {
                Manifest      = "Laundry in a Loopie bag.",
                ManifestItems = manifestItems,
                PickupName    = "Marcus",
                PickupAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "229 1st AVE N",
                    City           = "Seattle",
                    State          = UsStates.WA,
                    Country        = Countries.US,
                    ZipCode        = "98109"
                },
                PickupPhoneNumber = "3155140118",
                PickupNotes       = "Ring doorbell",
                DropoffName       = "Loopie HQ",
                DropoffAddress    = new PostmatesAddress()
                {
                    StreetAddress1 = "3958 6th AVE NW",
                    StreetAddress2 = "",
                    City           = "Seattle",
                    State          = UsStates.WA,
                    Country        = Countries.US,
                    ZipCode        = "98107"
                },
                DropoffPhoneNumber = "3155140118",
                DropoffNotes       = "Ring doorbell/Call"
            };
            var result = await PostmatesClient.CreateDeliveryAsync(delivery);

            Assert.IsType <PostmatesDelivery>(result);
        }
        public async Task CancelDeliveryAsync()
        {
            var deliveryCreateArgs = new PostmatesCreateDeliveryArgs()
            {
                Manifest      = "Laundry in a Loopie bag.",
                PickupName    = "Marcus",
                PickupAddress = new PostmatesAddress()
                {
                    StreetAddress1 = "229 1st AVE N",
                    City           = "Seattle",
                    State          = UsStates.WA,
                    Country        = Countries.US,
                    ZipCode        = "98109"
                },
                PickupPhoneNumber = "3155140118",
                PickupNotes       = "Ring doorbell",
                DropoffName       = "Loopie HQ",
                DropoffAddress    = new PostmatesAddress()
                {
                    StreetAddress1 = "3958 6th AVE NW",
                    StreetAddress2 = "",
                    City           = "Seattle",
                    State          = UsStates.WA,
                    Country        = Countries.US,
                    ZipCode        = "98107"
                },
                DropoffPhoneNumber = "3155140118",
                DropoffNotes       = "Ring doorbell/Call",
                PickupReady        = DateTime.UtcNow.AddMinutes(10),
                PickupDeadline     = DateTime.UtcNow.AddMinutes(25),
                DropoffReady       = DateTime.UtcNow.AddMinutes(20),
                DropofffDeadline   = DateTime.UtcNow.AddMinutes(60)
            };

            var deliveryToCancel = await PostmatesClient.CreateDeliveryAsync(deliveryCreateArgs);

            var result = await PostmatesClient.CancelDeliveryAsync(deliveryToCancel.Id);

            Assert.True(deliveryToCancel.Id == result.Id);
            Assert.True(result.Status == PostmatesDeliveryStatuses.Canceled);
        }
        /// <summary>
        /// After you've successfully created a delivery quote, it's time to create an actual delivery on the Postmates platform.
        /// It's recommended that you include the previously generated quote_id to ensure the costs and ETAs are consistent with
        /// the quote. Once a delivery is accepted, the delivery fee will be deducted from your account.
        ///
        /// To ensure your deliveries are being picked up and dropped off on time, you can specify a pickup window and a dropoff
        /// window.Our dispatch system will send a courier to pick up the order within the pickup window, and will make sure that
        /// the order is given to the customer during the dropoff window. Pickup and dropoff windows are specified using
        /// pickup_ready_dt, pickup_deadline_dt, dropoff_ready_dt, and dropoff_deadline_dt.These timestamps have the
        /// following requirements:
        ///
        ///     - pickup_ready_dt must be less than 30 days in the future.
        ///
        ///     - pickup_deadline_dt must be at least 10 mins later than pickup_ready_dt
        ///     and at least 20 minutes in the future, thus providing a realistic pickup window.
        ///
        ///     - dropoff_ready_dt must be less than or equal to pickup_deadline_dt.This is to prevent a scenario where a courier
        ///     has to hold onto an order between the pickup and dropoff windows.
        ///
        ///     - dropoff_deadline_dt must be at least 20 mins later than dropoff_ready_dt, thus providing a realistic
        ///     dropoff window.
        ///
        ///     - dropoff_deadline_dt must be greater than or equal to pickup_deadline_dt.
        ///
        /// </summary>
        /// <param name="args">The postmates delivery quote arguments</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <PostmatesDelivery> CreateDeliveryAsync(PostmatesCreateDeliveryArgs args, CancellationToken cancellationToken = default)
        {
            args.Validate();

            // Create the arguments to be sent to Postmates.
            // Address needs to be formatted as a string, etc.
            dynamic jsonObject = new JObject();

            jsonObject.quote_id                   = args.QuoteId;
            jsonObject.manifest                   = args.Manifest;
            jsonObject.manifest_reference         = args.ManifestReference;
            jsonObject.manifest_items             = (args.ManifestItems == null) ? null : JsonConvert.SerializeObject(args.ManifestItems);
            jsonObject.pickup_name                = args.PickupName;
            jsonObject.pickup_address             = args.PickupAddress.ToString();
            jsonObject.pickup_latitude            = args.PickupLatitude;
            jsonObject.pickup_longitude           = args.PickupLongitude;
            jsonObject.pickup_phone_number        = args.PickupPhoneNumber;
            jsonObject.pickup_business_name       = args.PickupBusinessName;
            jsonObject.pickup_notes               = args.PickupNotes;
            jsonObject.dropoff_name               = args.DropoffName;
            jsonObject.dropoff_address            = args.DropoffAddress.ToString();
            jsonObject.dropoff_latitude           = args.DropoffLatitude;
            jsonObject.dropoff_longitude          = args.DropoffLongitude;
            jsonObject.dropoff_phone_number       = args.DropoffPhoneNumber;
            jsonObject.dropoff_business_name      = args.DropoffBusinessName;
            jsonObject.dropoff_notes              = args.DropoffNotes;
            jsonObject.requires_id                = args.RequiresId;
            jsonObject.requires_dropoff_signature = args.RequiresDropoffSignature;
            jsonObject.pickup_ready_dt            = args.PickupReady;
            jsonObject.pickup_deadline_dt         = args.PickupDeadline;
            jsonObject.dropoff_ready_dt           = args.DropoffReady;
            jsonObject.dropoff_deadline_dt        = args.DropofffDeadline;

            var result = await PostFormAsync <PostmatesDelivery>(FormatPath("deliveries"), jsonObject, cancellationToken);

            return(result);
        }