/// <summary> /// Returns Square items with the supplied catalogObjectIds /// </summary> /// <param name="catalogObjectsIds"></param> /// <param name="cancellationToken"></param> /// <param name="mark"></param> /// <returns></returns> public async Task <IEnumerable <SquareItem> > GetCatalogObjectsByIdsAsync(IEnumerable <string> catalogObjectsIds, CancellationToken cancellationToken, Mark mark) { if (cancellationToken.IsCancellationRequested) { var exceptionDetails = CreateMethodCallInfo(url: SquareEndPoint.BatchRetrieveCatalogObjectsUrl, mark: mark, additionalInfo: this.AdditionalLogInfo()); var squareException = new SquareException(string.Format("{0}. Search item by id request was cancelled", exceptionDetails)); SquareLogger.LogTraceException(squareException); throw squareException; } if (catalogObjectsIds == null || !catalogObjectsIds.Any()) { return(null); } var requestBody = new BatchRetrieveCatalogObjectsRequest(catalogObjectsIds.ToList()); var response = await base.ThrottleRequest(SquareEndPoint.SearchCatalogUrl, requestBody.ToJson(), mark, (token) => { return(this._catalogApi.BatchRetrieveCatalogObjectsAsync(requestBody)); }, cancellationToken).ConfigureAwait(false); var errors = response.Errors; if (errors != null && errors.Any()) { var methodCallInfo = CreateMethodCallInfo(SquareEndPoint.BatchRetrieveCatalogObjectsUrl, mark, additionalInfo: this.AdditionalLogInfo(), errors: errors.ToJson()); var squareException = new SquareException(string.Format("{0}. Batch retrieve catalog objects errors", methodCallInfo)); SquareLogger.LogTraceException(squareException); throw squareException; } return(response.Objects?.Select(c => c.ToSvItemVariation())); }
public void TestBatchRetrieveCatalogObjects() { var request = new BatchRetrieveCatalogObjectsRequest(ObjectIds: new List <string>() { idMap[COFFEE_ID], idMap[SALES_TAX_ID] }); var response = instance.BatchRetrieveCatalogObjects(request); Assert.AreEqual(2, response.Objects.Count); CatalogObject actualCoffee = response.Objects[0]; Assert.AreEqual(TypeEnum.ITEM, actualCoffee.Type); Assert.AreEqual(idMap[COFFEE_ID], actualCoffee.Id); CatalogObject actualTax = response.Objects[1]; Assert.AreEqual(TypeEnum.TAX, actualTax.Type); Assert.AreEqual(idMap[SALES_TAX_ID], actualTax.Id); }