Ejemplo n.º 1
0
        public async Task <StripeResponse> CreateCreditCard(StripeTempToken token)
        {
            string JToken = JsonConvert.SerializeObject(token);
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("posttoken", JToken);
            try
            {
                StripeResponse temp = await cloudService.client.InvokeApiAsync <string, StripeResponse>("Stripe", JToken, HttpMethod.Post, parameters);

                return(temp);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Stripe Failure", ex.Message, "OK");
            }
            return(null);
        }
Ejemplo n.º 2
0
        public async Task ExecuteSaveCardDetailsCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            card   = new Card
            {
                Number      = _cardNumber,
                ExpiryMonth = int.Parse(_expirationDateM),
                ExpiryYear  = int.Parse(_expirationDateY),
                CVC         = _CVC.ToString()
            };
            try
            {
                var token = await StripeClient.CreateToken(card);

                var stripeService = (StripeService)ServiceLocator.Instance.Resolve <IStripeProvider>();

                StripeTempToken stripeToken = new StripeTempToken(token);
                StripeResponse  response    = await stripeService.CreateCreditCard(stripeToken);

                var loginProvider = DependencyService.Get <ILoginProvider>();

                Account acc = loginProvider.RetreiveAccountFromSecureStore();
                acc.Properties.Add(Constants.stripeAccountIdPropertyName, response.ObjectJson);
                loginProvider.SaveAccountInSecureStore(acc);

                Console.WriteLine("Response: " + response.RequestDate);
                // Slightly different for non-Apple Pay use, see
                // 'Sending the token to your server' for more info
                //await CreateBackendCharge(token);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Items Not Loaded", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }