from __future__ import annotations
import stripe
[docs]
class DatatransPaymentError(Exception):
pass
[docs]
class DatatransApiError(DatatransPaymentError):
def __init__(self, code: str, message: str, terminal: bool) -> None:
super().__init__(f'{code}: {message}')
[docs]
self.terminal = terminal
[docs]
class SaferpayPaymentError(Exception):
pass
[docs]
class SaferpayApiError(SaferpayPaymentError):
def __init__(
self,
name: str,
message: str,
behavior: str,
detail: list[str] | None = None
) -> None:
details = tuple(detail) if detail else ()
super().__init__('\n'.join((
f'{name}: {message}',
*details,
)))
[docs]
self.behavior = behavior
# the following exceptions should be caught and logged - the user should be
# informed that the payment failed, but not why
[docs]
CARD_ERRORS = (
stripe.error.CardError,
DatatransPaymentError,
SaferpayPaymentError,
)