o
    ÚtBh_!  ã                   @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    )Ú	APIHelper)ÚApiResponse)ÚBaseApi)ÚOAuth2c                       sN   e Zd ZdZd‡ fdd„	Z					ddd„Zdd	„ Zd
d„ Zdd„ Z‡  Z	S )ÚCardsApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| ƒ ||¡ d S ©N)Úsuperr   Ú__init__)ÚselfÚconfigÚ	call_back©Ú	__class__© úk/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/cards_api.pyr	      s   zCardsApi.__init__Fc                 C   s¨   d}| j  ¡ }||7 }|||||dœ}t ||¡}t |¡}	ddi}
| j jj|	|
d}t | j |¡ |  	|¡}t 
|j¡}t|ƒtu rI| d¡}nd}t|||d}|S )	ao  Does a GET request to /v2/cards.

        Retrieves a list of cards owned by the account making the request.
        A max of 25 cards will be returned.

        Args:
            cursor (string, optional): A pagination cursor returned by a
                previous call to this endpoint. Provide this to retrieve the
                next set of results for your original query.  See
                [Pagination](https://developer.squareup.com/docs/basics/api101/
                pagination) for more information.
            customer_id (string, optional): Limit results to cards associated
                with the customer supplied. By default, all cards owned by the
                merchant are returned.
            include_disabled (bool, optional): Includes disabled cards. By
                default, all enabled cards owned by the merchant are
                returned.
            reference_id (string, optional): Limit results to cards associated
                with the reference_id supplied.
            sort_order (SortOrder, optional): Sorts the returned list by when
                the card was created with the specified order. This field
                defaults to ASC.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        ú	/v2/cards)ÚcursorÚcustomer_idÚinclude_disabledÚreference_idÚ
sort_orderÚacceptúapplication/json©ÚheadersÚerrorsN©Úbodyr   )r   Úget_base_urir   Ú append_url_with_query_parametersÚ	clean_urlÚhttp_clientÚgetr   ÚapplyÚexecute_requestÚjson_deserializeÚtextÚtypeÚdictr   )r
   r   r   r   r   r   Ú	_url_pathÚ_query_builderÚ_query_parametersÚ
_query_urlÚ_headersÚ_requestÚ	_responseÚdecodedÚ_errorsÚ_resultr   r   r   Ú
list_cards   s2   *
ûþ
ÿ
zCardsApi.list_cardsc                 C   s–   d}| j  ¡ }||7 }t |¡}dddœ}| j jj||t |¡d}t | j |¡ |  	|¡}t 
|j¡}t|ƒtu r@| d¡}	nd}	t|||	d}
|
S )aé  Does a POST request to /v2/cards.

        Adds a card on file to an existing merchant.

        Args:
            body (CreateCardRequest): An object containing the fields to POST
                for the request.  See the corresponding object definition for
                field details.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        r   r   )r   zContent-Type)r   Ú
parametersr   Nr   )r   r   r   r    r!   ÚpostÚjson_serializer   r#   r$   r%   r&   r'   r(   r"   r   )r
   r   r)   r*   r,   r-   r.   r/   r0   r1   r2   r   r   r   Úcreate_card\   s    

þ
zCardsApi.create_cardc                 C   s¢   d}t  |d|ddœi¡}| j ¡ }||7 }t  |¡}ddi}| jjj||d}t | j|¡ |  	|¡}t  
|j¡}t|ƒtu rF| d¡}	nd	}	t|||	d
}
|
S )ao  Does a GET request to /v2/cards/{card_id}.

        Retrieves details for a specific Card.

        Args:
            card_id (string): Unique ID for the desired Card.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        z/v2/cards/{card_id}Úcard_idT©ÚvalueÚencoder   r   r   r   Nr   )r   Ú#append_url_with_template_parametersr   r   r    r!   r"   r   r#   r$   r%   r&   r'   r(   r   ©r
   r8   r)   r*   r,   r-   r.   r/   r0   r1   r2   r   r   r   Úretrieve_cardŒ   s$   
ÿ

ÿ
zCardsApi.retrieve_cardc                 C   s¢   d}t  |d|ddœi¡}| j ¡ }||7 }t  |¡}ddi}| jjj||d}t | j|¡ |  	|¡}t  
|j¡}t|ƒtu rF| d¡}	nd	}	t|||	d
}
|
S )aØ  Does a POST request to /v2/cards/{card_id}/disable.

        Disables the card, preventing any further updates or charges.
        Disabling an already disabled card is allowed but has no effect.

        Args:
            card_id (string): Unique ID for the desired Card.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        z/v2/cards/{card_id}/disabler8   Tr9   r   r   r   r   Nr   )r   r<   r   r   r    r!   r5   r   r#   r$   r%   r&   r'   r(   r"   r   r=   r   r   r   Údisable_card¼   s$   
ÿ

ÿ
zCardsApi.disable_cardr   )NNFNN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r3   r7   r>   r?   Ú__classcell__r   r   r   r   r   	   s    
ûL00r   N)	Úsquare.api_helperr   Úsquare.http.api_responser   Úsquare.api.base_apir   Úsquare.http.auth.o_auth_2r   r   r   r   r   r   Ú<module>   s
   