polyticket-api/poly-ticket-api-client/poly_ticket_api_client/models/payment_intent.py

179 lines
5.6 KiB
Python

import datetime
from collections.abc import Mapping
from typing import Any, TypeVar, Union, cast
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse
from .. import types
from ..types import UNSET, Unset
T = TypeVar("T", bound="PaymentIntent")
@_attrs_define
class PaymentIntent:
"""A serializer for Payment Intent. This serializer may contain invoice or invoice_id depending on what the expand
parameter is.
Attributes:
id (int):
created_at (datetime.datetime):
module_key (str):
invoice_id (int): Id of the related invoice
error_message (str): Payment provider's error message if payment is refused
created_by (Union[None, Unset, int]):
psp_id (Union[Unset, str]):
is_error (Union[Unset, bool]):
is_cancelled (Union[Unset, bool]):
"""
id: int
created_at: datetime.datetime
module_key: str
invoice_id: int
error_message: str
created_by: Union[None, Unset, int] = UNSET
psp_id: Union[Unset, str] = UNSET
is_error: Union[Unset, bool] = UNSET
is_cancelled: Union[Unset, bool] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
id = self.id
created_at = self.created_at.isoformat()
module_key = self.module_key
invoice_id = self.invoice_id
error_message = self.error_message
created_by: Union[None, Unset, int]
if isinstance(self.created_by, Unset):
created_by = UNSET
else:
created_by = self.created_by
psp_id = self.psp_id
is_error = self.is_error
is_cancelled = self.is_cancelled
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"id": id,
"created_at": created_at,
"module_key": module_key,
"invoice_id": invoice_id,
"error_message": error_message,
}
)
if created_by is not UNSET:
field_dict["created_by"] = created_by
if psp_id is not UNSET:
field_dict["psp_id"] = psp_id
if is_error is not UNSET:
field_dict["is_error"] = is_error
if is_cancelled is not UNSET:
field_dict["is_cancelled"] = is_cancelled
return field_dict
def to_multipart(self) -> types.RequestFiles:
files: types.RequestFiles = []
files.append(("id", (None, str(self.id).encode(), "text/plain")))
files.append(("created_at", (None, self.created_at.isoformat().encode(), "text/plain")))
files.append(("module_key", (None, str(self.module_key).encode(), "text/plain")))
files.append(("invoice_id", (None, str(self.invoice_id).encode(), "text/plain")))
files.append(("error_message", (None, str(self.error_message).encode(), "text/plain")))
if not isinstance(self.created_by, Unset):
if isinstance(self.created_by, int):
files.append(("created_by", (None, str(self.created_by).encode(), "text/plain")))
else:
files.append(("created_by", (None, str(self.created_by).encode(), "text/plain")))
if not isinstance(self.psp_id, Unset):
files.append(("psp_id", (None, str(self.psp_id).encode(), "text/plain")))
if not isinstance(self.is_error, Unset):
files.append(("is_error", (None, str(self.is_error).encode(), "text/plain")))
if not isinstance(self.is_cancelled, Unset):
files.append(("is_cancelled", (None, str(self.is_cancelled).encode(), "text/plain")))
for prop_name, prop in self.additional_properties.items():
files.append((prop_name, (None, str(prop).encode(), "text/plain")))
return files
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
id = d.pop("id")
created_at = isoparse(d.pop("created_at"))
module_key = d.pop("module_key")
invoice_id = d.pop("invoice_id")
error_message = d.pop("error_message")
def _parse_created_by(data: object) -> Union[None, Unset, int]:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(Union[None, Unset, int], data)
created_by = _parse_created_by(d.pop("created_by", UNSET))
psp_id = d.pop("psp_id", UNSET)
is_error = d.pop("is_error", UNSET)
is_cancelled = d.pop("is_cancelled", UNSET)
payment_intent = cls(
id=id,
created_at=created_at,
module_key=module_key,
invoice_id=invoice_id,
error_message=error_message,
created_by=created_by,
psp_id=psp_id,
is_error=is_error,
is_cancelled=is_cancelled,
)
payment_intent.additional_properties = d
return payment_intent
@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties