Esempio n. 1
0
        public async Task <IActionResult> Verify(Guid id)
        {
            try
            {
                var application = await GetApplicationAsync();

                if (application == null || application.Status != 0)
                {
                    return(Unauthorized());
                }

                var transaction = await _transactionRepository.Get(id);

                if (transaction == null)
                {
                    return(Unauthorized());
                }

                switch (transaction.Bank.Code)
                {
                case (byte)BankCodeEnum.Mellat:
                    var mellatHelper = new MellatHelper(_logger, _transactionRepository, _applicationBankRepository);
                    var mellatResult = await mellatHelper.VerifyTransaction(transaction);

                    return(Ok(mellatResult));

                case (byte)BankCodeEnum.Efarda:
                    var efardaHelper = new EfardaHelper(_logger, _transactionRepository, _applicationBankRepository);
                    var efardaResult = await efardaHelper.VerifyTransaction(transaction);

                    return(Ok(efardaResult));

                case (byte)BankCodeEnum.Saman:
                default:
                    var samanHelper = new SamanHelper(_logger, _transactionRepository, _applicationBankRepository);
                    var result      = await samanHelper.VerifyTransaction(transaction);

                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                if (ex.InnerException != null)
                {
                    _logger.LogError(ex.InnerException.Message);
                }
                throw;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Verify(string publicKey, Guid id)
        {
            try
            {
                Application application = await _applicationRepository.GetFirstBy(x => x.PublicKey == publicKey);

                if (application == null || application.Status != 0)
                {
                    return(Unauthorized());
                }

                var transaction = await _transactionRepository.Get(id);

                if (transaction == null)
                {
                    return(Unauthorized());
                }

                switch (transaction.Bank.Code)
                {
                case ((byte)BankCodeEnum.Mellat):
                    MellatHelper mellatHelper = new MellatHelper(_logger, _transactionRepository, _applicationRepository, _bankRepository, _applicationBankRepository);
                    VerifyTransactionResponseModel mellatResult = await mellatHelper.VerifyTransaction(transaction);

                    return(Ok(mellatResult));

                case ((byte)BankCodeEnum.Saman):
                default:
                    SamanHelper samanHelper = new SamanHelper(_logger, _transactionRepository, _applicationRepository, _bankRepository, _applicationBankRepository);
                    VerifyTransactionResponseModel result = await samanHelper.VerifyTransaction(transaction);

                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                if (ex.InnerException != null)
                {
                    _logger.LogError(ex.InnerException.Message);
                }
                throw;
            }
        }