Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a294aaa
initial query api model
ahwm Jul 6, 2023
8180986
suppressing netcoreapp3.1 warning for System.Text.Json
ahwm Jul 6, 2023
42b78aa
Update build.yml
ahwm Jul 6, 2023
a0f66b0
progress on query api
ahwm Aug 8, 2023
8b86faf
Merge branch 'main' into query-api
ahwm Sep 20, 2023
257ec46
fixing build errors
ahwm Sep 20, 2023
55e5feb
Merge branch 'query-api' of https://github.com/ahwm/payment-gateway-c…
ahwm Sep 20, 2023
0f5f577
fixing build errors
ahwm Sep 20, 2023
af84d77
Merge branch 'main' into query-api
ahwm Oct 27, 2023
eb3bcb0
Merge branch 'main' into query-api
ahwm Mar 26, 2024
cf56083
Merge branch 'main' into query-api
ahwm Apr 23, 2024
9a14290
fixing build error
ahwm Apr 23, 2024
8262509
fixing build error, fixing warning
ahwm Apr 23, 2024
0627ad6
adjusting frameworks
ahwm Apr 23, 2024
75fe246
fixed wrong tfm
ahwm Apr 23, 2024
d2af07d
suppress tfm build warnings on tests project
ahwm Apr 23, 2024
42ca9c3
Merge branch 'main' into query-api
ahwm Oct 8, 2024
cd9bf82
Merge branch 'main' into query-api
ahwm Oct 8, 2024
101c277
Merge branch 'main' into query-api
ahwm Oct 21, 2024
77875a4
Merge branch 'main' into query-api
ahwm Oct 21, 2025
49848e4
Update PaymentGateway/GatewayClient.cs
ahwm Oct 22, 2025
19ba3bd
Update PaymentGateway/Models/QueryResponse.cs
ahwm Oct 22, 2025
5e4f145
Initial plan
Copilot Feb 3, 2026
5b3fe75
Add ConfigureAwait(false) to Payment, Recurring, and Invoices methods
Copilot Feb 3, 2026
6bde6cb
Merge pull request #115 from ahwm/copilot/sub-pr-49
ahwm Feb 3, 2026
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
28 changes: 14 additions & 14 deletions PaymentGateway/CustomerVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public partial class GatewayClient
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse AddCustomer(AddCustomer request)
public async Task<GatewayResponse> AddCustomerAsync(AddCustomer request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -26,9 +26,9 @@ public GatewayResponse AddCustomer(AddCustomer request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse UpdateCustomer(UpdateCustomer request)
public async Task<GatewayResponse> UpdateCustomerAsync(UpdateCustomer request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -38,9 +38,9 @@ public GatewayResponse UpdateCustomer(UpdateCustomer request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse DeleteCustomer(DeleteCustomer request)
public async Task<GatewayResponse> DeleteCustomerAsync(DeleteCustomer request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -50,9 +50,9 @@ public GatewayResponse DeleteCustomer(DeleteCustomer request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CustomerSale(CustomerSale request)
public async Task<GatewayResponse> CustomerSaleAsync(CustomerSale request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -62,9 +62,9 @@ public GatewayResponse CustomerSale(CustomerSale request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CustomerAuth(CustomerAuth request)
public async Task<GatewayResponse> CustomerAuthAsync(CustomerAuth request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -74,9 +74,9 @@ public GatewayResponse CustomerAuth(CustomerAuth request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CustomerCredit(CustomerCredit request)
public async Task<GatewayResponse> CustomerCreditAsync(CustomerCredit request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -86,9 +86,9 @@ public GatewayResponse CustomerCredit(CustomerCredit request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CustomerOffline(CustomerOffline request)
public async Task<GatewayResponse> CustomerOfflineAsync(CustomerOffline request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand Down
53 changes: 50 additions & 3 deletions PaymentGateway/GatewayClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Serialization;
using PaymentGateway.Helpers;
using PaymentGateway.Models;
using PaymentGateway.Query.Models;

namespace PaymentGateway
{
Expand Down Expand Up @@ -63,7 +68,7 @@ public GatewayClient(string securityKey) : this(securityKey, GatewayProvider.NMI
public GatewayClient(string securityKey, string postUrl) : this(securityKey, new GatewayProvider(postUrl))
{ }

private Dictionary<string, string> MakeRequest(object model)
private async Task<Dictionary<string, string>> MakeRequest(object model)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Expand All @@ -84,12 +89,12 @@ private Dictionary<string, string> MakeRequest(object model)
using (HttpClient client = new HttpClient())
{
using (var postContent = new FormUrlEncodedContent(Values))
using (HttpResponseMessage response = client.PostAsync(Provider.PostUrl + "/transact.php", postContent).Result)
using (HttpResponseMessage response = await client.PostAsync(Provider.PostUrl + "/transact.php", postContent).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
using (HttpContent content = response.Content)
{
string result = content.ReadAsStringAsync().Result;
string result = await content.ReadAsStringAsync();
var values = HttpUtility.ParseQueryString(result);
foreach (var key in values.AllKeys)
resp.Add(key, values[key]);
Expand All @@ -106,5 +111,47 @@ private Dictionary<string, string> MakeRequest(object model)

return resp;
}

private async Task<QueryResponse> MakeQueryRequest(object model)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Dictionary<string, string> Values = new Dictionary<string, string>
{
{ "security_key", SecurityKey }
};

var attributes = AttributeHelper.GetAttributes(model);
foreach (var kv in attributes)
Values.Add(kv.Key, kv.Value);

RequestStarted?.Invoke(this, new GatewayEventArgs(Values));

var resp = new QueryResponse();
try
{
using (HttpClient client = new HttpClient())
{
using (var postContent = new FormUrlEncodedContent(Values))
using (HttpResponseMessage response = await client.PostAsync(Provider.PostUrl + "/query.php", postContent).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
using (HttpContent content = response.Content)
{
string result = await content.ReadAsStringAsync();
resp = (QueryResponse)new XmlSerializer(typeof(QueryResponse)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(result)));
}
}
}
}
catch (Exception ex)
{
throw new GatewayException($"Unable to communicate with gateway ({Provider.PostUrl}). Ensure {nameof(Provider.PostUrl)} has a correct value and the security key is correct. See inner exception for details.", ex);
}

//RequestCompleted?.Invoke(this, new GatewayEventArgs(resp));

return resp;
}
}
}
18 changes: 10 additions & 8 deletions PaymentGateway/Invoices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PaymentGateway.Models;
using System.Threading.Tasks;

namespace PaymentGateway
{
public partial class GatewayClient
Expand All @@ -8,9 +10,9 @@ public partial class GatewayClient
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CreateInvoice(CreateInvoice request)
public async Task<GatewayResponse> CreateInvoiceAsync(CreateInvoice request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -20,9 +22,9 @@ public GatewayResponse CreateInvoice(CreateInvoice request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse UpdateInvoice(UpdateInvoice request)
public async Task<GatewayResponse> UpdateInvoiceAsync(UpdateInvoice request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -32,9 +34,9 @@ public GatewayResponse UpdateInvoice(UpdateInvoice request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse SendInvoice(SendInvoice request)
public async Task<GatewayResponse> SendInvoiceAsync(SendInvoice request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand All @@ -44,9 +46,9 @@ public GatewayResponse SendInvoice(SendInvoice request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public GatewayResponse CloseInvoice(CloseInvoice request)
public async Task<GatewayResponse> CloseInvoiceAsync(CloseInvoice request)
{
var data = new GatewayResponse(MakeRequest(request));
var data = new GatewayResponse(await MakeRequest(request).ConfigureAwait(false));

return data;
}
Expand Down
6 changes: 0 additions & 6 deletions PaymentGateway/Models/CustomerVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,6 @@ public class CustomerSale : Sale
[ParameterName("order_description")]
public string OrderDescription { get; set; }

/// <summary>
///
/// </summary>
[ParameterName("order_id")]
public string OrderId { get; set; }

/// <summary>
/// Who initiated the transaction. Values: 'customer' or 'merchant'
/// </summary>
Expand Down
Loading
Loading