private dynamic ExpressSetup(dynamic parameters)
        {
            _setConfigurations();

            var callbackUrl = Contants.callbackURL + "express/";

            RequestTokenResponse requestTokenResponse1 = RequestTokenApi.Create(callbackUrl);
            string pairingRequestToken = requestTokenResponse1.OauthToken;
            RequestTokenResponse requestTokenResponse2 = RequestTokenApi.Create(callbackUrl);
            string requestToken = requestTokenResponse2.OauthToken;

            //Create an instance of MerchantInitializationRequest
            MerchantInitializationRequest merchantInitializationRequest = new MerchantInitializationRequest()
                                                                          .WithOriginUrl(Contants.callbackURL)
                                                                          .WithOAuthToken(pairingRequestToken);

            //Call the MerchantInitializationApi Service with required params
            MerchantInitializationResponse merchantInitializationResponse = MerchantInitializationApi.Create(merchantInitializationRequest);

            var model = new
            {
                requestToken        = requestToken,
                pairingRequestToken = pairingRequestToken,
                merchantCheckoutId  = Contants.checkoutId,
                callbackUrl         = callbackUrl
            };

            return(View["express_setup.htm", model]);
        }
Example #2
0
        private string _GetToken()
        {
            _SetTls();

            if (_TokenExpirationTime > DateTime.Now.AddMinutes(5))
            {
                return(this._AccessToken);
            }

            var oauthCredentials = $"{this._ClientId}:{this._ClientSecret}";

            var client  = new RestClient($"{this._Host}{this._RelativeUrl_requestToken}");
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(oauthCredentials)));
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

            request.AddParameter("grant_type", "client_credentials");

            RequestTokenResponse requestTokenResponse = null;

            try
            {
                var response = client.Execute(request);
                requestTokenResponse = JsonConvert.DeserializeObject <RequestTokenResponse>(response?.Content);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            this._AccessToken         = requestTokenResponse?.access_token;
            this._TokenExpirationTime = DateTime.Now.AddSeconds(requestTokenResponse.expires_in);

            Console.WriteLine("Access Token: " + this._AccessToken);
            return(this._AccessToken);
        }