connect / routes /hello.py
habulaj's picture
Update routes/hello.py
15a58fb verified
raw
history blame
2.59 kB
import stripe
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
router = APIRouter()
stripe.api_key = "sk_test_51N6K5JB9VMe0qzbOjlJvMEsfdQyrFgV49vRaeErtmhrzHV3Cu3f5jMDJmrhKdI5uqvpHubjkmwDQgMOtCEmz19t800AouH7W6g"
stripe.api_version = "2023-10-16"
### **1️⃣ CREATE CONNECTED ACCOUNT** ###
class AccountRequest(BaseModel):
email: str
name: str # Name of the individual account owner
@router.post("/create_account")
def create_account(account_data: AccountRequest):
try:
account = stripe.Account.create(
type="express", # Express account type for individual accounts
email=account_data.email,
country="BR", # Brazil
business_type="individual", # Ensuring the account is individual, not business
business_profile={
"mcc": "7298",
"name": account_data.name, # Using the name from the request body
"product_description": "We connect stylists with clients through subscription services.",
"support_email": "[email protected]"
},
default_currency="brl", # Set currency to BRL (Brazilian Real)
capabilities={
"transfers": {"requested": True},
"card_payments": {"requested": True}
}
)
return {"account_id": account.id}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/check_onboarding/{account_id}")
def check_onboarding(account_id: str):
try:
account = stripe.Account.retrieve(account_id)
if account.requirements.currently_due:
return {"status": "incomplete", "pending_requirements": account.requirements.currently_due}
return {"status": "complete"}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
### **2️⃣ CREATE ACCOUNT LINK FOR ONBOARDING** ###
class AccountLinkRequest(BaseModel):
account_id: str
@router.post("/account_link")
def create_account_link(link_data: AccountLinkRequest):
try:
account_link = stripe.AccountLink.create(
account=link_data.account_id,
return_url="https://ameddes.com/onboarding?success=true", # Updated return URL
refresh_url="https://ameddes.com/onboarding?success=false", # Updated refresh URL
type="account_onboarding",
)
return {"url": account_link.url}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))