o
    Q?h	                     @   s   d dl Z d dlZd dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZ d dlmZmZ d dlmZ edeZd	d
 Zeddd Zeddd Zeddd Zeddd Zeddd Z eddd Z!dS )    N)	BlueprintResponseabortrequest)getAppCredentials)sendResponse)AuthFulfillmentOrdersProducts)confirmChargecreateRecurringCharge)getShopByIdappc                 C   s:   t | d|tj }t|}t |t	|dS )Nzutf-8)
hmacnewencodehashlibsha256digestbase64	b64encodecompare_digeststr)	apiSecretdatahmac_headerr   computed_hmac r   ?/var/www/html/riverr-enterprise-integrations-main/routes/app.pyverify_webhook   s   
r    z/authc                   C      t tjtddS NFauthRequired)r   r   shopifyAuthr   r   r   r   r   auth      r&   z
/auth/<id>c                 C   s"   t j }ttdd| i|S )Nidr   )r   argsto_dictr   shopifyDirectAuthdict)r(   r)   r   r   r   
directAuth   s   
r-   z/anonymous-authc                   C   r!   r"   )r   r   	anonyAuthr   r   r   r   r   anonymousAuth   r'   r/   z/<enterpriseId>/cdrc                 C   N   t d|  }t }t|d|tjd}|stdddS ttj	tddS 	N2r   zX-Shopify-Hmac-SHA256zWebhook verification failed.i  )statusFr#   )
r   r   get_datar    getheadersr   r   r   customDataRequestenterpriseIdr   r   verifiedr   r   r   r7          r7   z/<enterpriseId>/cdec                 C   r0   r1   )
r   r   r4   r    r5   r6   r   r   r   customersRedactr8   r   r   r   r<   )   r;   r<   z/<enterpriseId>/sdec                 C   sV   t d|  }t }t| t|d|tjd}|s#tdddS tt	j
tddS r1   )r   r   r4   printr    r5   r6   r   r   r   
shopRedactr8   r   r   r   r>   2   s   r>   )"r   r   r   flaskr   r   r   r   functions.Applicationsr   functions.Responser   functions.Shopifyr   r	   r
   r   functions.Shopify.Charger   r   functions.Shopsr   __name__appBlueprintr    router&   r5   r-   r/   postr7   r<   r>   r   r   r   r   <module>   s.    





