Beispiel #1
0
        public async Task UpdateTransactionStatus(string id, TransactionRequestStatus transactionRequestStatus)
        {
            logger.LogInformation($"UpdateTransactionStatus : Setting status {transactionRequestStatus} for : {id}");

            try
            {
                var transaction = await applicationDbContext.TransactionRequests.SingleOrDefaultAsync(x => x.Id == id);

                transaction.Status = transactionRequestStatus;

                await applicationDbContext.SaveChangesAsync();
                await UpdatePaymentAndExchangeStatuses(transactionRequestStatus, id);
            }
            catch (Exception e)
            {
                logger.LogWarning(e, $"Error UpdateTransactionStatus.");
            }
        }
Beispiel #2
0
        private async Task UpdatePaymentAndExchangeStatuses(TransactionRequestStatus transactionRequestStatus, params string[] ids)
        {
            logger.LogInformation($"UpdatePaymentAndExchangeStatuses : Setting status {transactionRequestStatus} for : {string.Join(",", ids)}");

            GraftTransactionStatus newStatus;

            switch (transactionRequestStatus)
            {
            case TransactionRequestStatus.Failed:
                newStatus = GraftTransactionStatus.Failed;
                break;

            case TransactionRequestStatus.New:
                newStatus = GraftTransactionStatus.New;
                break;

            case TransactionRequestStatus.InProgress:
            case TransactionRequestStatus.Sent:
                newStatus = GraftTransactionStatus.Pending;
                break;

            case TransactionRequestStatus.Out:
                newStatus = GraftTransactionStatus.Out;
                break;

            default:
                newStatus = GraftTransactionStatus.NotFound;
                break;
            }

            try
            {
                var exchanges = from exchange in applicationDbContext.Exchange
                                where ids.Contains(exchange.BuyerTransactionId)
                                select exchange;

                exchanges.ToList().ForEach(x => x.BuyerTransactionStatus = newStatus);

                await applicationDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogWarning(e, $"Error UpdatePaymentAndExchangeStatuses : Set Exchanges.");
            }

            try
            {
                var payments = from exchange in applicationDbContext.Payment
                               where ids.Contains(exchange.MerchantTransactionId)
                               select exchange;

                payments.ToList().ForEach(x => x.MerchantTransactionStatus = newStatus);

                await applicationDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogWarning(e, $"Error UpdatePaymentAndExchangeStatuses : Set Payments : Merchant transaction.");
            }

            try
            {
                var payments = from exchange in applicationDbContext.Payment
                               where ids.Contains(exchange.ProviderTransactionId)
                               select exchange;

                payments.ToList().ForEach(x => x.ProviderTransactionStatus = newStatus);

                await applicationDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogWarning(e, $"Error UpdatePaymentAndExchangeStatuses : Set Payments : Provider transaction.");
            }
        }
Beispiel #3
0
 private Task UpdatePaymentAndExchangeStatuses(TransactionRequestStatus transactionRequestStatus, IEnumerable <string> ids)
 {
     return(UpdatePaymentAndExchangeStatuses(transactionRequestStatus, ids.ToArray()));
 }