o
    Q?h	                     @   sh   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ dd Zd	d
 Zdd ZdS )    )	urlencodeAPI)
PROJECT_ID)SERVER_TIMESTAMPdb)getEnterpriseById)saveShopc           
      C   s,  |  d d|  d|  d d}}}|  d}tddd|ddd	d
dd ddd   }|D ]}|j  td|j  q9t|}t	|d	||dd	| |d| t
t
d d d d| }d}t|ru| ddndd||r| dnddt dd} t| }	td|||	f dS )NcurrentUseruidurlenterpriseIdhostnameshopsCredentials==
platformId3consumerKeyconsumerSecretshopsWooCommercezhttps://)r   r   r   platformShopIdplatformNameappIdnamer   	createdAt	updatedAtr   r   z/wc-auth/v1/authorizer   Riverr
read_writez/shopszhttp://localhost:3000/shopsz+https://riverr-enterprise-integrations-dot-z".uc.r.appspot.com/woocommerce/auth)app_namescopeuser_id
return_urlcallback_urlz%s%s?%s)r   )getr   
collectionwhere	referencedeletedocumentidr   r	   r   dictr   r   )
paramsr   r   r   origin	noneShopss
enterpriseendpointquery_string r3   O/var/www/html/riverr-enterprise-integrations-main/functions/WooCommerce/Auth.pyauthUrl   s@   .
6


r5   c                 C   s   |  d}|  d}|  d}tddd|dddd	dd d
dd   }tt|||| |D ]}|jt||d t|j	  dS dS )Nr!   consumer_keyconsumer_secretr   r   r   r   r   r   r   )r   r   TF)
r$   r   r%   r&   printlenr'   updater+   r*   )datar   r   r   refdocr3   r3   r4   saveWooCommerceShop.   s   


6
r>   c                 C   s   t | ||ddd}|S )Nzwc/v3i  )r   r6   r7   versiontimeoutr   )r   r   r   wcapir3   r3   r4   wooAPI>   s   rB   N)urllib.parser   woocommercer   configs.envr   configs.firebaser   r   functions.Enterprisesr   functions.Shopsr	   r5   r>   rB   r3   r3   r3   r4   <module>   s    #