Created
November 25, 2025 00:29
-
-
Save jakkaj/5f15910c87a3bb0569007265e6d6d4d8 to your computer and use it in GitHub Desktop.
[md-export] constitution-code-4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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