o
    sg                     @   s   d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 eddgddd	iig d
Z
e
d			ddededB dedB dedB fddZdS )zPayments router    N)	APIRouterHTTPException)StripeInvoicez	/paymentspaymentsi  descriptionz	Not found)prefixtags	responsesdependenciesz	/invoices
   stripe_customer_idlimitstarting_afterstatusc           
   
      sf  z~t dt_| ||d}|r| r||d< tjjdi |}g }|jD ]R}tdi d|j	d|j
d d|jd d|jd d	|jd
|jd|jd|jd|jd|jd|jd|jd|jd|jd|jd|j}|| q&||jdW S  tjjy }	 zt|jdt|	 d|	d}	~	w t y }	 zt|j!dt|	 d|	d}	~	ww )z Getting Stripe Invoices for teamSTRIPE_API_KEY)customerr   r   r   id
amount_dueg      Y@amount_paidamount_remainingcurrencyr   r   createddue_dateinvoice_pdfhosted_invoice_urlnumberpaidperiod_start
period_endsubscription)invoiceshas_morezStripe error: )status_codedetailNzFailed to retrieve invoices:  )"osgetenvstripeapi_keystripInvoicelistdatar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   appendr!   errorStripeErrorr   HTTP_400_BAD_REQUESTstr	ExceptionHTTP_500_INTERNAL_SERVER_ERROR)
r   r   r   r   query_paramsr    formatted_invoicesinvoiceformatted_invoiceer$   r$   6/var/www/html/XCapMarket/controllers/payment_router.pyget_invoices   s~   



	
r:   )r   NN)__doc__loggingr%   pydanticr'   fastapir   r   models.paymentsr   r   getr1   intr:   r$   r$   r$   r9   <module>   s4    
