public async Task <VoucherApplyStatus?> ApplyVoucher(string code)
        {
            if (code.IsEmpty())
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (await UIContext.IsOffline())
            {
                throw new Exception("Network connection is not available.");
            }

            if (User == null)
            {
                throw new Exception("User is not available.");
            }

            var url     = new Uri(Options.BaseUri, Options.VoucherApplyPath).ToString();
            var @params = new { User.Ticket, User.UserId, Code = code };

            var result = await BaseApi.Post <ApplyVoucherResult>(url, @params, OnError.Ignore, showWaiting : false);

            if (result?.Status == VoucherApplyStatus.Succeeded)
            {
                await Refresh();
            }

            return(result?.Status);
        }
Exemplo n.º 2
0
            public static async Task <bool> LoginAsync(string userName, string password)
            {
                var auth = new AuthenticationRequest
                {
                    UserName    = userName,
                    Credentials = password,
                    GrantType   = "password"
                };


                var uri = $"{GlobalSettings.AuthenticationEndpoint}{"api/login"}";

                var authenticationInfo = await BaseApi.Post <AuthenticationResponse>(uri, auth);

                if (authenticationInfo == null)
                {
                    return(false);
                }
                Settings.UserId      = authenticationInfo.UserId;
                Settings.ProfileId   = authenticationInfo.ProfileId;
                Settings.AccessToken = authenticationInfo.AccessToken;
                if (authenticationInfo.UserId != 0)
                {
                    Settings.UserProfile = await ProfileService.GetCurrentProfileAsync();

                    Device.IO.File("Session.txt").WriteAllText(authenticationInfo.UserId.ToString());
                    return(true);
                }
                return(false);
            }
Exemplo n.º 3
0
 public void CreateOrUpdate(User user)
 {
     if (user._id == "")
     {
         BaseApi.Post(playerCollection, new BaseUser(user.Name, user.UserAuthenticationId)).completed += ReadUserCallback;
     }
     else
     {
         BaseApi.Put(playerCollection, user, user._id);
     }
 }
        async Task DoRefresh()
        {
            if (User == null) return;

            var url = new Uri(Options.BaseUri, Options.SubscriptionStatusPath).ToString();
            var @params = new { User.Ticket, User.UserId };
            var current = await BaseApi.Post<Subscription>(url, @params, errorAction: OnError.Ignore);

            Subscription = current;
            await SubscriptionFileStore.Save();

            await SubscriptionRestored.Raise(current.ToEventArgs());
        }
            public static async Task <bool> SendIssueAsync(ReportedIssue issue)
            {
                await AddUserAndBikeIdsToIssue(issue);
                await AddLocationToIssue(issue);

                var uri = $"{GlobalSettings.IssuesEndpoint}api/Issues";

                if (await BaseApi.Post(uri, issue))
                {
                    return(true);
                }
                return(false);
            }
        internal async Task <VerifyPurchaseResult> VerifyPurchase(VerifyPurchaseEventArgs args)
        {
            if (await UIContext.IsOffline())
            {
                throw new Exception("Network connection is not available.");
            }

            if (User == null)
            {
                throw new Exception("User is not available.");
            }

            var url     = new Uri(Options.BaseUri, Options.VerifyPurchasePath).ToString();
            var @params = new { User.Ticket, User.UserId, Platform = PaymentAuthority, args.ProductId, args.TransactionId, args.ReceiptData };

            return(await BaseApi.Post <VerifyPurchaseResult>(url, @params, OnError.Ignore, showWaiting : false));
        }
        internal async Task PurchaseAttempt(SubscriptionPurchasedEventArgs args)
        {
            if (await UIContext.IsOffline())
            {
                throw new Exception("Network connection is not available.");
            }

            if (User == null)
            {
                throw new Exception("User is not available.");
            }

            var url     = new Uri(Options.BaseUri, Options.PurchaseAttemptPath).ToString();
            var @params = new { User.Ticket, User.UserId, Platform = PaymentAuthority, args.ProductId, args.TransactionId, args.TransactionDateUtc, args.PurchaseToken };

            await BaseApi.Post(url, @params, OnError.Ignore, showWaiting : false);

            await SubscriptionPurchased.Raise(args);
        }
        internal async Task <PurchaseAttemptResult> PurchaseAttempt(SubscriptionPurchasedEventArgs args)
        {
            if (await UIContext.IsOffline())
            {
                throw new Exception("Network connection is not available.");
            }

            if (User == null)
            {
                throw new Exception("User is not available.");
            }

            var url     = new Uri(Options.BaseUri, Options.PurchaseAttemptPath).ToString();
            var @params = new { User.Ticket, User.UserId, Platform = PaymentAuthority, args.ProductId, args.PurchaseToken };

            var result = await BaseApi.Post <PurchaseAttemptResult>(url, @params, OnError.Ignore, showWaiting : false);

            if (result?.Status == PurchaseAttemptStatus.Succeeded)
            {
                await SubscriptionPurchased.Raise(args);
            }

            return(result);
        }
Exemplo n.º 9
0
            public static async Task <UserAndProfileModel> SignUpAsync(UserAndProfileModel profile)
            {
                var uri = $"{GlobalSettings.AuthenticationEndpoint}api/Profiles/";

                return(await BaseApi.Post <UserAndProfileModel>(uri, profile));
            }