Coverage for functions \ flipdare \ request \ data \ stripe_request_adapter.py: 88%

164 statements  

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

1#!/usr/bin/env python 

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

3# 

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

5# confidential and copyrighted material. Unauthorised copying, 

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

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

8# 

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

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

11# 

12 

13from typing import override 

14from flipdare.generated import ( 

15 PaymentConfirmRequestSchema, 

16 PaymentCreateRequestSchema, 

17 StripeCreateAccountRequestSchema, 

18 StripeRefreshAccountRequestSchema, 

19 StripeWebhookRequestSchema, 

20 StripeLinkRequestSchema, 

21 StripeAccountType, 

22 StripeCountryCode, 

23 StripeCurrencyCode, 

24) 

25from flipdare.generated.schema.payment.stripe_upgrade_customer_request_schema import ( 

26 StripeUpgradeCustomerRequestSchema, 

27) 

28from flipdare.request.request_adapter import RequestAdapter 

29from flipdare.request.request_validator import ( 

30 EmailRequestValidator, 

31 IpAddressRequestValidator, 

32 PaymentAccountUidRequestValidator, 

33 PaymentCustomerUidRequestValidator, 

34 TextPresentRequestValidator, 

35 UidRequestValidator, 

36) 

37 

38__all__ = [ 

39 "StripeCreateAccountRequestAdapter", 

40 "StripeWebhookRequestAdapter", 

41 "PaymentCreateRequestAdapter", 

42 "PaymentConfirmRequestAdapter", 

43 "StripeRefreshAccountRequestAdapter", 

44] 

45 

46# --------------------------------------------------------------------------------------------------------------------- 

47# Account 

48# --------------------------------------------------------------------------------------------------------------------- 

49 

50 

51class StripeCreateAccountRequestAdapter(RequestAdapter[StripeCreateAccountRequestSchema]): 

52 

53 SCHEMA_CLS = StripeCreateAccountRequestSchema 

54 VALIDATORS = (UidRequestValidator, TextPresentRequestValidator) 

55 

56 @property 

57 def uid(self) -> str: 

58 return self.data["uid"] 

59 

60 @property 

61 def email(self) -> str | None: 

62 return self.data.get("email", None) 

63 

64 @property 

65 def first_name(self) -> str: 

66 return self.data["first_name"] 

67 

68 @property 

69 def last_name(self) -> str: 

70 return self.data["last_name"] 

71 

72 @property 

73 def account_type(self) -> StripeAccountType: 

74 return self.data["account_type"] 

75 

76 @property 

77 def currency_code(self) -> StripeCurrencyCode: 

78 return self.data["currency_code"] 

79 

80 @property 

81 def country_code(self) -> StripeCountryCode: 

82 return self.data["country_code"] 

83 

84 @property 

85 def overwrite(self) -> bool: 

86 return self.data.get("overwrite", False) 

87 

88 

89class StripeUpgradeCustomerRequestAdapter(RequestAdapter[StripeUpgradeCustomerRequestSchema]): 

90 

91 SCHEMA_CLS = StripeUpgradeCustomerRequestSchema 

92 VALIDATORS = (UidRequestValidator, TextPresentRequestValidator) 

93 

94 @property 

95 def uid(self) -> str: 

96 return self.data["uid"] 

97 

98 @property 

99 def email(self) -> str | None: 

100 return self.data.get("email", None) 

101 

102 @property 

103 def customer_id(self) -> str: 

104 return self.data["customer_id"] 

105 

106 @property 

107 def first_name(self) -> str: 

108 return self.data["first_name"] 

109 

110 @property 

111 def last_name(self) -> str: 

112 return self.data["last_name"] 

113 

114 @property 

115 def account_type(self) -> StripeAccountType: 

116 return self.data["account_type"] 

117 

118 @property 

119 def currency_code(self) -> StripeCurrencyCode: 

120 return self.data["currency_code"] 

121 

122 @property 

123 def country_code(self) -> StripeCountryCode: 

124 return self.data["country_code"] 

125 

126 

127class StripeWebhookRequestAdapter(RequestAdapter[StripeWebhookRequestSchema]): 

128 SCHEMA_CLS = StripeWebhookRequestSchema 

129 VALIDATORS = (UidRequestValidator,) 

130 

131 @property 

132 def uid(self) -> str: 

133 return self.data["uid"] 

134 

135 @property 

136 def stripe_account_id(self) -> str: 

137 return self.data["stripe_account_id"] 

138 

139 @property 

140 def stripe_account_type(self) -> StripeAccountType: 

141 return self.data["stripe_account_type"] 

142 

143 @property 

144 def webhook_key(self) -> str: 

145 return self.data["webhook_key"] 

146 

147 

148class StripeRefreshAccountRequestAdapter(RequestAdapter[StripeRefreshAccountRequestSchema]): 

149 SCHEMA_CLS = StripeRefreshAccountRequestSchema 

150 VALIDATORS = (UidRequestValidator,) 

151 

152 @property 

153 def uid(self) -> str: 

154 return self.data["uid"] 

155 

156 @property 

157 def stripe_account_id(self) -> str: 

158 return self.data["stripe_account_id"] 

159 

160 @property 

161 def account_type(self) -> StripeAccountType: 

162 return self.data["account_type"] 

163 

164 

165class StripeLinkRequestAdapter(RequestAdapter[StripeLinkRequestSchema]): 

166 SCHEMA_CLS = StripeLinkRequestSchema 

167 VALIDATORS = (UidRequestValidator,) 

168 

169 @property 

170 def uid(self) -> str: 

171 return self.data["uid"] 

172 

173 @property 

174 def stripe_account_id(self) -> str: 

175 return self.data["stripe_account_id"] 

176 

177 

178# --------------------------------------------------------------------------------------------------------------------- 

179# Payments 

180# --------------------------------------------------------------------------------------------------------------------- 

181 

182 

183class PaymentCreateRequestAdapter(RequestAdapter[PaymentCreateRequestSchema]): 

184 

185 SCHEMA_CLS = PaymentCreateRequestSchema 

186 VALIDATORS = ( 

187 EmailRequestValidator, 

188 PaymentCustomerUidRequestValidator, 

189 IpAddressRequestValidator, 

190 ) 

191 

192 @property 

193 @override 

194 def ip_address(self) -> str: 

195 return self.data["ip_address"] 

196 

197 @property 

198 def device_fingerprint(self) -> str: 

199 return self.data["device_fingerprint"] 

200 

201 @property 

202 def customer_uid(self) -> str: 

203 return self.data["customer_uid"] 

204 

205 @property 

206 def customer_id(self) -> str | None: 

207 return self.data.get("customer_id", None) 

208 

209 @property 

210 def account_uid(self) -> str: 

211 return self.data["account_uid"] 

212 

213 @property 

214 def account_id(self) -> str: 

215 return self.data["account_id"] 

216 

217 @property 

218 def dare_id(self) -> str: 

219 return self.data["dare_id"] 

220 

221 @property 

222 def email(self) -> str: 

223 return self.data["email"] 

224 

225 @property 

226 def name(self) -> str | None: 

227 return self.data.get("name", None) 

228 

229 @property 

230 def pledge_amount(self) -> int: # in cents/units 

231 return self.data["pledge_amount"] 

232 

233 @property 

234 def overwrite(self) -> bool: 

235 return self.data.get("overwrite", False) 

236 

237 @property 

238 def currency_code(self) -> StripeCurrencyCode: 

239 return self.data["currency_code"] 

240 

241 

242class PaymentConfirmRequestAdapter(RequestAdapter[PaymentConfirmRequestSchema]): 

243 

244 SCHEMA_CLS = PaymentConfirmRequestSchema 

245 VALIDATORS = (PaymentCustomerUidRequestValidator, PaymentAccountUidRequestValidator) 

246 

247 @property 

248 def customer_uid(self) -> str: 

249 return self.data["customer_uid"] 

250 

251 @property 

252 def account_uid(self) -> str: 

253 return self.data["account_uid"] 

254 

255 @property 

256 @override 

257 def ip_address(self) -> str: 

258 return self.data["ip_address"] 

259 

260 @property 

261 def device_fingerprint(self) -> str: 

262 return self.data["device_fingerprint"] 

263 

264 @property 

265 def dare_id(self) -> str: 

266 return self.data["dare_id"] 

267 

268 @property 

269 def pledge_amount(self) -> int: # in cents/units 

270 return self.data["pledge_amount"] 

271 

272 @property 

273 def payment_intent_id(self) -> str: 

274 return self.data["payment_intent_id"] 

275 

276 @property 

277 def pledge_id(self) -> str: 

278 return self.data["pledge_id"]