コード例 #1
0
ファイル: Session.cs プロジェクト: ramatceler/CPLib
        /// <summary>
        /// Reset the password.
        /// </summary>
        /// <returns>
        /// Reset state: true for success, false for failure
        /// </returns>
        public static async Task <bool> ResetPassword()
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new UnauthorizedAccessException("User is not logged to perform reset password");
            }

            var rest   = new RestWrapper();
            var result =
                await
                rest.Post <User>(
                    Service.ResetPassword,
                    new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(
                    "username",
                    user.UserName)
            });

            if (!(result is Error))
            {
                return(!string.IsNullOrEmpty(result.ToString()));
            }

            Utility.ParseAndThrowError((result as Error).Response);

            return(false);
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<bool> UpdateProfile(UserProfile userProfile)
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            if (signInToken == null || string.IsNullOrEmpty(signInToken.AccessToken))
            {
                throw new UnauthorizedAccessException("User is not logged to perform the action: Update Password");
            }

            //var request = new List<KeyValuePair<string, string>>
            //    {
            //        new KeyValuePair<string, string>("firstname", userProfile.FirstName), 
            //        new KeyValuePair<string, string>("lastname", userProfile.LastName),
            //    };
            UserProfileRequest userprofilepostData = new UserProfileRequest()
            {
                Email = "",
                Mobile = "",
                FirstName = userProfile.FirstName,
                LastName = userProfile.LastName,
            };

            var rest = new RestWrapper();
            var response = await rest.Put<UserProfile>(Service.UpdateProfile, AuthTokenType.SignIn, userprofilepostData, true);
            if (!(response is Error))
            {
                var user = response as ResponseEntity;
                return true;
            }

            return false;
        }
コード例 #3
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<bool> GenerateOTPUsingEmailId(string EmailId)
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            //if (signInToken == null || string.IsNullOrEmpty(signInToken.AccessToken))
            //{
            //    throw new UnauthorizedAccessException("User is not logged to perform the action: Generate OTP");
            //}

            var request = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("source", "RIO"), 
                    new KeyValuePair<string, string>("otpType", "Email"), 
                    new KeyValuePair<string, string>("identity", EmailId)
                };
            var rest = new RestWrapper();
            var result = await rest.Post<OAuthToken>(Service.GenerateOTP, request, AuthTokenType.None);

            if (!(result is Error))
            {
                return true;
            }
            else
            {
                var error = result as Error;
                if (error != null)
                {
                    Utility.ParseAndThrowError(error.Response);
                }
            }
            return false;
        }
コード例 #4
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<bool> SignInUsingOTP(string EmailId, string OTP)
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            if (Session.Config == null || string.IsNullOrEmpty(Session.Config.SignInId) || string.IsNullOrEmpty(Session.Config.SignInSecret))
            {
                throw new ServiceException("Invalid Configuration: Client ID & Client Secret");
            }

            //Renew token
            var rest = new RestWrapper();
            var result = await rest.Post<OAuthToken>(
                    Service.Signin,
                    new List<KeyValuePair<string, string>>()
                            {
                                new KeyValuePair<string, string>("client_id", Session.Config.SignInId),
                                new KeyValuePair<string, string>("client_secret", Session.Config.SignInSecret),
                                new KeyValuePair<string, string>("grant_type", "onetimepass"),
                                new KeyValuePair<string, string>("username", EmailId),
                                new KeyValuePair<string, string>("password", OTP)
                            },
                    AuthTokenType.None);

            if (!(result is Error))
            {
                signInToken = result as OAuthToken;
                simpleToken = result as OAuthToken;
                Utility.SaveToLocalStorage(Utility.SignInTokenKey, signInToken);
                Utility.SaveToLocalStorage(Utility.SimpleTokenKey, simpleToken);
                return signInToken != null && !string.IsNullOrEmpty(signInToken.AccessToken);
            }

            Utility.ParseAndThrowError((result as Error).Response);
            return false;
        }
コード例 #5
0
        public static async Task <string> GetCookie(string email, string password)
        {
            var restWrapper = new RestWrapper();
            var result      =
                await restWrapper.PostNonRedirect(
                    Service.GetCookies,
                    AuthTokenType.None,
                    new WebCookie()
            {
                Email    = email,
                Password = password,
                RMCookie = "true"
            });

            if (!result.IsSuccessStatusCode)
            {
                string Set_Cookie = ((string[])result.Headers.GetValues("Set-Cookie"))[0];
                //Set_Cookie = Set_Cookie.Substring(Set_Cookie.IndexOf("prepaiduser-payauth=") + 20);
                //Set_Cookie = Set_Cookie.Substring(0, Set_Cookie.IndexOf("; Expires="));

                //Set_Cookie = Set_Cookie.Substring(Set_Cookie.IndexOf("prepaiduser-payauth=") + 20).Substring(0, Set_Cookie.Substring(Set_Cookie.IndexOf("prepaiduser-payauth=") + 20).IndexOf("; Expires="));
                return(Set_Cookie);
            }

            return(null);
        }
コード例 #6
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<bool> UpdateMobile(string newMobile)
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            if (signInToken == null || string.IsNullOrEmpty(signInToken.AccessToken))
            {
                throw new UnauthorizedAccessException("User is not logged to perform the action: Update Password");
            }

            var request = new List<KeyValuePair<string, string>>
                              {
                                  new KeyValuePair<string, string>("mobile", newMobile), 
                              };
            var rest = new RestWrapper();
            var result = await rest.Put(Service.UpdateMobile, request, AuthTokenType.SignIn);

            if (result is bool && (bool)result)
            {
                return true;
            }
            else
            {
                var error = result as Error;
                if (error != null)
                {
                    Utility.ParseAndThrowError(error.Response);
                }
            }

            return false;
        }
コード例 #7
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        /// <summary>
        /// Reset the password.
        /// </summary>
        /// <returns>
        /// Reset state: true for success, false for failure
        /// </returns>
        public static async Task ResetPassword(string userName)
        {
            if (string.IsNullOrEmpty(Config.SignUpId) || string.IsNullOrEmpty(Config.SignUpSecret))
            {
                throw new ServiceException("Invalid Configuration: Client ID & Client Secret");
            }

            await GetSignupToken();
            var rest = new RestWrapper();
            var result =
                await
                rest.Post<User>(
                    Service.ResetPassword,
                    new List<KeyValuePair<string, string>>
                        {
                            new KeyValuePair<string, string>(
                                "username", 
                                userName)
                        },
                    AuthTokenType.SignUp);

            if (result is Error)
            {
                Utility.ParseAndThrowError((result as Error).Response);
            }
        }
コード例 #8
0
        public static async Task <bool> SavePaymentOptions(IEnumerable <PaymentOption> paymentOptions)
        {
            await Session.GetTokenIfEmptyAsync(AuthTokenType.Simple);

            //var token = await Session.GetAuthTokenAsync(AuthTokenType.Simple);
            //if (string.IsNullOrEmpty(token))
            //{
            //    throw new UnauthorizedAccessException("User is not logged to perform the action: Get Wallet");
            //}

            RestWrapper restWrapper = new RestWrapper();
            var         request     = new JObject();

            request["type"] = "payment";

            var paymentOptionsList = new JArray();

            foreach (var option in paymentOptions)
            {
                paymentOptionsList.Add(option.ToJson());
            }

            request["paymentOptions"] = paymentOptionsList;

            var json = request.ToString();

            var response = await restWrapper.Put(Service.Wallet, json, AuthTokenType.Simple);

            return(response.IsSuccessStatusCode);
        }
コード例 #9
0
        public static async Task <bool> DeletePaymentOption(PaymentOption paymentOption)
        {
            await Session.GetTokenIfEmptyAsync(AuthTokenType.Simple);

            var token = await Session.GetAuthTokenAsync(AuthTokenType.Simple);

            if (string.IsNullOrEmpty(token))
            {
                throw new UnauthorizedAccessException("User is not logged in to perform the action: Delete Payment option");
            }

            if (paymentOption == null)
            {
                return(false);
            }

            RestWrapper restWrapper = new RestWrapper();

            if (paymentOption.CardType != CardType.UnKnown)
            {
                var response = await restWrapper.Delete(Service.Wallet + "/" + paymentOption.CardNumber.Substring(12, 4) + ":" + paymentOption.Scheme, AuthTokenType.Simple);

                return(response.IsSuccessStatusCode);
            }
            else
            {
                var response = await restWrapper.Delete(Service.Wallet + "/" + paymentOption.Token, AuthTokenType.Simple);

                return(response.IsSuccessStatusCode);
            }

            return(false);
        }
コード例 #10
0
ファイル: Question.cs プロジェクト: PzeKnm/MoreOrLess
        public Question GetQuestion()
        {
            string sExclude = "";

            foreach (int n in _lstAlreadyAsked)
            {
                if (sExclude.Length > 0)
                {
                    sExclude += ",";
                }
                else
                {
                    sExclude += "&ExcludeKeys=";
                }
                sExclude += n.ToString();
            }

            string sReply = _restApi.GetHttpRequestWithDeviceDetails("MoreOrLessGetQuestion", sExclude);

            RestWrapper <Question> wrap = JsonConvert.DeserializeObject <RestWrapper <Question> >(sReply);
            Question q = wrap.Data;

            if (_lstAlreadyAsked.Contains(q.QuestionKey))
            {
                Console.WriteLine("Duplicate question obtained");
            }

            _lstAlreadyAsked.Add(q.QuestionKey);
            return(q);
        }
コード例 #11
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<User> BindUser(string email, string mobile)
        {
            if (string.IsNullOrEmpty(Config.SignUpId) || string.IsNullOrEmpty(Config.SignUpSecret))
            {
                throw new ServiceException("Invalid Configuration: Client ID & Client Secret");
            }

            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentException("Invalid parameter", "email");
            }

            if (string.IsNullOrEmpty(mobile))
            {
                throw new ArgumentException("Invalid parameter", "mobile");
            }

            await GetSignupToken();
            var objectToPost = new User { Email = email, Mobile = mobile };
            user = objectToPost;
            var rest = new RestWrapper();
            var result = await rest.Post<User>(Service.BindUser, AuthTokenType.SignUp, objectToPost);
            if (!(result is Error))
            {
                user.UserName = ((User)result).UserName;
                if (!string.IsNullOrEmpty(user.UserName))
                {
                    var signInRequest = new List<KeyValuePair<string, string>>
                    {
                        new KeyValuePair<string, string>("client_id", Config.SignInId),
                        new KeyValuePair<string, string>("client_secret", Config.SignInSecret),
                        new KeyValuePair<string, string>("grant_type", "username"),
                        new KeyValuePair<string, string>("username", user.Email)
                    };

                    var authTokenResult = await rest.Post<OAuthToken>(Service.Signin, signInRequest, AuthTokenType.None);

                    if (!(authTokenResult is Error))
                    {
                        signInToken = null;
                        Utility.RemoveEntry(Utility.SignInTokenKey);
                        simpleToken = authTokenResult as OAuthToken;
                        return user;
                    }

                    Utility.ParseAndThrowError((authTokenResult as Error).Response);
                    return null;
                }
            }
            else
            {
                Utility.ParseAndThrowError((result as Error).Response);
            }

            return null;
        }
コード例 #12
0
        private static void RequestWithJsonAsObject()
        {
            var response = RestWrapper.CreateWithHttpClient(_client)
                           .Url($"https://reqres.in/api/users/2")
                           .Build()
                           .SendGet <JsonToObject>()
                           .GetAwaiter().GetResult();

            Console.WriteLine($"\n>>> Result as object: {response.Data.Email}");
        }
コード例 #13
0
        private static void RequestWithStatusCodeAsResult()
        {
            var response = RestWrapper.CreateWithHttpClient(_client)
                           .Url($"https://reqres.in/api/users/2")
                           .AddHeaders("Custom", "Test")
                           .Build()
                           .SendGet(disableBodyLogs: true)
                           .GetAwaiter().GetResult();

            Console.WriteLine($"\n>>> Result status code: {(int)response.StatusCode}");
        }
コード例 #14
0
        private static void RequestWithJsonElementAsResponse()
        {
            var response = RestWrapper.CreateWithHttpClient(_client)
                           .Url($"https://reqres.in/api/users/2")
                           .LogsEnabled(false)
                           .Build()
                           .SendGet <JsonElement>()
                           .GetAwaiter().GetResult();

            Console.WriteLine($"\n>>> Result from jsonElement: {response.GetProperty("data").GetProperty("email")}");
        }
コード例 #15
0
ファイル: RestWrapperTest.cs プロジェクト: justdude/dotLastFm
        public void RestWebException()
        {
            var config = Substitute.For<ILastFmConfig>();
            config.BaseUrl.Returns("http://blablainvalidtotalerrorurl.last.fm");
            config.ApiKey.Returns("somekey");
            config.Secret.Returns("somesecret");

            var w = new RestWrapper(config);

            Assert.Throws<WebException>(() => w.Method("track.getTopTags").Execute<TopTagListWrapper>());
        }
コード例 #16
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        /// <summary>
        /// Sign up an user account.
        /// </summary>
        /// <param name="email">
        /// Email
        /// </param>
        /// <param name="mobile">
        /// Mobile
        /// </param>
        /// <param name="password"></param>
        /// <returns>
        /// Logged In user's detail
        /// </returns>
        public static async Task<User> SignupUser(string email, string mobile, string password)
        {
            if (string.IsNullOrEmpty(Config.SignUpId) || string.IsNullOrEmpty(Config.SignUpSecret))
            {
                throw new ServiceException("Invalid Configuration: Client ID & Client Secret");
            }

            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentException("Invalid parameter", "email");
            }

            if (string.IsNullOrEmpty(mobile))
            {
                throw new ArgumentException("Invalid parameter", "mobile");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Invalid parameter", "password");
            }

            await GetSignupToken();
            var objectToPost = new User { Email = email, Mobile = mobile };
            user = objectToPost;
            var rest = new RestWrapper();
            var result = await rest.Post<User>(Service.Signup, AuthTokenType.SignUp, objectToPost);
            if (!(result is Error))
            {
                user.UserName = ((User)result).UserName;
                if (!string.IsNullOrEmpty(user.UserName))
                {
                    var randomPasswordGenerator = new RandomPasswordGenerator();
                    user.Password = randomPasswordGenerator.Generate(user.Email, user.Mobile);

                    var success = await SigninUser(user.UserName, user.Password);
                    if (success)
                    {
                        success = await UpdatePassword(user.Password, password);
                        if (success)
                        {
                            user.Password = password;
                            return await GetBalance();
                        }
                    }
                }
            }
            else
            {
                Utility.ParseAndThrowError((result as Error).Response);
            }

            return new User();
        }
コード例 #17
0
        public void RestWebException()
        {
            var config = Substitute.For <ILastFmConfig>();

            config.BaseUrl.Returns("http://blablainvalidtotalerrorurl.last.fm");
            config.ApiKey.Returns("somekey");
            config.Secret.Returns("somesecret");

            var w = new RestWrapper(config);

            Assert.Throws <WebException>(() => w.Method("track.getTopTags").Execute <TopTagListWrapper>());
        }
コード例 #18
0
ファイル: Session.cs プロジェクト: ramatceler/CPLib
        /// <summary>
        /// Update old password with new password
        /// </summary>
        /// <param name="oldPassword">
        /// Old Password.
        /// </param>
        /// <param name="newPassword">
        /// New Password.
        /// </param>
        /// <returns>
        /// </returns>
        public static async Task <bool> UpdatePassword(string oldPassword, string newPassword)
        {
            var request = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("old", oldPassword),
                new KeyValuePair <string, string>("new", newPassword)
            };
            var rest   = new RestWrapper();
            var result = await rest.Post <object>(Service.UpdatePassword, request);

            return(result != null);
        }
コード例 #19
0
ファイル: Session.cs プロジェクト: ramatceler/CPLib
        /// <summary>
        /// Sign in the user account.
        /// </summary>
        /// <param name="userName">
        /// Citrus Pay UserName.
        /// </param>
        /// <param name="password">
        /// Citrus Pay Password.
        /// </param>
        /// <returns>
        /// Sign In state, true for success, false for failure
        /// </returns>
        public static async Task <bool> SigninUser(string userName, string password)
        {
            var request = new SigninRequest {
                User = new User {
                    UserName = userName, Password = password
                }
            };

            var rest   = new RestWrapper();
            var result = await rest.Post <object>(Service.Signin, request);

            return(result != null);
        }
コード例 #20
0
        private static int RequestWithWrongUrl()
        {
            var postObj = new ObjToJson {
                Job = "leader", Name = "morpheus"
            };

            return((int)RestWrapper.CreateWithHttpClient(_client)
                   .Url($"raasdasdasdsdasdasdeqres.in/users/2")
                   .AddHeaders("Custom", "Test")
                   .AddHeaders("Custom2", "Test2")
                   .Build()
                   .SendPost <ObjToJson>(postObj)
                   .GetAwaiter().GetResult().StatusCode);
        }
コード例 #21
0
        private static void RequestWithPostObject()
        {
            var postObj = new ObjToJson {
                Job = "leader", Name = "morpheus"
            };

            var response = RestWrapper.CreateWithHttpClient(_client)
                           .Url($"https://reqres.in/api/users/2")
                           .Build()
                           .SendPost <JsonElement, ObjToJson>(postObj)
                           .GetAwaiter().GetResult();

            Console.WriteLine($"\n>>> Id from response is: {response.GetProperty("id")}");
        }
コード例 #22
0
        public static async Task GetMerchantPaymentOptions()
        {
            RestWrapper restWrapper    = new RestWrapper();
            var         paymentOptions = await restWrapper.Post <MerchantPaymentOptions>(Service.GetMerchantPaymentOptions, new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("vanity", Session.Config.Vanity)
            }, AuthTokenType.Simple);

            if (!(paymentOptions is Error))
            {
                merchantPaymentOptions = paymentOptions as MerchantPaymentOptions;
                return;
            }

            Utility.ParseAndThrowError(((Error)paymentOptions).Response);
        }
コード例 #23
0
ファイル: OAuthToken.cs プロジェクト: citruspay/open-windows
        public async Task <string> GetActiveTokenAsync()
        {
            if (this.ExpirationTime != default(DateTime) && DateTime.Now > this.ExpirationTime)
            {
                if (Session.Config == null || string.IsNullOrEmpty(Session.Config.SignInId) || string.IsNullOrEmpty(Session.Config.SignInSecret))
                {
                    throw new ServiceException("Invalid Configuration: Client ID & Client Secret");
                }

                //Renew token
                var rest   = new RestWrapper();
                var result = await rest.Post <OAuthToken>(
                    Service.Signin,
                    new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("client_id", Session.Config.SignInId),
                    new KeyValuePair <string, string>("client_secret", Session.Config.SignInSecret),
                    new KeyValuePair <string, string>("grant_type", "refresh_token"),
                    new KeyValuePair <string, string>("refresh_token", this.RefreshToken)
                },
                    AuthTokenType.None);

                if (!(result is Error))
                {
                    var oauthToken = result as OAuthToken;
                    if (oauthToken != null)
                    {
                        this.AccessToken  = oauthToken.AccessToken;
                        this.RefreshToken = oauthToken.RefreshToken;
                        this.ExpiresIn    = oauthToken.ExpiresIn;
                        this.Scope        = oauthToken.Scope;
                        this.TokenType    = oauthToken.TokenType;
                        if (oauthToken.prepaid_Pay_Token != null)
                        {
                            this.PrepaidAccessToken = oauthToken.prepaid_Pay_Token.AccessToken;
                        }
                        else
                        {
                            this.PrepaidAccessToken = oauthToken.AccessToken;
                        }
                    }
                }
            }

            return(this.AccessToken);
        }
コード例 #24
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<bool> IsCitrusMemeber(string email, string mobile)
        {
            var newUser = await BindUser(email, mobile);
            var randomPasswordGenerator = new RandomPasswordGenerator();
            newUser.Password = randomPasswordGenerator.Generate(newUser.Email, newUser.Mobile);

            var request = new SigninRequest { User = new User { UserName = newUser.UserName, Password = newUser.Password } };

            var rest = new RestWrapper();
            var result = await rest.Post<OAuthToken>(Service.Signin, AuthTokenType.None, request);
            if (!(result is Error))
            {
                return false;
            }

            return true;
        }
コード例 #25
0
        public static async Task <MerchantPaymentOptions> GetLoadMoneyPaymentOptions()
        {
            string      CitrusVanity   = "prepaid";
            RestWrapper restWrapper    = new RestWrapper();
            var         paymentOptions = await restWrapper.Post <MerchantPaymentOptions>(Service.GetMerchantPaymentOptions, new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("vanity", CitrusVanity)
            }, AuthTokenType.Simple);

            if (!(paymentOptions is Error))
            {
                MerchantPaymentOptions merchantPaymentOptions = paymentOptions as MerchantPaymentOptions;
                return(merchantPaymentOptions);
            }

            Utility.ParseAndThrowError(((Error)paymentOptions).Response);
            return(null);
        }
コード例 #26
0
ファイル: Session.cs プロジェクト: ramatceler/CPLib
        /// <summary>
        /// Gets the User account's balance.
        /// </summary>
        /// <returns>
        /// Account balance
        /// </returns>
        public static async Task <bool> GetBalance()
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new UnauthorizedAccessException("User is not logged to perform Get Balance");
            }

            var rest   = new RestWrapper();
            var result = await rest.Post <User>(Service.GetBalance);

            if (!(result is Error))
            {
                return(!string.IsNullOrEmpty(result.ToString()));
            }

            Utility.ParseAndThrowError((result as Error).Response);

            return(false);
        }
コード例 #27
0
ファイル: Session.cs プロジェクト: ramatceler/CPLib
        /// <summary>
        /// Get the Signup Token.
        /// </summary>
        /// <returns>
        /// </returns>
        private static async Task GetSignupToken()
        {
            if (signUpToken != null)
            {
                return;
            }

            var rest   = new RestWrapper();
            var result = await rest.Post <OAuthToken>(Service.SignUpToken, new SignupTokenRequest());

            if (!(result is Error))
            {
                signUpToken = (OAuthToken)result;
            }
            else
            {
                Utility.ParseAndThrowError((result as Error).Response);
            }
        }
コード例 #28
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        public static async Task<UserProfile> GetProfileInfo()
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            if (signInToken == null || string.IsNullOrEmpty(signInToken.AccessToken))
            {
                throw new UnauthorizedAccessException("User is not logged to perform the action: Get Profile Info");
            }

            var restWrapper = new RestWrapper();
            var response = await restWrapper.Get<UserProfile>(Service.GetProfileInfo, AuthTokenType.SignIn);
            if (!(response is Error))
            {
                var user = response as UserProfile;
                return user;
            }

            return null;
        }
コード例 #29
0
        public static async Task <Transaction> LoadMoneyAsync(LoadMoneyRequest request)
        {
            await Session.GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            if (Session.signInToken == null || string.IsNullOrEmpty(Session.signInToken.AccessToken))
            {
                throw new UnauthorizedAccessException("User is not logged to perform this operation");
            }

            var cardPayment = request.PaymentDetails as CardPayment;

            if (cardPayment != null && !Utility.PassesLuhnTest(cardPayment.Card.CardNumber))
            {
                throw new ArgumentException("Invalid card number, Please provide a valid card detail");
            }

            var prepaidBill = await GetPrepaidBillAsync(
                request.BillAmount.Value,
                request.BillAmount.CurrencyType,
                request.RedirectUrl);

            if (prepaidBill != null)
            {
                request.ReturnUrl             = prepaidBill.ReturnUrl;
                request.NotifyUrl             = prepaidBill.NotifyUrl;
                request.BillAmount            = prepaidBill.BillAmount;
                request.MerchantAccessKey     = prepaidBill.MerchantAccessKey;
                request.MerchantTransactionId = prepaidBill.MerchantTransactionId;
                request.Signature             = prepaidBill.Signature;
            }

            RestWrapper rest   = new RestWrapper();
            var         result = await rest.Post <Transaction>(Service.LoadMoney, AuthTokenType.SignIn, request, true);

            if (!(result is Error))
            {
                return((Transaction)result);
            }

            Utility.ParseAndThrowError(((Error)result).Response);
            return(null);
        }
コード例 #30
0
        public static async Task <bool> SaveWithdrawInfo(WithdrawInfoResponse withdrawInfoResponse)
        {
            await Session.GetTokenIfEmptyAsync(AuthTokenType.SignIn);

            var token = await Session.GetAuthTokenAsync(AuthTokenType.SignIn);

            if (string.IsNullOrEmpty(token))
            {
                throw new UnauthorizedAccessException("User is not logged to perform the action: Save Withdraw Info");
            }
            RestWrapper rest = new RestWrapper();

            var serializer    = new JsonSerializer();
            var stringContent = new StringWriter();

            serializer.Serialize(stringContent, withdrawInfoResponse);
            var result = await rest.Put(Service.GetWithdrawInfo, stringContent.ToString(), AuthTokenType.SignIn);

            return(result.IsSuccessStatusCode);
        }
コード例 #31
0
ファイル: Session.cs プロジェクト: citruspay/open-windows
        /// <summary>
        /// Get the Signup Token.
        /// </summary>
        /// <returns>
        /// </returns>
        public static async Task GetSignupToken()
        {
            await GetTokenIfEmptyAsync(AuthTokenType.SignUp);

            if (signUpToken != null)
            {
                return;
            }

            var rest = new RestWrapper();
            var result = await rest.Post<OAuthToken>(Service.SignUpToken, AuthTokenType.None, new SignupTokenRequest());
            if (!(result is Error))
            {
                signUpToken = (OAuthToken)result;
                Utility.SaveToLocalStorage(Utility.SignUpTokenKey, signUpToken);
            }
            else
            {
                Utility.ParseAndThrowError((result as Error).Response);
            }
        }
コード例 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YoutubeApiBase"/> class.
 /// </summary>
 /// <param name="api">The session.</param>
 protected YoutubeApiBase(IYoutubeApi api)
 {
     Api = api;
     Rest = new RestWrapper(Api.Config);
 }
コード例 #33
0
ファイル: LastFmApiBase.cs プロジェクト: justdude/dotLastFm
 /// <summary>
 /// Initializes a new instance of the <see cref="LastFmApiBase"/> class.
 /// </summary>
 /// <param name="api">The session.</param>
 protected LastFmApiBase(ILastFmApi api)
 {
     Api = api;
     Rest = new RestWrapper(Api.Config);
 }
コード例 #34
0
ファイル: RestWrapperTest.cs プロジェクト: justdude/dotLastFm
 /// <summary>
 /// Initializes a new instance of the <see cref="RestWrapperTest"/> class.
 /// </summary>
 public RestWrapperTest()
 {
     Wrapper = new RestWrapper(new TestLastFmConfig());
 }
コード例 #35
0
 protected ExternalApiBase(IExternalApi api)
 {
     Api = api;
     Rest = new RestWrapper(Api.Config);
 }