// Create a new checkout with the selected product. For convenience in the sample app we will hardcode the user's shipping address.
        // The shipping rates fetched in ShippingRateListActivity will be for this address.
        public void CreateCheckout(Product product, Action <Checkout, Response> success, Action <RetrofitError> failure)
        {
            var cart = new Cart();

            cart.AddVariant(product.Variants[0]);

            Checkout = new Checkout(cart);
            Checkout.ShippingAddress = new Address
            {
                FirstName   = "Dinosaur",
                LastName    = "Banana",
                Address1    = "421 8th Ave",
                City        = "New York",
                Province    = "NY",
                Zip         = "10001",
                CountryCode = "US"
            };
            Checkout.Email = "*****@*****.**";
            Checkout.SetWebReturnToUrl(GetString(Resource.String.web_return_to_url));
            Checkout.SetWebReturnToLabel(GetString(Resource.String.web_return_to_label));

            BuyClient.CreateCheckout(Checkout, (data, response) =>
            {
                Checkout = data;
                success(data, response);
            }, failure);
        }
示例#2
0
        private void DemoNativeFlowWithProduct(Product product)
        {
            if (checkoutCreationTask != null && checkoutCreationTask.State == NSUrlSessionTaskState.Running)
            {
                checkoutCreationTask.Cancel();
            }

            var cart = new Cart();

            cart.AddVariant(product.Variants [0]);

            var checkout = new Checkout(cart);

            // Apply billing and shipping address, as well as email to the checkout
            checkout.ShippingAddress = Address;
            checkout.BillingAddress  = Address;
            checkout.Email           = "*****@*****.**";

            client.UrlScheme = "xamarinsample://";

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
            checkoutCreationTask = client.CreateCheckout(checkout, (chkout, error) => {
                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

                if (error == null && chkout != null)
                {
                    var shippingController = new ShippingRatesTableViewController(client, chkout);
                    NavigationController.PushViewController(shippingController, true);
                }
                else
                {
                    Console.WriteLine("Error creating checkout: {0}", error);
                }
            });
        }