Last active
May 27, 2020 21:18
-
-
Save mariobittencourt/0d6137fc09fbdf6538dc9b0999acd4d6 to your computer and use it in GitHub Desktop.
Payment entity + create + record_that
This file contains 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
from __future__ import annotations | |
from typing import List | |
from src.domain.models.domain_event import DomainEvent | |
from src.domain.models.payment_created import PaymentCreated | |
class Payment: | |
def __init__(self, payment_id: str): | |
self._payment_id = payment_id | |
self._events = [] | |
@classmethod | |
def create(cls, payment_id: str, amount_due: float) -> Payment: | |
payment = cls(payment_id) | |
payment.record_that(PaymentCreated(payment_id, amount_due)) | |
return payment | |
def apply_payment_created(self, event: PaymentCreated): | |
self._status = 'PENDING_PROCESSING' | |
self._amount_due = event.amount_due | |
def clear_events(self): | |
self._events = [] | |
def record_that(self, event: DomainEvent): | |
if isinstance(event, PaymentCreated): | |
self.apply_payment_created(event) | |
self.events.append(event) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment