Esempio n. 1
0
        public void OnSuccess(Token token)
        {
            try
            {
                // Send token to your own web service
                //var stripeBankAccount = token.BankAccount;
                //var stripeCard = token.Card;
                //var stripeCreated = token.Created;
                TokenId = token.Id;
                //var stripeLiveMode = token.Livemode;
                //var stripeType = token.Type;
                //var stripeUsed = token.Used;
                var currencyCode = ListUtils.SettingsSiteList?.StripeCurrency ?? "USD";

                CustomerSession.InitCustomerSession(this);
                CustomerSession.Instance.SetCustomerShippingInformation(this, new ShippingInformation());
                CustomerSession.Instance.AddProductUsageTokenIfValid(TokenId);

                // Create the PaymentSession
                PaymentSession = new PaymentSession(this);
                PaymentSession.Init(this, GetPaymentSessionConfig());

                var priceInt = Convert.ToInt32(Price) * 100;
                Stripe.CreateSource(SourceParams.CreateAlipaySingleUseParams(priceInt, currencyCode.ToLower(), EtName.Text, UserDetails.Email, "stripe://payment_intent_return"), this);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                AndHUD.Shared.Dismiss(this);
            }
        }
        private void CreateThreeDSecureSource(string sourceId, bool shouldPollWithBlockingMethod)
        {
            SourceParams threeDParams = SourceParams.CreateThreeDSecureParams(
                1000L,
                "EUR",
                GetUrl(shouldPollWithBlockingMethod),
                sourceId);

            IObservable <Source> threeDSecureObservable = System.Reactive.Linq.Observable.FromAsync(() =>
            {
                return(Task.Run(() => mStripe.CreateSourceSynchronous(
                                    threeDParams,
                                    FUNCTIONAL_SOURCE_PUBLISHABLE_KEY)));
            });

            mCompositeSubscription.Add(threeDSecureObservable
                                       .SubscribeOn(Scheduler.Immediate)
                                       .ObserveOn(Scheduler.CurrentThread)
                                       .Do((s) => { }, (t) =>
            {
                RunOnUiThread(() =>
                {
                    mProgressDialogController.FinishProgress();
                });
            })
                                       .Subscribe(
                                           (source) =>
            {
                RunOnUiThread(() =>
                {
                    ShowDialog(source);
                });
            },
                                           (t) =>
            {
                RunOnUiThread(() =>
                {
                    mErrorDialogHandler.ShowError(t.Message);
                });
            }));
        }
        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);
                });
            }));
        }