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) ));
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()); }
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 );
private async Task <Validation <Failure, CreatePayment> > ValidatePayment(CreatePayment command) => (await ValidateIfPaymentAlreadyExists(command), await ValidateIfCardExistWithDifferentUser(command))
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)); };