public async Task <PaymentResponse> GetPaymentResponse(Guid bankResponseId)
        {
            var payment = await _paymentsRepository.GetItem(x => x.BankResponseId == bankResponseId);

            if (payment == null)
            {
                return(null);
            }

            return(await GetExistingPaymentResponse(payment.Id));
        }
示例#2
0
        public async Task ReturnPaymentResultOfFirstRequestToDuplicateRequest()
        {
            //Arrange
            var newPaymentDetails = new PaymentRequest
            {
                Amount        = 10,
                Currency      = "GBP",
                PaymentMethod = new PaymentMethod()
                {
                    CardExpiry = "12/22",
                    CardNumber = "1000200030004000",
                    Cvv        = "000"
                }
            };

            var idempotencyKey = Guid.NewGuid();

            await _paymentController.Post(idempotencyKey, newPaymentDetails);

            var payment = await _idempotencyRespository.GetItem(x => x.Id == idempotencyKey);

            var existingPaymentDetails = await _dbRepository.GetItem(x => x.Id == payment.PaymentId);

            var paymentResponse = new PaymentResponse()
            {
                BankResponseId = existingPaymentDetails.BankResponseId,
                Status         = existingPaymentDetails.Status
            };

            //Act
            var response = await _paymentController.Post(idempotencyKey, newPaymentDetails);

            var result             = response as OkObjectResult;
            var resultingPaymentId = (PaymentResponse)result?.Value;

            //Assert
            result.Should().NotBeNull();
            result.Value.IsSameOrEqualTo(paymentResponse);
            resultingPaymentId.BankResponseId.Should().Be(existingPaymentDetails.BankResponseId);
        }
        public async Task <PaymentResponse> SubmitPaymentRequest(Guid idempotencyKey, PaymentRequest paymentRequest)
        {
            var idemKey = await _idempotencyRepository.GetItem(x => x.Id == idempotencyKey);

            if (idemKey != null)
            {
                return(await GetExistingPaymentResponse(idemKey.PaymentId));
            }

            var paymentId = Guid.NewGuid();
            await _idempotencyRepository.AddNewItem(new IdempotencyKey()
            {
                Id        = idempotencyKey,
                PaymentId = paymentId
            });

            //Better done with a Mapper
            var payment = new PaymentDetails()
            {
                Amount        = paymentRequest.Amount,
                Currency      = paymentRequest.Currency,
                Id            = paymentId,
                PaymentMethod = paymentRequest.PaymentMethod
            };

            //Want to add encryption
            await _paymentsRepository.AddNewItem(payment);

            var response = await _bankService.InitiatePayment(paymentRequest);

            payment.Status         = response.Status;
            payment.BankResponseId = response.BankResponseId;
            await _paymentsRepository.UpdateItem(payment);

            return(await GetExistingPaymentResponse(payment.Id));
        }