public static EServicePaymentRequestModel ToModel(this EservicePaymentRequest entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new EServicePaymentRequestModel
            {
                Id = entity.Id,
                EserviceTypeCode   = entity.EserviceTypeCode,
                EserviceTypeName   = entity.EserviceTypeCodeNavigation?.Name,
                EserviceTypeNameEn = entity.EserviceTypeCodeNavigation?.NameEn,
                SeizedPropertyCertificateRequestId = entity.SeizedPropertyCertificateRequestId,
                SeizedPropertyReportRequestId      = entity.SeizedPropertyReportRequestId,
                ServiceRequestId = entity.SeizedPropertyCertificateRequestId.HasValue
                ? entity.SeizedPropertyCertificateRequestId.Value
                : (entity.SeizedPropertyReportRequestId.HasValue
                    ? entity.SeizedPropertyReportRequestId.Value
                    : 0),
                PaymentRequestId = entity.PaymentRequestId,
                CreatedAt        = entity.CreatedAt,
                StatusCode       = entity.StatusCode,
                StatusName       = entity.StatusCodeNavigation?.Name,
                StatusNameEn     = entity.StatusCodeNavigation?.NameEn,
                UpdatedAt        = entity.UpdatedAt.HasValue ? entity.UpdatedAt.Value : default(DateTime),
            };

            return(model);
        }
Esempio n. 2
0
        public async Task ProcessPaymentRequestSendResult(EservicePaymentRequest request, string jsonResult)
        {
            if (request == null)
            {
                throw new Exception("EservicePaymentRequest not found for sent status update!");
            }

            if (String.IsNullOrWhiteSpace(jsonResult))
            {
                throw new Exception("EservicePaymentRequest received empty result!");
            }

            Log.Information($"EPaymentService/ProcessPaymentRequestSendResult - jsonResult: {jsonResult}");

            object resultModel = JsonConvert.DeserializeObject(jsonResult, typeof(PaymentRequestSendResultModel));

            if (resultModel != null)
            {
                PaymentRequestSendResultModel model = resultModel as PaymentRequestSendResultModel;
                if (model.AcceptedReceipt != null && model.AcceptedReceipt.Id == request.PaymentRequest.AisPaymentId)
                {
                    DateTime timestamp = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
                    string   status    = Shared.Enums.PaymentRequestStatus.ACCEPTED.ToString();
                    request.UpdatedAt  = timestamp;
                    request.StatusCode = status;

                    _context.EservicePaymentRequest.Update(request);
                    await _context.SaveChangesAsync();

                    DateTime serviceTimestamp = DateTime.SpecifyKind(model.AcceptedReceipt.RegistrationTime, DateTimeKind.Utc);
                    await AddEServicePaymentRequestStatusHistory(request.Id, status, timestamp, serviceTimestamp, null);
                }
                else
                {
                    if (model.UnacceptedReceipt != null)
                    {
                        DateTime timestamp = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
                        string   status    = Shared.Enums.PaymentRequestStatus.REJECTED.ToString();
                        request.UpdatedAt  = timestamp;
                        request.StatusCode = status;

                        _context.EservicePaymentRequest.Update(request);
                        await _context.SaveChangesAsync();

                        DateTime serviceTimestamp = DateTime.SpecifyKind(model.UnacceptedReceipt.ValidationTime, DateTimeKind.Utc);
                        string   errors           = String.Join("; ", model.UnacceptedReceipt.Errors);
                        await AddEServicePaymentRequestStatusHistory(request.Id, status, timestamp, serviceTimestamp, errors);
                    }
                    else
                    {
                        throw new Exception("Json send result is not recognized as valid accepted/rejected model!");
                    }
                }
            }
            else
            {
                throw new Exception("Json send result is not recognized as valid model!");
            }
        }
Esempio n. 3
0
        public async Task <EservicePaymentRequest> GetServicePaymentRequestAsync(int paymentRequestId)
        {
            EservicePaymentRequest entity = await _context.EservicePaymentRequest
                                            .Include(x => x.PaymentRequest)
                                            .Where(x => x.PaymentRequest != null && x.PaymentRequest.AisPaymentId == paymentRequestId)
                                            .FirstOrDefaultAsync();

            return(entity);
        }
Esempio n. 4
0
        public async Task SetPaymentRequestErrorAsync(EservicePaymentRequest request, string error)
        {
            if (request == null)
            {
                throw new Exception($"EservicePaymentRequest missing for error update!");
            }

            DateTime timestamp = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
            string   status    = Shared.Enums.PaymentRequestStatus.ERROR.ToString();

            request.UpdatedAt  = timestamp;
            request.StatusCode = status;

            _context.EservicePaymentRequest.Update(request);
            await _context.SaveChangesAsync();

            await AddEServicePaymentRequestStatusHistory(request.Id, status, timestamp, null, error);
        }
        public static EservicePaymentRequest ToEntity(this EServicePaymentRequestCreateModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new EservicePaymentRequest
            {
                EserviceTypeCode = model.EserviceTypeCode,
                SeizedPropertyCertificateRequestId = model.SeizedPropertyCertificateRequestId,
                SeizedPropertyReportRequestId      = model.SeizedPropertyReportRequestId,
                PaymentRequestId = model.PaymentRequestId,
                CreatedAt        = DateTime.Now,
                StatusCode       = model.StatusCode,
            };

            return(entity);
        }
Esempio n. 6
0
        public async Task <EServicePaymentRequestCreateModel> GeneratePaymentRequestAsync(Shared.Enums.EServiceType serviceType, int requestId)
        {
            // Взима данни на заявителя.
            ApplicantData applicantData = await GetApplicantDataAsync(serviceType, requestId);

            // Взеима данните за доставчик на ЕАУ, в случая Министерство на правосъдието.
            EServicesSettingsModel settings = await _eServiceSettingsService.GetEServiceSettingsAsync();

            PaymentRequestModel paymentRequest = CreatePaymentRequest(serviceType, settings, applicantData);

            paymentRequest = await SavePaymentRequestAsync(paymentRequest);

            EServicePaymentRequestCreateModel servicePaymentRequest = new EServicePaymentRequestCreateModel();

            servicePaymentRequest.EserviceTypeCode = serviceType.ToString();
            if (serviceType == Shared.Enums.EServiceType.SEIZEDPROPERTYCERTIFICATE)
            {
                servicePaymentRequest.SeizedPropertyCertificateRequestId = requestId;
            }
            else if (serviceType == Shared.Enums.EServiceType.SEIZEDPROPERTYBYOWNERREPORT)
            {
                servicePaymentRequest.SeizedPropertyReportRequestId = requestId;
            }
            servicePaymentRequest.PaymentRequestId = paymentRequest.AisPaymentId;
            servicePaymentRequest.StatusCode       = Shared.Enums.PaymentRequestStatus.NEW.ToString();

            EservicePaymentRequest entity = servicePaymentRequest.ToEntity();

            await _context.EservicePaymentRequest.AddAsync(entity);

            await _context.SaveChangesAsync();

            await AddEServicePaymentRequestStatusHistory(entity.Id, entity.StatusCode, entity.CreatedAt, null, null);

            servicePaymentRequest.Id = entity.Id;
            return(servicePaymentRequest);
        }
Esempio n. 7
0
        public async Task <IActionResult> SendPaymentRequest(int id)
        {
            try
            {
                EservicePaymentRequest request = await paymentService.GetServicePaymentRequestAsync(id);

                if (request == null)
                {
                    return(BadRequest("Request not found!"));
                }

                string result = await paymentJobService.SendPaymentRequest(request.PaymentRequest.ToModel());

                await paymentService.ProcessPaymentRequestSendResult(request, result);

                Log.Information($"IntegrationController/sendPaymentRequest - sent request with Id: {id} / {result}");
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"ERROR sending payment request");
                return(BadRequest("Error sending payment request"));
            }
        }
Esempio n. 8
0
        public async Task ChangePaymentRequestStatusAsync(PaymentRequestStatusChangeModel request)
        {
            int?paymentRequestId          = request?.Id;
            EservicePaymentRequest entity = await _context.EservicePaymentRequest
                                            .Include(x => x.PaymentRequest)
                                            .Include(x => x.SeizedPropertyCertificateRequest)
                                            .Include(x => x.SeizedPropertyReportRequest).ThenInclude(x => x.RequestorUser)
                                            .Include(x => x.SeizedPropertyReportRequest).ThenInclude(x => x.RequestorPerson)
                                            .Include(x => x.SeizedPropertyReportRequest).ThenInclude(x => x.RequesterCompany)
                                            .Where(x => x.AisPaymentId == paymentRequestId)
                                            .FirstOrDefaultAsync();

            if (entity == null)
            {
                throw new ArgumentNullException(nameof(EservicePaymentRequest), $"EservicePaymentRequest not found for status update! (id:{paymentRequestId})");
            }

            string newStatus = (request?.Status ?? "").Trim().ToUpper();

            DateTime serviceTimestamp = request.ChangeTime.HasValue ? DateTime.SpecifyKind(request.ChangeTime.Value, DateTimeKind.Utc) : DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc);
            DateTime timestamp        = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);

            entity.UpdatedAt  = timestamp;
            entity.StatusCode = newStatus;

            _context.EservicePaymentRequest.Update(entity);
            await _context.SaveChangesAsync();

            await AddEServicePaymentRequestStatusHistory(entity.Id, newStatus, timestamp, serviceTimestamp, null);

            //Изпрашане на email
            string email = entity.SeizedPropertyCertificateRequestId.HasValue
                ? entity.SeizedPropertyCertificateRequest.Email
                : (entity.SeizedPropertyReportRequestId.HasValue
                    ? (string.IsNullOrWhiteSpace(entity.SeizedPropertyReportRequest.RequestorUserId) == false
                        ? entity.SeizedPropertyReportRequest.RequestorUser.Email
                        : (entity.SeizedPropertyReportRequest.RequestorPersonId.HasValue
                            ? entity.SeizedPropertyReportRequest.RequestorPerson.Email
                            : (entity.SeizedPropertyReportRequest.RequesterCompanyId.HasValue
                                ? "" // Как ще се вземе email
                                : ""
                               ))
                       )
                    : ""
                   );

            if (!string.IsNullOrWhiteSpace(email))
            {
                string subject = $"Промяна на статуса на заявка с ИД №: {paymentRequestId} в системата за електронно плащане";
                string body    = $"Статусът на заявка с ИД №: {paymentRequestId} в системата за електронно плащане е променен на '{newStatus}'.{Environment.NewLine}" +
                                 $"За детайли посетете платформата за електронно плащане на адрес: {(_settings.UseTestEnv ? "https://pay-test.egov.bg/" : "https://pay.egov.bg/")} .";

                if (newStatus.Equals(Shared.Enums.PaymentRequestStatus.PAID.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    // Платено да се мисли как ще си получи услугата
                    if (!string.IsNullOrWhiteSpace(entity.PaymentRequest?.PaymentReferenceNumber))
                    {
                        body += $"{Environment.NewLine} Връзка за получване на услугата: {_settings.AdministrativeServiceSupplierUri}#/seizedPropertyAvailability/paidReport?id={entity.PaymentRequest.PaymentReferenceNumber}";
                    }
                }

                _emailService.SendEmail(email, null, null, subject, body);
            }
        }