import json from collections.abc import Mapping from typing import TYPE_CHECKING, Any, TypeVar, Union from attrs import define as _attrs_define from attrs import field as _attrs_field from .. import types from ..types import UNSET, Unset if TYPE_CHECKING: from ..models.payment_intent import PaymentIntent T = TypeVar("T", bound="PaymentStart") @_attrs_define class PaymentStart: """A serializer with a basket as an input to start the payment and with a payment link for the response Attributes: basket (int): The basket you want to start the payment for link (str): If the chosen payment method requires an external redirect, this attribute will contain the fully qualified URL to redirect the user to is_external_redirect (bool): If true, the user must be redirected to the link. Otherwise, the payment process requires more actions in the front end. is_terms_of_service_accepted (bool): Must be true to validate a payment start. payment_intent (PaymentIntent): A serializer for Payment Intent. This serializer may contain invoice or invoice_id depending on what the expand parameter is. active_module_id (Union[Unset, int]): The ID of the payment method's active module you want to start a payment with. If this is a free payment, the attribute is not required. """ basket: int link: str is_external_redirect: bool is_terms_of_service_accepted: bool payment_intent: "PaymentIntent" active_module_id: Union[Unset, int] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: basket = self.basket link = self.link is_external_redirect = self.is_external_redirect is_terms_of_service_accepted = self.is_terms_of_service_accepted payment_intent = self.payment_intent.to_dict() active_module_id = self.active_module_id field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "basket": basket, "link": link, "is_external_redirect": is_external_redirect, "is_terms_of_service_accepted": is_terms_of_service_accepted, "payment_intent": payment_intent, } ) if active_module_id is not UNSET: field_dict["active_module_id"] = active_module_id return field_dict def to_multipart(self) -> types.RequestFiles: files: types.RequestFiles = [] files.append(("basket", (None, str(self.basket).encode(), "text/plain"))) files.append(("link", (None, str(self.link).encode(), "text/plain"))) files.append(("is_external_redirect", (None, str(self.is_external_redirect).encode(), "text/plain"))) files.append( ("is_terms_of_service_accepted", (None, str(self.is_terms_of_service_accepted).encode(), "text/plain")) ) files.append(("payment_intent", (None, json.dumps(self.payment_intent.to_dict()).encode(), "application/json"))) if not isinstance(self.active_module_id, Unset): files.append(("active_module_id", (None, str(self.active_module_id).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: from ..models.payment_intent import PaymentIntent d = dict(src_dict) basket = d.pop("basket") link = d.pop("link") is_external_redirect = d.pop("is_external_redirect") is_terms_of_service_accepted = d.pop("is_terms_of_service_accepted") payment_intent = PaymentIntent.from_dict(d.pop("payment_intent")) active_module_id = d.pop("active_module_id", UNSET) payment_start = cls( basket=basket, link=link, is_external_redirect=is_external_redirect, is_terms_of_service_accepted=is_terms_of_service_accepted, payment_intent=payment_intent, active_module_id=active_module_id, ) payment_start.additional_properties = d return payment_start @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