Example #1
0
 internal static GetBankPaymentVerification ToBankVerificationQuery(this CreatePayment payment) =>
 new GetBankPaymentVerification
 (
     payment.TimeStamp,
     new Common.Money(payment.Value.Amount, payment.Value.Currency),
     new Common.Card
     (
         payment.CardDetails.Number,
         payment.CardDetails.CVV,
         new Common.ExpirationDate(payment.CardDetails.Expiration.Year, payment.CardDetails.Expiration.Year)
     ));
Example #2
0
        public async Task <Either <Seq <Failure>, int> > Handle(CreatePayment request, CancellationToken cancellationToken)
        {
            var paymentValidation = await ValidatePayment(request);

            return(await(await paymentValidation
                         .MatchAsync(
                             ValidateWithBank(request),
                             left => left
                             ))
                   .ToEitherAsync());
        }
Example #3
0
 internal static Payment ToPayment(this CreatePayment command) =>
 new Payment
 (
     command.UserId,
     new Card
     (
         command.UserId,
         command.CardDetails.Number,
         command.CardDetails.CVV,
         new ExpirationDate(command.CardDetails.Expiration.Year, command.CardDetails.Expiration.Month)
     ),
     new Money(command.Value.Amount, command.Value.Currency),
     command.TimeStamp
 );
Example #4
0
 private async Task <Validation <Failure, CreatePayment> > ValidatePayment(CreatePayment command) =>
 (await ValidateIfPaymentAlreadyExists(command), await ValidateIfCardExistWithDifferentUser(command))
Example #5
0
        private Func <CreatePayment, Task <Validation <Failure, Task <int> > > > ValidateWithBank(CreatePayment request) =>
        async right =>
        {
            var bankValidation = await GetBankValidation(request);

            var payment = request.ToPayment();
            return((await bankValidation.MatchAsync <Validation <Error, Payment> >(
                        async r =>
            {
                payment.UpdateStatus(PaymentStatus.Success);
                return payment;
            },
                        async l =>
            {
                await CreateAsync(payment);
                return l;
            })
                    .Apply(p => p))
                   .MapFail(Failure.Of(request))
                   .Map(CreateAsync));
        };