Ejemplo n.º 1
0
        public async Task ShouldThowBussinessExceptionWhenPaymentNotificationNotVerify()
        {
            PaymentNotificationServiceModel postedModel = new PaymentNotificationServiceModel();

            _billQueriesMock.Setup(x => x.FindBulkBillByInvoiceNumberWithTenderInfoAsync(It.IsAny <string>()))
            .Returns(() =>
            {
                return(Task.FromResult <BillInfo>(new BillDefaults().GetBillInfoDataForPaidBill()));
            });
            await Assert.ThrowsAsync <InvalidDataException>(async() => await _billAppService.SetBillPaid(postedModel));
        }
        public async Task <PaymentNotificationResponseModel> SetBillPaidPaymentNotification([FromBody] PaymentNotificationModel paymentNotificationModelList)
        {
            try
            {
                if (paymentNotificationModelList == null)
                {
                    throw new Exception("model is null");
                }
                PaymentNotificationServiceModel paymentNotification = new PaymentNotificationServiceModel(paymentNotificationModelList.AgencyCode, paymentNotificationModelList.IntermediatePaymentId, paymentNotificationModelList.BillCategory, paymentNotificationModelList.BillAccount, paymentNotificationModelList.PaymentAmount, paymentNotificationModelList.PaymentDate, paymentNotificationModelList.PaymentMethod, paymentNotificationModelList.PaymentStatusCode, paymentNotificationModelList?.PaymentReferenceInfo, paymentNotificationModelList.PaymentMethodDetail.SADADPaymentTransactionId, paymentNotificationModelList.PaymentMethodDetail.BankId, paymentNotificationModelList.PaymentMethodDetail.BankReversalTransactionID, paymentNotificationModelList.PaymentMethodDetail.BankPaymentId, paymentNotificationModelList.PaymentMethodDetail.PaymentChannel, paymentNotificationModelList?.PayorPOI?.POINumber, paymentNotificationModelList?.PayorPOI?.POIType);
                var updatedBillNumbersList = await _billsInqueryAppService.SetBillPaid(paymentNotification);

                return(new PaymentNotificationResponseModel()
                {
                    StatusCode = ServiceStatusCodes.Success, StatusDesc = "Success", UpdatedPaymentNotificationList = updatedBillNumbersList
                });
            }
            catch (EntityNotFoundException ex)
            {
                Logger.LogToFile(ex.Message.ToString(), "EntityNotFoundException");
                _logger.LogError(ex.ToString(), ex);
                return(new PaymentNotificationResponseModel()
                {
                    StatusCode = ServiceStatusCodes.NoDataFound, StatusDesc = ex.Message
                });
            }
            catch (NullReferenceException ex)
            {
                Logger.LogToFile(ex.Message.ToString(), "NullReferenceException");
                _logger.LogError(ex.ToString(), ex);
                return(new PaymentNotificationResponseModel()
                {
                    StatusCode = ServiceStatusCodes.NoDataFound, StatusDesc = ex.Message
                });
            }
            catch (InvalidDataException ex)
            {
                Logger.LogToFile(ex.Message.ToString(), "InvalidDataException");
                _logger.LogError(ex.ToString(), ex);
                return(new PaymentNotificationResponseModel()
                {
                    StatusCode = ServiceStatusCodes.WrongTypeCode, StatusDesc = ex.Message
                });
            }
            catch (Exception ex)
            {
                Logger.LogToFile(ex.Message.ToString(), "Exception");
                _logger.LogError(ex.ToString(), ex);
                return(new PaymentNotificationResponseModel()
                {
                    StatusCode = ServiceStatusCodes.UnrecoverableDatabaseError, StatusDesc = ex.Message
                });
            }
        }
Ejemplo n.º 3
0
 private void VerifyPaymentNotification(PaymentNotificationServiceModel paymentNotificationModel)
 {
     if (string.IsNullOrEmpty(paymentNotificationModel.BillAccount))
     {
         throw new InvalidDataException("Empty or incorrect BillAccount: " + paymentNotificationModel.BillAccount);
     }
     else if (string.IsNullOrEmpty(paymentNotificationModel.AgencyCode))
     {
         throw new InvalidDataException("Empty or incorrect AgencyCode: " + paymentNotificationModel.AgencyCode);
     }
     else if (string.IsNullOrEmpty(paymentNotificationModel.IntermediatePaymentId) ||
              paymentNotificationModel.PaymentMethodDetail == null ||
              string.IsNullOrEmpty(paymentNotificationModel.PaymentStatusCode) ||
              paymentNotificationModel.PaymentDate == DateTime.MinValue || !paymentNotificationModel.PaymentDate.HasValue ||
              string.IsNullOrEmpty(paymentNotificationModel.PaymentMethod) ||
              string.IsNullOrEmpty(paymentNotificationModel.BillAccount) ||
              paymentNotificationModel.PaymentAmount == 0 || !paymentNotificationModel.PaymentAmount.HasValue)
     {
         throw new NullReferenceException("missing some required data");
     }
 }
Ejemplo n.º 4
0
        public async Task <string> SetBillPaid(PaymentNotificationServiceModel postedModel)
        {
            VerifyPaymentNotification(postedModel);

            var bill = await _billQueries.FindBulkBillByInvoiceNumberWithTenderInfoAsync(postedModel.BillAccount);

            var billnumbersUpdated = bill.BillInvoiceNumber;
            var CurrentBillStatus  = bill.BillStatusId;

            try
            {
                Check.EntityNotNull(nameof(bill), bill, Resources.SharedResources.DisplayInputs.NotFound);
                if (bill.InvitationId != null)
                {
                    bill.Invitation.UpdateStatus((int)Enums.InvitationStatus.Approved, "");
                }
                bill.UpdatePaymentDetails(postedModel.IntermediatePaymentId, postedModel.PaymentMethodDetail?.SadadPaymentTranactionId, postedModel.PaymentMethodDetail.BankReversalTransactionID,
                                          postedModel.PaymentStatusCode, postedModel.BillAccount, postedModel.PaymentAmount,
                                          postedModel.PaymentDate,
                                          postedModel.PaymentMethodDetail.BankId, postedModel.PaymentMethodDetail.PaymentChannel, postedModel.PaymentMethod, postedModel?.PaymentReferenceInfo,
                                          postedModel.PaymentMethodDetail.BankPaymentID, postedModel.PayorPOIDetail.POINumber, postedModel.PayorPOIDetail.POIType);
                await _billCommands.UpdateBillAsync(bill);

                if (CurrentBillStatus != (int)Enums.BillStatus.Paid)
                {
                    if (bill.ConditionsBookletID != null)
                    {
                        var billobj = await _billQueries.FindBillByInvoiceNumberWithTender(postedModel.BillAccount);

                        var tender = billobj.ConditionsBooklet.Tender;

                        NotificationArguments NotificationArgument = new NotificationArguments
                        {
                            BodyEmailArgs = new object[] { bill.ConditionsBooklet.CommericalRegisterNo, tender.TenderName },
                            PanelArgs     = new object[] { tender.TenderName },
                            SMSArgs       = new object[] { tender.TenderName }
                        };
                        MainNotificationTemplateModel billStatusSuccessUploadedForSupplier = new MainNotificationTemplateModel(
                            NotificationArgument,
                            $"Tender/Details?STenderId={Util.Encrypt(tender.TenderId)}",
                            NotificationEntityType.Tender,
                            tender.TenderId.ToString(),
                            tender.BranchId);
                        await _notificationAppService.SendNotificationForSuppliers(NotificationOperations.Supplier.OperationsOnTheTender.sadadpaymentnotification, new List <string> {
                            bill.ConditionsBooklet.CommericalRegisterNo
                        }, billStatusSuccessUploadedForSupplier);
                    }
                    else
                    {
                        var tender = bill.Invitation.Tender;
                        NotificationArguments NotificationArgument = new NotificationArguments
                        {
                            BodyEmailArgs = new object[] { bill.Invitation.CommericalRegisterNo, tender.TenderName },
                            PanelArgs     = new object[] { tender.TenderName },
                            SMSArgs       = new object[] { tender.TenderName }
                        };
                        MainNotificationTemplateModel billStatusSuccessUploadedForSupplier = new MainNotificationTemplateModel(
                            NotificationArgument,
                            $"Tender/Details?STenderId={Util.Encrypt(tender.TenderId)}",
                            NotificationEntityType.Tender,
                            tender.TenderId.ToString(),
                            tender.BranchId
                            );
                        await _notificationAppService.SendNotificationForSuppliers(NotificationOperations.Supplier.OperationsOnTheTender.sadadpaymentnotification, new List <string> {
                            bill.Invitation.CommericalRegisterNo
                        }, billStatusSuccessUploadedForSupplier);
                    }
                }


                return(billnumbersUpdated);
            }
            catch (Exception ex)
            {
                _logger.LogError("ex", ex.Message.ToString());
                throw;
            }
        }