-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I have the following code:
try {
ApiResponse response = gateway.TransactionInquiry(ipgTransactionId);
var success = true;
}
catch (ApiException ex)
{
var success = false;
}
I'm currently waiting for my apiKey and secret, so these variables are set to junk. If I attach debugging tools then I can see that this code triggers the expected TransactionInquiry call, and the API returns a 401 response. So far so good. However, if I step through the code, no lines are called after I step past the TransactionInquiry line. I would expect an ApiException to be thrown and success to be set to false.
To track down the problem, I unwrapped TransactionInquiry using this code:
var apiSecret = "def";
var credentials = new MerchantCredentials(apiKey, apiSecret);
var clientContext = new ClientContext(credentials);
var signatureService = new Signature(apiKey, apiSecret);
var payApi = new PaymentApi(clientContext.Config);
try
{
var apiResponse = payApi.TransactionInquiryWithHttpInfo(
"application/json",
signatureService.ClientRequestId,
apiKey,
signatureService.TimeStamp,
ipgTransactionId,
signatureService.Sign(),
null,
null
);
var success = true;
}
catch (Exception e)
{
var success = false;
}
This has the same problem. However, if I change the line apiResponse line to use Async:
var apiResponse = payApi.TransactionInquiryWithHttpInfo(...)
Then it will throw the expected ApiException.
Reviewing the code in https://github.com/GBSEcom/DotNet/blob/master/src/Org.OpenAPITools/Client/ApiClient.cs I can see the Get method is:
{
return GetAsync(path, options).Result;
}
I believe this is hitting the deadlock problem described at https://docs.microsoft.com/en-us/archive/msdn-magazine/2015/july/async-programming-brownfield-async-development (see the section starting "The Blocking Hack").
To get that method working properly I think you'll need to implement one of the solutions described in the article. However, I'm calling your API from a method that supports async code, so a much better solution for me would be if you could provide a version of Gateway.cs that included Async method calls.
Something like:
{
Signature signatureService = GetSignatureService();
string messageSignature = signatureService.Sign();
return await payApi.TransactionInquiryAsync(
CONTENT_TYPE,
signatureService.ClientRequestId,
GetApiKey(),
signatureService.TimeStamp,
transactionId,
messageSignature,
region,
storeId
);
}