|
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" |
|
|
|
|
|
class AccountRequest(BaseModel): |
|
email: str |
|
name: str |
|
|
|
class CreateCustomerRequest(BaseModel): |
|
email: str |
|
phone: str |
|
name: str |
|
|
|
@router.post("/create_customer") |
|
def create_customer(data: CreateCustomerRequest): |
|
try: |
|
|
|
customer = stripe.Customer.create( |
|
email=data.email, |
|
phone=data.phone, |
|
name=data.name |
|
) |
|
|
|
|
|
return {"customer_id": customer.id} |
|
|
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=f"Error creating customer: {str(e)}") |
|
|
|
@router.post("/create_account") |
|
def create_account(account_data: AccountRequest): |
|
try: |
|
account = stripe.Account.create( |
|
type="express", |
|
email=account_data.email, |
|
country="BR", |
|
business_type="individual", |
|
business_profile={ |
|
"mcc": "7298", |
|
"name": account_data.name, |
|
"product_description": "We connect stylists with clients through subscription services.", |
|
"support_email": "[email protected]" |
|
}, |
|
default_currency="brl", |
|
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)) |
|
|
|
|
|
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", |
|
refresh_url="https://ameddes.com/onboarding?success=false", |
|
type="account_onboarding", |
|
) |
|
return {"url": account_link.url} |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |