Beispiel #1
0
        public void PaymentRequestUpdateInitsWithNoArgs()
        {
            var paymentRequestUpdate = new PaymentRequestUpdate();

            Assert.NotNull(paymentRequestUpdate);
            Assert.IsType <PaymentRequestUpdate>(paymentRequestUpdate);
        }
        private async Task <PaymentRequestUpdateResult> ProcessShippingUpdate(PaymentRequestUpdate paymentRequestUpdate, ShippingUpdateKind updateKind, CancellationToken token = default(CancellationToken))
        {
            var catalogItem = await this.catalogService.GetItemByIdAsync(Guid.Parse(paymentRequestUpdate.Id));

            if (catalogItem == null)
            {
                throw new ArgumentException("Invalid cart identifier within payment request provided.");
            }

            var result = new PaymentRequestUpdateResult(paymentRequestUpdate.Details);

            if (ShippingUpdateKind.Both.Equals(updateKind) || ShippingUpdateKind.Address.Equals(updateKind))
            {
                result.Details.ShippingOptions = (await this.shippingService.GetShippingOptionsAsync(catalogItem, paymentRequestUpdate.ShippingAddress)).ToList();
            }

            if (ShippingUpdateKind.Both.Equals(updateKind) || ShippingUpdateKind.Options.Equals(updateKind))
            {
                foreach (var shippingOption in result.Details.ShippingOptions)
                {
                    shippingOption.Selected = shippingOption.Id.Equals(paymentRequestUpdate.ShippingOption, StringComparison.OrdinalIgnoreCase);
                }
            }

            if (result.Details.ShippingOptions.Count(option => option.Selected.HasValue && option.Selected.Value) != 1)
            {
                throw new ArgumentException("Expected exactly zero or one selected shipping option.");
            }

            // update payment details after shipping changed
            await this.shippingService.UpdatePaymentDetailsAsync(result.Details, paymentRequestUpdate.ShippingAddress, catalogItem);

            return(result);
        }
Beispiel #3
0
        public void PaymentRequestUpdateInits()
        {
            var id              = "id";
            var details         = new PaymentDetails();
            var shippingAddress = GetShippingAddress();
            var shippingOption  = "ground";

            var paymentRequestUpdate = new PaymentRequestUpdate(id, details, shippingAddress, shippingOption);

            Assert.NotNull(paymentRequestUpdate);
            Assert.IsType <PaymentRequestUpdate>(paymentRequestUpdate);
            Assert.Equal(id, paymentRequestUpdate.Id);
            Assert.Equal(details, paymentRequestUpdate.Details);
            Assert.Equal(shippingAddress, paymentRequestUpdate.ShippingAddress);
            Assert.Equal(shippingOption, paymentRequestUpdate.ShippingOption);
        }