
    _j                         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	e          Z G d
 de          ZdS )    N)OrderedDict)sha256)Eventsecure_compare)SignatureVerificationError)_APIRequestorc                   .    e Zd ZdZeedfd            ZdS )Webhooki,  Nc                 ,   t          | d          r|                     d          } t                              | |||           t	          j        | t                    }t          j        |t          j
        |pt          j                  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events          S/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/stripe/_webhook.pyconstruct_eventzWebhook.construct_event   s     7H%% 	.nnW--G&&w
FINNNz'[AAA%#816>   
 
 
     )__name__
__module____qualname__DEFAULT_TOLERANCEstaticmethodr$    r%   r#   r   r      s=        /@$   \  r%   r   c                   V    e Zd ZdZed             Zed             Zedd            ZdS )r   v1c                     t          j        |                    d          |                     d          t                    }|                                S )Nr   )msg	digestmod)hmacnewencoder   	hexdigest)r   r   macs      r#   _compute_signaturez#WebhookSignature._compute_signature*   sI    hMM'""w''
 
 

 }}r%   c                     d |                      d          D             }t          d |D             d                   }fd|D             }||fS )Nc                 :    g | ]}|                     d d          S )=   )split.0is     r#   
<listcomp>zBWebhookSignature._get_timestamp_and_signatures.<locals>.<listcomp>5   s$    AAA!aggc1ooAAAr%   ,c                 6    g | ]}|d          dk    |d         S )r   t   r+   r<   s     r#   r?   zBWebhookSignature._get_timestamp_and_signatures.<locals>.<listcomp>6   s%    AAA!QqTS[[1[[[r%   r   c                 8    g | ]}|d          k    |d         S )r   rC   r+   )r=   r>   schemes     r#   r?   zBWebhookSignature._get_timestamp_and_signatures.<locals>.<listcomp>7   s&    AAAq!A$&..ad...r%   )r;   int)headerrE   
list_items	timestamp
signaturess    `   r#   _get_timestamp_and_signaturesz.WebhookSignature._get_timestamp_and_signatures3   sg    AAv||C/@/@AAA
AAzAAA!DEE	AAAAJAAA
*$$r%   Nc                    	 |                      || j                  \  }}n# t          $ r t          d||          w xY w|st          d| j        z  ||          d||fz  }|                     ||          t          fd|D                       st          d||          |r.|t          j                    |z
  k     rt          d|z  ||          dS )Nz6Unable to extract timestamp and signatures from headerz+No signatures found with expected scheme %sz%d.%sc              3   8   K   | ]}t          |          V  d S Nr   )r=   sexpected_sigs     r#   	<genexpr>z1WebhookSignature.verify_header.<locals>.<genexpr>Q   s-      GGq>,22GGGGGGr%   z?No signatures found matching the expected signature for payloadz)Timestamp outside the tolerance zone (%d)T)rK   EXPECTED_SCHEME	Exceptionr   r6   anytime)	clsr   rG   r   r    rI   rJ   signed_payloadrP   s	           @r#   r   zWebhookSignature.verify_header:   sD   		$'$E$E+% %!Izz  	 	 	,H  	  	,*+	   !Iw#77--nfEEGGGGJGGGGG 	,	    	TY[[9%<<<,;iG   ts   " >rN   )	r&   r'   r(   rR   r*   r6   rK   classmethodr   r+   r%   r#   r   r   '   sm        O  \ % % \% % % % [% % %r%   r   )r1   r   rU   collectionsr   hashlibr   r   stripe._eventr   stripe._utilr   stripe._errorr   stripe._api_requestorr	   objectr   r   r+   r%   r#   <module>r`      s       # # # # # #              ' ' ' ' ' ' 4 4 4 4 4 4 / / / / / /    f   09 9 9 9 9v 9 9 9 9 9r%   