Esempio n. 1
0
        public async Task <IActionResult> GetPayment(string paymentId, [FromQuery] string fields)
        {
            var merchantIdentity = await _merchantQuery.GetMerchantIdAsync(GetAuthorizationKey());

            var payment = await _paymentQuery.GetPaymentInfoAsync(paymentId, merchantIdentity);

            if (payment.IsSuccess)
            {
                return(Ok(payment.Value.ShapeData(fields)));
            }

            if (!payment.IsSuccess && payment.Error.Equals(ExternalErrorReason.PaymentNotFound))
            {
                return(NotFound());
            }

            return(UnprocessableEntity(payment.Error));
        }
Esempio n. 2
0
        public async Task<IActionResult> TokenizeCard([FromBody] TokenizeCardRequest request)
        {
            var merchantIdentity = await _merchantQuery.GetMerchantIdAsync(GetAuthorizationKey());
            if (merchantIdentity.Equals(Guid.Empty))
                return new UnauthorizedObjectResult(ExternalErrorReason.InvalidSecretKey);

            var innerCommand = new AddNewCardCommand(request.Name, request.Number, request.ExpiryMonth, request.ExpiryYear, request.Cvv, null, HttpContext.TraceIdentifier);
            var command = new IdentifiedCommand<AddNewCardCommand, Result>(innerCommand);
            var result = await _mediator.Send(command);

            if (result.IsSuccess)
            {
                var card = await _cardQuery.GetCardByCardNumberAsync(request.Number);
                return Ok(card);
            }
            return UnprocessableEntity(result.Error);
        }