Pular para conteúdo

Customers reference

CustomerClient

Bases: BaseClient

Source code in abacatepay/customers/client.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class CustomerClient(BaseClient):
    def create(self, customer: Optional[CustomerMetadata | dict] = None, **kwargs) -> Customer:
        """creates a new customer using an or named arguments

        Args:
            customer (Optional[CustomerMetadata  |  dict], optional): You customer data, it can be \
            a dict, an instance of `abacatepay.customers.CustomerMetadata`.

        Returns:
            Customer: An instance of the new customer.
        """
        logger.debug(f"Creating customer with URL: {BASE_URL}/customer/create")

        json_data = prepare_data(customer or kwargs, CustomerMetadata)
        response = self._request(
            f"{BASE_URL}/customer/create",
            method="POST",
            json=json_data,
        )
        return Customer(**response.json()["data"])

    def list(self) -> list[Customer]:
        logger.debug(f"Listing customers with URL: {BASE_URL}/customer/list")
        response = self._request(f"{BASE_URL}/customer/list", method="GET")
        return [Customer(**bill) for bill in response.json()["data"]]

create(customer=None, **kwargs)

creates a new customer using an or named arguments

Parameters:

Name Type Description Default
customer Optional[CustomerMetadata | dict]

You customer data, it can be a dict, an instance of abacatepay.customers.CustomerMetadata.

None

Returns:

Name Type Description
Customer Customer

An instance of the new customer.

Source code in abacatepay/customers/client.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def create(self, customer: Optional[CustomerMetadata | dict] = None, **kwargs) -> Customer:
    """creates a new customer using an or named arguments

    Args:
        customer (Optional[CustomerMetadata  |  dict], optional): You customer data, it can be \
        a dict, an instance of `abacatepay.customers.CustomerMetadata`.

    Returns:
        Customer: An instance of the new customer.
    """
    logger.debug(f"Creating customer with URL: {BASE_URL}/customer/create")

    json_data = prepare_data(customer or kwargs, CustomerMetadata)
    response = self._request(
        f"{BASE_URL}/customer/create",
        method="POST",
        json=json_data,
    )
    return Customer(**response.json()["data"])

Customer

Bases: CustomerInline

Customer returned by API.

Parameters:

Name Type Description Default
id CustomerID

the customer unique ID in abacatepay.

required
email str

the customer's email

required
name str

the customer's name

required
cellphone str

the customer's phone number

required
Source code in abacatepay/customers/models.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Customer(CustomerInline):
    """
    Customer returned by API.

    Args:
        id (CustomerID): the customer unique ID in abacatepay.
        tax_id (str) the customer identification (CPF or CNPJ).
        email (str): the customer's email
        name (str): the customer's name
        cellphone (str): the customer's phone number
    """
    id: CustomerID

    @property
    def tax_id(self) -> str:
        """the customer identification (CPF or CNPJ)."""
        return self.metadata.tax_id

    @property
    def name(self) -> str:
        """the customer's name"""
        return self.metadata.name

    @property
    def email(self) -> str:
        """the customer's email"""
        return self.metadata.email

    @property
    def cellphone(self) -> str:
        """the customer's phone number"""
        return self.metadata.cellphone

cellphone property

the customer's phone number

email property

the customer's email

name property

the customer's name

tax_id property

the customer identification (CPF or CNPJ).

CustomerInline

Bases: BaseModel

The customer model attached to other models

Parameters:

Name Type Description Default
metadata Customer

the metadata of the customer.

required
Source code in abacatepay/customers/models.py
23
24
25
26
27
28
29
class CustomerInline(BaseModel):
    """The customer model attached to other models

    Args:
        metadata (Customer): the metadata of the customer.
    """
    metadata: CustomerMetadata

CustomerMetadata

Bases: BaseModel

Customer model

Parameters:

Name Type Description Default
tax_id str

the customer identifier such as CPF or CNPJ.

required
name str

the customer name

required
email str

the customer email address

required
cellphone

(str): the customer phone number.

required
Source code in abacatepay/customers/models.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class CustomerMetadata(BaseModel):
    """Customer model

    Args:
        tax_id (str):  the customer identifier such as CPF or CNPJ.
        name (str): the customer name
        email (str): the customer email address
        cellphone: (str): the customer phone number.
    """
    tax_id: str = Field(
        serialization_alias='taxId',
        validation_alias=AliasChoices('taxId', 'tax_id'),
    )
    name: str
    email: str
    cellphone: str