Как удалить внешний фискализованный платеж с IIKO?C#

Место общения программистов C#
Ответить
Anonymous
 Как удалить внешний фискализованный платеж с IIKO?

Сообщение Anonymous »

Теперь работа с плагином IIKO и нуждается в создании банкета с предоплатой. Создание работы без проблем. Но когда я пытаюсь отменить с помощью deleteexternalfiscisticalizedPaymentItem < /code>, у меня есть < /p>

resto.front.api.exceptions.constraintviolationExcept Оплата? < /p>
private void CancelBanquet(IikoPrepaidBookingRq rq, string callBackUrl)
{
if (rq.BanquetId is null)
{
PluginContext.Log.Error($"Banquet {rq.BanquetId} is empty : {nameof(PrepaidBookingHandler)} : {nameof(CancelBanquet)}");
SentryHelper.SendException($"Banquet {rq.BanquetId} is empty", new Exception(),
$"{nameof(PrepaidBookingHandler)} : {nameof(CreateBanquetAndOrder)}");

operationProvider.SendPrepaidBanquetId(new IikoPrepaidBookingRp
{
State = "Error",
Message = "BanquetId is empty"
}, callBackUrl);

return;
}

var reserves = PluginContext.Operations.GetReserves();

var banquetId = Guid.Parse(rq.BanquetId);

var userBanquet = reserves.SingleOrDefault(x => x.Id == banquetId);

if (userBanquet is null)
{
PluginContext.Log.Error(
$"User ${rq.UserName} : {rq.UserPhone} : Reserve with tableId {rq.TableId} not found : " +
$"{nameof(PrepaidBookingHandler)} : {nameof(CancelBanquet)}");
SentryHelper.SendException(
$"User ${rq.UserName} : {rq.UserPhone} : Reserve with tableId {rq.TableId} not found",
new Exception(), $"{nameof(PrepaidBookingHandler)} : {nameof(CreateBanquetAndOrder)}");

operationProvider.SendPrepaidBanquetId(new IikoPrepaidBookingRp
{
State = "NotFound",
Message = "userBanquet not found"
}, callBackUrl);

return;
}

var credentials = PluginContext.Operations.GetCredentials(AppDataV2.PaymentProcessorUserPin);

var prepaidPayment = userBanquet.Order.Payments.FirstOrDefault(p => p.IsPrepay);

//TODo добавить лог посмотерть как создается через UI платеж к банкету

//Todo Resto.Front.Api.Exceptions.ConstraintViolationException: Cannot delete payment item in status PROCESSED
PluginContext.Operations.DeleteExternalFiscalizedPaymentItem(prepaidPayment, userBanquet.Order, credentials);

PluginContext.Operations.CancelReserve(credentials, userBanquet, ReserveCancelReason.ClientRefused);

operationProvider.SendPrepaidBanquetId(new IikoPrepaidBookingRp
{
State = "Success"
}, callBackUrl);
}
#endregion

#region CreateBanquetAndOrder
private void CreateBanquetAndOrder(IikoPrepaidBookingRq rq, string callBackUrl)
{
var editSession = PluginContext.Operations.CreateEditSession();
var credentials = PluginContext.Operations.GetCredentials(AppDataV2.PaymentProcessorUserPin);

var phones = new List
{
new PhoneDto
{
PhoneValue = rq.UserPhone,
IsMain = true
}
};

var client = editSession.CreateClient(Guid.NewGuid(), rq.UserName, phones, null, DateTime.Now);

var table = PluginContext.Operations.GetTables()
.SingleOrDefault(x =>
x.RestaurantSection.Id == Guid.Parse(rq.SectionId) && x.Id == Guid.Parse(rq.TableId));

var order = editSession.CreateOrder(table);
editSession.AddOrderGuest(rq.UserName, order);
editSession.ChangeEstimatedOrderGuestsCount(rq.GuestsCount, order);

var banquetSub = editSession.CreateBanquet(rq.CheckinTime, client, order);
var createdBanquet = PluginContext.Operations.SubmitChanges(credentials, editSession).Get(banquetSub);

PluginContext.Operations.ChangeReserveGuestsCount(rq.GuestsCount, createdBanquet, credentials);

if (!string.IsNullOrEmpty(rq.Comment))
{
PluginContext.Operations.ChangeReserveComment(rq.Comment, createdBanquet, credentials);
}

AddExternalFiscalizedPrepay(createdBanquet.Order, rq.PrepaidAmount, rq.PaymentTypeId);

operationProvider.SendPrepaidBanquetId(new IikoPrepaidBookingRp
{
State = "Success",
BanquetId = createdBanquet.Id.ToString()
}, callBackUrl);
}
#endregion

#region AddExternalFiscalizedPrepay for banquet order
private void AddExternalFiscalizedPrepay(IOrder order, int prepaidAmount, string paymentTypeId)
{
var paymentType = PluginContext.Operations.GetPaymentTypes().First(x => x.Id == Guid.Parse(paymentTypeId));

var credentials = PluginContext.Operations.GetCredentials(AppDataV2.PaymentProcessorUserPin);

var paymentItem = PluginContext.Operations.AddExternalFiscalizedPaymentItem(
prepaidAmount,
null,
paymentType,
order,
credentials
);

PluginContext.Operations.ProcessPrepay(credentials, order, paymentItem);
}
#endregion


Подробнее здесь: https://stackoverflow.com/questions/797 ... -with-iiko
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»