a
    bg                     @   sn   d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ dddd	d
ddZG dd deZdS )    N)ListOptional)Document)get_from_envstringify_dict)
BaseLoaderz.https://api.stripe.com/v1/balance_transactionsz!https://api.stripe.com/v1/chargesz#https://api.stripe.com/v1/customersz https://api.stripe.com/v1/eventsz!https://api.stripe.com/v1/refundsz"https://api.stripe.com/v1/disputes)Zbalance_transactionsZchargesZ	customerseventsZrefundsZdisputesc                   @   s`   e Zd ZdZdeee ddddZeee dddZ	ee d	d
dZ
ee d	ddZdS )StripeLoaderzLoad from `Stripe` API.N)resourceaccess_tokenreturnc                 C   s(   || _ |ptdd}dd| i| _dS )zInitialize with a resource and an access token.

        Args:
            resource: The resource.
            access_token: The access token.
        r   ZSTRIPE_ACCESS_TOKENAuthorizationzBearer N)r
   r   headers)selfr
   r    r   y/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/stripe.py__init__   s
    zStripeLoader.__init__)urlr   c                 C   sr   t jj|| jd}t j|@}t|  }t	|}d|i}t
||dgW  d    S 1 sd0    Y  d S )N)r   source)Zpage_contentmetadata)urllibrequestRequestr   urlopenjsonloadsreaddecoder   r   )r   r   r   responseZ	json_datatextr   r   r   r   _make_request$   s    zStripeLoader._make_request)r   c                 C   s"   t | j}|d u rg S | |S N)STRIPE_ENDPOINTSgetr
   r    )r   Zendpointr   r   r   _get_resource-   s    zStripeLoader._get_resourcec                 C   s   |   S r!   )r$   )r   r   r   r   load3   s    zStripeLoader.load)N)__name__
__module____qualname____doc__strr   r   r   r   r    r$   r%   r   r   r   r   r	      s
   	r	   )r   urllib.requestr   typingr   r   Zlangchain_core.documentsr   Zlangchain_core.utilsr   r   Z)langchain_community.document_loaders.baser   r"   r	   r   r   r   r   <module>   s   
