Beispiel #1
0
        private async Task OnSaveCommandExecute()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Int64 orderId = await IdService.CreateOrderIdAsync();

                User user = await UserService.GetUserAsync(Helpers.DeviceHelper.GetMunchyId());

                Card card = await CreditCardService.CreateCreditCard();

                card = await CreditCardService.AuthorizeCreditCard(card.id.ToString(), "1000000000000008", "2112", 123);

                Subscription subscription = await SubscriptionService.CreateSubscription(orderId);

                CardDetails cardDetails = await CreditCardService.CreateCreditCardToken(card.id.ToString());

                Subscription authSub = await SubscriptionService.AuthorizeSubscription(subscription.id.ToString(), 1000, cardDetails.token);

                authSub = await SubscriptionService.GetSubscription(authSub.id.ToString());

                if (authSub.accepted)
                {
                    SimpleCreditCard creditCard = new SimpleCreditCard(card.metadata.brand.ToString(), card.metadata.exp_year.ToString(), card.metadata.exp_month.ToString(), "XXXX XXXX XXXX " + card.metadata.last4);
                    await this.UserService.CreateUserCreditCard(user.Id, creditCard);

                    await Application.Current.MainPage.Navigation.PushAsync(new CreatePaymentAuthenticationPage(authSub.id.ToString()));
                }
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Fejl!", e.ToString(), "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }