public string CreateConnectedExpressAccount() { StripeConfiguration.ApiKey = "sk_test_xx"; //Stripe secret key var options = new AccountCreateOptions { Type = "express", }; var service = new AccountService(); var account = service.Create(options); var linkOptions = new AccountLinkCreateOptions { Account = account.Id, RefreshUrl = "https://example.com/reauth", ReturnUrl = "https://example.com/return", Type = "account_onboarding", }; var linkService = new AccountLinkService(); //user should redirect to this link and complete onboarding process var accountLink = linkService.Create(linkOptions); return(account.Id);//this is connectedStripeAccountId }
private string GenerateStripeLink(string accountId) { if (string.IsNullOrEmpty(accountId)) { return(string.Empty); } var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); string refreshUrl; string returnUrl; if (environment == "Production") { refreshUrl = Configuration.GetValue <string>("RefreshUrls:ForProduction"); returnUrl = Configuration.GetValue <string>("RefreshUrls:ForProduction"); } else { refreshUrl = Configuration.GetValue <string>("RefreshUrls:ForDevelopment"); returnUrl = Configuration.GetValue <string>("RefreshUrls:ForDevelopment"); } var options = new AccountLinkCreateOptions { Account = accountId, RefreshUrl = refreshUrl, ReturnUrl = returnUrl, Type = "account_onboarding", }; var service = new AccountLinkService(); var accountLink = service.Create(options); return(accountLink.Url); }
public IActionResult Create(CreateStripeAccountViewModel model) { if (model.userEmail == null) { return BadRequest("User email cannot be empty"); } try { StripeConfiguration.ApiKey = "sk_test_51HvkPWGZgacNuBfZVUQCM2e3KO5iuMqwmIKnqujztMX0UvbkCyFJWhccLBPjKXxck92QwyMiVun9s7AS6zie6uFs00XbjswQBt"; var options = new AccountCreateOptions { Type = "express", }; var service = new AccountService(); var account = service.Create(options); var optionsLink = new AccountLinkCreateOptions { Account = account.Id, RefreshUrl = "https://makeaquiz.azurewebsites.net/somethingWentWrong", ReturnUrl = "https://makeaquiz.azurewebsites.net/createFullQuiz", Type = "account_onboarding", }; var serviceAccount = new AccountLinkService(); var accountLink = serviceAccount.Create(optionsLink); if (accountLink != null) { var responseFromGet = _stripeService.GetByEmail(model.userEmail); if (responseFromGet.DTO != null) { var newDTO = responseFromGet.DTO; newDTO.StripeAccountId = account.Id; var response = _stripeService.Update(newDTO); if (response.DidError) { return BadRequest(); } return Ok(accountLink.Url.ToString()); } else { var response = _stripeService.Create(new StripeAccountDTO { StripeAccountId = account.Id, UserEmail = model.userEmail }); if (response.DidError) { return BadRequest(); } return Ok(accountLink.Url.ToString()); } } else { return BadRequest(); } } catch (Exception ex) { return BadRequest(ex.Message); } }
public string createAcountLink(string account) { StripeConfiguration.ApiKey = "sk_test_51H4bEIAVJDEhYcbP8AniC54IhmNxi8AOAkQpTgSCdwJjXwd8eoYEZmpBdZPOn7mpkBhQWkuzYYIFUv1y8Y3ncnKO008t1vsMSK"; var options = new AccountLinkCreateOptions { Account = account, RefreshUrl = "https://example.com/reauth", ReturnUrl = "https://localhost:44337/Billing/ListTutorBankAccounts", Type = "account_onboarding", }; var service = new AccountLinkService(); var accountLink = service.Create(options); UserAccount newAccount = new UserAccount() { StripeAccountID = account, UserID = currentUser.UserId }; Dc.UserAccounts.Add(newAccount); Dc.SaveChanges(); return(accountLink.Url); }
public IActionResult CreateStripeAccountLink(AccountLinkCreateOptions options) { if (options == null || string.IsNullOrWhiteSpace(options.Account) || string.IsNullOrWhiteSpace(options.RefreshUrl) || string.IsNullOrWhiteSpace(options.ReturnUrl)) { return(BadRequest(new { message = "You need to specify Account Id, Refresh Url and Return Url." })); } options.Type = "account_onboarding"; var service = new AccountLinkService(); var accountLink = service.Create(options); return(Ok(accountLink)); }