protected override void OnHandleIntent(Intent intent)
        {
            string errorMessage = null;
            Token  token        = null;

            if (intent != null)
            {
                string  cardNumber = intent.GetStringExtra(EXTRA_CARD_NUMBER);
                Integer month      = (Integer)intent.Extras.Get(EXTRA_MONTH);
                Integer year       = (Integer)intent.Extras.Get(EXTRA_YEAR);
                string  cvc        = intent.GetStringExtra(EXTRA_CVC);

                string publishableKey = intent.GetStringExtra(EXTRA_PUBLISHABLE_KEY);
                Card   card           = new Card(cardNumber, month, year, cvc);

                Stripe stripe = new Stripe(this);
                try
                {
                    token = stripe.CreateTokenSynchronous(card, publishableKey);
                }
                catch (StripeException stripeEx)
                {
                    errorMessage = stripeEx.LocalizedMessage;
                }
            }

            Intent localIntent = new Intent(TOKEN_ACTION);

            if (token != null)
            {
                localIntent.PutExtra(STRIPE_CARD_LAST_FOUR, token.Card.Last4);
                localIntent.PutExtra(STRIPE_CARD_TOKEN_ID, token.Id);
            }

            if (errorMessage != null)
            {
                localIntent.PutExtra(STRIPE_ERROR_MESSAGE, errorMessage);
            }

            // Broadcasts the Intent to receivers in this app.
            LocalBroadcastManager.GetInstance(this).SendBroadcast(localIntent);
        }
Ejemplo n.º 2
0
        private void SaveCard()
        {
            Card cardToSave = mCardInputWidget.Card;

            if (cardToSave == null)
            {
                mErrorDialogHandler.ShowError("Invalid Card Data");
                return;
            }

            Stripe stripe = new Stripe(mContext);

            IObservable <Token> tokenObservable = Observable.FromAsync((s) =>
            {
                return(Task.Run(() => stripe.CreateTokenSynchronous(cardToSave, mPublishableKey)));
            });

            mCompositeSubscription.Add(
                tokenObservable
                .SubscribeOn <Token>(Scheduler.Immediate)
                .ObserveOn <Token>(Scheduler.CurrentThread)
                .Do <Token>(
                    (token) =>
            {
                mProgressDialogController.StartProgress();
            },
                    (b) =>
            {
                mProgressDialogController.FinishProgress();
            })
                .Subscribe(
                    (token) =>
            {
                mOutputListController.AddToList(token);
            },
                    (throwable) =>
            {
                mErrorDialogHandler.ShowError(throwable.Message);
            }));
        }