public async Task <IActionResult> Get(Guid id) { if (id == Guid.Empty) { return(BadRequest()); } GetPayment result; using (var operation = _telemetrySubmitter.BeginTimedOperation(new ServiceOperation(nameof(PaymentsController), nameof(Get)))) { try { result = await _paymentManager.GetByIdAsync(id); } catch (Exception ex) { _logger.LogError(ex, "Failed to Get payment Id: {0} due to {1}", id, ex.Message); operation.SetFaulted(ex); throw; } } if (result == null) { return(NotFound()); } return(Ok(result)); }
/// <summary> /// Processes the pending payment /// Without knowing the internals of the bank, we can assume a response containing the success along with a unique identifier /// This has been abstracted into the IBankServiceClient /// </summary> /// <param name="submitPaymentCommand">The payment command.</param> /// <returns></returns> public async Task ProcessPaymentAsync(SubmitPaymentCommand submitPaymentCommand) { _logger.LogInformation("Processing payment Id: {0}", submitPaymentCommand.PaymentId); using (var operation = _telemetrySubmitter.BeginTimedOperation(new ServiceOperation(nameof(CreatePaymentProcessor), nameof(ProcessPaymentAsync)))) { try { var payment = await _paymentRepository.GetByIdAsync(submitPaymentCommand.PaymentId); var result = await _bankServiceClient.CreateOrderAsync(submitPaymentCommand); payment.PaymentStatus = result.IsSuccessful ? PaymentStatus.Success : PaymentStatus.Failed; _logger.LogInformation("Setting payment Id: {0} as {1}", submitPaymentCommand.PaymentId, payment.PaymentStatus); payment.BankTransactionId = result.Id; await _paymentRepository.UpdateAsync(payment); } catch (Exception ex) { _logger.LogError(ex, "Failed to CreatePayment due to {0}", ex.Message); operation.SetFaulted(ex); } } }