
    8ix                        d Z ddlmZ ddlmZ  G d dej
                        Z G d dej
                        Z G d d	ej
                        Z G d
 dej
                        Z	y)zCPayment gateway contracts for deposits, withdrawals, and callbacks.    )annotations)modelsc                     e Zd ZdZdZdZdZedfedfedfgZ ej                  dej                  d	
      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dee      Z ej                  ddd      Z ej$                  dd      Z ej(                  ed      Z ej$                  d      Z ej$                  d      Z G d d      ZddZy) PaymentAddresszCReusable deposit address allocated to a user on a specific network.activerevokedexpiredActiveRevokedExpired
users.Userpayment_addresses	on_deleterelated_name2   T
max_lengthdb_index   USDTr   default   )r   uniquer   choicesr   d   z=Optional label or derivation path reference from the gateway.)r   blank	help_textnullr   r   r   auto_now_add)auto_nowc                  d    e Zd ZdZ ej
                  ddg       ej
                  ddg      gZy)PaymentAddress.Metar   user
blockchainfieldsstatus
expires_atN__name__
__module____qualname__db_tabler   Indexindexes     E/home/cursorai/projects/telegram-earn/backend/apps/payments/models.pyMetar(   (   s4    &FLL 67FLL< 89
r7   r9   c                R    | j                    d| j                   d| j                   S )N:)r*   assetaddressselfs    r8   __str__zPaymentAddress.__str__/   s&    //"!DJJ<q??r7   Nreturnstr)r0   r1   r2   __doc__STATUS_ACTIVESTATUS_REVOKEDSTATUS_EXPIREDSTATUS_CHOICESr   
ForeignKeyCASCADEr)   	CharFieldr*   r<   r=   r-   labelDateTimeFieldr.   	JSONFielddictmetadata
created_at
updated_atr9   r@   r6   r7   r8   r   r      s!   MMNN	!	#	#N 6..(D
 "!!R$?JFF;Ef#d;GV^][FFQE
 &%%4t<JvD9H%%%48J%%%t4J
 
@r7   r   c                     e Zd ZdZdZdZdZdZedfedfedfed	fgZ e	j                  d
e	j                  d      Z e	j                  ee	j                  d      Z e	j                   ddde	j"                  dd      Z e	j&                  dd      Z e	j&                  dd      Z e	j,                  dd      Z e	j&                  dd      Z e	j2                  d      Z e	j&                  dee      Z e	j8                  d      Z e	j8                  dd      Z e	j>                  e d      Z! e	j>                  e d      Z" G d  d!      Z#d$d"Z$y#)%DepositzCInbound payment detected by the gateway; links to on-chain tx hash.pending	confirmedfailed	duplicatePending	ConfirmedFailed	Duplicater   depositsr   transactions.TransactionTdepositz:Corresponding wallet transaction once balance is credited.r"   r   r   r   r    r   r   r   r   r      
max_digitsdecimal_placesr   r   )r   r   r$   r!   r#   c                      e Zd ZdZ ej
                  ddg       ej
                  ddg      gZ ej                  ddgd      gZy	)
Deposit.Metapayment_depositsr)   r-   r+   transaction_hashr*   unique_payment_deposit_tx)r,   nameN)	r0   r1   r2   r3   r   r4   r5   UniqueConstraintconstraintsr6   r7   r8   r9   rf   `   sY    %FLL 23FLL!3\ BC

 $F##*L90
r7   r9   c                T    d| j                    d| j                   d| j                   S )NzDeposit  r*   r<   amountr>   s    r8   r@   zDeposit.__str__m   s(    $//*!DJJ<qFFr7   NrA   )%r0   r1   r2   rD   STATUS_PENDINGSTATUS_CONFIRMEDSTATUS_FAILEDSTATUS_DUPLICATErH   r   rI   rJ   r)   r   PROTECTr=   OneToOneFieldSET_NULLtransactionrK   r*   r<   DecimalFieldrp   rh   PositiveIntegerFieldconfirmationsr-   rM   detected_atconfirmed_atrN   rO   raw_payloadrP   r9   r@   r6   r7   r8   rT   rT   3   s   MN"M"	#	;'	!	;'	N 6..D
  f..G
 '&&&"//NK "!!R$?JFF;E V  BqAF'v''3F/F//:MV^^\F&&&&D9K'6''T>L"&""4t<KvD9H
 
Gr7   rT   c                  z   e Zd ZdZdZdZdZdZdZedfedfed	fed
fedfgZ	 e
j                  de
j                  d      Z e
j                  ddde
j                  dd      Z e
j"                  dd      Z e
j"                  dd      Z e
j(                  dd      Z e
j"                  d      Z e
j"                  de	e      Z e
j"                  dddd      Z e
j"                  dddd       Z e
j4                  d!      Z e
j4                  dd"      Z e
j:                  ed#      Z G d$ d%      Z d(d&Z!y'))WithdrawalRequestz/Outbound payout request to the payment gateway.	requested
processingsentrW   	cancelled	Requested
ProcessingSentr[   	Cancelledr   withdrawal_requestsr   r^   Twithdrawal_requestz2Wallet transaction when the withdrawal is debited.r`   r   r   r   r   r   ra   rb   r   )r   r   z:External reference or request id from the payment gateway.)r   r   r   r    zOn-chain hash when available.r$   r!   r#   c                      e Zd ZdZ ej
                  ddg       ej
                  dg       ej
                  ddg      gZy)	WithdrawalRequest.Metapayment_withdrawalsr)   r-   r+   gateway_referencerh   r*   Nr/   r6   r7   r8   r9   r      sG    (FLL 23FLL!4 56FLL!3\ BC
r7   r9   c                T    d| j                    d| j                   d| j                   S )NzWithdrawal rn   ro   r>   s    r8   r@   zWithdrawalRequest.__str__   s(    T__-Qtzzl!DKK=IIr7   NrA   )"r0   r1   r2   rD   STATUS_REQUESTEDSTATUS_PROCESSINGSTATUS_SENTrs   STATUS_CANCELLEDrH   r   rI   rJ   r)   rv   rw   rx   rK   r*   r<   ry   rp   destination_addressr-   r   rh   rM   requested_atprocessed_atrN   rO   rP   r9   r@   r6   r7   r8   r   r   q   s   9"$KM"	;'	L)	f	!	;'N 6..*D
 '&&&"//)FK "!!R$?JFF;E V  BqAF*&**c:V^M]^F(((N	 (v''1	 (6''T:L'6''T>LvD9H
 
Jr7   r   c                     e Zd ZdZdZdZdZedfedfedfgZ ej                  dd	
      Z
 ej                  ed	d	ej                  d      Z ej                  ed	d	ej                  d      Z ej                  dee      Z ej$                  d	      Z ej(                  ed	      Z ej(                  ed	      Z ej0                  d	      Z ej0                  d	d	      Z G d d      ZddZy)GatewayCallbackLogz>Audit log of inbound webhook callbacks to aid troubleshooting.rU   	processederrorrY   	ProcessedErrorr   Tr   callback_logs)r"   r   r   r   r   r   )r   r#   r$   r!   c                  b    e Zd ZdZ ej
                  ddg       ej
                  dg      gZy)GatewayCallbackLog.Metapayment_callback_logs
event_typer-   r+   received_atNr/   r6   r7   r8   r9   r      s1    *FLLx 89FLL0
r7   r9   c                <    d| j                    d| j                   dS )Nz	Callback z [])r   r-   r>   s    r8   r@   zGatewayCallbackLog.__str__   s     4??+2dkk]!<<r7   NrA   )r0   r1   r2   rD   rq   STATUS_PROCESSEDSTATUS_ERRORrH   r   rK   r   rI   rT   rw   related_depositr   related_withdrawalr-   	TextFielderror_messagerN   rO   payloadheadersrM   r   r   r9   r@   r6   r7   r8   r   r      s   HN"L	#	;'	wN "!!S4@J'f''//$O +**//$ V^^\F$F$$40Mft48Gft48G&&&&D9K'6''T>L
 
=r7   r   N)
rD   
__future__r   	django.dbr   Modelr   rT   r   r   r6   r7   r8   <module>r      sW    I " (@V\\ (@V;Gfll ;G|>J >JB+= +=r7   