diff --git a/unit/models/__init__.py b/unit/models/__init__.py index 19c3d2c..88e69d0 100644 --- a/unit/models/__init__.py +++ b/unit/models/__init__.py @@ -444,7 +444,10 @@ def __init__( self.id = _id @staticmethod - def from_json_api(data: Dict): + def from_json_api(data: Dict = None): + if data is None: + return None + return Merchant( data["name"], data["type"], data.get("category"), data.get("location"), data.get("id") ) diff --git a/unit/models/transaction.py b/unit/models/transaction.py index 8d66e04..4f5ed86 100644 --- a/unit/models/transaction.py +++ b/unit/models/transaction.py @@ -131,7 +131,7 @@ def from_json_api(_id, _type, attributes, relationships): class PurchaseTransactionDTO(BaseTransactionDTO): def __init__(self, id: str, created_at: datetime, direction: str, amount: int, balance: int, - summary: str, card_last_4_digits: str, merchant: Merchant, coordinates: Optional[Coordinates], + summary: str, card_last_4_digits: str, merchant: Optional[Merchant], coordinates: Optional[Coordinates], recurring: bool, ecommerce: bool, card_present: bool, card_verification_data, interchange: Optional[int] = None, payment_method: Optional[str] = None, digital_wallet: Optional[str] = None, card_network: Optional[str] = None, @@ -142,7 +142,8 @@ def __init__(self, id: str, created_at: datetime, direction: str, amount: int, b BaseTransactionDTO.__init__(self, id, created_at, direction, amount, balance, summary, tags, relationships) self.type = 'purchaseTransaction' self.attributes["cardLast4Digits"] = card_last_4_digits - self.attributes["merchant"] = merchant + if merchant: + self.attributes["merchant"] = merchant self.attributes["coordinates"] = coordinates self.attributes["recurring"] = recurring self.attributes["interchange"] = interchange @@ -219,14 +220,15 @@ def from_json_api(_id, _type, attributes, relationships): class CardTransactionDTO(BaseTransactionDTO): def __init__(self, id: str, created_at: datetime, direction: str, amount: int, balance: int, - summary: str, card_last_4_digits: str, merchant: Merchant, recurring: Optional[bool], + summary: str, card_last_4_digits: str, merchant: Optional[Merchant], recurring: Optional[bool], interchange: Optional[int], payment_method: Optional[str], digital_wallet: Optional[str], card_verification_data: Optional[Dict], card_network: Optional[str], tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]): BaseTransactionDTO.__init__(self, id, created_at, direction, amount, balance, summary, tags, relationships) self.type = 'cardTransaction' self.attributes["cardLast4Digits"] = card_last_4_digits - self.attributes["merchant"] = merchant + if merchant: + self.attributes["merchant"] = merchant self.attributes["recurring"] = recurring self.attributes["interchange"] = interchange self.attributes["paymentMethod"] = payment_method @@ -239,7 +241,7 @@ def __init__(self, id: str, created_at: datetime, direction: str, amount: int, b def from_json_api(_id, _type, attributes, relationships): return CardTransactionDTO(_id, date_utils.to_datetime(attributes["createdAt"]), attributes["direction"], attributes["amount"], attributes["balance"], attributes["summary"], - attributes["cardLast4Digits"], Merchant.from_json_api(attributes["merchant"]), + attributes["cardLast4Digits"], Merchant.from_json_api(attributes.get("merchant")), attributes.get("recurring"), attributes.get("interchange"), attributes.get("paymentMethod"), attributes.get("digitalWallet"), attributes.get("cardVerificationData"), attributes.get("cardNetwork"),