Spaces:
Running on T4
Running on T4
Download backend/app/modules/billing/controller.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/billing/controller.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/modules/billing/controller.py
-
curl -L -o controller.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/billing/controller.py
2.2 kB
| """G1 entitlement, G2 receipt validation, G3 store webhooks.""" | |
| from typing import Annotated | |
| from fastapi import APIRouter, Depends, Header | |
| from app.core.dependencies import CurrentAccount, Db | |
| from app.core.errors import NotFound | |
| from app.integrations.app_store import AppStoreClient, get_app_store | |
| from app.integrations.play_store import PlayStoreClient, PubSubVerifier, get_play_store, get_pubsub_verifier | |
| from app.modules.billing.entitlement import Entitlement | |
| from app.modules.billing.schemas import AppleWebhookIn, PubSubPushIn, ReceiptIn, ReceiptOut, WebhookAck | |
| from app.modules.billing.service import BillingService | |
| router = APIRouter(prefix="/v1", tags=["billing"]) | |
| def get_billing_service( | |
| db: Db, | |
| app_store: Annotated[AppStoreClient, Depends(get_app_store)], | |
| play_store: Annotated[PlayStoreClient, Depends(get_play_store)], | |
| pubsub: Annotated[PubSubVerifier, Depends(get_pubsub_verifier)], | |
| ) -> BillingService: | |
| return BillingService(db, app_store, play_store, pubsub) | |
| Billing = Annotated[BillingService, Depends(get_billing_service)] | |
| async def get_entitlement(account: CurrentAccount, service: Billing) -> Entitlement: | |
| return await service.entitlement(account.id) | |
| async def submit_receipt(body: ReceiptIn, account: CurrentAccount, service: Billing) -> ReceiptOut: | |
| return ReceiptOut(entitlement=await service.submit_receipt(account.id, body)) | |
| async def apple_webhook(body: AppleWebhookIn, service: Billing) -> WebhookAck: | |
| await service.apple_webhook(body.signed_payload) | |
| return WebhookAck() | |
| async def google_webhook(body: PubSubPushIn, service: Billing, | |
| authorization: Annotated[str | None, Header()] = None) -> WebhookAck: | |
| await service.google_webhook(authorization, body.message.data) | |
| return WebhookAck() | |
| async def unknown_webhook(provider: str) -> None: | |
| raise NotFound() | |