create an invoice this will let s imagine let the api user some external developer create an invoice and this path operation will send the invoice to the client collect the money from the client send a notification back to the api user the external developer as a callback at this point is that the api will somehow send a post request to the external api with the notification of the invoice event e g payment successful send the invoice collect the money send the notification the callback create an invoice this will let s imagine let the api user some external developer create an invoice and this path operation will send the invoice to the client collect the money from the client send a notification back to the api user the external developer as a callback at this point is that the api will somehow send a post request to the external api with the notification of the invoice event e g payment successful send the invoice collect the money send the notification the callback
from typing import Union

from fastapi import APIRouter, FastAPI
from pydantic import BaseModel, HttpUrl

app = FastAPI()


class Invoice(BaseModel):
    id: str
    title: Union[str, None] = None
    customer: str
    total: float


class InvoiceEvent(BaseModel):
    description: str
    paid: bool


class InvoiceEventReceived(BaseModel):
    ok: bool


invoices_callback_router = APIRouter()


@invoices_callback_router.post(
    "{$callback_url}/invoices/{$request.body.id}", response_model=InvoiceEventReceived
)
def invoice_notification(body: InvoiceEvent):
    pass


@app.post("/invoices/", callbacks=invoices_callback_router.routes)
def create_invoice(invoice: Invoice, callback_url: Union[HttpUrl, None] = None):
    
    
    return {"msg": "Invoice received"}