Add payment import
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace Hcs.Client.Api.Payload.Payments
|
||||
{
|
||||
// http://open-gkh.ru/Payment/importSupplierNotificationsOfOrderExecutionRequest/SupplierNotificationOfOrderExecution.html
|
||||
public class ImportSupplierNotificationsOfOrderExecutionPayload
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата внесения платы (в случае отсутствия: дата поступления средств)
|
||||
/// </summary>
|
||||
public DateTime orderDate;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Месяц, за который вносится плата. Указывать совместно с <see cref="year"/>.
|
||||
/// </summary>
|
||||
public int? month;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Год, за который вносится плата. Указывать совместно с <see cref="month"/>.
|
||||
/// </summary>
|
||||
public short? year;
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор платежного документа
|
||||
/// </summary>
|
||||
public string paymentDocumentId;
|
||||
|
||||
/// <summary>
|
||||
/// Сумма
|
||||
/// </summary>
|
||||
public decimal amount;
|
||||
|
||||
/// <summary>
|
||||
/// Необязательное. Признак онлайн-оплаты.
|
||||
/// </summary>
|
||||
public bool? onlinePayment;
|
||||
}
|
||||
}
|
||||
23
Hcs.Client/Client/Api/PaymentsApi.cs
Normal file
23
Hcs.Client/Client/Api/PaymentsApi.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Hcs.Client.Api.Payload.Payments;
|
||||
using Hcs.Client.Api.Request.Payments;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api
|
||||
{
|
||||
// http://open-gkh.ru/PaymentsServiceAsync/
|
||||
public class PaymentsApi(ClientBase client) : ApiBase(client)
|
||||
{
|
||||
/// <summary>
|
||||
/// Импорт пакета документов "Извещение о принятии к исполнению распоряжения", размещаемых исполнителем
|
||||
/// </summary>
|
||||
/// <param name="payload">Пейлоад документа</param>
|
||||
/// <param name="token">Токен отмены</param>
|
||||
/// <returns>true, если операция выполнена успешно, иначе - false</returns>
|
||||
public async Task<bool> ImportSupplierNotificationsOfOrderExecutionAsync(ImportSupplierNotificationsOfOrderExecutionPayload payload, CancellationToken token = default)
|
||||
{
|
||||
var request = new ImportSupplierNotificationsOfOrderExecutionRequest(client);
|
||||
return await request.ExecuteAsync(payload, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,8 @@ namespace Hcs.Client
|
||||
|
||||
public OrgRegistryCommonApi OrgRegistryCommon => new(this);
|
||||
|
||||
public PaymentsApi Payments => new(this);
|
||||
|
||||
public void SetSigningCertificate(X509Certificate2 cert, string pin = null)
|
||||
{
|
||||
pin ??= Constants.DEFAULT_CERTIFICATE_PIN;
|
||||
|
||||
@ -79,6 +79,8 @@
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportNotificationDataPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportSupplyResourceContractProjectPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\HouseManagement\ImportSupplyResourceContractDataPayload.cs" />
|
||||
<Compile Include="Client\Api\Payload\Payments\ImportSupplierNotificationsOfOrderExecutionPayload.cs" />
|
||||
<Compile Include="Client\Api\PaymentsApi.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry16.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry2.cs" />
|
||||
<Compile Include="Client\Api\Registry\Registry239.cs" />
|
||||
@ -126,6 +128,8 @@
|
||||
<Compile Include="Client\Api\Request\OrgRegistryCommon\ExportOrgRegistryRequest.cs" />
|
||||
<Compile Include="Client\Api\Request\OrgRegistryCommon\OrgRegistryCommonRequestBase.cs" />
|
||||
<Compile Include="Client\Api\Request\PaginationData.cs" />
|
||||
<Compile Include="Client\Api\Request\Payments\ImportSupplierNotificationsOfOrderExecutionRequest.cs" />
|
||||
<Compile Include="Client\Api\Request\Payments\PaymentsRequestBase.cs" />
|
||||
<Compile Include="Client\Api\Request\RequestBase.cs" />
|
||||
<Compile Include="Client\Api\Request\Nsi\ExportDataProviderNsiItemRequest.cs" />
|
||||
<Compile Include="Client\Api\Request\AsyncRequestStateType.cs" />
|
||||
|
||||
@ -76,6 +76,7 @@
|
||||
<Compile Include="TestApp\Scenario\NsiCommonScenario.cs" />
|
||||
<Compile Include="TestApp\Scenario\NsiScenario.cs" />
|
||||
<Compile Include="TestApp\Scenario\OrgRegistryCommonScenario.cs" />
|
||||
<Compile Include="TestApp\Scenario\PaymentsScenario.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
|
||||
|
||||
@ -42,6 +42,7 @@ namespace Hcs.TestApp
|
||||
var nsiScenario = new NsiScenario(client);
|
||||
var nsiCommonScenario = new NsiCommonScenario(client);
|
||||
var orgRegistryCommonScenario = new OrgRegistryCommonScenario(client);
|
||||
var paymentsScenario = new PaymentsScenario(client);
|
||||
try
|
||||
{
|
||||
//billsScenario.ImportPaymentDocument();
|
||||
@ -77,6 +78,8 @@ namespace Hcs.TestApp
|
||||
//nsiCommonScenario.ExportNsiItem276();
|
||||
|
||||
//orgRegistryCommonScenario.ExportOrgRegistry();
|
||||
|
||||
//paymentsScenario.ImportSupplierNotificationsOfOrderExecution();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
27
Hcs.TestApp/TestApp/Scenario/PaymentsScenario.cs
Normal file
27
Hcs.TestApp/TestApp/Scenario/PaymentsScenario.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Hcs.Client;
|
||||
using Hcs.Client.Api.Payload.Payments;
|
||||
using System;
|
||||
|
||||
namespace Hcs.TestApp.Scenario
|
||||
{
|
||||
internal class PaymentsScenario(UniClient client)
|
||||
{
|
||||
private readonly UniClient client = client;
|
||||
|
||||
internal void ImportSupplierNotificationsOfOrderExecution()
|
||||
{
|
||||
var payload = new ImportSupplierNotificationsOfOrderExecutionPayload()
|
||||
{
|
||||
orderDate = new DateTime(2025, 9, 5),
|
||||
month = 8,
|
||||
year = 2025,
|
||||
paymentDocumentId = "00АА095186-02-5081",
|
||||
amount = 4000M,
|
||||
onlinePayment = true
|
||||
};
|
||||
|
||||
var result = client.Payments.ImportSupplierNotificationsOfOrderExecutionAsync(payload).Result;
|
||||
Console.WriteLine("Scenario execution " + (result ? "succeeded" : "failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user