Update routes/hello.py
Browse files- routes/hello.py +42 -5
routes/hello.py
CHANGED
@@ -1,7 +1,44 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import stripe
|
2 |
+
from fastapi import FastAPI, HTTPException
|
3 |
+
from routes.hello import router as hello_router
|
4 |
+
from pydantic import BaseModel
|
5 |
|
6 |
+
app = FastAPI()
|
7 |
|
8 |
+
# Incluindo a rota separada
|
9 |
+
app.include_router(hello_router)
|
10 |
+
|
11 |
+
stripe.api_key = "sk_test_51N6K5JB9VMe0qzbOjlJvMEsfdQyrFgV49vRaeErtmhrzHV3Cu3f5jMDJmrhKdI5uqvpHubjkmwDQgMOtCEmz19t800AouH7W6g"
|
12 |
+
stripe.api_version = "2023-10-16"
|
13 |
+
|
14 |
+
class AccountRequest(BaseModel):
|
15 |
+
email: str
|
16 |
+
|
17 |
+
@app.post("/create_account")
|
18 |
+
def create_account(account_data: AccountRequest):
|
19 |
+
try:
|
20 |
+
account = stripe.Account.create(
|
21 |
+
type="express",
|
22 |
+
email=account_data.email,
|
23 |
+
country="BR", # Ajuste para o país correto
|
24 |
+
capabilities={"transfers": {"requested": True}},
|
25 |
+
)
|
26 |
+
return {"account_id": account.id}
|
27 |
+
except Exception as e:
|
28 |
+
raise HTTPException(status_code=500, detail=str(e))
|
29 |
+
|
30 |
+
class AccountLinkRequest(BaseModel):
|
31 |
+
account_id: str
|
32 |
+
|
33 |
+
@app.post("/account_link")
|
34 |
+
def create_account_link(link_data: AccountLinkRequest):
|
35 |
+
try:
|
36 |
+
account_link = stripe.AccountLink.create(
|
37 |
+
account=link_data.account_id,
|
38 |
+
return_url=f"http://localhost:4242/success",
|
39 |
+
refresh_url=f"http://localhost:4242/retry",
|
40 |
+
type="account_onboarding",
|
41 |
+
)
|
42 |
+
return {"url": account_link.url}
|
43 |
+
except Exception as e:
|
44 |
+
raise HTTPException(status_code=500, detail=str(e))
|