54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from infrasynth.billing.gateways.base import (
|
|
BasePaymentGateway,
|
|
CheckoutSessionResult,
|
|
WebhookResult,
|
|
)
|
|
|
|
|
|
class FakeGateway(BasePaymentGateway):
|
|
"""Deterministic in-memory gateway for tests and demos."""
|
|
|
|
gateway_slug = "fake"
|
|
|
|
def __init__(self, config: dict | None = None):
|
|
self.config = config or {}
|
|
self.create_should_fail = self.config.get("create_should_fail", False)
|
|
|
|
def create_checkout_session(self, plan, user, **kwargs) -> CheckoutSessionResult:
|
|
if self.create_should_fail:
|
|
raise ValueError("Fake gateway failure")
|
|
return CheckoutSessionResult(
|
|
session_id="cs_fake_123",
|
|
checkout_url="https://checkout.example.com/cs_fake_123",
|
|
client_secret="secret_123",
|
|
)
|
|
|
|
def handle_webhook(self, payload, headers) -> WebhookResult:
|
|
if payload.get("event") == "ignored":
|
|
return WebhookResult(event_type="ignored", is_handled=False, data={})
|
|
return WebhookResult(
|
|
event_type=payload.get("event", "checkout.session.completed"),
|
|
is_handled=True,
|
|
data={"id": payload.get("data", {}).get("id")},
|
|
)
|
|
|
|
def cancel_subscription(self, subscription) -> bool:
|
|
return True
|
|
|
|
def sync_subscription(self, subscription) -> dict:
|
|
return {
|
|
"status": "active",
|
|
"current_period_end": "2026-12-31T00:00:00Z",
|
|
"metadata": {"synced": True},
|
|
}
|
|
|
|
def get_invoice(self, invoice) -> dict:
|
|
return {
|
|
"external_id": "inv_fake_1",
|
|
"status": "paid",
|
|
"amount": 10.0,
|
|
"currency": "USD",
|
|
}
|
|
|
|
def health_check(self) -> bool:
|
|
return True
|