Esempio n. 1
0
        public void Create_ShouldReturnError_WhenCvvHasAnExpectedLength(string code)
        {
            var cvv = Cvv.Create(code);

            cvv.IsSuccess.Should().BeFalse();
            cvv.Error.Should().Be(Errors.InvalidCvv);
        }
Esempio n. 2
0
        public void Create_ShouldReturnCvv(string code)
        {
            var cvv = Cvv.Create(code);

            cvv.IsSuccess.Should().BeTrue();

            var value = cvv.GetValue();

            value.Code.Should().Be(code);
        }
Esempio n. 3
0
            public override async Task <Result <Guid> > Handle(Command command, CancellationToken token = default)
            {
                // This cannot fail since we validated the entire command before
                var price      = Price.Create(command.Currency, command.Amount).GetValue();
                var number     = CardNumber.Create(command.Card.Number).GetValue();
                var expiryDate = ExpiryDate.Create(command.Card.ExpiryMonth, command.Card.ExpiryYear).GetValue();
                var cvv        = Cvv.Create(command.Card.Cvv).GetValue();

                var card = Card.Create(number, expiryDate, cvv, command.Card.HolderName);

                // Starts the async job
                return(Ok(
                           await _bus.StartAsync(
                               new MakePayment(command.MerchantId, card.GetValue(), price, command.Description ?? string.Empty), token)));
            }
Esempio n. 4
0
            public Validator()
            {
                RuleFor(x => Price.Create(x.Currency, x.Amount))
                .Must(x => x.IsSuccess)
                .WithState((x, res) => res.Error);

                RuleFor(x => CardNumber.Create(x.Card.Number))
                .Must(x => x.IsSuccess)
                .WithState((x, res) => res.Error);

                RuleFor(x => ExpiryDate.Create(x.Card.ExpiryMonth, x.Card.ExpiryYear))
                .Must(x => x.IsSuccess)
                .WithState((x, res) => res.Error);

                RuleFor(x => Cvv.Create(x.Card.Cvv))
                .Must(x => x.IsSuccess)
                .WithState((x, res) => res.Error);
            }
Esempio n. 5
0
        public override async Task <string> Execute(ConsumeContext <MakePayment> context)
        {
            var command = context.Message;

            var response = await _processor.ProcessAsync(
                command.Currency,
                command.Amount,
                command.CardNumber,
                command.ExpiryMonth,
                command.ExpiryYear,
                command.Cvv,
                command.CardHolderName);

            // We assume command sent through the bus are ALWAYS valid. In other words, the code below should never fail.
            var payment = Payment.Create(
                response.PaymentId,
                command.MerchantId,
                Card.Create(
                    CardNumber.Create(command.CardNumber).GetValue(),
                    ExpiryDate.Create(command.ExpiryMonth, command.ExpiryYear).GetValue(),
                    Cvv.Create(command.Cvv).GetValue(),
                    command.CardHolderName).GetValue(),
                Price.Create(command.Currency, command.Amount).GetValue(),
                command.Description);

            // This is simplistic :)
            if (response.Status == PaymentStatus.Approved)
            {
                payment.Approve();
            }
            else
            {
                payment.Decline("Payment was declined");
            }

            // Persist the payment
            await _repository.AddAsync(payment);

            // We return the Id of the created entity!
            return(response.PaymentId);
        }
Esempio n. 6
0
        public void Create_ShouldThrowArgumentNullException_WhenCvvIsNull()
        {
            Action action = () => Cvv.Create(null);

            action.Should().Throw <ArgumentNullException>().WithMessage("*code*");
        }