Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from VirtoCommerce/fix/VP-5696
Browse files Browse the repository at this point in the history
VP-5696: Fix invoice generation
  • Loading branch information
pushnitsa authored Oct 29, 2020
2 parents 50751bf + bd4da6f commit 820cfa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
37 changes: 12 additions & 25 deletions VirtoCommerce.Storefront/AutoRestClients/OrdersModuleApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ public OrderModule(OrdersModuleClient client)
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async Task<HttpOperationResponse<string>> GetInvoicePdfWithHttpMessagesAsync(string orderNumber, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
public async Task<HttpOperationResponse<Stream>> GetInvoicePdfWithHttpMessagesAsync(string orderNumber, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (orderNumber == null)
{
Expand Down Expand Up @@ -2332,7 +2332,7 @@ public OrderModule(OrdersModuleClient client)
ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
}
cancellationToken.ThrowIfCancellationRequested();
_httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
_httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
if (_shouldTrace)
{
ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
Expand Down Expand Up @@ -2363,26 +2363,13 @@ public OrderModule(OrdersModuleClient client)
throw ex;
}
// Create Result
var _result = new HttpOperationResponse<string>();
var _result = new HttpOperationResponse<Stream>();
_result.Request = _httpRequest;
_result.Response = _httpResponse;
// Deserialize Response
if ((int)_statusCode == 200)
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
_result.Body = SafeJsonConvert.DeserializeObject<string>(_responseContent, Client.DeserializationSettings);
}
catch (JsonException ex)
{
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
_result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
if (_shouldTrace)
{
Expand Down Expand Up @@ -2676,6 +2663,7 @@ namespace VirtoCommerce.Storefront.AutoRestClients.OrdersModuleApi
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -2999,7 +2987,7 @@ public partial interface IOrderModule
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
Task<HttpOperationResponse<string>> GetInvoicePdfWithHttpMessagesAsync(string orderNumber, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
Task<HttpOperationResponse<Stream>> GetInvoicePdfWithHttpMessagesAsync(string orderNumber, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <param name='id'>
/// </param>
/// <param name='customHeaders'>
Expand Down Expand Up @@ -3049,6 +3037,7 @@ namespace VirtoCommerce.Storefront.AutoRestClients.OrdersModuleApi
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -3568,7 +3557,7 @@ public static PaymentIn GetNewPayment(this IOrderModule operations, string id)
/// </param>
/// <param name='orderNumber'>
/// </param>
public static string GetInvoicePdf(this IOrderModule operations, string orderNumber)
public static Stream GetInvoicePdf(this IOrderModule operations, string orderNumber)
{
return operations.GetInvoicePdfAsync(orderNumber).GetAwaiter().GetResult();
}
Expand All @@ -3581,12 +3570,11 @@ public static string GetInvoicePdf(this IOrderModule operations, string orderNum
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task<string> GetInvoicePdfAsync(this IOrderModule operations, string orderNumber, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<Stream> GetInvoicePdfAsync(this IOrderModule operations, string orderNumber, CancellationToken cancellationToken = default(CancellationToken))
{
using (var _result = await operations.GetInvoicePdfWithHttpMessagesAsync(orderNumber, null, cancellationToken).ConfigureAwait(false))
{
return _result.Body;
}
var _result = await operations.GetInvoicePdfWithHttpMessagesAsync(orderNumber, null, cancellationToken).ConfigureAwait(false);
_result.Request.Dispose();
return _result.Body;
}

/// <param name='operations'>
Expand Down Expand Up @@ -3657,7 +3645,6 @@ namespace VirtoCommerce.Storefront.AutoRestClients.OrdersModuleApi
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -262,7 +263,7 @@ public async Task<ActionResult> GetInvoicePdf(string orderNumber)
return Unauthorized();
}

var stream = await _orderApi.GetInvoicePdfAsync(order.Number);
Stream stream = await _orderApi.GetInvoicePdfAsync(order.Number);
return File(stream, "application/pdf");
}

Expand Down

0 comments on commit 820cfa9

Please sign in to comment.