Skip to content

Instantly share code, notes, and snippets.

@jakkaj
Created November 25, 2025 00:29
Show Gist options
  • Select an option

  • Save jakkaj/5f15910c87a3bb0569007265e6d6d4d8 to your computer and use it in GitHub Desktop.

Select an option

Save jakkaj/5f15910c87a3bb0569007265e6d6d4d8 to your computer and use it in GitHub Desktop.
[md-export] constitution-code-4
# Interface visible to application services
from abc import ABC, abstractmethod
from dataclasses import dataclass
class PaymentAdapter(ABC):
@abstractmethod
async def charge(self, request: "PaymentRequest") -> "PaymentResult":
pass
# Domain-facing request/result types
@dataclass
class PaymentRequest:
booking_id: BookingId
amount: "Money"
@classmethod
def for_booking(cls, booking: "Booking") -> "PaymentRequest":
return cls(
booking_id=booking.id,
amount=booking.total_price,
)
@dataclass
class PaymentResult:
transaction_id: str
success: bool
# Infrastructure implementation wrapping a vendor SDK
class StripePaymentAdapter(PaymentAdapter):
def __init__(self, stripe: "StripeClient"):
self._stripe = stripe # vendor SDK type
async def charge(self, request: PaymentRequest) -> PaymentResult:
session = await self._stripe.charge(
amount_cents=request.amount.cents,
metadata={"booking_id": request.booking_id.value},
)
return PaymentResult(
transaction_id=session.id,
success=session.status == "succeeded",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment