o
    tBhV<                     @   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                       sf   e Zd ZdZd fdd	Z					dddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Z  ZS )GiftCardsApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ p/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/gift_cards_api.pyr	      s   zGiftCardsApi.__init__c                 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 )	aQ  Does a GET request to /v2/gift-cards.

        Lists all gift cards. You can specify optional filters to retrieve 
        a subset of the gift cards.

        Args:
            mtype (string, optional): If a [type]($m/GiftCardType) is
                provided, the endpoint returns gift cards of the specified
                type. Otherwise, the endpoint returns gift cards of all
                types.
            state (string, optional): If a [state]($m/GiftCardStatus) is
                provided, the endpoint returns the gift cards in the specified
                state. Otherwise, the endpoint returns the gift cards of all
                states.
            limit (int, optional): If a limit is provided, the endpoint
                returns only the specified number of results per page. The
                maximum value is 50. The default value is 30. For more
                information, see
                [Pagination](https://developer.squareup.com/docs/working-with-a
                pis/pagination).
            cursor (string, optional): A pagination cursor returned by a
                previous call to this endpoint. Provide this cursor to
                retrieve the next set of results for the original query. If a
                cursor is not provided, the endpoint returns the first page of
                the results.  For more information, see
                [Pagination](https://developer.squareup.com/docs/working-with-a
                pis/pagination).
            customer_id (string, optional): If a customer ID is provided, the
                endpoint returns only the gift cards linked to the specified
                customer.

        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/gift-cards)typestatelimitcursorcustomer_id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textr   dictr   )r
   mtyper   r   r   r   	_url_path_query_builder_query_parameters
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   list_gift_cards   s2   2


zGiftCardsApi.list_gift_cardsc                 C      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/gift-cards.

        Creates a digital gift card or registers a physical (plastic) gift
        card. You must activate the gift card before 
        it can be used for payment. For more information, see 
        [Selling gift
        cards](https://developer.squareup.com/docs/gift-cards/using-gift-cards-
        api#selling-square-gift-cards).

        Args:
            body (CreateGiftCardRequest): 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_gift_cardd   s    


zGiftCardsApi.create_gift_cardc                 C   r4   )a  Does a POST request to /v2/gift-cards/from-gan.

        Retrieves a gift card using the gift card account number (GAN).

        Args:
            body (RetrieveGiftCardFromGANRequest): 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.

        z/v2/gift-cards/from-ganr   r5   r6   r   Nr   r8   r;   r   r   r   retrieve_gift_card_from_gan   s    


z(GiftCardsApi.retrieve_gift_card_from_ganc                 C   r4   )a5  Does a POST request to /v2/gift-cards/from-nonce.

        Retrieves a gift card using a secure payment token that represents the
        gift card.

        Args:
            body (RetrieveGiftCardFromNonceRequest): 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.

        z/v2/gift-cards/from-noncer   r5   r6   r   Nr   r8   r;   r   r   r   retrieve_gift_card_from_nonce   s    


z*GiftCardsApi.retrieve_gift_card_from_noncec                 C      d}t |d|ddi}| j }||7 }t |}ddd}| jjj||t |d}t	| j| | 
|}t |j}	t|	tu rK|	d}
nd	}
t||	|
d
}|S )a  Does a POST request to /v2/gift-cards/{gift_card_id}/link-customer.

        Links a customer to a gift card, which is also referred to as adding a
        card on file.

        Args:
            gift_card_id (string): The ID of the gift card to be linked.
            body (LinkCustomerToGiftCardRequest): 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.

        z+/v2/gift-cards/{gift_card_id}/link-customergift_card_idTvalueencoder   r5   r6   r   Nr   r   #append_url_with_template_parametersr   r   r    r!   r9   r:   r   r#   r$   r%   r&   r   r'   r"   r   r
   r@   r   r)   r*   r,   r-   r.   r/   r0   r1   r2   r   r   r   link_customer_to_gift_card   &   



z'GiftCardsApi.link_customer_to_gift_cardc                 C   r?   )a  Does a POST request to /v2/gift-cards/{gift_card_id}/unlink-customer.

        Unlinks a customer from a gift card, which is also referred to as
        removing a card on file.

        Args:
            gift_card_id (string): The ID of the gift card to be unlinked.
            body (UnlinkCustomerFromGiftCardRequest): 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.

        z-/v2/gift-cards/{gift_card_id}/unlink-customerr@   TrA   r   r5   r6   r   Nr   rD   rF   r   r   r   unlink_customer_from_gift_card0  rH   z+GiftCardsApi.unlink_customer_from_gift_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 )al  Does a GET request to /v2/gift-cards/{id}.

        Retrieves a gift card using its ID.

        Args:
            id (string): The ID of the gift card to retrieve.

        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/gift-cards/{id}idTrA   r   r   r   r   Nr   )r   rE   r   r   r    r!   r"   r   r#   r$   r%   r&   r   r'   r   )r
   rJ   r)   r*   r,   r-   r.   r/   r0   r1   r2   r   r   r   retrieve_gift_cardf  s$   



zGiftCardsApi.retrieve_gift_cardr   )NNNNN)__name__
__module____qualname____doc__r	   r3   r<   r=   r>   rG   rI   rK   __classcell__r   r   r   r   r   	   s    
T50166r   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
   