コード例 #1
0
        private void CreateCardSource(Card card, bool shouldPollWithBlockingMethod)
        {
            SourceParams         cardSourceParams     = SourceParams.CreateCardParams(card);
            IObservable <Source> cardSourceObservable = System.Reactive.Linq.Observable.FromAsync(() =>
            {
                return(Task.Run(
                           () => mStripe.CreateSourceSynchronous(cardSourceParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY)));
            });

            mCompositeSubscription.Add(cardSourceObservable
                                       .SubscribeOn(Scheduler.Default)
                                       .ObserveOn(Scheduler.CurrentThread)
                                       .Do((s) =>
            {
                RunOnUiThread(() =>
                {
                    mProgressDialogController.SetMessageResource(Resource.String.createSource);
                    mProgressDialogController.StartProgress();
                });
            })
                                       .Subscribe(
                                           (s) =>
            {
                try
                {
                    SourceCardData sourceCardData = (SourceCardData)s.SourceTypeModel;
                    RunOnUiThread(() =>
                    {
                        mPollingAdapter.AddItem(
                            s.Status,
                            sourceCardData.ThreeDSecureStatus,
                            s.Id,
                            s.Type);

                        // If we need to get 3DS verification for this card, we
                        // first create a 3DS Source.
                        if (SourceCardData.Required.Equals(
                                sourceCardData.ThreeDSecureStatus))
                        {
                            // The card Source can be used to create a 3DS Source
                            CreateThreeDSecureSource(s.Id,
                                                     shouldPollWithBlockingMethod);
                        }
                        else
                        {
                            mProgressDialogController.FinishProgress();
                        }
                    });
                }
                catch (Exception e)
                {
                    mProgressDialogController.FinishProgress();
                    mErrorDialogHandler.ShowError(e.Message);
                }
                // Making a note of the Card Source in our list.
            },
                                           (t) =>
            {
                RunOnUiThread(() =>
                {
                    mErrorDialogHandler.ShowError(t.Message);
                });
            }));
        }