Untitled
unknown
csharp
a year ago
3.2 kB
7
Indexable
private async Task SendMerchantsToStoneAcquirerNotificationHandler(IEnumerable<MerchantIdAndMerchantReference>
merchants, IEnumerable<Product> products, MerchantAgreementStatus merchantAgreementStatus, CancellationToken
cancellationToken)
{
const string webhookLogMessage = "WebhookNotifications";
const string dnauthWebhookErrorsMessage = "DnauthWebhookErrors";
IList<object> webhookLogs = new List<object>();
IList<object> dnauthWebhookErrorLogs = new List<object>();
foreach (var merchantReference in merchants.OrderBy(x => x.MerchantReference).Select(merchant =>
merchant.MerchantReference))
{
var success = true;
Exception exception = default;
var stoneWebhookException = await SendMerchantToStoneAcquirerNotificationHandler(merchantReference,
products, merchantAgreementStatus, cancellationToken);
if (stoneWebhookException is null)
continue;
exception = new MerchantException(merchantReference.Unformat(), stoneWebhookException);
success = false;
webhookLogs.Add(new { Success = success, Exception = exception, SentToDnauthWebhook = !success });
var exceptionDnauthWebhook = await SendMerchantToDnauthNotificationHandler(merchantReference);
if (exceptionDnauthWebhook is null)
continue;
exception = new MerchantException(merchantReference, exceptionDnauthWebhook);
dnauthWebhookErrorLogs.Add(new { Exception = exception });
}
resumeLog.SetAdditionalData(webhookLogs, webhookLogMessage);
if (!dnauthWebhookErrorLogs.IsEmpty())
{
resumeLog.SetAdditionalData(dnauthWebhookErrorLogs, dnauthWebhookErrorsMessage);
resumeLog.SetSeverityIfMoreSevere(LogSeverity.Error);
}
}
private async Task<Exception> SendMerchantToStoneAcquirerNotificationHandler(string merchantReference,
IEnumerable<Product> products, MerchantAgreementStatus merchantAgreementStatus, CancellationToken
cancellationToken)
{
try
{
var notification = CreatePermissionAuthorizationUpdatedEvent(merchantReference.Unformat(),
requestContext.CardBrand.Scheme, products.OrderBy(x => x), merchantAgreementStatus);
await stoneAcquirerNotificationHandler.Execute(notification, cancellationToken);
return null;
}
catch (Exception ex)
{
return new MerchantException(merchantReference.Unformat(), ex);
}
}
private async Task<Exception> SendMerchantToDnauthNotificationHandler(string merchantReference)
{
IEnumerable<string> merchant = new List<string> { merchantReference };
try
{
await dnauthNotificationHandler.Execute(merchant, default);
return null;
}
catch (Exception e)
{
return new MerchantException(merchant.First().Unformat(), e);
}
}Editor is loading...
Leave a Comment