Ejemplo n.º 1
0
        public async Task <ActionResult <PaymentResponse> > Authorise(PaymentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var paymentId = Guid.NewGuid();

            using var _ = _logger.BeginScope(new Dictionary <string, object> { ["PaymentId"] = paymentId, ["MerchantId"] = DefaultMerchant.Id, ["MerchantName"] = DefaultMerchant.Name });

            _logger.LogInformation("Creating payment '{PaymentId}'", paymentId);

            var paymentResult = await AuthorisePayment(request, paymentId);

            var payment = new Payment(
                Id: paymentId,
                Amount: request.Amount,
                Description: request.Description,
                Card: new(request.Card.Pan.MaskedValue, request.Card.ExpiryMonth.Value),
                Timestamp: request.Timestamp,
                Result: paymentResult,
                CreatedAt: _clock.GetCurrentInstant());
            await _paymentStore.Create(payment, DefaultMerchant.Id);

            return(CreatedAtAction(nameof(Get), new { id = paymentId }, PaymentResponse.FromPayment(payment)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <PaymentResponse> > Get(Guid id)
        {
            using var _ = _logger.BeginScope(new Dictionary <string, object> { ["PaymentId"] = id, ["MerchantId"] = DefaultMerchant.Id, ["MerchantName"] = DefaultMerchant.Name });

            _logger.LogInformation("Retrieving payment '{PaymentId}'", id);
            return((await _paymentStore.Get(id, DefaultMerchant.Id)) switch
            {
                Payment p => base.Ok(PaymentResponse.FromPayment(p)),
                _ => base.NotFound()
            });
Ejemplo n.º 3
0
        public ActionResult <PaymentResponse> Get([FromRoute] string paymentId)
        {
            logger.LogInformation("GetPayment");

            try
            {
                var payment = paymentsProcessor.GetPayment(paymentId);

                if (payment == null)
                {
                    return(new NotFoundObjectResult(null));
                }
                else
                {
                    return(PaymentResponse.FromPayment(payment));
                }
            }
            catch (Exception exc)
            {
                logger.LogError(exc, $"Failed to retrieve Payment. PaymentId: {paymentId}");
                MetricsDataCollector.IncreaseErrors();
                return(GeneralError());
            }
        }