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                       s6   e Zd ZdZd	 fdd	Z	d	ddZdd Z  ZS )
MerchantsApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ o/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/merchants_api.pyr	      s   zMerchantsApi.__init__c                 C   s   d}| j  }||7 }d|i}t||}t|}ddi}| j jj||d}t| j | | 	|}t
|j}	t|	tu rE|	d}
nd}
t||	|
d}|S )	a  Does a GET request to /v2/merchants.

        Returns `Merchant` information for a given access token.
        If you don't know a `Merchant` ID, you can use this endpoint to
        retrieve the merchant ID for an access token.
        You can specify your personal access token to get your own merchant
        information or specify an OAuth token
        to get the information for the  merchant that granted you access.
        If you know the merchant ID, you can also use the
        [RetrieveMerchant]($e/Merchants/RetrieveMerchant)
        endpoint to get the merchant information.

        Args:
            cursor (int, optional): The cursor generated by the previous
                response.

        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/merchantscursor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   	_url_path_query_builder_query_parameters
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   list_merchants   s*   


zMerchantsApi.list_merchantsc                 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 GET request to /v2/merchants/{merchant_id}.

        Retrieve a `Merchant` object for the given `merchant_id`.

        Args:
            merchant_id (string): The ID of the merchant to retrieve. If the
                string "me" is supplied as the ID, then retrieve the merchant
                that is currently accessible to this call.

        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/merchants/{merchant_id}merchant_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
   r/   r$   r%   r'   r(   r)   r*   r+   r,   r-   r   r   r   retrieve_merchantM   s$   



zMerchantsApi.retrieve_merchantr   )__name__
__module____qualname____doc__r	   r.   r3   __classcell__r   r   r   r   r   	   s    
=r   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
   