Coverage for functions \ flipdare \ payments \ core \ stripe_guard.py: 100%
17 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 Any, TypeGuard
14from flipdare.payments.payment_types import KnownStripeErrorType
15import stripe._error as s
17from flipdare.generated.model.payment.stripe_account_model import StripeAccountModel
18from flipdare.generated.model.payment.stripe_customer_model import StripeCustomerModel
19from flipdare.generated.model.user_model import StripeSettingsType
21__all__ = ["StripeGuard"]
24class StripeGuard:
25 @staticmethod
26 def is_stripe_error(err: Any) -> TypeGuard[KnownStripeErrorType]:
27 return isinstance(err, s.StripeError)
29 @staticmethod
30 def is_customer(settings: StripeSettingsType | None) -> TypeGuard[StripeCustomerModel]:
31 return settings is not None and settings.type == "customer"
33 @staticmethod
34 def is_account(settings: StripeSettingsType | None) -> TypeGuard[StripeAccountModel]:
35 return settings is not None and settings.type == "account" # type: ignore[comparison-overlap]