예제 #1
0
        public async Task PublishAsync(
            IPaymentStatusRepository paymentStatusRepository,
            EncryptedMessage message,
            CancellationToken cancellationToken = default)
        {
            // decrypt the message
            var decryptedMessage = message.GetMessage <PaymentRequestMessage>(_cipherService);

            // save the payment status
            var paymentStatus = new PaymentStatus
            {
                Status    = PaymentStatusEnum.Scheduled.ToString(),
                RequestId = decryptedMessage.RequestId,
                PaymentId = decryptedMessage.PaymentRequestId
            };

            try
            {
                await paymentStatusRepository.AddPaymentStatus(paymentStatus);
            }
            catch (Exception e)
            {
                _logger.LogWarning($"Probable duplicated Id: {e.Message}");
            }

            await _writer.WriteAsync(message, cancellationToken);

            _logger.LogInformation($"Producer > published message {message.Id} '{message.TopicName}'");
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the PaymentController class.
 /// </summary>
 /// <param name="orderBraspagRepository">The order braspag repository.</param>
 /// <param name="branchsRepository">The branch repository.</param>
 /// <param name="optionsSnapshot">The Settings</param>
 /// <param name="paymentStatusRepository">The payment status repository.</param>
 public PaymentController(IOrderBraspagRepository orderBraspagRepository, IBranchsRepository branchsRepository, IOptionsSnapshot <Settings> optionsSnapshot, IPaymentStatusRepository paymentStatusRepository)
 {
     this.orderBraspagRepository  = orderBraspagRepository;
     this.branchsRepository       = branchsRepository;
     this.paymentStatusRepository = paymentStatusRepository;
     this.settings = optionsSnapshot.Value;
 }
예제 #3
0
 public OrdersController(IOrderRepository orderRepository,
                         IOrderDetailRepository orderDetailRepository,
                         IPaymentStatusRepository paymentStatusRepository,
                         IProductRepository productRepository,
                         UserManager <ApplicationUser> userManager,
                         IMapper mapper)
 {
     _orderRepository       = orderRepository;
     _orderDetailRepository = orderDetailRepository;
     _productRepository     = productRepository;
     _userManager           = userManager;
     _mapper = mapper;
 }
예제 #4
0
 public UnitOfWork(CoreContext context, IUserRepository userRepository, IExceptionLogRepository exceptionLogRepository,
                   IElectricityBillRepository electricityBillRepository, IElectricityProviderRepository electricityProviderRepository,
                   IMobileRechargeBillRepository mobileRechargeBillRepository, IMobileRechargeTypeRepository mobileRechargeTypeRepository,
                   IPaymentModeRepository paymentModeRepository, IPaymentRepository paymentRepository, IPaymentStatusRepository paymentStatusRepository,
                   IServiceProviderRepository serviceProviderRepository)
 {
     _context                      = context;
     UserRepository                = userRepository;
     ExceptionLogRepository        = exceptionLogRepository;
     ElectricityBillRepository     = electricityBillRepository;
     ElectricityProviderRepository = electricityProviderRepository;
     MobileRechargeBillRepository  = mobileRechargeBillRepository;
     MobileRechargeTypeRepository  = mobileRechargeTypeRepository;
     PaymentModeRepository         = paymentModeRepository;
     PaymentRepository             = paymentRepository;
     PaymentStatusRepository       = paymentStatusRepository;
     ServiceProviderRepository     = serviceProviderRepository;
 }
예제 #5
0
 public UnitOfWork(IPaymentRepository payments, IPaymentStatusRepository paymentStatusRepository)
 {
     _payments        = payments;
     _paymentStatuses = paymentStatusRepository;
 }
예제 #6
0
 public PaymentStatusApp(IPaymentStatusRepository repository)
 {
     this.repository = repository;
 }
        public async Task BeginConsumeAsync(IPaymentStatusRepository paymentStatusRepository, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"ChannelConsumer > starting");

            try
            {
                await foreach (var message in _reader.ReadAllAsync(cancellationToken))
                {
                    try
                    {
                        _logger.LogInformation($"ChannelConsumer > Received message {message.Id} : {message.TopicName}");

                        // decrypt the message
                        var           decryptedMessage = message.GetMessage <PaymentRequestMessage>(_cipherService);
                        PaymentStatus paymentStatus    = null;
                        try
                        {
                            paymentStatus = await paymentStatusRepository.GetPaymentStatus(decryptedMessage.PaymentRequestId);
                        }
                        catch (Exception e)
                        {
                            _logger.LogError($"PaymentRepositoryException:{e.Message}");
                        }

                        if (paymentStatus == null)
                        {
                            _logger.LogError($"No payment status present with id :{decryptedMessage.PaymentRequestId}. Skipping!");
                            continue;
                        }

                        PaymentResult bankPaymentResponse = null;
                        var           request             = _mapper.Map <CardPayment>(decryptedMessage);

                        #region Use Polly to rety calling the bank payment service, 3 times

                        var policy = Policy.Handle <SocketException>()
                                     .Or <BankNotAvailableException>()
                                     .WaitAndRetry(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                                                   (ex, time) =>
                        {
                            _logger.LogWarning(ex,
                                               "Bank Payment Service now available after {TimeOut}s ({ExceptionMessage})",
                                               $"{time.TotalSeconds:n1}", ex.Message);
                        }
                                                   );
                        policy.Execute(() =>
                        {
                            // perform the call
                            try
                            {
                                bankPaymentResponse = _bankPaymentProxy.CreatePaymentAsync(request).Result;
                            }
                            catch (AggregateException e)
                            {
                                var flatExceptions = e.Flatten().InnerExceptions;

                                foreach (var agrEx in flatExceptions)
                                {
                                    _logger.LogError($"{agrEx.GetType().Name}:{e.Message}");
                                }
                            }
                        });

                        #endregion

                        // check the response from the bank payment service
                        if (bankPaymentResponse == null || !string.IsNullOrEmpty(bankPaymentResponse.ErrorCode))
                        {
                            paymentStatus.Status = PaymentStatusEnum.Error.ToString();
                            _logger.LogError($"Bank payment service error. RequestId:{decryptedMessage.RequestId}. Additional Code:{bankPaymentResponse?.ErrorCode} .Additional Message:{bankPaymentResponse?.Message}");
                        }
                        else
                        {
                            paymentStatus.Status        = bankPaymentResponse?.TransactionStatus == TransactionStatus.Declined.ToString() ? PaymentStatusEnum.Error.ToString() : PaymentStatusEnum.Completed.ToString();
                            paymentStatus.TransactionId = bankPaymentResponse.TransactionId;
                        }

                        await paymentStatusRepository.UpdatePaymentStatus(paymentStatus);
                    }
                    catch (Exception e)
                    {
                        _logger.LogCritical($"Unexpected exception:{e.Message}");
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                _logger.LogWarning($"ChannelConsumer > forced stop");
            }

            _logger.LogInformation($"ChannelConsumer > shutting down");
        }
 public RepositoryWrapper(
     FactoryManagementContext dbContext,
     IAddressRepository Address,
     ICustomerRepository Customer,
     IDepartmentRepository Department,
     IEquipmentRepository Equipment,
     IEquipmentCategoryRepository EquipmentCategory,
     IExpenseRepository Expense,
     IExpenseTypeRepository ExpenseType,
     IFactoryRepository Factory,
     IIncomeRepository Income,
     IIncomeTypeRepository IncomeType,
     IInvoiceRepository Invoice,
     IInvoiceTypeRepository InvoiceType,
     IItemRepository Item,
     IItemCategoryRepository ItemCategory,
     IItemStatusRepository ItemStatus,
     IPayableRepository Payable,
     IPaymentStatusRepository PaymentStatus,
     IPhoneRepository Phone,
     IProductionRepository Production,
     IPurchaseRepository Purchase,
     IPurchaseTypeRepository PurchaseType,
     IRecievableRepository Recievable,
     IRoleRepository Role,
     ISalesRepository Sales,
     IStaffRepository Staff,
     IStockRepository Stock,
     IStockInRepository StockIn,
     IStockOutRepository StockOut,
     ISupplierRepository Supplier,
     ITransactionRepository Transaction,
     ITransactionTypeRepository TransactionType,
     IUserAuthInfoRepository UserAuthInfo,
     IUserRoleRepository UserRole,
     IUtilService util,
     IApiResourceMappingRepository ApiResourceMappingRepository)
 {
     this.dbContext          = dbContext;
     this._Address           = Address;
     this._Customer          = Customer;
     this._Department        = Department;
     this._Equipment         = Equipment;
     this._EquipmentCategory = EquipmentCategory;
     this._Expense           = Expense;
     this._ExpenseType       = ExpenseType;
     this._Income            = Income;
     this._IncomeType        = IncomeType;
     this._Invoice           = Invoice;
     this._InvoiceType       = InvoiceType;
     this._Item            = Item;
     this._ItemCategory    = ItemCategory;
     this._ItemStatus      = ItemStatus;
     this._Payable         = Payable;
     this._PaymentStatus   = PaymentStatus;
     this._Phone           = Phone;
     this._Production      = Production;
     this._Purchase        = Purchase;
     this._PurchaseType    = PurchaseType;
     this._Recievable      = Recievable;
     this._Role            = Role;
     this._Sales           = Sales;
     this._Staff           = Staff;
     this._Stock           = Stock;
     this._StockIn         = StockIn;
     this._StockOut        = StockOut;
     this._Supplier        = Supplier;
     this._Transaction     = Transaction;
     this._TransactionType = TransactionType;
     this._UserAuthInfo    = UserAuthInfo;
     this._UserRole        = UserRole;
     this._util            = util;
     this._ApiResourceMappingRepository = ApiResourceMappingRepository;
 }
예제 #9
0
 public PaymentStatusesController(IPaymentStatusRepository paymentStatusRepository, IMapper mapper, ILogger <PaymentStatusesController> logger)
 {
     _paymentStatusRepository = paymentStatusRepository;
     _mapper = mapper;
     _logger = logger;
 }