public async Task <OAuthTokensPair> RefreshAccessToken(string refreshToken, CancellationToken cancellationToken) { Condition.Requires(refreshToken, "refreshToken").IsNotNullOrWhiteSpace(); var mark = Mark.CreateNew(); var requestParameters = new Dictionary <string, string> { { "client_id", base.Config.ApplicationId }, { "grant_type", "refresh_token" }, { "refresh_token", refreshToken }, }; var url = SquareEndPoint.ObtainOAuth2TokenUrl + "?" + string.Join("&", requestParameters.Select(item => $"{ item.Key }={ item.Value }")); try { SquareLogger.LogStarted(this.CreateMethodCallInfo(url, mark, additionalInfo: this.AdditionalLogInfo())); var body = new Dictionary <string, string>() { { "client_secret", base.Config.ApplicationSecret } }; var tokens = await base.PostAsync <OAuthTokensPair>(url, body, cancellationToken, mark).ConfigureAwait(false); SquareLogger.LogEnd(this.CreateMethodCallInfo(url, mark, methodResult: tokens.ToJson(), additionalInfo: this.AdditionalLogInfo())); return(tokens); } catch (Exception exception) { var squareException = new SquareException(this.CreateMethodCallInfo(url, mark, additionalInfo: this.AdditionalLogInfo()), exception); SquareLogger.LogTraceException(squareException); throw squareException; } }
/// <summary> /// Returns orders created/modified between the start and end date /// </summary> /// <param name="startDateUtc"></param> /// <param name="endDateUtc"></param> /// <param name="token">Cancellation token for cancelling call to endpoint</param> /// <returns></returns> public async Task <IEnumerable <SquareOrder> > GetOrdersAsync(DateTime startDateUtc, DateTime endDateUtc, CancellationToken token) { Condition.Requires(startDateUtc).IsLessThan(endDateUtc); var mark = Mark.CreateNew(); if (token.IsCancellationRequested) { var exceptionDetails = CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo()); var squareException = new SquareException(string.Format("{0}. Get orders request was cancelled", exceptionDetails)); SquareLogger.LogTraceException(squareException); throw squareException; } IEnumerable <SquareOrder> response = null; try { SquareLogger.LogStarted(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo())); var locations = await _locationsService.GetActiveLocationsAsync(token, mark).ConfigureAwait(false); SquareLogger.LogTrace(this.CreateMethodCallInfo("", mark, payload: locations.ToJson(), additionalInfo: this.AdditionalLogInfo())); response = await CollectOrdersFromAllPagesAsync(startDateUtc, endDateUtc, locations, (requestBody) => GetOrdersWithRelatedDataAsync( requestBody, token, mark ), this.Config.OrdersPageSize).ConfigureAwait(false); SquareLogger.LogEnd(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo())); } catch (Exception ex) { var squareException = new SquareException(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo()), ex); SquareLogger.LogTraceException(squareException); throw squareException; } return(response); }