o
    tBhB                     @   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dd Z	dd Z
dd Z  ZS )PaymentsApiz3A 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/payments_api.pyr	      s   zPaymentsApi.__init__c
              
   C   s   d}
| j  }||
7 }|||||||||	d	}t||}t|}ddi}| j jj||d}t| j | | 	|}t
|j}t|tu rM|d}nd}t|||d}|S )	a[
  Does a GET request to /v2/payments.

        Retrieves a list of payments taken by the account making the request.
        Results are eventually consistent, and new payments or changes to
        payments might take several
        seconds to appear.
        The maximum results per page is 100.

        Args:
            begin_time (string, optional): The timestamp for the beginning of
                the reporting period, in RFC 3339 format. Inclusive. Default:
                The current time minus one year.
            end_time (string, optional): The timestamp for the end of the
                reporting period, in RFC 3339 format.  Default: The current
                time.
            sort_order (string, optional): The order in which results are
                listed: - `ASC` - Oldest to newest. - `DESC` - Newest to
                oldest (default).
            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).
            location_id (string, optional): Limit results to the location
                supplied. By default, results are returned for the default
                (main) location associated with the seller.
            total (long|int, optional): The exact amount in the `total_money`
                for a payment.
            last_4 (string, optional): The last four digits of a payment
                card.
            card_brand (string, optional): The brand of the payment card (for
                example, VISA).
            limit (int, optional): The maximum number of results to be
                returned in a single page. It is possible to receive fewer
                results than the specified limit on a given page.  The default
                value of 100 is also the maximum allowed value. If the
                provided value is  greater than 100, it is ignored and the
                default value is used instead.  Default: `100`

        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/payments)	
begin_timeend_time
sort_ordercursorlocation_idtotallast_4
card_brandlimit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   r   r   r   r   	_url_path_query_builder_query_parameters
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   list_payments   s:   ?


zPaymentsApi.list_paymentsc                 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 )at  Does a POST request to /v2/payments.

        Creates a payment using the provided source. You can use this endpoint
                to charge a card (credit/debit card or    
        Square gift card) or record a payment that the seller received outside
        of Square 
        (cash payment from a buyer or a payment that an external entity 
        processed on behalf of the seller).
        The endpoint creates a 
        `Payment` object and returns it in the response.

        Args:
            body (CreatePaymentRequest): 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.   r0   r1   r2   r3   r4   r5   r6   r   r   r   create_paymentu   s    


zPaymentsApi.create_paymentc                 C   r8   )a  Does a POST request to /v2/payments/cancel.

        Cancels (voids) a payment identified by the idempotency key that is
        specified in the
        request.
        Use this method when the status of a `CreatePayment` request is
        unknown (for example, after you send a
        `CreatePayment` request, a network error occurs and you do not get a
        response). In this case, you can
        direct Square to cancel the payment using this endpoint. In the
        request, you provide the same
        idempotency key that you provided in your `CreatePayment` request that
        you want to cancel. After
        canceling the payment, you can submit your `CreatePayment` request
        again.
        Note that if no payment with the specified idempotency key is found,
        no action is taken and the endpoint
        returns successfully.

        Args:
            body (CancelPaymentByIdempotencyKeyRequest): 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/payments/cancelr   r9   r:   r   Nr    r<   r?   r   r   r   !cancel_payment_by_idempotency_key   s    '


z-PaymentsApi.cancel_payment_by_idempotency_keyc                 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/payments/{payment_id}.

        Retrieves details for a specific payment.

        Args:
            payment_id (string): A unique ID for the desired payment.

        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/payments/{payment_id}
payment_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
   rC   r-   r.   r0   r1   r2   r3   r4   r5   r6   r   r   r   get_payment   s$   



zPaymentsApi.get_paymentc                 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 PUT request to /v2/payments/{payment_id}.

        Updates a payment with the APPROVED status.
        You can update the `amount_money` and `tip_money` using this
        endpoint.

        Args:
            payment_id (string): The ID of the payment to update.
            body (UpdatePaymentRequest): 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.

        rB   rC   TrD   r   r9   r:   r   Nr    )r   rG   r   r"   r$   r%   putr>   r   r'   r(   r)   r*   r+   r,   r&   r   r
   rC   r!   r-   r.   r0   r1   r2   r3   r4   r5   r6   r   r   r   update_payment  s&   



zPaymentsApi.update_paymentc                 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/payments/{payment_id}/cancel.

        Cancels (voids) a payment. You can use this endpoint to cancel a
        payment with 
        the APPROVED `status`.

        Args:
            payment_id (string): The ID of the payment to cancel.

        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/payments/{payment_id}/cancelrC   TrD   r   r   r   r   Nr    )r   rG   r   r"   r$   r%   r=   r   r'   r(   r)   r*   r+   r,   r&   r   rH   r   r   r   cancel_paymentR  s$   



zPaymentsApi.cancel_paymentc                 C   rJ   )a  Does a POST request to /v2/payments/{payment_id}/complete.

        Completes (captures) a payment.
        By default, payments are set to complete immediately after they are
        created.
        You can use this endpoint to complete a payment with the APPROVED
        `status`.

        Args:
            payment_id (string): The unique ID identifying the payment to be
                completed.
            body (CompletePaymentRequest): 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/payments/{payment_id}/completerC   TrD   r   r9   r:   r   Nr    )r   rG   r   r"   r$   r%   r=   r>   r   r'   r(   r)   r*   r+   r,   r&   r   rL   r   r   r   complete_payment  s&   



zPaymentsApi.complete_paymentr   )	NNNNNNNNN)__name__
__module____qualname____doc__r	   r7   r@   rA   rI   rM   rN   rO   __classcell__r   r   r   r   r   	   s&    
e7?072r   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
   