Ejemplo n.º 1
0
        private static void HandleShippingOptionUpdated(PaymentRequestChangedArgs args, ShoppingCart shoppingCart)
        {
            string selectedShippingOptionId = args.SelectedShippingOption.Tag;

            // If the payment provider app decides to send us nothing, just ignore the result.
            if (!string.IsNullOrEmpty(selectedShippingOptionId))
            {
                ShippingType selectedShippingType;

                if (!Enum.TryParse <ShippingType>(selectedShippingOptionId, out selectedShippingType))
                {
                    // A proper merchant app implementation might want to just ignore the bad result and
                    // send a correction to the payment provider app.
                    throw new Exception("Unrecognized shipping method id.");
                }

                shoppingCart.ShippingType = selectedShippingType;
            }
        }
Ejemplo n.º 2
0
        private static void PaymentRequestChangedEventHandler(
            Action abortSubmitFunc,
            PaymentRequestChangedArgs args,
            ShoppingCart shoppingCart)
        {
            switch (args.ChangeKind)
            {
            case PaymentRequestChangeKind.ShippingAddress:
                shoppingCart.SetShippingAddress(args.ShippingAddress);
                break;

            case PaymentRequestChangeKind.ShippingOption:
                HandleShippingOptionUpdated(args, shoppingCart);
                break;
            }

            var result = new PaymentRequestChangedResult(
                changeAcceptedByMerchant: true,
                updatedPaymentDetails: CreatePaymentDetails(shoppingCart));

            args.Acknowledge(result);
        }