public async Task <CaptureResponse> CaptureAsync(string authorizationKey, CaptureRequest request) { HttpRequestMessage requestMessage = BuildRequest(authorizationKey, $"api/v3/orders/{request.OrderNumber}/captures", HttpMethod.Post, request.GetIdempotentKey()); var requestDto = _mapper.Map <CaptureRequestDto>(request); string content = await SerializeDto(requestDto); requestMessage.Content = new StringContent(content, Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await CallAsync(() => Client.SendAsync(requestMessage), true); if (responseMessage == null) { _log.Error(new { message = "Capture query failed. Service response was NULL or not OK", request.OrderNumber }); return(null); } if (responseMessage.StatusCode != HttpStatusCode.OK) { ResponseMessageDto[] errorList = await ParseJsonArrayAsync <ResponseMessageDto>(responseMessage); _log.Warning(new { message = "Capture query faild.", request.OrderNumber, responseMessage.StatusCode, errorList }); return(null); } CaptureResponseDto responseDto = await ParseJsonAsync <CaptureResponseDto>(responseMessage); if (responseDto.HasError) { _log.Error(new { message = "Capture query failed", request.OrderNumber, responseDto.ErrorMessage }); return(null); } var result = _mapper.Map <CaptureResponse>(responseDto); _log.Information(new { message = "Capture query succeeded", request.OrderNumber, result }); return(result); }
public async Task <CaptureResponse> CaptureFullAsync(string authorizationKey, string orderNumber) { HttpRequestMessage requestMessage = BuildRequest(authorizationKey, $"api/v3/orders/{orderNumber}/captures", HttpMethod.Post, orderNumber); //INFO: No POST data needed for full captures. --tarjei HttpResponseMessage responseMessage = await CallAsync(() => Client.SendAsync(requestMessage), true); if (responseMessage == null) { _log.Error(new { message = "Full capture query failed. Service response was NULL or not OK", orderNumber }); return(null); } if (responseMessage.StatusCode != HttpStatusCode.OK) { ResponseMessageDto[] errorList = await ParseJsonArrayAsync <ResponseMessageDto>(responseMessage); _log.Warning(new { message = "Full capture query faild.", orderNumber, responseMessage.StatusCode, errorList }); return(null); } CaptureResponseDto responseDto = await ParseJsonAsync <CaptureResponseDto>(responseMessage); if (responseDto.HasError) { _log.Error(new { message = "Full capture query failed", orderNumber, responseDto.ErrorMessage }); return(null); } var result = _mapper.Map <CaptureResponse>(responseDto); _log.Information(new { message = "Full capture query succeeded", orderNumber, result }); return(result); }