Coverage for functions \ flipdare \ generated \ shared \ payment \ payment_event_status.py: 100%
0 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#
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#
21# pragma: no cover
23from enum import StrEnum
24from flipdare.generated.shared.app_log_category import AppLogCategory
25from flipdare.generated.shared.app_payment_error_code import AppPaymentErrorCode
28class PaymentEventStatus(StrEnum):
29 """Status for a Payment Event."""
31 # Declared here so type-checkers know these attributes exist.
32 # They are populated per-member inside __new__.
33 _http_code: int
34 _category: AppLogCategory
35 _display_title: str
37 def __new__(
38 cls,
39 code: str,
40 http_code: int | None = None,
41 category: AppLogCategory | None = None,
42 display_title: str | None = None,
43 ) -> "PaymentEventStatus":
44 obj = str.__new__(cls, code)
45 obj._value_ = code
46 # Only set attributes if they are provided (during member definition)
47 if http_code is not None:
48 obj._http_code = http_code
49 if category is not None:
50 obj._category = category
51 if display_title is not None:
52 obj._display_title = display_title
53 return obj
55 # ---- Members --------------------------------------------------------
56 # fmt: off
57 PENDING = ("pending", 200, AppLogCategory.PAYMENT, "Payment Pending")
58 TRANSFERRED = ("transferred", 200, AppLogCategory.PAYMENT, "Payment Transferred")
59 CAPTURED = ("captured", 200, AppLogCategory.PAYMENT, "Payment Captured")
60 ALREADY_CAPTURED = ("already_captured", 400, AppLogCategory.PAYMENT, "Already Captured")
61 DUPLICATE = ("duplicate", 400, AppLogCategory.PAYMENT, "Duplicate Payment Attempted")
62 FRAUDULENT = ("fraudulent", 402, AppLogCategory.PAYMENT, "Fraudulent Payment Detected")
63 CANCELLED = ("cancelled", 200, AppLogCategory.PAYMENT, "Payment Cancelled")
64 DISPUTED = ("disputed", 200, AppLogCategory.PAYMENT, "Payment Disputed by Cardholder")
65 REFUNDED = ("refunded", 200, AppLogCategory.PAYMENT, "Payment Refunded")
66 REQUIRES_CAPTURE = ("requires_capture", 200, AppLogCategory.PAYMENT, "Requires Capture")
67 REQUIRES_REAUTH = ("requires_reauth", 200, AppLogCategory.PAYMENT, "Requires Reauthentication")
68 REQUIRES_3D_SECURE = ("requires_3d_secure", 200, AppLogCategory.PAYMENT, "Requires 3D Secure")
69 REQUIRES_NEW_PAYMENT_METHOD = ("requires_new_payment_method", 200, AppLogCategory.PAYMENT, "Requires New Payment Method")
70 INSUFFICIENT_FUNDS = ("insufficient_funds", 402, AppLogCategory.PAYMENT, "Insufficient Funds")
71 STRIPE_PROCESSING = ("stripe_processing", 200, AppLogCategory.PAYMENT, "Stripe Processing")
72 REQUIRES_USER_ACTION = ("requires_user_action", 200, AppLogCategory.PAYMENT, "Requires User Action")
73 INVALID_PAYMENT_INTENT = ("invalid_payment_intent", 400, AppLogCategory.PAYMENT, "Invalid Payment Intent")
74 EXPIRED = ("expired", 200, AppLogCategory.PAYMENT, "Charge Expired Due to Inactivity or Time Limit Reached")
75 DECLINED = ("declined", 402, AppLogCategory.PAYMENT, "Payment Declined")
76 CARD_ISSUE = ("card_issue", 402, AppLogCategory.PAYMENT, "Card Issue Detected")
77 TIMEOUT = ("timeout", 408, AppLogCategory.PAYMENT, "Charge Timed Out")
78 ERROR = ("error", 500, AppLogCategory.PAYMENT, "Unknown Payment Error")
79 UNKNOWN = ("unknown", 500, AppLogCategory.PAYMENT, "Unknown Payment Status")
80 # fmt: on
81 # ---- Properties -----------------------------------------------------
82 @property
83 def http_code(self) -> int:
84 return self._http_code
86 @property
87 def category(self) -> AppLogCategory:
88 return self._category
90 @property
91 def display_title(self) -> str:
92 return self._display_title
94 # ---- Convenience predicates -----------------------------------------
96 @property
97 def is_captured(self) -> bool:
98 return self == PaymentEventStatus.CAPTURED
100 @property
101 def is_transferred(self) -> bool:
102 return self == PaymentEventStatus.TRANSFERRED
104 @property
105 def expired(self) -> bool:
106 return self == PaymentEventStatus.EXPIRED
108 @property
109 def can_try_capture(self) -> bool:
110 return self in {
111 PaymentEventStatus.INSUFFICIENT_FUNDS,
112 PaymentEventStatus.REQUIRES_CAPTURE,
113 PaymentEventStatus.ERROR, # these are things like connection timeouts etc.
114 PaymentEventStatus.UNKNOWN, # should try again to get a better status.
115 }
117 @property
118 def needs_recheck(self) -> bool:
119 return self in {
120 PaymentEventStatus.STRIPE_PROCESSING, # see if stripe has updated the status yet.
121 PaymentEventStatus.ERROR, # these are things like connection timeouts etc.
122 PaymentEventStatus.UNKNOWN, # should try again to get a better status.
123 }
125 @property
126 def payment_error_code(self) -> AppPaymentErrorCode | None:
127 if self in (PaymentEventStatus.CAPTURED, PaymentEventStatus.TRANSFERRED):
128 return None
130 mapping = {
131 PaymentEventStatus.ALREADY_CAPTURED: AppPaymentErrorCode.ALREADY_CAPTURED,
132 PaymentEventStatus.DUPLICATE: AppPaymentErrorCode.DUPLICATE,
133 PaymentEventStatus.FRAUDULENT: AppPaymentErrorCode.FRAUDULENT,
134 PaymentEventStatus.CANCELLED: AppPaymentErrorCode.CHARGE_CANCELED,
135 PaymentEventStatus.DISPUTED: AppPaymentErrorCode.CHARGE_DISPUTED,
136 PaymentEventStatus.REFUNDED: AppPaymentErrorCode.REFUND_FAILED,
137 PaymentEventStatus.REQUIRES_CAPTURE: AppPaymentErrorCode.CHARGE_REQUIRES_CAPTURE,
138 PaymentEventStatus.REQUIRES_REAUTH: AppPaymentErrorCode.CHARGE_REQUIRES_REAUTH,
139 PaymentEventStatus.REQUIRES_3D_SECURE: AppPaymentErrorCode.CHARGE_REQUIRES_3D_SECURE,
140 PaymentEventStatus.REQUIRES_NEW_PAYMENT_METHOD: AppPaymentErrorCode.CHARGE_REQUIRES_NEW_PAYMENT_METHOD,
141 PaymentEventStatus.INSUFFICIENT_FUNDS: AppPaymentErrorCode.INSUFFICIENT_FUNDS,
142 PaymentEventStatus.STRIPE_PROCESSING: AppPaymentErrorCode.INTENT_PENDING,
143 PaymentEventStatus.INVALID_PAYMENT_INTENT: AppPaymentErrorCode.INTENT_NOT_CONFIRMED,
144 PaymentEventStatus.EXPIRED: AppPaymentErrorCode.INTENT_PENDING,
145 PaymentEventStatus.DECLINED: AppPaymentErrorCode.CHARGE_FAILED,
146 PaymentEventStatus.CARD_ISSUE: AppPaymentErrorCode.CARD_ERROR,
147 PaymentEventStatus.TIMEOUT: AppPaymentErrorCode.INTENT_TIMEOUT,
148 PaymentEventStatus.ERROR: AppPaymentErrorCode.CHARGE_FAILED,
149 PaymentEventStatus.UNKNOWN: AppPaymentErrorCode.UNKNOWN_ERROR,
150 }
152 return mapping.get(self, AppPaymentErrorCode.UNKNOWN_ERROR)