Ejemplo n.º 1
0
        internal async Task <ResultDto> AuthorizePaymentAsync(BankPaymentDto bankPaymentDto)
        {
            //here i supposed that the PSP support Idempotency
            if (IdempotencyCheck(bankPaymentDto))
            {
                return(await Task.FromResult(Results[bankPaymentDto.Reference]));
            }

            ForwardedPayments.Add(bankPaymentDto.Reference, bankPaymentDto);
            ResultDto resultDto = bankPaymentDto.Amount == 4242
                ? new ResultDto("fail", "myPaymentReference")
                : new ResultDto("success", "myPaymentReference");

            Results.Add(bankPaymentDto.Reference ?? Guid.NewGuid().ToString(), resultDto);

            if (bankPaymentDto.Amount == 666)
            {
                throw new WebException("timeout trigger by special amount for testing", WebExceptionStatus.Timeout);
            }

            return(await Task.FromResult(resultDto));
        }
Ejemplo n.º 2
0
 private static bool IdempotencyCheck(BankPaymentDto bankPaymentDto)
 {
     return(bankPaymentDto.Reference != null && ForwardedPayments.ContainsKey(bankPaymentDto.Reference));
 }