o
    tBhP                     @   sP   d dl mZ 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)FileWrapper)BaseApi)OAuth2c                       s|   e Zd ZdZd fdd	Z			dddZdd Zd	d
 Z	dddZ		dddZ	dd Z
dd Zdd Zdd Z  ZS )DisputesApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ n/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/disputes_api.pyr
      s   zDisputesApi.__init__c                 C   s   d}| j  }||7 }|||d}t||}t|}ddi}| j jj||d}	t| j |	 | 	|	}
t
|
j}t|tu rG|d}nd}t|
||d}|S )	a  Does a GET request to /v2/disputes.

        Returns a list of disputes associated with a particular account.

        Args:
            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. For
                more information, see
                [Pagination](https://developer.squareup.com/docs/basics/api101/
                pagination).
            states (DisputeState, optional): The dispute states to filter the
                result. If not specified, the endpoint returns all open
                disputes (the dispute status is not `INQUIRY_CLOSED`, `WON`,
                or `LOST`).
            location_id (string, optional): The ID of the location for which
                to return a list of disputes. If not specified, the endpoint
                returns all open disputes (the dispute status is not
                `INQUIRY_CLOSED`, `WON`, or `LOST`) associated with all
                locations.

        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/disputes)cursorstateslocation_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texttypedictr   )r   r   r   r   	_url_path_query_builder_query_parameters
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   list_disputes   s.   &


zDisputesApi.list_disputesc                 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/disputes/{dispute_id}.

        Returns details about a specific dispute.

        Args:
            dispute_id (string): The ID of the dispute you want more details
                about.

        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/disputes/{dispute_id}
dispute_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   r2   r'   r(   r*   r+   r,   r-   r.   r/   r0   r   r   r   retrieve_disputeW   s$   



zDisputesApi.retrieve_disputec                 C      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 )u  Does a POST request to /v2/disputes/{dispute_id}/accept.

        Accepts the loss on a dispute. Square returns the disputed amount to
        the cardholder and
        updates the dispute state to ACCEPTED.
        Square debits the disputed amount from the seller’s Square account. If
        the Square account
        does not have sufficient funds, Square debits the associated bank
        account.

        Args:
            dispute_id (string): The ID of the dispute you want to accept.

        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/disputes/{dispute_id}/acceptr2   Tr3   r   r   r   r   Nr   r   r7   r   r   r   r   postr   r!   r"   r#   r$   r%   r&   r    r   r8   r   r   r   accept_dispute   s$   



zDisputesApi.accept_disputec                 C   s   d}t |d|ddi}| j }||7 }d|i}t ||}t |}ddi}| jjj||d}t	| j| | 
|}	t |	j}
t|
tu rP|
d	}nd
}t|	|
|d}|S )a  Does a GET request to /v2/disputes/{dispute_id}/evidence.

        Returns a list of evidence associated with a dispute.

        Args:
            dispute_id (string): The ID of the dispute.
            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. For
                more information, see
                [Pagination](https://developer.squareup.com/docs/basics/api101/
                pagination).

        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/disputes/{dispute_id}/evidencer2   Tr3   r   r   r   r   r   Nr   )r   r7   r   r   r   r   r   r    r   r!   r"   r#   r$   r%   r&   r   )r   r2   r   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r   r   list_dispute_evidence   s0   



z!DisputesApi.list_dispute_evidencec                 C   s   d}t |d|ddi}| j }||7 }t |}t|tr'|j}|j}n|}d}dt 	|df|j
||fd}	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/disputes/{dispute_id}/evidence-files.

        Uploads a file to use as evidence in a dispute challenge. The endpoint
        accepts HTTP
        multipart/form-data file uploads in HEIC, HEIF, JPEG, PDF, PNG, and
        TIFF formats.

        Args:
            dispute_id (string): The ID of the dispute you want to upload
                evidence for.
            request (CreateDisputeEvidenceFileRequest, optional): Defines the
                parameters for a `CreateDisputeEvidenceFile` request.
            image_file (typing.BinaryIO, optional): TODO: type description
                here.

        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/disputes/{dispute_id}/evidence-filesr2   Tr3   z
image/jpegNzapplication/json; charset=utf-8)request
image_filer   r   )r   filesr   r   )r   r7   r   r   r   
isinstancer   file_streamcontent_typejson_serializenamer   r<   r   r!   r"   r#   r$   r%   r&   r    r   )r   r2   r?   r@   r'   r(   r*   image_file_wrapperimage_file_content_type_filesr+   r,   r-   r.   r/   r0   r   r   r   create_dispute_evidence_file   s4    





z(DisputesApi.create_dispute_evidence_filec                 C   s   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/disputes/{dispute_id}/evidence-text.

        Uploads text to use as evidence for a dispute challenge.

        Args:
            dispute_id (string): The ID of the dispute you want to upload
                evidence for.
            body (CreateDisputeEvidenceTextRequest): 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/disputes/{dispute_id}/evidence-textr2   Tr3   r   )r   zContent-Type)r   
parametersr   Nr   )r   r7   r   r   r   r   r<   rE   r   r!   r"   r#   r$   r%   r&   r    r   )r   r2   r   r'   r(   r*   r+   r,   r-   r.   r/   r0   r   r   r   create_dispute_evidence_textC  s&   



z(DisputesApi.create_dispute_evidence_textc                 C   s   d}t ||dd|ddd}| j }||7 }t |}ddi}| jjj||d}t| j| | 	|}t 
|j}	t|	tu rJ|	d}
nd	}
t||	|
d
}|S )a  Does a DELETE request to /v2/disputes/{dispute_id}/evidence/{evidence_id}.

        Removes specified evidence from a dispute.
        Square does not send the bank any evidence that is removed. Also, you
        cannot remove evidence after
        submitting it to the bank using
        [SubmitEvidence]($e/Disputes/SubmitEvidence).

        Args:
            dispute_id (string): The ID of the dispute you want to remove
                evidence from.
            evidence_id (string): The ID of the evidence you want to remove.

        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.

        0/v2/disputes/{dispute_id}/evidence/{evidence_id}Tr3   r2   evidence_idr   r   r   r   Nr   )r   r7   r   r   r   r   deleter   r!   r"   r#   r$   r%   r&   r    r   r   r2   rO   r'   r(   r*   r+   r,   r-   r.   r/   r0   r   r   r   delete_dispute_evidencey  &   


z#DisputesApi.delete_dispute_evidencec                 C   s   d}t ||dd|ddd}| j }||7 }t |}ddi}| jjj||d}t| j| | 	|}t 
|j}	t|	tu rJ|	d}
nd	}
t||	|
d
}|S )a  Does a GET request to /v2/disputes/{dispute_id}/evidence/{evidence_id}.

        Returns the evidence metadata specified by the evidence ID in the
        request URL path
        You must maintain a copy of the evidence you upload if you want to
        reference it later. You cannot
        download the evidence after you upload it.

        Args:
            dispute_id (string): The ID of the dispute that you want to
                retrieve evidence from.
            evidence_id (string): The ID of the evidence 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.

        rM   Tr3   rN   r   r   r   r   Nr   r6   rQ   r   r   r   retrieve_dispute_evidence  rS   z%DisputesApi.retrieve_dispute_evidencec                 C   r:   )a:  Does a POST request to /v2/disputes/{dispute_id}/submit-evidence.

        Submits evidence to the cardholder's bank.
        Before submitting evidence, Square compiles all available evidence.
        This includes evidence uploaded
        using the
        [CreateDisputeEvidenceFile]($e/Disputes/CreateDisputeEvidenceFile)
        and
        [CreateDisputeEvidenceText]($e/Disputes/CreateDisputeEvidenceText)
        endpoints and
        evidence automatically provided by Square, when available.

        Args:
            dispute_id (string): The ID of the dispute that you want to submit
                evidence for.

        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/disputes/{dispute_id}/submit-evidencer2   Tr3   r   r   r   r   Nr   r;   r8   r   r   r   submit_evidence  s$   



zDisputesApi.submit_evidencer   )NNN)NN)__name__
__module____qualname____doc__r
   r1   r9   r=   r>   rJ   rL   rR   rT   rU   __classcell__r   r   r   r   r   
   s$    
F18
@
G688r   N)square.api_helperr   square.http.api_responser   square.utilities.file_wrapperr   square.api.base_apir   square.http.auth.o_auth_2r   r   r   r   r   r   <module>   s   