Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions QuickBooksSharp.Tests/DataServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ public async Task CreatePaymentAndVoidAsync()
Assert.IsNotNull(voidPaymentResponse.Response);
}

[TestMethod]
public async Task SendInvoiceTest()
{
var response = await _service.QueryAsync<Invoice>("SELECT * FROM Invoice MAXRESULTS 1");

Assert.IsTrue(response.Response!.Entities!.Length > 0);

var sentInvoice = await _service.SendInvoice(response.Response!.Entities![0].Id!);
Assert.IsTrue(sentInvoice.Response.EmailStatus == EmailStatusEnum.EmailSent);
}

[TestMethod]
public async Task CreateTaxCodeAndRateAsync()
{
Expand Down
1 change: 1 addition & 0 deletions QuickBooksSharp/Infrastructure/IQuickBooksHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IQuickBooksHttpClient
{
Task<TResponse> GetAsync<TResponse>(Url url);
Task<TResponse> PostAsync<TResponse>(Url url, object content);
Task<TResponse> PostAsync<TResponse>(Url url);
Task<HttpResponseMessage> SendAsync(Func<HttpRequestMessage> makeRequest);
Task<TResponse> SendAsync<TResponse>(Func<HttpRequestMessage> makeRequest);
}
Expand Down
6 changes: 6 additions & 0 deletions QuickBooksSharp/Infrastructure/QuickBooksHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public async Task<TResponse> PostAsync<TResponse>(Url url, object content)
return await this.SendAsync<TResponse>(makeRequest);
}

public async Task<TResponse> PostAsync<TResponse>(Url url)
{
Func<HttpRequestMessage> makeRequest = () => new HttpRequestMessage(HttpMethod.Post, url);
return await this.SendAsync<TResponse>(makeRequest);
}

public async Task<TResponse> SendAsync<TResponse>(Func<HttpRequestMessage> makeRequest)
{
var response = await this.SendAsync(makeRequest);
Expand Down
21 changes: 21 additions & 0 deletions QuickBooksSharp/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ private async Task<TEntity> PostWithEntityResultAsync<TEntity>(TEntity e)
return await _client.PostAsync<TEntity>(url, e);
}

public async Task<IntuitResponse<Invoice>> SendInvoice(string invoiceId, string? sendTo = null)
{
var url = new Url(_serviceUrl).AppendPathSegment($"invoice/{invoiceId}/send");

if (!string.IsNullOrEmpty(sendTo))
{
url = url.SetQueryParam("sendTo", sendTo);
}

var res = await _client.PostAsync<IntuitResponse>(url);
return new IntuitResponse<Invoice>
{
RequestId = res.requestId,
Time = res.time,
Status = res.status,
Warnings = res.Warnings,
Fault = res.Fault,
Response = (Invoice?)res.IntuitObject
};
}

/// <remarks>
/// Unlike other entities, TaxService is a special case where the return type is not an IntuitResponse but the entity itself.
/// </remarks>
Expand Down
10 changes: 10 additions & 0 deletions QuickBooksSharp/Services/IDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public interface IDataService
/// <param name="invoiceId">Unique identifier for this object</param>
/// <returns>This resource returns the specified object in the response body as an Adobe Portable Document Format (PDF) file. The resulting PDF file is formatted according to custom form styles in the company settings.</returns>
Task<Stream> GetInvoicePDFAsync(string invoiceId);

/// <summary>
/// Sends an invoice to a customer or vendor. This will update the Invoice.EmailStatus to EmailSent and Invoice.DeliveryInfo
/// will be populated with the sending information.
/// </summary>
/// <param name="invoiceId">Id of the invoice to send</param>
/// <param name="sendTo">Email address to send the invoice to. Optional. If not provided, the Invoice.BillEmail address will be used.
/// If provided, this will replace the Invoice.BillEmail with this value</param>
/// <returns>The updated invoice after sending information</returns>
Task<IntuitResponse<Invoice>> SendInvoice(string invoiceId, string? sendTo = null);

Task<TaxService> PostTaxServiceAsync(TaxService taxService);
}
Expand Down