Add payment import

This commit is contained in:
2025-09-15 11:28:08 +09:00
parent 5ebcdfae6e
commit e37f0b25ef
9 changed files with 250 additions and 0 deletions

View File

@ -0,0 +1,97 @@
using Hcs.Client.Api.Payload.Payments;
using Hcs.Client.Api.Request.Exception;
using Hcs.Client.Internal;
using Hcs.Service.Async.Payments;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Hcs.Client.Api.Request.Payments
{
internal class ImportSupplierNotificationsOfOrderExecutionRequest(ClientBase 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;
}
}
}

View File

@ -0,0 +1,55 @@
using Hcs.Client.Api.Request;
using Hcs.Client.Api.Request.Adapter;
using Hcs.Service.Async.Payments;
using System.Threading.Tasks;
namespace Hcs.Service.Async.Payments
{
#pragma warning disable IDE1006
public partial class getStateResult : IGetStateResultMany { }
#pragma warning restore IDE1006
public partial class PaymentPortsTypeAsyncClient : IAsyncClient<RequestHeader>
{
public async Task<IGetStateResponse> GetStateAsync(RequestHeader header, IGetStateRequest request)
{
return await getStateAsync(header, (getStateRequest)request);
}
}
#pragma warning disable IDE1006
public partial class getStateResponse : IGetStateResponse
#pragma warning restore IDE1006
{
public IGetStateResult GetStateResult => getStateResult;
}
public partial class AckRequestAck : IAck { }
public partial class ErrorMessageType : IErrorMessage { }
#pragma warning disable IDE1006
public partial class getStateRequest : IGetStateRequest { }
#pragma warning restore IDE1006
}
namespace Hcs.Client.Api.Request.Payments
{
internal class PaymentsRequestBase(ClientBase client) :
RequestBase<getStateResult,
PaymentPortsTypeAsyncClient,
PaymentPortsTypeAsync,
RequestHeader,
AckRequestAck,
ErrorMessageType,
getStateRequest>(client)
{
protected override EndPoint EndPoint => EndPoint.PaymentsAsync;
protected override bool EnableMinimalResponseWaitDelay => true;
protected override bool CanBeRestarted => true;
protected override int RestartTimeoutMinutes => 20;
}
}