Coverage for functions \ flipdare \ generated \ model \ payment \ payment_result_model.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# 

3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

4# 

5# This file is part of Flipdare's proprietary software and contains 

6# confidential and copyrighted material. Unauthorised copying, 

7# modification, distribution, or use of this file is strictly 

8# prohibited without prior written permission from Flipdare Pty Ltd. 

9# 

10# This software includes third-party components licensed under MIT, 

11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

12# 

13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT. 

14# 

15# Generated by codegen_models.py 

16# 

17# Modify 'codegen_models.py' 

18# and re-run the script above to update. 

19# 

20# pragma: no cover 

21from __future__ import annotations 

22from typing import Any, TypedDict, cast, Unpack 

23from enum import StrEnum 

24from pydantic import Field, ConfigDict, TypeAdapter 

25from flipdare.firestore.core.app_base_model import AppBaseModel 

26 

27 

28class PaymentResultKeys(StrEnum): 

29 AMOUNT_TRANSFERRED = "amount_transferred" 

30 AMOUNT_CAPTURED = "amount_captured" 

31 AMOUNT_REFUNDED = "amount_refunded" 

32 STRIPE_FEE_AMOUNT = "stripe_fee_amount" 

33 APP_FEE_AMOUNT = "app_fee_amount" 

34 

35 

36class PaymentResultModel(AppBaseModel): 

37 model_config = ConfigDict(populate_by_name=True) 

38 

39 # The amount transferred to the account (including fees). 

40 amount_transferred: int = Field(default=0) 

41 amount_captured: int = Field(default=0) 

42 amount_refunded: int = Field(default=0) 

43 stripe_fee_amount: int = Field(default=0) 

44 app_fee_amount: int = Field(default=0) 

45 

46 @classmethod 

47 def validate_partial(cls, **data: Unpack[PaymentResultDict]) -> dict[str, Any]: 

48 """ 

49 Uses Unpack to give you autocomplete and static warnings 

50 if you pass an invalid key or type in your code. 

51 

52 Returns a dict with Firestore field names (aliases) for use with batch.update(). 

53 """ 

54 result: dict[str, Any] = {} 

55 for k, v in data.items(): 

56 if k in cls.__pydantic_fields__: 

57 field_info = cls.__pydantic_fields__[k] 

58 validated_value = cast( 

59 "Any", 

60 TypeAdapter(field_info.annotation).validate_python(v), 

61 ) 

62 # Use alias if defined, otherwise use field name 

63 output_key = field_info.alias or k 

64 result[output_key] = validated_value 

65 return result 

66 

67 # ---- Convenience factories ----------------------------------------- 

68 

69 def accumulate(self, updated: PaymentResultModel) -> None: 

70 """Accumulates another PaymentResultModel by summing their fields.""" 

71 self.amount_transferred += updated.amount_transferred 

72 self.amount_captured += updated.amount_captured 

73 self.stripe_fee_amount += updated.stripe_fee_amount 

74 self.app_fee_amount += updated.app_fee_amount 

75 

76 

77PAYMENTRESULT_FIELD_NAMES: list[str] = list(PaymentResultModel.model_fields.keys()) 

78 

79 

80class PaymentResultDict(TypedDict, total=False): 

81 amount_transferred: int | None 

82 amount_captured: int | None 

83 amount_refunded: int | None 

84 stripe_fee_amount: int | None 

85 app_fee_amount: int | None