public async Task <IActionResult> CreateDeposit([FromBody] DepositCreationDto deposits) { if (deposits == null) { return(BadRequest()); } var depositEntity = _mapper.Map <Deposit>(deposits); depositEntity.Date = DateTime.Now; if (!ModelState.IsValid) { return(new ModelValidator.UnprocessableEntityObjectResult(ModelState)); } await _depositserv.AddDeposit(depositEntity); var x = _depositserv.ConvertCurrency(depositEntity); await _accountService.AddDepositToBalance(deposits.UserId, x.Result); var DepositMapToReturn = _mapper.Map <DepositViewDto>(depositEntity); return(Ok(DepositMapToReturn)); }
public async Task <IActionResult> StartDeposit([FromBody] DepositCreationDto depositCreationDto) { if (!ModelState.IsValid) { return(BadRequest(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) })); } try { StripeConfiguration.ApiKey = ServiceKey; var transferGroup = Guid.NewGuid().ToString(); var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = depositCreationDto.Amount, Currency = "usd", PaymentMethodTypes = new List <string> { "card" }, Metadata = new Dictionary <string, string>() { { "UserId", User.FindFirstValue(ClaimTypes.Name) } }, TransferData = new PaymentIntentTransferDataOptions { Destination = (await _accountsRepository.GetByUserId(User.FindFirstValue(ClaimTypes.Name))).StripeUserId } }; var intent = service.Create(options); ; return(Ok(new PaymentIntentCreatedDto { ClientSecret = intent.ClientSecret })); } catch (Exception e) { return(BadRequest(new MessageObj(e.Message))); } }