Add new Hcs.Broker to communicate with ГИС ЖКХ via CryptoPro LibCore
This commit is contained in:
@ -0,0 +1,93 @@
|
||||
using Hcs.Broker.Api.Payload.Payments;
|
||||
using Hcs.Broker.Api.Request.Exception;
|
||||
using Hcs.Broker.Internal;
|
||||
using Hcs.Service.Async.Payments;
|
||||
|
||||
namespace Hcs.Broker.Api.Request.Payments
|
||||
{
|
||||
internal class ImportSupplierNotificationsOfOrderExecutionRequest(Client client) : PaymentsRequestBase(client)
|
||||
{
|
||||
protected override bool CanBeRestarted => false;
|
||||
|
||||
internal async Task<bool> ExecuteAsync(ImportSupplierNotificationsOfOrderExecutionPayload payload, CancellationToken token)
|
||||
{
|
||||
ThrowIfPayloadIncorrect(payload);
|
||||
|
||||
// http://open-gkh.ru/Payment/importSupplierNotificationsOfOrderExecutionRequest.html
|
||||
var request = new importSupplierNotificationsOfOrderExecutionRequest
|
||||
{
|
||||
Id = Constants.SIGNED_XML_ELEMENT_ID,
|
||||
version = "10.0.1.1",
|
||||
SupplierNotificationOfOrderExecution = [GetNotificationFromPayload(payload)]
|
||||
};
|
||||
|
||||
var result = await SendAndWaitResultAsync(request, async asyncClient =>
|
||||
{
|
||||
var response = await asyncClient.importSupplierNotificationsOfOrderExecutionAsync(CreateRequestHeader(), request);
|
||||
return response.AckRequest.Ack;
|
||||
}, token);
|
||||
|
||||
result.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
|
||||
result.Items.OfType<CommonResultType>().ToList().ForEach(commonResult =>
|
||||
{
|
||||
commonResult.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ThrowIfPayloadIncorrect(ImportSupplierNotificationsOfOrderExecutionPayload payload)
|
||||
{
|
||||
if (payload.month.HasValue && !payload.year.HasValue)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.month)} has value but {nameof(payload.year)} has not");
|
||||
}
|
||||
|
||||
if (!payload.month.HasValue && payload.year.HasValue)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.year)} has value but {nameof(payload.month)} has not");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(payload.paymentDocumentId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(payload.paymentDocumentId)} is empty");
|
||||
}
|
||||
}
|
||||
|
||||
private importSupplierNotificationsOfOrderExecutionRequestSupplierNotificationOfOrderExecution GetNotificationFromPayload(ImportSupplierNotificationsOfOrderExecutionPayload payload)
|
||||
{
|
||||
var notification = new importSupplierNotificationsOfOrderExecutionRequestSupplierNotificationOfOrderExecution()
|
||||
{
|
||||
TransportGUID = Guid.NewGuid().ToString(),
|
||||
OrderDate = payload.orderDate,
|
||||
Item = payload.paymentDocumentId,
|
||||
ItemElementName = ItemChoiceType1.PaymentDocumentID,
|
||||
Amount = payload.amount
|
||||
};
|
||||
|
||||
if (payload.month.HasValue)
|
||||
{
|
||||
notification.OrderPeriod = new SupplierNotificationOfOrderExecutionTypeOrderPeriod()
|
||||
{
|
||||
Month = payload.month.Value,
|
||||
Year = payload.year.Value
|
||||
};
|
||||
}
|
||||
|
||||
if (payload.onlinePayment.HasValue && payload.onlinePayment.Value)
|
||||
{
|
||||
notification.OnlinePayment = true;
|
||||
notification.OnlinePaymentSpecified = true;
|
||||
}
|
||||
|
||||
return notification;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user