Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion unit/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
12 changes: 7 additions & 5 deletions unit/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"),
Expand Down
Loading