public async Task <BaseApiResponse> PaymentRejected(ProcessorPaymentRequest request) { request.CheckNotNull(nameof(request)); var paymentDTO = WaitUntilAvailable(request.PaymentId); if (paymentDTO == null) { return(new BaseApiResponse { Code = 400, Message = "没有支付项目" }); } var command = new CancelPaymentCommand { AggregateRootId = request.PaymentId }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }
public async void Handle_ShouldCancelPayment() { var accountsRepo = new Mock <IAccountRepository>(); var account = new Account(Guid.NewGuid(), 100); account.AddPaymentRequest(new DateTime(2020, 3, 1), 40); accountsRepo.Setup(a => a.GetAsync(account.Id)).ReturnsAsync(account); var paymentRepo = new Mock <IPaymentRepository>(); var payment = account.PaymentRequests.First(); paymentRepo.Setup(p => p.GetAsync(payment.Id)).ReturnsAsync(payment); paymentRepo.Setup(p => p.UnitOfWork.SaveEntitiesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(true); var reason = "cancelled"; var command = new CancelPaymentCommand(account.Id, payment.Id, reason); var handler = new CancelPaymentHandler(accountsRepo.Object, paymentRepo.Object); await handler.Handle(command, new CancellationToken()); Assert.Equal(PaymentStatus.Closed, payment.Status); Assert.Equal(reason, payment.Reason); }
public void Handle_WhenProcessed_ShouldThrowException() { var sut = new CancelPaymentCommandHandler(_context, _mediator.Object, CurrentUser); var request = new CancelPaymentCommand { Id = Guid.Parse("154f10e0-85be-4da7-9499-b05dbcc40b92") }; Assert.ThrowsAsync <ValidationException>(() => sut.Handle(request, CancellationToken.None)); }
public async Task <ActionResult> CancelPaymentAsync([FromHeader(Name = "ACCOUNT_KEY")] Guid accountId, Guid id, [FromBody] CancelReasonDTO cancelReason) { var command = new CancelPaymentCommand(accountId, id, cancelReason.Reason); try { var response = await _mediator.Send(command); return(Ok()); } catch (KeyNotFoundException) { return(NotFound()); } }
public void Handle_WhenPending_ShouldClosePayment() { var sut = new CancelPaymentCommandHandler(_context, _mediator.Object, CurrentUser); var request = new CancelPaymentCommand { Id = Guid.Parse("b162e88d-a3a6-4341-87da-725658d743f3") }; var result = sut.Handle(request, CancellationToken.None).Result; Assert.AreEqual(Unit.Value, result); var record = _context.Payments.Single(i => i.Id == request.Id); Assert.AreEqual(PaymentStatus.Closed, record.Status); }
public async Task GivenCancelPaymentCommand_ReturnsSuccessCode() { var client = _factory.CreateClient(); var id = "b162e88d-a3a6-4341-87da-725658d743f3"; var command = new CancelPaymentCommand { Id = Guid.Parse(id), Reason = "Random Reason" }; var content = Helper.GetRequestContent(command); Console.Write(content); var response = await client.PostAsync($"/payment/cancel", content); response.EnsureSuccessStatusCode(); }
public Checkout_ViewModel() { allCheckoutVMs.Add(this); CheckOuts = new ObservableCollection <Checkout>(); foreach (Checkout b in PetrolStations.Checkouts) { CheckOuts.Add(b); } ChosenPump = null; PaymentCommand = new PaymentCommand(this); CreditCardCommand = new CreditCardCommand(this); CancelPaymentCommand = new CancelPaymentCommand(this); ChangeMoneyCommand = new ChangeMoneyCommand(this); RefreshCommand = new RefreshCommand(this); ReceiptCommand = new ReceiptCommand(this); }
public void Handle(ICommandContext context, CancelPaymentCommand command) { context.Get <Payment>(command.AggregateRootId).Cancel(); }
public async Task <IActionResult> CancelPaymentAsync([FromBody] CancelPaymentCommand payment) { await _mediator.Send(payment); return(Ok()); }
public async Task <IActionResult> Cancel([FromBody] CancelPaymentCommand command) => Ok(await Mediator.Send(command));