Exemplo n.º 1
0
        public void PaymentRequestUpdateResultInitsWithNoArgs()
        {
            var paymentRequestUpdateResult = new PaymentRequestUpdateResult();

            Assert.NotNull(paymentRequestUpdateResult);
            Assert.IsType <PaymentRequestUpdateResult>(paymentRequestUpdateResult);
        }
        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);
        }
Exemplo n.º 3
0
        public void PaymentRequestUpdateResultInits()
        {
            var details = new PaymentDetails(new PaymentItem(), new List <PaymentItem>(), new List <PaymentShippingOption>(), new List <PaymentDetailsModifier>(), "uh-oh");

            var paymentRequestUpdateResult = new PaymentRequestUpdateResult(details);

            Assert.NotNull(paymentRequestUpdateResult);
            Assert.IsType <PaymentRequestUpdateResult>(paymentRequestUpdateResult);
            Assert.Equal(details, paymentRequestUpdateResult.Details);
        }