public TransactionDTO Map(PaymentServiceConstants.PaymentType transactionType, PaymentModel payment, dynamic response, DateTime time) { return(new TransactionDTO() { Amount = payment.Amount, Status = response.Status, ExternalId = response.Id, Instrument = response.PaymentMethodDetails.Type, OrderId = payment.OrderId, UserId = payment.UserId, VendorId = payment.VendorId, Metadata = JsonConvert.SerializeObject(payment), Response = response.ToJson(), TransactionTime = time, TransactionType = transactionType.ToString(), }); }
public IPaymentExecute GetPaymentOperation(PaymentServiceConstants.PaymentType type) { return(PAYMENT_OPERATIONS[type]); }
private async Task <TransactionDTO> CallPayment(Func <Task <TransactionDTO> > action, PaymentServiceConstants.PaymentType type, PaymentModel payment) { DateTime time = DateTime.UtcNow; try { return(await action()); } catch (Exception e) { return(_mappingProvider.GetMappingOperation(PaymentServiceConstants.PaymentMappingType.Failed).Map(type, payment, e.Message, time)); } }
public async Task <IEnumerable <TransactionModel> > Pay(PaymentServiceConstants.PaymentType type, PaymentModel payment) { var response = await _paymentProvider.GetPaymentOperation(type).Execute(payment); return(_mapper.Map <IEnumerable <TransactionDTO>, IEnumerable <TransactionModel> >(response)); }
public async Task <IEnumerable <TransactionDTO> > RetryIfThrown(Func <Task <TransactionDTO> > action, PaymentServiceConstants.PaymentType type, PaymentModel payment, PaymentServiceConstants.isSucceeded isSucceeded, int triesNumber = RetryConstants.NUMBER_OF_TRIES) { List <TransactionDTO> transactions = new List <TransactionDTO>(3); var timeDelay = RetryConstants.DELAY; var retryPolicy = Policy .HandleResult <IEnumerable <TransactionDTO> >(x => !x.LastOrDefault().Status.ToUpper().Equals(isSucceeded.ToString().ToUpper())) .WaitAndRetryAsync(triesNumber, i => { var time = TimeSpan.FromSeconds(timeDelay); timeDelay = timeDelay * RetryConstants.EXPONENT_TIME_PARAMETER; return(time); }); return(await retryPolicy.ExecuteAsync(async() => { var transaction = await CallPayment(() => action(), type, payment); transactions.Add(transaction); return transactions; })); }