public async Task <CreditResponse> CreditAsync(string authorizationKey, CreditRequest request) { HttpRequestMessage requestMessage = BuildRequest(authorizationKey, $"api/v3/orders/{request.OrderNumber}/refunds", HttpMethod.Post, request.GetIdempotentKey()); var requestDto = _mapper.Map <RefundOrderRequestDto>(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 = "Credit query failed. Service response was NULL or not OK", request }); return(null); } if (responseMessage.StatusCode != HttpStatusCode.OK) { ResponseMessageDto[] errorList = await ParseJsonArrayAsync <ResponseMessageDto>(responseMessage); _log.Warning(new { message = "Credit query faild.", request, responseMessage.StatusCode, errorList }); return(null); } RefundOrderResponseDto responseDto = await ParseJsonAsync <RefundOrderResponseDto>(responseMessage); if (responseDto.HasError) { _log.Error(new { message = "Credit query failed", request, responseDto.ErrorMessage }); return(null); } var result = _mapper.Map <CreditResponse>(responseDto); _log.Information(new { message = "Credit query succeeded", orderNumber = request.OrderNumber, result }); return(result); }
public async Task <CreditResponse> CreditFullAsync(string authorizationKey, string orderNumber) { HttpRequestMessage requestMessage = BuildRequest(authorizationKey, $"api/v3/orders/{orderNumber}/refunds", HttpMethod.Post, orderNumber); //INFO: No POST data needed for full refunds. --tarjei HttpResponseMessage responseMessage = await CallAsync(() => Client.SendAsync(requestMessage), true); if (responseMessage == null) { _log.Error(new { message = "Full credit 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 credit query faild.", orderNumber, responseMessage.StatusCode, errorList }); return(null); } RefundOrderResponseDto responseDto = await ParseJsonAsync <RefundOrderResponseDto>(responseMessage); if (responseDto.HasError) { _log.Error(new { message = "Full credit query failed", orderNumber, responseDto.ErrorMessage }); return(null); } var result = _mapper.Map <CreditResponse>(responseDto); _log.Information(new { message = "Full credit query succeeded", orderNumber, result }); return(result); }