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 )    )
deprecated)	APIHelper)ApiResponse)BaseApic                       s@   e Zd ZdZd fdd	Ze dd Zdd Zd	d
 Z  Z	S )OAuthApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ l/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/o_auth_api.pyr	      s   zOAuthApi.__init__c                 C   s   d}t |d|ddi}| j }||7 }t |}dd|d}| jjj||t |d}| |}	t 	|	j
}
t|
tu rE|
d}nd	}t|	|
|d
}|S )a  Does a POST request to /oauth2/clients/{client_id}/access-token/renew.

        `RenewToken` is deprecated. For information about refreshing OAuth
        access tokens, see
        [Migrate from Renew to Refresh OAuth
        Tokens](https://developer.squareup.com/docs/oauth-api/migrate-to-refres
        h-tokens).
        Renews an OAuth access token before it expires.
        OAuth access tokens besides your application's personal access token
        expire after __30 days__.
        You can also renew expired tokens within __15 days__ of their
        expiration.
        You cannot renew an access token that has been expired for more than
        15 days.
        Instead, the associated user must re-complete the OAuth flow from the
        beginning.
        __Important:__ The `Authorization` header for this endpoint must have
        the
        following format:
        ```
        Authorization: Client APPLICATION_SECRET
        ```
        Replace `APPLICATION_SECRET` with the application secret on the
        Credentials
        page in the [developer
        dashboard](https://developer.squareup.com/apps).

        Args:
            client_id (string): Your application ID, available from the OAuth
                page for your  application on the Developer Dashboard.
            body (RenewTokenRequest): An object containing the fields to POST
                for the request.  See the corresponding object definition for
                field details.
            authorization (string): Client APPLICATION_SECRET

        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./oauth2/clients/{client_id}/access-token/renew	client_idT)valueencodeapplication/jsonacceptContent-TypeAuthorizationheaders
parameterserrorsNbodyr   )r   #append_url_with_template_parametersr   get_base_uri	clean_urlhttp_clientpostjson_serializeexecute_requestjson_deserializetexttypedictgetr   )r
   r   r   authorization	_url_path_query_builder
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   renew_token   s&   5



zOAuthApi.renew_tokenc                 C   s   d}| j  }||7 }t|}dd|d}| j jj||t|d}| |}t|j	}	t
|	tu r:|	d}
nd}
t||	|
d}|S )a  Does a POST request to /oauth2/revoke.

        Revokes an access token generated with the OAuth flow.
        If an account has more than one OAuth access token for your
        application, this
        endpoint revokes all of them, regardless of which token you specify.
        When an
        OAuth access token is revoked, all of the active subscriptions
        associated
        with that OAuth token are canceled immediately.
        __Important:__ The `Authorization` header for this endpoint must have
        the
        following format:
        ```
        Authorization: Client APPLICATION_SECRET
        ```
        Replace `APPLICATION_SECRET` with the application secret on the OAuth
        page for your application on the Developer Dashboard.

        Args:
            body (RevokeTokenRequest): An object containing the fields to POST
                for the request.  See the corresponding object definition for
                field details.
            authorization (string): Client APPLICATION_SECRET

        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/oauth2/revoker   r   r   r   Nr   r   r    r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   )r
   r   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   r   r   revoke_token`   s    )


zOAuthApi.revoke_tokenc                 C   s   d}| j  }||7 }t|}ddd}| j jj||t|d}| |}t|j	}t
|tu r9|d}	nd}	t|||	d}
|
S )a&  Does a POST request to /oauth2/token.

        Returns an OAuth access token and a refresh token unless the 
        `short_lived` parameter is set to `true`, in which case the endpoint 
        returns only an access token.
        The `grant_type` parameter specifies the type of OAuth request. If 
        `grant_type` is `authorization_code`, you must include the
        authorization 
        code you received when a seller granted you authorization. If
        `grant_type` 
        is `refresh_token`, you must provide a valid refresh token. If you are
        using 
        an old version of the Square APIs (prior to March 13, 2019),
        `grant_type` 
        can be `migration_token` and you must provide a valid migration
        token.
        You can use the `scopes` parameter to limit the set of permissions
        granted 
        to the access token and refresh token. You can use the `short_lived`
        parameter 
        to create an access token that expires in 24 hours.
        __Note:__ OAuth tokens should be encrypted and stored on a secure
        server. 
        Application clients should never interact directly with OAuth tokens.

        Args:
            body (ObtainTokenRequest): 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/oauth2/tokenr   )r   r   r   r   Nr   r6   )r
   r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   r   r   obtain_token   s   -


zOAuthApi.obtain_tokenr   )
__name__
__module____qualname____doc__r	   r   r5   r7   r8   __classcell__r   r   r   r   r   	   s    
OAr   N)	deprecationr   square.api_helperr   square.http.api_responser   square.api.base_apir   r   r   r   r   r   <module>   s
   