Exemplo n.º 1
0
        private async Task <ProcessESBResult> ValidateEsbResponse(ProcessESBResponse esbResponse, PaymentRequestStatus paymentRequestStatus)
        {
            if (paymentRequestStatus != null)
            {
                var interfaceStatus = (InterfaceStatus)paymentRequestStatus.DocumentStatus;
                if (!(interfaceStatus == InterfaceStatus.StandBy || interfaceStatus == InterfaceStatus.ReadyToTransmit || interfaceStatus == InterfaceStatus.Interfaced))
                {
                    string message = "The payment request " + esbResponse.DocumentReference + " is not in status 'ready to transmit' or 'stand by' or 'interfaced' (current status: " + interfaceStatus + " )";
                    processESBResult.Error     = message;
                    processESBResult.IsSuccess = false;
                }
                else if (paymentRequestStatus.CounterParty != esbResponse.Counterparty)
                {
                    string message = "The Counterparty should be the same code as in the original payment order.";
                    processESBResult.Error     = message;
                    processESBResult.IsSuccess = false;
                }
                else
                {
                    processESBResult.IsSuccess = true;
                    if (!string.IsNullOrEmpty(paymentRequestStatus.UUID))
                    {
                        processESBResult.UUID = paymentRequestStatus.UUID;
                    }
                }
            }
            else
            {
                string message = "Invalid Cash Document Reference";
                processESBResult.Error     = message;
                processESBResult.IsSuccess = false;
            }

            return(processESBResult);
        }
Exemplo n.º 2
0
        public async Task <ProcessESBResult> Handle(ProcessESBResponse esbRequest, CancellationToken cancellationToken)
        {
            var         eventHistoryData = new EventHistory();
            var         eventData        = new Event();
            CultureInfo cultureInfo      = Thread.CurrentThread.CurrentCulture;
            TextInfo    textInfo         = cultureInfo.TextInfo;
            var         companyDate      = await _systemDateTimeService.GetCompanyDate(esbRequest.CompanyId);

            long sourceId = await _interfaceEventLogService.GetAccountingIdandCashIdbyDocumentReference(esbRequest.CompanyId, esbRequest.DocumentReference, (int)BusinessApplicationType.TRAX, (int)esbRequest.BusinessObjectType);

            var eventDto    = new EventDto(sourceId, esbRequest.DocumentReference, (int)esbRequest.BusinessObjectType, esbRequest.CompanyId);
            var eventStatus = await _interfaceEventLogService.FindEventAsync(eventDto);

            eventHistoryData = new EventHistory(eventStatus.EventId, "Callback message received from ESB", esbRequest.ESBMessage, null, null);
            await _interfaceEventLogService.CreateEventHistoryAsync(eventHistoryData, esbRequest.CompanyId);

            var paymentRequestStatus = await _paymentRequestRepository.GetPaymentRequestStatus((int)BusinessApplicationType.TRAX, esbRequest.CompanyId, esbRequest.DocumentReference);

            _unitOfWork.BeginTransaction();

            try
            {
                var responseToESB = await ValidateEsbResponse(esbRequest, paymentRequestStatus);

                if (responseToESB.IsSuccess)
                {
                    var processInterfaceData = new ProcessInterfaceDataChangeLogsRequest();
                    processInterfaceData.CashDocumentRef         = esbRequest.DocumentReference;
                    processInterfaceData.CompanyId               = esbRequest.CompanyId;
                    processInterfaceData.BusinessApplicationType = Convert.ToInt32(BusinessApplicationType.TRAX, CultureInfo.InvariantCulture);
                    processInterfaceData.ESBMessage              = esbRequest.ESBMessage;
                    processInterfaceData.AcknowledgementId       = esbRequest.AckBusinessDocId;
                    processInterfaceData.DocumentDate            = esbRequest.ValueDate;

                    InterfaceStatus status;
                    if (Enum.TryParse(textInfo.ToTitleCase(esbRequest.ResponseStatus.ToLower(CultureInfo.InvariantCulture)), out status))
                    {
                        switch (status)
                        {
                        case InterfaceStatus.Signed:
                            await ProcessEventUpdate(eventStatus.EventId, InterfaceStatus.Signed, "ESB callback Message integration", esbRequest.ESBMessage, ResultCode.Ok.ToString(), null, esbRequest.CompanyId);
                            await ProcessStatusUpdate(processInterfaceData, InterfaceStatus.Signed, esbRequest.ESBMessage);
                            await EnqueueMessage(paymentRequestStatus.TransactionDocumentId.ToString(CultureInfo.InvariantCulture), esbRequest.CompanyId);

                            break;

                        case InterfaceStatus.Error:
                            await ProcessEventUpdate(eventStatus.EventId, InterfaceStatus.Error, "ESB callback Message integration", esbRequest.ESBMessage, ResultCode.Error.ToString(), esbRequest.ResponseMessage, esbRequest.CompanyId);
                            await ProcessStatusUpdate(processInterfaceData, InterfaceStatus.Error, esbRequest.ResponseMessage);

                            break;

                        case InterfaceStatus.Included:
                            await ProcessEventUpdate(eventStatus.EventId, InterfaceStatus.Included, "ESB callback Message integration", esbRequest.ESBMessage, ResultCode.Ok.ToString(), null, esbRequest.CompanyId);
                            await ProcessStatusUpdate(processInterfaceData, InterfaceStatus.Interfaced, esbRequest.ResponseMessage);

                            break;

                        case InterfaceStatus.Rejected:
                            await ProcessEventUpdate(eventStatus.EventId, InterfaceStatus.Rejected, "ESB callback Message integration", esbRequest.ESBMessage, ResultCode.Error.ToString(), esbRequest.ResponseMessage, esbRequest.CompanyId);
                            await ProcessStatusUpdate(processInterfaceData, InterfaceStatus.Rejected, esbRequest.ResponseMessage);

                            break;
                        }
                    }
                }

                _unitOfWork.Commit();
                _logger.LogInformation("Cash with DocumentId {Atlas_PaymentRequestCashDocumentId} recieved status {Atlas_PaymentRequestStatus} from Treasury System at {Atlas_DateTime}", esbRequest.DocumentReference, esbRequest.ResponseStatus, companyDate);
                return(responseToESB);
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }