public async Task <IActionResult> BuyTokensProcessing(PaymeSuccessCallback model, [FromQuery] int points, [FromServices] ICommandBus commandBus, [FromServices] TelemetryClient logger, CancellationToken token) { if (model.Status.Equals("success", StringComparison.OrdinalIgnoreCase)) { var command = new TransferMoneyToPointsCommand(model.UserId, points, model.TransactionId); await commandBus.DispatchAsync(command, token); } else { var values = Request.Form.ToDictionary(s => s.Key, x => x.Value.ToString()); values.Add("userId", model.UserId.ToString()); logger.TrackTrace("Credit Card Process Failed", values); } return(View("Processing", model)); }
public async Task <IActionResult> BuyTokensAsync(PayPalTransactionRequest model, [FromServices] IPayPalService payPal, CancellationToken token) { var userId = _userManager.GetLongUserId(User); var result = await payPal.GetPaymentAsync(model.Id, token); var amount = result.ReferenceId switch { "points_1" => 100, "points_2" => 500, "points_3" => 1000, _ => throw new ArgumentException(message: "invalid value") }; var command = new TransferMoneyToPointsCommand(userId, amount, model.Id); await _commandBus.DispatchAsync(command, token); return(Ok()); } #endregion }