Skip to content

Commit 3a57ba9

Browse files
committed
add create_stripe_account_link
move modify_stripe_account_capability into Flask_SaaS class
1 parent d7de94f commit 3a57ba9

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/flask_saas/blueprints/stripe_connect.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
) # noqa: E501
2020

2121

22-
def modify_stripe_account_capability(account_id):
23-
"""Request (again) card_payments capability after kyc onboarding
24-
is complete"""
25-
log.debug("Called modify_stripe_account_capability")
26-
stripe.Account.modify_capability(account_id, "card_payments", requested=True)
27-
28-
2922
def _generate_account_link(account_id):
3023
"""
3124
From the Stripe Docs:
@@ -50,7 +43,6 @@ def _generate_account_link(account_id):
5043
@stripe_connect.route("/stripe-set-livemode", methods=["POST"])
5144
def set_stripe_livemode():
5245
log.debug("Called set_stripe_livemode")
53-
breakpoint()
5446
flask_saas: Flask_SaaS = current_app.config["flask_saas"]
5547
livemode = request.data.decode("utf-8")
5648
if livemode == "0" or livemode == "1":
@@ -90,7 +82,7 @@ def index() -> str:
9082
# Attempt to Updates an existing Account Capability to accept card payments
9183
try:
9284
account = flask_saas.get_stripe_connect_account()
93-
modify_stripe_account_capability(account.id)
85+
flask_saas.modify_stripe_account_capability(account.id)
9486
except Exception as e:
9587
log.error(f"Could not update card_payments capability for account. {e}")
9688

@@ -113,7 +105,6 @@ def index() -> str:
113105
@stripe_connect.route("/stripe-onboard", methods=["POST"])
114106
def stripe_onboarding() -> jsonify:
115107
log.debug("called stripe_onboarding")
116-
117108
flask_saas: Flask_SaaS = current_app.config["flask_saas"]
118109
stripe.api_key = flask_saas.get_stripe_secret_key()
119110

src/flask_saas/flask_saas.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,30 @@ def create_stripe_connect_account(self) -> stripe.Account:
8888
)
8989

9090
return account
91+
92+
def create_stripe_account_link(
93+
self, account_id: stripe.Account, refresh_url: str, return_url: str
94+
) -> str:
95+
"""
96+
From the Stripe Docs: https://stripe.com/docs/api/account_links/create
97+
A user that is redirected to your return_url might not have completed the
98+
onboarding process. Use the /v1/accounts endpoint to retrieve the user’s
99+
account and check for charges_enabled. If the account is not fully onboarded,
100+
provide UI prompts to allow the user to continue onboarding later. The user
101+
can complete their account activation through a new account link (generated
102+
by your integration). You can check the state of the details_submitted
103+
parameter on their account to see if they’ve completed the onboarding process.
104+
"""
105+
account_link = stripe.AccountLink.create(
106+
type="account_onboarding",
107+
account=account_id,
108+
refresh_url=refresh_url,
109+
return_url=return_url,
110+
)
111+
return account_link.url
112+
113+
def modify_stripe_account_capability(self, account_id: str) -> None:
114+
"""Request (again) card_payments capability after kyc onboarding
115+
is complete"""
116+
log.debug("Called modify_stripe_account_capability")
117+
stripe.Account.modify_capability(account_id, "card_payments", requested=True)

0 commit comments

Comments
 (0)