o
    i                     @   s   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	 d dl
mZ d dlmZ d dlmZ G dd	 d	eZG d
d deZdS )    N)OrderedDict)sha256)Eventsecure_compare)SignatureVerificationError)_APIRequestorc                   @   s"   e Zd ZdZeedfddZdS )Webhooki,  Nc                 C   sT   t | dr
| d} t| ||| tj| td}tj|t	j
|p"tjddd}|S )Ndecodeutf-8)object_pairs_hook)api_keyV1)values	requestorapi_mode)hasattrr
   WebhookSignatureverify_headerjsonloadsr   r   _construct_fromr   _global_with_optionsstriper   )payload
sig_headersecret	tolerancer   dataevent r    o/var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/env/lib/python3.10/site-packages/stripe/_webhook.pyconstruct_event   s   

zWebhook.construct_event)__name__
__module____qualname__DEFAULT_TOLERANCEstaticmethodr"   r    r    r    r!   r	      s
    r	   c                   @   s6   e Zd ZdZedd Zedd Zed	ddZdS )
r   v1c                 C   s$   t j|d| dtd}| S )Nr   )msg	digestmod)hmacnewencoder   	hexdigest)r   r   macr    r    r!   _compute_signature*   s   z#WebhookSignature._compute_signaturec                    sD   dd |  dD }tdd |D d } fdd|D }||fS )Nc                 S   s   g | ]}| d dqS )=   )split.0ir    r    r!   
<listcomp>5   s    zBWebhookSignature._get_timestamp_and_signatures.<locals>.<listcomp>,c                 S   s    g | ]}|d  dkr|d qS )r   t   r    r4   r    r    r!   r7   6        r   c                    s    g | ]}|d   kr|d qS )r   r:   r    r4   schemer    r!   r7   7   r;   )r3   int)headerr=   
list_items	timestamp
signaturesr    r<   r!   _get_timestamp_and_signatures3   s   z.WebhookSignature._get_timestamp_and_signaturesNc                    s   z|  || j\}}W n ty   td||w |s$td| j ||d||f }| || t fdd|D sAtd|||rS|t | k rStd| ||dS )	Nz6Unable to extract timestamp and signatures from headerz+No signatures found with expected scheme %sz%d.%sc                 3   s    | ]}t  |V  qd S Nr   )r5   sexpected_sigr    r!   	<genexpr>Q   s    z1WebhookSignature.verify_header.<locals>.<genexpr>z?No signatures found matching the expected signature for payloadz)Timestamp outside the tolerance zone (%d)T)rC   EXPECTED_SCHEME	Exceptionr   r0   anytime)clsr   r?   r   r   rA   rB   signed_payloadr    rF   r!   r   :   sD   zWebhookSignature.verify_headerrD   )	r#   r$   r%   rI   r'   r0   rC   classmethodr   r    r    r    r!   r   '   s    

r   )r+   r   rL   collectionsr   hashlibr   r   stripe._eventr   stripe._utilr   stripe._errorr   stripe._api_requestorr   objectr	   r   r    r    r    r!   <module>   s    