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
« 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#
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)
38__all__ = [
39 "StripeCreateAccountRequestAdapter",
40 "StripeWebhookRequestAdapter",
41 "PaymentCreateRequestAdapter",
42 "PaymentConfirmRequestAdapter",
43 "StripeRefreshAccountRequestAdapter",
44]
46# ---------------------------------------------------------------------------------------------------------------------
47# Account
48# ---------------------------------------------------------------------------------------------------------------------
51class StripeCreateAccountRequestAdapter(RequestAdapter[StripeCreateAccountRequestSchema]):
53 SCHEMA_CLS = StripeCreateAccountRequestSchema
54 VALIDATORS = (UidRequestValidator, TextPresentRequestValidator)
56 @property
57 def uid(self) -> str:
58 return self.data["uid"]
60 @property
61 def email(self) -> str | None:
62 return self.data.get("email", None)
64 @property
65 def first_name(self) -> str:
66 return self.data["first_name"]
68 @property
69 def last_name(self) -> str:
70 return self.data["last_name"]
72 @property
73 def account_type(self) -> StripeAccountType:
74 return self.data["account_type"]
76 @property
77 def currency_code(self) -> StripeCurrencyCode:
78 return self.data["currency_code"]
80 @property
81 def country_code(self) -> StripeCountryCode:
82 return self.data["country_code"]
84 @property
85 def overwrite(self) -> bool:
86 return self.data.get("overwrite", False)
89class StripeUpgradeCustomerRequestAdapter(RequestAdapter[StripeUpgradeCustomerRequestSchema]):
91 SCHEMA_CLS = StripeUpgradeCustomerRequestSchema
92 VALIDATORS = (UidRequestValidator, TextPresentRequestValidator)
94 @property
95 def uid(self) -> str:
96 return self.data["uid"]
98 @property
99 def email(self) -> str | None:
100 return self.data.get("email", None)
102 @property
103 def customer_id(self) -> str:
104 return self.data["customer_id"]
106 @property
107 def first_name(self) -> str:
108 return self.data["first_name"]
110 @property
111 def last_name(self) -> str:
112 return self.data["last_name"]
114 @property
115 def account_type(self) -> StripeAccountType:
116 return self.data["account_type"]
118 @property
119 def currency_code(self) -> StripeCurrencyCode:
120 return self.data["currency_code"]
122 @property
123 def country_code(self) -> StripeCountryCode:
124 return self.data["country_code"]
127class StripeWebhookRequestAdapter(RequestAdapter[StripeWebhookRequestSchema]):
128 SCHEMA_CLS = StripeWebhookRequestSchema
129 VALIDATORS = (UidRequestValidator,)
131 @property
132 def uid(self) -> str:
133 return self.data["uid"]
135 @property
136 def stripe_account_id(self) -> str:
137 return self.data["stripe_account_id"]
139 @property
140 def stripe_account_type(self) -> StripeAccountType:
141 return self.data["stripe_account_type"]
143 @property
144 def webhook_key(self) -> str:
145 return self.data["webhook_key"]
148class StripeRefreshAccountRequestAdapter(RequestAdapter[StripeRefreshAccountRequestSchema]):
149 SCHEMA_CLS = StripeRefreshAccountRequestSchema
150 VALIDATORS = (UidRequestValidator,)
152 @property
153 def uid(self) -> str:
154 return self.data["uid"]
156 @property
157 def stripe_account_id(self) -> str:
158 return self.data["stripe_account_id"]
160 @property
161 def account_type(self) -> StripeAccountType:
162 return self.data["account_type"]
165class StripeLinkRequestAdapter(RequestAdapter[StripeLinkRequestSchema]):
166 SCHEMA_CLS = StripeLinkRequestSchema
167 VALIDATORS = (UidRequestValidator,)
169 @property
170 def uid(self) -> str:
171 return self.data["uid"]
173 @property
174 def stripe_account_id(self) -> str:
175 return self.data["stripe_account_id"]
178# ---------------------------------------------------------------------------------------------------------------------
179# Payments
180# ---------------------------------------------------------------------------------------------------------------------
183class PaymentCreateRequestAdapter(RequestAdapter[PaymentCreateRequestSchema]):
185 SCHEMA_CLS = PaymentCreateRequestSchema
186 VALIDATORS = (
187 EmailRequestValidator,
188 PaymentCustomerUidRequestValidator,
189 IpAddressRequestValidator,
190 )
192 @property
193 @override
194 def ip_address(self) -> str:
195 return self.data["ip_address"]
197 @property
198 def device_fingerprint(self) -> str:
199 return self.data["device_fingerprint"]
201 @property
202 def customer_uid(self) -> str:
203 return self.data["customer_uid"]
205 @property
206 def customer_id(self) -> str | None:
207 return self.data.get("customer_id", None)
209 @property
210 def account_uid(self) -> str:
211 return self.data["account_uid"]
213 @property
214 def account_id(self) -> str:
215 return self.data["account_id"]
217 @property
218 def dare_id(self) -> str:
219 return self.data["dare_id"]
221 @property
222 def email(self) -> str:
223 return self.data["email"]
225 @property
226 def name(self) -> str | None:
227 return self.data.get("name", None)
229 @property
230 def pledge_amount(self) -> int: # in cents/units
231 return self.data["pledge_amount"]
233 @property
234 def overwrite(self) -> bool:
235 return self.data.get("overwrite", False)
237 @property
238 def currency_code(self) -> StripeCurrencyCode:
239 return self.data["currency_code"]
242class PaymentConfirmRequestAdapter(RequestAdapter[PaymentConfirmRequestSchema]):
244 SCHEMA_CLS = PaymentConfirmRequestSchema
245 VALIDATORS = (PaymentCustomerUidRequestValidator, PaymentAccountUidRequestValidator)
247 @property
248 def customer_uid(self) -> str:
249 return self.data["customer_uid"]
251 @property
252 def account_uid(self) -> str:
253 return self.data["account_uid"]
255 @property
256 @override
257 def ip_address(self) -> str:
258 return self.data["ip_address"]
260 @property
261 def device_fingerprint(self) -> str:
262 return self.data["device_fingerprint"]
264 @property
265 def dare_id(self) -> str:
266 return self.data["dare_id"]
268 @property
269 def pledge_amount(self) -> int: # in cents/units
270 return self.data["pledge_amount"]
272 @property
273 def payment_intent_id(self) -> str:
274 return self.data["payment_intent_id"]
276 @property
277 def pledge_id(self) -> str:
278 return self.data["pledge_id"]