Esempio n. 1
0
        public 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
            client.GetShop((shop, error) => {
                this.shop = shop;
            });
        }
Esempio n. 2
0
        private void PollForCompletionStatusAsync()
        {
            if (IsCancelled)
            {
                return;
            }

            task = client.GetShop((shop, error) => {
                WillChangeValue("isFinished");
                done = true;
                DidChangeValue("isFinished");

                if (error != null)
                {
                    FailedToReceiveShop?.Invoke(this, error);
                }
                else
                {
                    DidReceiveShop?.Invoke(this, shop);
                }
            });
        }
        private void 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);

            BuyClient.GetShop(
                (shop, response) =>
            {
                Shop = shop;
            },
                (error) =>
            {
                Toast.MakeText(this, Resource.String.shop_error, ToastLength.Long).Show();
            });
        }