public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Checkout";

            var footerView = new UIView(new CGRect(0, 0, View.Bounds.Width, 164));

            var creditCardButton = new UIButton(UIButtonType.RoundedRect);

            creditCardButton.SetTitle("Checkout with Credit Card", UIControlState.Normal);
            creditCardButton.BackgroundColor    = UIColor.FromRGBA(0.48f, 0.71f, 0.36f, 1.0f);
            creditCardButton.Layer.CornerRadius = 6;
            creditCardButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            creditCardButton.TranslatesAutoresizingMaskIntoConstraints = false;
            creditCardButton.TouchUpInside += CheckoutWithCreditCard;
            footerView.AddSubview(creditCardButton);

            var webCheckoutButton = new UIButton(UIButtonType.RoundedRect);

            webCheckoutButton.SetTitle("Web Checkout", UIControlState.Normal);
            webCheckoutButton.BackgroundColor    = UIColor.FromRGBA(0.48f, 0.71f, 0.36f, 1.0f);
            webCheckoutButton.Layer.CornerRadius = 6;
            webCheckoutButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            webCheckoutButton.TranslatesAutoresizingMaskIntoConstraints = false;
            webCheckoutButton.TouchUpInside += CheckoutOnWeb;
            footerView.AddSubview(webCheckoutButton);

            var applePayButton = PaymentButton.Create(PaymentButtonType.Buy, PaymentButtonStyle.Black);

            applePayButton.TranslatesAutoresizingMaskIntoConstraints = false;
            applePayButton.TouchUpInside += CheckoutWithApplePay;
            footerView.AddSubview(applePayButton);

            var views = NSDictionary.FromObjectsAndKeys(new[] {
                creditCardButton,
                webCheckoutButton,
                applePayButton
            }, new[] {
                "creditCardButton",
                "webCheckoutButton",
                "applePayButton"
            });

            footerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-[creditCardButton]-|", 0, null, views));
            footerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-[webCheckoutButton]-|", 0, null, views));
            footerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-[applePayButton]-|", 0, null, views));
            footerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-[creditCardButton(44)]-[webCheckoutButton(==creditCardButton)]-[applePayButton(==creditCardButton)]-|", 0, null, views));

            TableView.TableFooterView = footerView;

            // Prefetch the shop object for Apple Pay
            this.shop = await client.GetShopAsync();
        }
        private async Task GetShopAsync()
        {
            try
            {
                var shop = await client.GetShopAsync();

                currencyFormatter              = new NSNumberFormatter();
                currencyFormatter.NumberStyle  = NSNumberFormatterStyle.Currency;
                currencyFormatter.CurrencyCode = shop.Currency;
            }
            catch (NSErrorException ex)
            {
                Console.WriteLine("Failed to retrieve shop: {0}", ex.Error);
            }
        }
Exemple #3
0
        private async Task InitializeBuyClient()
        {
            var shopUrl = GetString(Resource.String.shop_url);

            if (string.IsNullOrEmpty(shopUrl))
            {
                throw new ArgumentException("You must populate the 'shop_url' entry in strings.xml, in the form '<myshop>.myshopify.com'");
            }

            var shopifyApiKey = GetString(Resource.String.shopify_api_key);

            if (string.IsNullOrEmpty(shopifyApiKey))
            {
                throw new ArgumentException("You must populate the 'shopify_api_key' entry in strings.xml");
            }

            var channelId = GetString(Resource.String.channel_id);

            if (string.IsNullOrEmpty(channelId))
            {
                throw new ArgumentException("You must populate the 'channel_id' entry in the strings.xml");
            }

            var applicationName = PackageName;

            // Create the BuyClient
            BuyClient = BuyClientFactory.GetBuyClient(shopUrl, shopifyApiKey, channelId, applicationName);

            try
            {
                Shop = await BuyClient.GetShopAsync();
            }
            catch
            {
                Toast.MakeText(this, Resource.String.shop_error, ToastLength.Long).Show();
            }
        }