
    <@gu                        U d dl mZmZ d dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZmZmZmZ d dlZd dlmZmZmZ d dlZd dlmZmZmZmZm Z  d dl!m"Z" d dl#m$Z% 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/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA erd dlBmCZC ed   ZDdaEeeF   eGd<    G d deH      ZIy)    )BytesIOIOBaseN)
AnyAsyncIterableDictListMappingOptionalTupleUnioncastClassVar)TYPE_CHECKINGLiteralNoReturnUnpack)urlsplit
urlunsplitparse_qs)	log_debuglog_infodashboard_link_convert_to_stripe_objectget_api_mode)VERSION)MultipartDataGenerator)	urlencode)_api_encode_json_encode_date_callback)StripeResponseStripeStreamResponseStripeStreamResponseAsync)RequestOptionsmerge_options)RequestorOptions_GlobalRequestorOptions)
HTTPClientnew_default_http_clientnew_http_client_async_fallback)AppInfo)BaseAddress)ApiMode)StripeObject)getpostdelete_default_proxyc                      e Zd ZU dZed   ed<   	 	 d.dee   dee   fdZ	defdZ
dee   dd fd	Zed
        Zed        Zed        Zed        Zed        Zedee   dd fd       Zed        Z	 	 d.dddededeeeef      dee   dedeee      ddfdZ	 	 d.dddededeeeef      dee   dedeee      ddfdZ	 	 d.dddededeeeef      dee   dedeee      defdZ 	 	 d.dddededeeeef      dee   dedeee      de!fdZ"de#fdZ$d Z%d Z&d Z'de(d e)defd!Z*	 	 d.dddededeeeef      dee   ded e)deee      fd"Z+	 	 	 d/dddededeeeef      dee   d#e,ded e)deee      de-e.e/eeef   f   fd$Z0	 	 	 d/dddededeeeef      dee   d#e,ded e)deee      de-e1e2   e/eeef   f   fd%Z3d& Z4d'e.d(e/d)eeef   d e)de5f
d*Z6d+e7d(e/d)eeef   d e)def
d,Z8d+e1e2   d(e/d)eeef   d e)de!f
d-Z9y)0_APIRequestorNz_APIRequestor|None	_instanceoptionsclientc                 8    |
t               }|| _        || _        y N)r%   _options_client)selfr5   r6   s      T/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/stripe/_api_requestor.py__init__z_APIRequestor.__init__H   s    
 ?&(G    returnc           	         | j                   }|t        j                  sQt        j                  t        j                  d}t        ddt        di |i|t        _        t        j                  an,t        j                  t        k7  rdd l}|j                  d       t        j                  J t        j                  S |S )N)verify_ssl_certsproxyasync_fallback_clientr   zstripe.proxy was updated after sending a request - this is a no-op. To use a different proxy, set stripe.default_http_client to a new client configured with the proxy. )
r:   stripedefault_http_clientrA   rB   r(   r)   r1   warningswarn)r;   r6   kwargsrG   s       r<   _get_http_clientz_APIRequestor._get_http_clientV   s    > --(.(?(?#\\ .E .*H + +. 	.* "(/1 --999---r>   c                     |xs i }| j                   j                         }dD ]  }||v s||   ||   ||<    t        t        di || j                        S )N)api_keystripe_accountstripe_versionr5   r6   rD   )r9   to_dictr3   r%   r:   )r;   r5   new_optionskeys       r<   _replace_optionsz_APIRequestor._replace_optionsx   sl     -Rmm++-B 	0Cg~'#,":#*3<C 	0 $3{3DLL
 	
r>   c                 .    | j                   j                  S r8   )r9   rL   r;   s    r<   rL   z_APIRequestor.api_key   s    }}$$$r>   c                 .    | j                   j                  S r8   )r9   rM   rU   s    r<   rM   z_APIRequestor.stripe_account       }}+++r>   c                 .    | j                   j                  S r8   )r9   rN   rU   s    r<   rN   z_APIRequestor.stripe_version   rW   r>   c                 .    | j                   j                  S r8   )r9   base_addressesrU   s    r<   rZ   z_APIRequestor.base_addresses   rW   r>   c                 `    | j                    | t               d      | _         | j                   S )z
        Returns the singleton instance of _APIRequestor, to be used when
        calling a static method such as stripe.Customer.create(...)
        NrO   )r4   r&   )clss    r<   _global_instancez_APIRequestor._global_instance   s*     == (?(A$OCM}}r>   paramsc                  H    t         j                         j                  |       S r8   )r3   r]   rS   )r^   s    r<   _global_with_optionsz"_APIRequestor._global_with_options   s     --/@@HHr>   c                 R    |d   }|d   r|d|d   z  }|d   r|d|d   dz  }|S )Nnameversion/urlz ()rD   )r\   infostrs      r<   _format_app_infoz_APIRequestor._format_app_info   s@    6l	?DO--C;d5k++C
r>   )usagemethodre   base_addressrj   r-   c          
          t        |      }| j                  |      }|j                  |j                         ||d||||      \  }	}
}|j	                  |	|
||      }t        ||||      }|S NFis_streamingapi_moderl   r5   rj   )respr^   	requestorrq   )r   rS   request_rawlower_interpret_responser   r;   rk   re   r^   r5   rl   rj   rq   rs   rbodyrcoderheadersrr   objs                 r<   requestz_APIRequestor.request   s      $))'2	!*!6!6LLN% "7 	"
uh ,,UE8XN'	
 
r>   c          
         K   t        |      }| j                  |      }|j                  |j                         ||d||||       d {   \  }	}
}|j	                  |	|
||      }t        ||||      }|S 7 -wrn   )r   rS   request_raw_asyncru   rv   r   rw   s                 r<   request_asyncz_APIRequestor.request_async   s       $))'2	'0'B'BLLN% (C 	(
 	"
uh ,,UE8XN'	
 
'	"
s   AA9	A7
.A9c          
          t        |      }| j                  |j                         ||d||||      \  }}	}
| j                  t	        t
        |      |	|
|      }|S NTro   )r   rt   ru   _interpret_streaming_responser   r   r;   rk   re   r^   r5   rl   rj   rq   streamry   rz   rr   s               r<   request_streamz_APIRequestor.request_stream   sv      $"&"2"2LLN% #3 	#
x 11  
 r>   c          
         K   t        |      }| j                  |j                         ||d||||       d {   \  }}	}
| j                  ||	|
|       d {   }|S 7 &7 wr   )r   r~   ru   #_interpret_streaming_response_asyncr   s               r<   request_stream_asyncz"_APIRequestor.request_stream_async  s       $(,(>(>LLN% )? 	)
 	#
x ==	
 
 !	#

s!   6A#AA#A!A#!A#c                 "   	 |d   }d }t	        |t
              r| j                  |||||      }|/|dk(  r| j                  |||||      n| j                  |||||      }|# t         t        f$ r t        j                  d||fz  |||      w xY w)Nerrorz@Invalid response object from API: %r (HTTP response code was %d)V2)	KeyError	TypeErrorr   APIError
isinstancerh   specific_oauth_errorspecific_v2_api_errorspecific_v1_api_error)r;   rx   ry   rr   rz   rq   
error_dataerrs           r<   handle_error_responsez#_APIRequestor.handle_error_response-  s    		gJ 
 j#&++udHjC ;
 t# **5$* //5$*  	= )$ 	.."EN+ 	s   A! !-Bc           	      r   |j                  d      }|j                  d      }|j                  d      }||||||d}	t        d||j                  d      ||j                  d             |dk(  rt        j                  ||||||      S |d	k(  rt        j                  d
i |	S | j                  |||||      S )Ntypecodemessage)r   	http_bodyhttp_status	json_bodyheadersr   zStripe v2 API error receivedparam
error_code
error_typeerror_messageerror_paramidempotency_errortemporary_session_expiredrD   )r.   r   r   IdempotencyErrorTemporarySessionExpiredErrorr   )
r;   rx   ry   rr   rz   r   r   r   r   
error_argss
             r<   r   z#_APIRequestor.specific_v2_api_errorR  s    ~~f%~~f%..+ 

 	*!~~f-!"w/	
 &&))  0055C
CC ))5$*
 	
r>   c           	         t        d|j                  d      |j                  d      |j                  d      |j                  d             |dk(  s|dk(  r<|j                  d      d	k(  r(t        j                  |j                  d      ||||      S |d
v r|j                  d      dk(  r(t        j                  |j                  d      ||||      S t        j
                  |j                  d      |j                  d      |j                  d      ||||      S |dk(  r(t        j                  |j                  d      ||||      S |dk(  rHt        j                  |j                  d      |j                  d      |j                  d      ||||      S |dk(  r(t        j                  |j                  d      ||||      S t        j                  |j                  d      ||||      S )NzStripe v1 API error receivedr   r   r   r   r   i    
rate_limit)r   i  r   i  i  i  )
r   r.   r   RateLimitErrorr   InvalidRequestErrorAuthenticationError	CardErrorPermissionErrorr   )r;   rx   ry   rr   rz   r   s         r<   r   z#_APIRequestor.specific_v1_api_errory  s   *!~~f-!~~f-$..3"w/	
 C<SLZ^^F3|C''y)5%x  j ~~f%)<<--NN9-ueT8  00NN9-NN7+NN6*  c\,,y)5%x  c\??y)w'v&  c\((y)5%x  >>y)5%x r>   c                 h   |j                  d|      }t        d||       ||||||g}|dk(  rt        j                  | S |dk(  rt        j                  | S |dk(  rt        j
                  | S |dk(  rt        j                  | S |dk(  rt        j                  | S |d	k(  rt        j                  | S y )
Nerror_descriptionzStripe OAuth error received)r   r   invalid_clientinvalid_grantinvalid_requestinvalid_scopeunsupported_grant_typeunsupported_response_type)	r.   r   oauth_errorInvalidClientErrorInvalidGrantErrorr   InvalidScopeErrorUnsupportedGrantTypeErrorUnsupportedResponseTypeError)r;   rx   ry   rr   rz   r   descriptionargss           r<   r   z"_APIRequestor.specific_oauth_error  s    hh2J?)!)	
 KtXF))11488?*00$77,,22D99?*00$773388$??66;;TBBr>   rq   c                    d|j                         dt        }t        j                  r%|d| j	                  t        j                        z   z  }t        dd| j                         j                  d}dt        j                  gdt        j                  gd	d
 gfD ]  \  }}	  |       }|||<    t        j                  rt        j                  |d<   t        j                  |      |d|j                  d      d}	|j                  d      }
|
r|
|	d<   |j                  d      }|r||	d<   |j                  d      }|r||	d<   |dk(  s
|dk(  r2|dk(  r-|	j                  dt        t        j                                       |dk(  r|dk(  rd|	d<   nd|	d<   |j                  d      }|r||	d<   |	S # t        $ r d}Y w xY w)NzStripe/z PythonBindings/ pythonrE   )bindings_versionlang	publisherhttpliblang_versionplatformunamec                  H    dj                  t        j                               S )Nr   )joinr   r   rD   r>   r<   <lambda>z/_APIRequestor.request_headers.<locals>.<lambda>  s    chhx~~'78 r>   z
(disabled)applicationzBearer rL   )zX-Stripe-Client-User-Agentz
User-AgentAuthorizationrM   zStripe-Accountstripe_contextzStripe-Contextidempotency_keyzIdempotency-Keyr/   r   r0   zapplication/jsonContent-Typez!application/x-www-form-urlencodedrN   zStripe-Version)ru   r   rE   app_infori   rJ   rb   r   python_version	Exceptionjsondumpsr.   
setdefaultrh   uuiduuid4)r;   rk   rq   r5   
user_agentuaattrfuncvalr   rM   r   r   rN   s                 r<   request_headersz_APIRequestor.request_headers  s    NN

 ??# 5 5foo FFFJ !(!,,.33	.
 X445**+89
 		JD$
#f BtH		 ?? &B} +/**R.$,3KK	,BD#
 !%56(6G$% %56(6G$%!++&78)8G%& VD 0Vx5G0#djjl2CDV4*<'*M' %56(6G$%M  #"#s   "F11G ?G c          
      r   t        | j                  |      }|rd|v r|d   |d   |d<   |j                  d      t        j                  d      | j                  j
                  j                  |      |}	|xs i }|r|dk(  s|dk(  ri }
t        t        |      j                        j                         D ]7  \  }}|j                  d      r	||
|dd <    t        |      d	k(  r|d
   n||
|<   9 d|
v r%d|v r!t        t        g |
d   |d               |d<   i |
|}t        t        t        |xs i |                  }|j!                  dd      j!                  dd      }|dk(  r t#        j$                  |xs i t&              }n|}d}d|v r|d   t)        |d         }| j+                  t-        t.        |      ||      }|dk(  s|dk(  r&|r!t        |	      \  }}}}}t1        |||||f      }	d}ny|dk(  r[|V|j                  d      dk(  rBt3               }|j5                  |xs i        |j7                         }d|j8                  |d<   n|}nt        j:                  d|d      ||j                         D ]
  \  }}|||<    |j                  d      }||	||||||j                  d      fS )z`
        Mechanism for issuing an API call.  Used by request_raw and request_raw_async.
        rN   NrL   zNo API key provided. (HINT: set your API key using "stripe.api_key = <API-KEY>"). You can generate API keys from the Stripe web interface.  See https://stripe.com/api for details, or email support@stripe.com if you have any questions.r.   r0   z[]   r   expandz%5B[z%5D]r   )defaultr   r/   content_typezmultipart/form-datazmultipart/form-data; boundary=r   zUnrecognized HTTP method ze.  This may indicate a bug in the Stripe bindings.  Please contact support@stripe.com for assistance.max_network_retries)r$   r9   r.   r   r   rZ   r   r   queryitemsendswithlenlistsetr   r   replacer   r   r   dictr   r   HttpVerbr   r   
add_paramsget_post_databoundaryAPIConnectionError)r;   rk   re   r^   r5   rl   rq   rj   request_optionsabs_urlexisting_paramskvencoded_paramsencoded_bodysupplied_headersr   schemenetlocpath_fragment	post_data	generatorrR   valuer   s                              r<   _args_for_request_with_retriesz,_APIRequestor._args_for_request_with_retries  sS    (w?  G+)*6 188H0IO,-y)1++  MM((,,\:

 2v&H*< !O #!4!45;;= D1::d#./OAcrF+ 25Q11!OA&D ?*x6/A#'G/(3GfX6FGH$x ! F #4FLb((K#LM
 (//s;CCE3Ot::"&@L *L(	*6#OI$>?&&6"	
 U?f0 5=W4E1a$VT>8D Iv#KK/3HH24	$$V\r2%335	:C:L:LN ' )	** "(*  '.446 %
U$% .112GH  01
 	
r>   rp   c          	         | j                  |||||||      \  }}	}
}}}}}t        d||	       t        d||       |r*| j                         j	                  ||	|
|||      \  }}}n)| j                         j                  ||	|
|||      \  }}}t        d|	|       t        d	|
       d|v r|d   }t        dt        |             |||fS )Nrl   rq   rj   Request to Stripe apirk   re   Post detailsr  api_versionr   _usageStripe API responser  response_codeAPI response bodybody
Request-IdDashboard link for requestlink)r  r   r   rJ   request_stream_with_retriesrequest_with_retriesr   r;   rk   re   r^   r5   rp   rl   rq   rj   r   r   r  r   r   r  rcontentry   rz   
request_ids                      r<   rt   z_APIRequestor.request_raw  s7   * //% 0 
		
 	(WEn+	
 
 %%'CC$7 D 	 %%'<<$7 = 	 	&WEJ%H58#!,/J,#J/
 ((r>   c          	        K   |xs g }|dgz   }| j                  |||||||      \  }}	}
}}}}}t        d||	       t        d||       |r2| j                         j	                  ||	|
|||       d{   \  }}}n1| j                         j                  ||	|
|||       d{   \  }}}t        d	|	|
       t        d|       d|v r|d   }t        dt        |             |||fS 7 y7 Iw)z3
        Mechanism for issuing an API call
        asyncr	  r
  r  r  r  r  Nr  r  r  r  r  r  r  )r  r   r   rJ   !request_stream_with_retries_asyncrequest_with_retries_asyncr   r  s                      r<   r~   z_APIRequestor.request_raw_async  sk      	! //% 0 
		
 	(WE$#	
 
 ++-OO$7 P  	 ++-HH$7 I  	 	&WEJ%H58#!,/J,#J/
 ((As%   A4C46C071C4(C2)AC42C4c                 &    d|cxk  xr dk   S c  S )N   i,  rD   )r;   ry   s     r<   _should_handle_code_as_errorz*_APIRequestor._should_handle_code_as_error8  s    %%#%%%%%%r>   rx   ry   rz   c                 d   	 t        |d      rt        t        |      j                  d      }t	        t        t
        |      ||      }| j                  |      r| j                  |||j                  ||       |S # t        $ r, t        j                  d||fz  t        t        |      ||      w xY w)Ndecodezutf-8z>Invalid response body from API: %s (HTTP response code was %d))hasattrr   bytesr(  r    rh   r   r   r   r&  r   data)r;   rx   ry   rz   rq   rr   s         r<   rv   z!_APIRequestor._interpret_response;  s    	uh' UE*11':!S% D ,,U3&&udii8   	...16?UE" 	s   AA: :5B/r   c                 X   | j                  |      rt        |d      rt        t        |      j	                         }nCt        |d      r|j                         }n&t        d| j                         j                  z        | j                  ||||       t        d      t        |||      S )Ngetvaluereadz`HTTP client %s does not return an IOBase object which can be consumed when streaming a response./_interpret_response should have raised an error)r&  r)  r   r   r-  r.  NotImplementedErrorrJ   rb   rv   RuntimeErrorr!   )r;   r   ry   rz   rq   json_contents         r<   r   z+_APIRequestor._interpret_streaming_responseZ  s     ,,U3vz*#GV4==?(%{{})A++-223  $$\5(HMA  (x@@r>   c                    K   | j                  |      rdj                  |2 cg c3 d {   }|t	        |||      S 7 6 nc c}w c}      }| j                  ||||       t        d      w)Nr>   r/  )r&  r   rv   r1  r"   )r;   r   ry   rz   rq   chunkr2  s          r<   r   z1_APIRequestor._interpret_streaming_response_asyncy  sq      ,,U388f$E$EUU -VUHEE %F$E$EFL$$\5(HMA s3   !A-AA 
>A 
AA-A 
 A,A-)NN)NNF):__name__
__module____qualname__r4   r   __annotations__r
   r%   r'   r=   rJ   r#   rS   propertyrL   rM   rN   rZ   classmethodr]   staticmethodr   r`   ri   rh   r	   r   r+   r   r|   r   r!   r   r"   r   r   r   r   r   r   r   r,   r   r  boolr   objectintrt   r   r*  r~   r&  r    rv   r   r   r   rD   r>   r<   r3   r3   E   s   04Ix,-4 /3'+*+ $ *  D

/

	

 % % , , , , , , 	 	 I(I	I I
   /3,0 &*  c*+	
 .) " S	" 
J /3,0 &*  c*+	
 .) " S	" 
J /3,0 &*  c*+	
 .) " S	" 
F /3,0 &*  c*+	
 .) " S	" 
#:#	#J%
N4l4==*1=<J=F /3,0O
 &*O
O
 O
 c*+	O

 .)O
 "O
 O
 S	"O
j /3,0"I) &*I)I) I) c*+	I)
 .)I) I) "I) I) S	"I) 
vsGCH--	.I)^ /3,0"R) &*R)R) R) c*+	R)
 .)R) R) "R) R) S	"R) 
}U#S'#s(*;;	<R)h&  #s(#	
  
>AA A #s(#	A
 A 
A>Fe$F F #s(#	F
 F 
#Fr>   r3   )Jior   r   r   r   typingr   r   r   r   r	   r
   r   r   r   r   typing_extensionsr   r   r   r   r   urllib.parser   r   r   rE   stripe._utilr   r   r   r   r   stripe._versionr   stripe._error_errorr   stripe.oauth_errorr    stripe._multipart_data_generatorr   r   stripe._encoder   r   stripe._stripe_responser    r!   r"   stripe._request_optionsr#   r$   stripe._requestor_optionsr%   r&   stripe._http_clientr'   r(   r)   stripe._app_infor*   stripe._base_addressr+   stripe._api_moder,   stripe._stripe_objectr-   r   r1   rh   r8  r=  r3   rD   r>   r<   <module>rR     s            7 7   $  ( C " B 
 B 
 % , $2*+ !% $CFF CFr>   