/// <summary>
        /// Test QBO api call
        /// </summary>
        public async Task qboApiCall(string callType)
        {
            try
            {
                if ((dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("realmId")))
                {
                    QBOServiceInitializer initialize     = new QBOServiceInitializer(dictionary["accessToken"], dictionary["refreshToken"], dictionary["realmId"]);
                    ServiceContext        servicecontext = initialize.InitializeQBOServiceContextUsingoAuth();

                    if (callType == "All")
                    {
                        output("Making QBO API Call.");
                        TestQBOCalls.allqbocalls(servicecontext);
                        output("QBO calls successful.");
                        lblQBOCall.Visible = true;
                        lblQBOCall.Text    = "QBO Call successful";
                    }
                    else
                    {
                        output("Making AST Invoice API Call.");
                        TestQBOCalls.automatedSalestaxEnabledInvoiceCall(servicecontext);
                        output("AST Invoice calls successful.");
                        lblQBOCall.Visible = true;
                        lblQBOCall.Text    = "AST Invoice Calls successful";
                    }
                }
            }
            catch (IdsException ex)
            {
                if (ex.Message == "Unauthorized-401")
                {
                    output("Invalid/Expired Access Token.");

                    var tokenResp = await client.RefreshTokenAsync(dictionary["refreshToken"]);

                    if (tokenResp.AccessToken != null && tokenResp.RefreshToken != null)
                    {
                        dictionary["accessToken"]  = tokenResp.AccessToken;
                        dictionary["refreshToken"] = tokenResp.RefreshToken;
                        await qboApiCall(callType);
                    }
                    else
                    {
                        output("Error while refreshing tokens: " + tokenResp.Raw);
                    }
                }
                else
                {
                    output(ex.Message);
                }
            }
            catch (Exception ex)
            {
                output("Invalid/Expired Access Token.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Test QBO api call
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="refresh_token"></param>
        /// <param name="realmId"></param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task qboApiCall(string access_token, string refresh_token, string realmId)
        {
            try
            {
                if (realmId != "")
                {
                    output("Making QBO API Call.");
                    QBOServiceInitializer initialize     = new QBOServiceInitializer(access_token, refresh_token, realmId);
                    ServiceContext        servicecontext = initialize.InitializeQBOServiceContextUsingoAuth();
                    TestQBOCalls.allqbocalls(servicecontext);

                    output("QBO calls successful.");
                    lblQBOCall.Visible = true;
                    lblQBOCall.Text    = "QBO Call successful";
                }
            }
            catch (IdsException ex)
            {
                if (ex.Message == "UnAuthorized-401")
                {
                    output("Invalid/Expired Access Token.");
                    //if you get a 401 token expiry then perform token refresh
                    await performRefreshToken(refresh_token);

                    //if (Session["accessToken"] != null && Session["refreshToken"] != null && Session["relamId"] != null)
                    //{
                    if ((dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("realmId")))
                    {
                        //await qboApiCall(Session["accessToken"].ToString(), Session["refreshToken"].ToString(), Session["realmId"].ToString() );
                        await qboApiCall(dictionary["accessToken"], dictionary["refreshToken"], dictionary["realmId"]);
                    }
                }
                else
                {
                    output(ex.Message);
                }
            }
            catch (Exception ex)
            {
                //Check Status Code 401 and then
                output("Invalid/Expired Access Token.");
            }
        }