private void Init()
        {
            base.RemoveAllViews();

            Orientation = Orientation.Vertical;

            cardImageView = new CardImageView(Context);
            cardImageView.SetCardImageWithoutAnimation(JudoSDKManager.GetCardResourceId(Context, currentCard, true));

            LinearLayout layoutHolder = new LinearLayout(Context);
            layoutHolder.Orientation = Orientation.Horizontal;
            layoutHolder.SetGravity(GravityFlags.CenterVertical);

            LinearLayout cardFrame = new LinearLayout(Context);
            cardFrame.SetGravity(GravityFlags.CenterVertical);
            cardFrame.SetPadding(UiUtils.ToPixels(Context, 8), 0, UiUtils.ToPixels(Context, 8), 0);
            cardFrame.AddView(cardImageView);

            LayoutParams parameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            parameters.Gravity = GravityFlags.Center;

            cardNumberTextView = new CardNumberTextView(Context);
            cardNumberTextView.LayoutParameters = parameters;

            cardExpiryCv2TextView = new CardExpiryCV2TextView(Context, null, Resource.Style.judo_payments_CardText);
            cardExpiryCv2TextView.LayoutParameters = parameters;
            cardExpiryCv2TextView.Visibility = ViewStates.Invisible;

            layoutHolder.AddView(cardFrame, LayoutParams.WrapContent, LayoutParams.MatchParent);
            layoutHolder.AddView(cardNumberTextView);
            layoutHolder.AddView(cardExpiryCv2TextView);

            AddView(layoutHolder);

            int lastPos = 0;
            CardBase.CardType currentCardType;

            cardNumberTextView.OnEntryComplete += cardNumber =>
            {
                if (OnCreditCardEntered != null)
                {
                    OnCreditCardEntered(cardNumber);
                }
                SetStage(Stage.STAGE_CC_EXP);
            };

            cardNumberTextView.OnProgress += position =>
            {
                if (position == 0)
                {
                    return;
                }

                string cardNumber = cardNumberTextView.GetText();
                currentCardType = ValidationHelper.GetCardType(cardNumber);

                if (currentCardType != currentCard)
                {
                    if (currentCard == CardBase.CardType.AMEX && !JudoSDKManager.Configuration.IsAVSEnabled)
                    {
                        cardNumberTextView.ShowInvalid("AmEx not accepted");
                    }
                    else if (currentCard == CardBase.CardType.MASTRO && !JudoSDKManager.Configuration.IsMaestroEnabled)
                    {
                        cardNumberTextView.ShowInvalid("Maestro not accepted");
                    }
                    else
                    {
                        cardImageView.SetCardImage(JudoSDKManager.GetCardResourceId(Context, currentCardType, true), false);
                        cardNumberTextView.SetHintText(JudoSDKManager.GetCardHintFormat(currentCardType));
                        cardExpiryCv2TextView.SetHintText(JudoSDKManager.GetExpiryAndValidationHintFormat(currentCardType));
                        cardExpiryCv2TextView.SetErrorText(JudoSDKManager.GetExpiryAndValidationErrorMessage(currentCardType));
                    }

                    currentCard = currentCardType;
                }
                lastPos = position;
            };

            cardExpiryCv2TextView.OnEntryComplete += expiryAndCV2 =>
            {
                string[] temp = expiryAndCV2.Split(' ');
                if (temp.Length < 2)
                {
                    Log.Error(this.ToString(), "Error: Invalid expiry and/or cv2");
                    return;
                }

                var expiry = temp[0];
                var cv2 = temp[1];

                if (OnExpireAndCV2Entered != null)
                {
                    OnExpireAndCV2Entered(expiry, cv2);
                }
            };

            cardExpiryCv2TextView.OnProgress += position =>
            {
                cardExpiryCv2TextView.ValidatePartialInput();

                if (position > 4)
                {
                    cardImageView.SetCardImage(JudoSDKManager.GetCardResourceId(Context, currentCard, false), true);
                    if (HintTextView != null)
                    {
                        HintTextView.SetText(Resource.String.enter_card_cv2);
                    }

                    if (position == 5)
                    {
                        try
                        {
                            cardExpiryCv2TextView.ValidateExpiryDate(cardExpiryCv2TextView.GetText());
                        }
                        catch (Exception e)
                        {
                            cardExpiryCv2TextView.ShowInvalid(e.Message);
                        }
                    }
                }
                else
                {
                    cardImageView.SetCardImage(JudoSDKManager.GetCardResourceId(Context, currentCard, true), true);
                    if (HintTextView != null)
                    {
                        HintTextView.SetText(Resource.String.enter_card_expiry);
                    }
                }
            };

            cardExpiryCv2TextView.OnBackKeyPressed = () =>
            {
                if (cardExpiryCv2TextView.GetText().Length == 0)
                {
                    cardExpiryCv2TextView.SetText("");
                    SetStage(Stage.STAGE_CC_NO);
                }
            };
        }
        private void dealWithResult(int requestCode, Result resultCode, IResult<ITransactionResult> data)
        {
            Receipt receipt = null;
            string msg_prefix = "";

            if (resultCode == Result.Canceled)
            {
                ResponseText = "Payment Canceled.";
                return;
            }
            else if (resultCode == JudoSDKManager.JUDO_ERROR)
            {
                ResponseText = string.Format("Error: {0}", data.Error.ErrorMessage);
                return;
            }

            if (data != null)
            {
                receipt = new Receipt(data.Response);
            }

            if (receipt == null)
            {
                ResponseText = string.Format("Error: {0}", data.Error.ErrorMessage);
                return;
            }

            switch (requestCode)
            {
                case ACTION_CARD_PAYMENT:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            cardToken = paymentReceipt.CardDetails.CardToken;
                            consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            lastFour = paymentReceipt.CardDetails.CardLastfour;
                            cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }
                        msg_prefix = "Payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "Payment failed";
                    }
                    break;
                case ACTION_PREAUTH:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            preAuth_cardToken = paymentReceipt.CardDetails.CardToken;
                            preAuth_consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            preAuth_rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            preAuth_lastFour = paymentReceipt.CardDetails.CardLastfour;
                            preAuth_cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }

                        msg_prefix = "PreAuth card payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "PreAuth card payment failed";
                    }
                    break;
                case ACTION_TOKEN_PAYMENT:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        msg_prefix = "Token payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "Token payment failed";
                    }
                    break;
                case ACTION_TOKEN_PREAUTH:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        msg_prefix = "PreAuth Token payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "PreAuth Token payment failed";
                    }
                    break;
                case ACTION_REGISTER_CARD:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            cardToken = paymentReceipt.CardDetails.CardToken;
                            consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            lastFour = paymentReceipt.CardDetails.CardLastfour;
                            cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }

                        msg_prefix = "Register card succeeded";
                    }
                    else
                    {
                        msg_prefix = "Register card failed";
                    }
                    break;
            }

            if (receipt != null)
            {
                ResponseText = string.Format("{0}: id: {1},\r\nMessage: {2},\r\nresult: {3}", msg_prefix, receipt.ReceiptId, receipt.Message, receipt.Result);
            }
        }
        public void Reset()
        {
            cardNumberTextView.GetEditText().Text = "";
            cardExpiryCv2TextView.GetEditText().Text = "";
            currentCard = CardBase.CardType.UNKNOWN;
            cardImageView.SetCardImage(JudoSDKManager.GetCardResourceId(Context, currentCard, true), false);

            if (HintTextView != null)
            {
                HintTextView.SetText(Resource.String.enter_card_no);
            }

            SetStage(Stage.STAGE_CC_NO);

            //Show keyboard
            InputMethodManager imm = (InputMethodManager) Context.GetSystemService(Context.InputMethodService);
            imm.HideSoftInputFromInputMethod(cardNumberTextView.WindowToken, 0);
            imm.ToggleSoftInput(ShowFlags.Forced, 0);
        }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            Receipt receipt = null;
            string msg_prefix = "";

            if (resultCode == Result.Canceled) 
            {
                Toast.MakeText(this, "Payment Canceled.", ToastLength.Long).Show();
                return;
            }
            else if (resultCode == JudoSDKManager.JUDO_ERROR)
            {
                Error err =  data.GetParcelableExtra(JudoSDKManager.JUDO_ERROR_EXCEPTION) as Error;

                Toast.MakeText(this, string.Format("Error: {0} {1}", data.GetStringExtra(JudoSDKManager.JUDO_ERROR_MESSAGE),
                    err != null && err.Exception != null ? "\r\nException: " + err.Exception.Message : ""), ToastLength.Long).Show();
                return;
            }

            if(data != null)
                receipt = data.GetParcelableExtra(JudoSDKManager.JUDO_RECEIPT) as Receipt;

            if (receipt == null)
            {
                Toast.MakeText(this, string.Format("Error: {0}", data.GetStringExtra(JudoSDKManager.JUDO_ERROR_MESSAGE)), ToastLength.Long).Show();
                return;
            }

            switch (requestCode)
            {
                case ACTION_CARD_PAYMENT:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            cardToken = paymentReceipt.CardDetails.CardToken;
                            consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            lastFour = paymentReceipt.CardDetails.CardLastfour;
                            cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }
                        msg_prefix = "Payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "Payment failed";
                    }
                    break;
                case ACTION_PREAUTH:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            preAuth_cardToken = paymentReceipt.CardDetails.CardToken;
                            preAuth_consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            preAuth_rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            preAuth_lastFour = paymentReceipt.CardDetails.CardLastfour;
                            preAuth_cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }

                        msg_prefix = "PreAuth card payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "PreAuth card payment failed";
                    }
                    break;
                case ACTION_TOKEN_PAYMENT:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        msg_prefix = "Token payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "Token payment failed";
                    }
                    break;
                case ACTION_TOKEN_PREAUTH:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        msg_prefix = "PreAuth Token payment succeeded";
                    }
                    else
                    {
                        msg_prefix = "PreAuth Token payment failed";
                    }
                    break;
                case ACTION_REGISTER_CARD:
                    if (resultCode == Result.Ok && receipt.Result != "Declined")
                    {
                        PaymentReceiptModel paymentReceipt;
                        if ((paymentReceipt = receipt.FullReceipt as PaymentReceiptModel) != null)
                        {
                            cardToken = paymentReceipt.CardDetails.CardToken;
                            consumerToken = paymentReceipt.Consumer.ConsumerToken;
                            rcp_consumerRef = paymentReceipt.Consumer.YourConsumerReference;
                            lastFour = paymentReceipt.CardDetails.CardLastfour;
                            cardType = (CardBase.CardType)paymentReceipt.CardDetails.CardType;
                        }

                        msg_prefix = "Register card succeeded";
                    }
                    else
                    {
                        msg_prefix = "Register card failed";
                    }
                    break;
            }

            if (receipt != null)
            {
                Toast.MakeText(this, string.Format("{0}: id: {1},\r\nMessage: {2},\r\nresult: {3}", msg_prefix, receipt.ReceiptId, receipt.Message, receipt.Result), ToastLength.Long).Show();
            }

        }