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
        }
        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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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));
        }
        public async Task <AccountLink> CreateAccountLinkAsync(string accountId, string refreshUrl, string returnUrl, AccountLinkTypes type)
        {
            var options = new AccountLinkCreateOptions
            {
                Account    = accountId,
                RefreshUrl = refreshUrl,
                ReturnUrl  = returnUrl,
                Type       = type == AccountLinkTypes.Onboarding ? "account_onboarding" : "account_update"
            };

            var service = new AccountLinkService();

            return(await service.CreateAsync(options));;
        }
        public AccountLinkServiceTest(MockHttpClientFixture mockHttpClientFixture)
            : base(mockHttpClientFixture)
        {
            this.service = new AccountLinkService();

            this.createOptions = new AccountLinkCreateOptions()
            {
                AccountId  = "acct_123",
                Collect    = "eventually_due",
                FailureUrl = "https://stripe.com/failure",
                SuccessUrl = "https://stripe.com/success",
                Type       = "custom_account_verification",
            };
        }
        public AccountLinkServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new AccountLinkService(this.StripeClient);

            this.createOptions = new AccountLinkCreateOptions
            {
                Account    = "acct_123",
                Collect    = "eventually_due",
                RefreshUrl = "https://stripe.com/refresh",
                ReturnUrl  = "https://stripe.com/return",
                Type       = "custom_account_verification",
            };
        }