Coverage for functions \ flipdare \ generated \ shared \ stripe \ stripe_currency_code.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# ruff: noqa 

3# pyright: reportGeneralTypeIssues=false 

4# mypy: ignore-errors 

5# pragma: no cover 

6# 

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

8# 

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

10# confidential and copyrighted material. Unauthorised copying, 

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

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

13# 

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

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

16# 

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

18# 

19# Generated by stripe_config.py 

20# 

21# Modify 'stripe_config.py' 

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

23# 

24 

25from __future__ import annotations 

26 

27from enum import StrEnum 

28from typing import TYPE_CHECKING 

29 

30if TYPE_CHECKING: 

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

32 

33__all__ = ["StripeCurrencyCode"] 

34 

35 

36class StripeCurrencyCode(StrEnum): 

37 USD = ("USD", 2, "$", True) 

38 AUD = ("AUD", 2, "$", True) 

39 CAD = ("CAD", 2, "$", True) 

40 EUR = ("EUR", 2, "€", True) 

41 GBP = ("GBP", 2, "£", True) 

42 BGN = ("BGN", 2, "лв", True) 

43 BRL = ("BRL", 2, "R$", True) 

44 CZK = ("CZK", 2, "Kč", False) 

45 DKK = ("DKK", 2, "kr", True) 

46 HKD = ("HKD", 2, "HK$", True) 

47 HUF = ("HUF", 2, "Ft", False) 

48 INR = ("INR", 2, "₹", True) 

49 JPY = ("JPY", 0, "¥", True) 

50 CHF = ("CHF", 2, "CHF", False) 

51 MXN = ("MXN", 2, "$", True) 

52 MYR = ("MYR", 2, "RM", True) 

53 NOK = ("NOK", 2, "kr", True) 

54 NZD = ("NZD", 2, "$", True) 

55 PLN = ("PLN", 2, "zł", True) 

56 RON = ("RON", 2, "lei", True) 

57 SGD = ("SGD", 2, "$", True) 

58 SEK = ("SEK", 2, "kr", False) 

59 AED = ("AED", 2, "د.إ", True) 

60 

61 # for type checkers 

62 _code: str 

63 _decimals: int 

64 _symbol: str 

65 _symbol_on_left: bool 

66 

67 def __new__( 

68 cls, 

69 code: str, 

70 decimals: int = 0, 

71 symbol: str = "", 

72 symbol_on_left: bool = True, 

73 ) -> StripeCurrencyCode: 

74 obj = str.__new__(cls, code) 

75 obj._value_ = code # makes .value == code, e.g. "usd" 

76 obj._code = code 

77 obj._decimals = decimals 

78 obj._symbol = symbol 

79 obj._symbol_on_left = symbol_on_left 

80 return obj 

81 

82 @classmethod 

83 def from_stripe(cls, code: str) -> StripeCurrencyCode: 

84 try: 

85 return cls(code.upper()) 

86 except ValueError: 

87 raise ValueError(f"Unrecognised currency code: {code}") 

88 

89 @property 

90 def symbol(self) -> str: 

91 return self._symbol 

92 

93 @property 

94 def code(self) -> str: 

95 return self._code 

96 

97 @property 

98 def stripe_code(self) -> str: 

99 return self._code.lower() 

100 

101 @property 

102 def decimals(self) -> int: 

103 return self._decimals 

104 

105 @property 

106 def is_zero_decimal(self) -> bool: 

107 return self._decimals == 0 

108 

109 @property 

110 def minor_unit_factor(self) -> int: 

111 return int(10**self._decimals) 

112 

113 @property 

114 def symbol_on_left(self) -> bool: 

115 return self._symbol_on_left 

116 

117 def cvt_cents_to_dollars_and_cents(self, cents: int) -> float: 

118 """Convert given currency cents to dollars and cents.""" 

119 if self.is_zero_decimal: 

120 # For zero decimal currencies, cents are whole units 

121 return float(cents) 

122 return float(cents) / 100.0 

123 

124 def display_dollars_and_cents(self, cents: int) -> str: 

125 symbol = self.symbol 

126 on_left = self.symbol_on_left 

127 amt = self.cvt_cents_to_dollars_and_cents(cents) 

128 if self.is_zero_decimal: 

129 amt_str = f"{int(amt)}" 

130 else: 

131 amt_str = f"{amt:.2f}" 

132 

133 if on_left: 

134 return f"{symbol}{amt_str}" 

135 else: 

136 return f"{amt_str}{symbol}" 

137 

138 @property 

139 def fallback_country_code(self) -> StripeCountryCode: 

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

141 

142 match self: 

143 case StripeCurrencyCode.USD: 

144 return StripeCountryCode.US 

145 case StripeCurrencyCode.AUD: 

146 return StripeCountryCode.AU 

147 case StripeCurrencyCode.CAD: 

148 return StripeCountryCode.CA 

149 case StripeCurrencyCode.EUR: 

150 return StripeCountryCode.DE 

151 case StripeCurrencyCode.GBP: 

152 return StripeCountryCode.GB 

153 case StripeCurrencyCode.BGN: 

154 return StripeCountryCode.BG 

155 case StripeCurrencyCode.BRL: 

156 return StripeCountryCode.BR 

157 case StripeCurrencyCode.CZK: 

158 return StripeCountryCode.CZ 

159 case StripeCurrencyCode.DKK: 

160 return StripeCountryCode.DK 

161 case StripeCurrencyCode.HKD: 

162 return StripeCountryCode.HK 

163 case StripeCurrencyCode.HUF: 

164 return StripeCountryCode.HU 

165 case StripeCurrencyCode.INR: 

166 return StripeCountryCode.IN 

167 case StripeCurrencyCode.JPY: 

168 return StripeCountryCode.JP 

169 case StripeCurrencyCode.CHF: 

170 return StripeCountryCode.LI 

171 case StripeCurrencyCode.MXN: 

172 return StripeCountryCode.MX 

173 case StripeCurrencyCode.MYR: 

174 return StripeCountryCode.MY 

175 case StripeCurrencyCode.NOK: 

176 return StripeCountryCode.NO 

177 case StripeCurrencyCode.NZD: 

178 return StripeCountryCode.NZ 

179 case StripeCurrencyCode.PLN: 

180 return StripeCountryCode.PL 

181 case StripeCurrencyCode.RON: 

182 return StripeCountryCode.RO 

183 case StripeCurrencyCode.SGD: 

184 return StripeCountryCode.SG 

185 case StripeCurrencyCode.SEK: 

186 return StripeCountryCode.SE 

187 case StripeCurrencyCode.AED: 

188 return StripeCountryCode.AE