Coverage for functions \ flipdare \ generated \ model \ payment \ stripe_customer_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 datetime import datetime 

23from google.cloud.firestore_v1.transforms import Sentinel 

24from flipdare.core.firestore_field import FirestoreField 

25from flipdare.util.time_util import FirestoreTime 

26from typing import Any, TypedDict, cast, Unpack, Literal 

27from enum import StrEnum 

28from pydantic import Field, ConfigDict, TypeAdapter 

29from flipdare.firestore.core.app_base_model import AppBaseModel 

30from flipdare.generated.shared.stripe.stripe_country_code import StripeCountryCode 

31from flipdare.generated.shared.stripe.stripe_currency_code import StripeCurrencyCode 

32from pydantic import model_validator 

33 

34 

35class StripeCustomerKeys(StrEnum): 

36 UPDATED_AT = "updated_at" 

37 CREATED_AT = "created_at" 

38 EMAIL = "email" 

39 NAME = "name" 

40 CUSTOMER_ID = "customer_id" 

41 COUNTRY_CODE = "country_code" 

42 CURRENCY_CODE = "currency_code" 

43 INVOICE_PREFIX = "invoice_prefix" 

44 

45 

46# !! IMPORTANT !! 

47# !! 

48# !! this should only be used in the database to query. 

49# !! 

50class StripeCustomerInternalKeys(StrEnum): 

51 UPDATED_AT = "updated_at" 

52 CREATED_AT = "created_at" 

53 

54 

55class StripeCustomerModel(AppBaseModel): 

56 """Internal Stripe Customer Settings Schema""" 

57 

58 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True) 

59 

60 type: Literal["customer"] = "customer" # type: ignore 

61 updated_at: FirestoreField = Field( 

62 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

63 ) 

64 created_at: FirestoreField = Field( 

65 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

66 ) 

67 email: str 

68 name: str 

69 customer_id: str 

70 country_code: StripeCountryCode 

71 # we set to the country code fallback in post init, this is a placeholder. 

72 currency_code: StripeCurrencyCode = Field(default=StripeCurrencyCode.USD) 

73 invoice_prefix: str 

74 

75 @classmethod 

76 def validate_partial(cls, **data: Unpack[StripeCustomerDict]) -> dict[str, Any]: # type: ignore 

77 """ 

78 Uses Unpack to give you autocomplete and static warnings 

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

80 

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

82 """ 

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

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

85 if k in cls.__pydantic_fields__: 

86 field_info = cls.__pydantic_fields__[k] 

87 validated_value = cast( 

88 "Any", 

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

90 ) 

91 # Use alias if defined, otherwise use field name 

92 output_key = field_info.alias or k 

93 result[output_key] = validated_value 

94 return result 

95 

96 # ---- Validation ----------------------------------------- 

97 

98 @model_validator(mode="after") 

99 def set_currency_fallback(self) -> StripeCustomerModel: 

100 # Check if "currency_code" was NOT in the original input data 

101 # hence the placeholder was used.. 

102 if "currency_code" not in self.model_fields_set: 

103 self.currency_code = self.country_code.fallback_currency_code 

104 return self 

105 

106 

107STRIPECUSTOMER_FIELD_NAMES: list[str] = list(StripeCustomerModel.model_fields.keys()) 

108 

109 

110class StripeCustomerDict(TypedDict, total=False): 

111 updated_at: Sentinel | datetime | str 

112 created_at: Sentinel | datetime | str 

113 email: str 

114 name: str 

115 customer_id: str 

116 country_code: StripeCountryCode 

117 currency_code: StripeCurrencyCode | None 

118 invoice_prefix: str