o
    Q?h                     @   s   d dl mZmZmZ d dlmZ d dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlZd dlmZmZmZmZmZmZ dd Zd	d
 Zdd Zdd ZdS )    )SANDBOXSERVER_TIMESTAMPdb)getAppCredentialsN)saveShop)	API_Error)OrdersProductsListingsItemsCatalogCatalogItemsInventoriesc                  C   s   t d} t| }|S )N   )osurandombase64	b64encode)randomstate r   J/var/www/html/riverr-enterprise-integrations-main/functions/Amazon/Auth.pygenerate_state_parameter	   s   

r   c                 C   s`   |  d d}d|  d d}td| }| d}t }d| d	| d
| }t||dS )NcurrentUserenterpriseIdhttps://hostname/shops7appIdzGhttps://sellercentral.amazon.com/apps/authorize/consent?application_id=z&state=z&redirect_uri=)urlr   )getr   r   dict)paramsr   redirect_uriappr   r   r   r   r   r   authUrl   s   
r%   c              	   C   s  |  d d}|  d d}|  d d}|  d}td| }| d| d}}|  d	}|  d
}	|  d}
d}td|||
d| dd}| dtddd d}tj||ddid}|jdv r| }| d}| d}| d}| d}tj|td|||dddid}|jdv r| }| d}| d}| d}| d}td1i d|ddd|d |d!| d"d#td$td%|  d&| d'd(d)d|  d*d+|d,|d-|d.|d/|	d0|
d|}|S t	|j
|j)2Nr   r   displayNameuidr   r   apiKey	apiSecretselling_partner_idmws_auth_tokenspapi_oauth_codez$https://api.amazon.com/auth/o2/tokenauthorization_coder   r   )
grant_type	client_idclient_secretcoder#   marketplaceUSz https://sellercentral.amazon.com)idr   r   zContent-Typez!application/x-www-form-urlencoded)dataheaders)      access_tokenrefresh_token
expires_in
token_type)r.   r/   r0   r:   
platformIdplatformShopIdr   r4   	createdAt	updatedAtnameshopNamez's Amazon ShopplatformNameAmazonshopUrlaccessTokenrefreshToken	expiresIn	tokenType	authToken	oauthCoder   )r    r   r!   requestspoststatus_codejsonr   r   r   text)r"   r   r&   r'   r   r$   clientIdclientSecretr*   r+   r,   lwaUrllwaBodyr2   resr5   r9   r:   r;   r<   shopr   r   r   rJ      s   















	

rJ   c                 C   s   t | dddddd}|S )Nz=amzn1.application-oa2-client.e1a6249812354517bedb25cfa235d7d6@a673880d59f6c9316b76aae8edac205851e34fcf2a48a3844b2f700ba7776946AKIA6P6DU7MLYWOG327Oz(ENzvf4BFZa/OAHOZcMj/ZxtRSzWB6doSM+/WV7cRz$arn:aws:iam::996305861399:role/Admin)r:   
lwa_app_idlwa_client_secretaws_access_keyaws_secret_keyrole_arn)r!   )rG   credentialsr   r   r   createCredentialsU   s   r_   )configs.firebaser   r   r   functions.Applicationsr   r   r   rL   functions.Shopsr   functions.Responser   
sp_api.apir   r	   r
   r   r   r   r   r%   rJ   r_   r   r   r   r   <module>   s     
=