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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 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&ed-d.d/ Z'ed0d1d2 Z(ed3d4d5 Z)ed6d7d8 Z*ed9d:d; Z+ed<d=d> Z,d?d@ Z-dS )A    N)	BlueprintResponseabortrequest)getAppCredentials)sendResponse)AuthFulfillmentOrdersProducts)confirmChargecreateRecurringCharge)getShopByIdshopifyz/authc                   C      t tjtddS NFauthRequired)r   r   shopifyAuthr    r   r   C/var/www/html/riverr-enterprise-integrations-main/routes/shopify.py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/anonymous-tokenc                   C   r   r   r   r   
anonyTokenr   r   r   r   r   anonymousToken   r   r#   z/tokenc                   C      t tjtS Nr!   r   r   r   r   token       r&   z/cart-placementsc                   C   r$   r%   )r   r   shopifyCustomizerr   r   r   r   r   r(   $   r'   r(   z	/productsc                   C   r   r   )r   r   updateAllProductsr   r   r   r   r   products(   r   r*   z/ordersc                   C   r   r   )r   r
   updateAllOrdersr   r   r   r   r   orders,   r   r,   z/pub-sub/ordersc                   C   r   r   )r   r
   acceptPubsubRequestr   r   r   r   r   pubsubOrders0   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2	apiSecretX-Shopify-Hmac-SHA256zWebhook verification failed.  )statusFr   )
r   r   get_dataverify_webhookgetheadersr   r   r   customDataRequestenterpriseIdappdataverifiedr   r   r   r:   8      r:   z/<enterpriseId>/cdec                 C   r/   r0   )
r   r   r6   r7   r8   r9   r   r   r   customersRedactr;   r   r   r   rA   A   r@   rA   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 r0   )r   r   r6   printr7   r8   r9   r   r   r   
shopRedactr;   r   r   r   rC   J   s   rC   z+/fulfillment/fulfillment_order_notificationc                   C   r   r   )r   r
   fulfillmentRequestr   r   r   r   r   rD   T   r   rD   z"/fulfillment/connect_item_locationc                   C   r$   r%   )r   r   $connectProductToLocationAfterMappingr   r   r   r   r   rE   X   r'   rE   z/webhooks/ordersc                   C   r$   r%   )r   r
   orderWebhookr   r   r   r   r   ordersWebhook\   r'   rG   z/webhooks/<shopId>/ordersc                 C   sZ   t  }t| }|d}t|}t|d|t jd}|s$td tt	j
t | ddS )NappIdr2   r3   r4   F)r   r   )r   r6   r   r8   r   r7   r9   r   r   r
   ordersWebhookEvent)shopIdr>   shoprH   r=   r?   r   r   r   rI   `   s   
rI   z/subscriptionc                   C   
   t ttS r%   )r   r   r   r   r   r   r   subscriptionk      
rM   z/confirm-subscriptionc                   C   rL   r%   )r   r   r   r   r   r   r   confirmSubscriptiono   rN   rO   c                 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)r2   r>   hmac_headerrU   computed_hmacr   r   r   r7   s   s   
r7   ).rV   rS   rP   flaskr   r   r   r   functions.Applicationsr   functions.Responser   functions.Shopifyr   r	   r
   r   functions.Shopify.Charger   r   functions.Shopsr   __name__shopifyBlueprintrouter   r8   r   r    postr#   r&   r(   r*   r,   r.   r:   rA   rC   rD   rE   rG   rI   rM   rO   r7   r   r   r   r   <module>   s^    












	






