o
    êË·e^	  ã                   @   s\   d Z ddlZe d¡e d¡e d¡e d¡e d¡dœZg d	¢Zd
d„ ZG dd„ dƒZdS )zÓ
Adapted from:
    - http://www.djangosnippets.org/snippets/764/
    - http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/apps/satchmo_utils/views.py
    - http://tinyurl.com/shoppify-credit-cards
é    Nz^4\d{12}(\d{3})?$z^(5[1-5]\d{4}|677189)\d{10}$z^3(0[0-5]|[68]\d)\d{11}$z^3[47]\d{13}$z^(6011|65\d{2})\d{12}$)ÚVisaÚ
MastercardÚ
DinersclubÚAmexÚDiscover)Ú378282246310005Ú371449635398431Ú378734493671000Ú30569309025904Ú38520000023237Ú6011111111111117Ú6011000990139424Ú555555555554444Ú5105105105105100Ú4111111111111111Ú4012888888881881Ú4222222222222c                 C   s   t | ƒ ¡ S )z?Returns the card type for given card number or None if invalid.)Ú
CreditCardÚverify©Únumber© r   úL/var/www/ideatree/venv/lib/python3.10/site-packages/paypal/pro/creditcard.pyÚverify_credit_card%   s   r   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )r   c                 C   s
   || _ d S )Nr   )Úselfr   r   r   r   Ú__init__+   s   
zCreditCard.__init__c                 C   s   t  dd| j¡| _| j ¡ S )z.True if there is at least one digit in number.z[^\d]Ú )ÚreÚsubr   Úisdigit©r   r   r   r   Ú	is_number.   s   
zCreditCard.is_numberc                 C   sh   d}d}t t| jƒd ddƒD ]}t|d t| j| ƒ ƒD ]}|t|ƒ }q|d d }q|d dkS )z3Returns True if number is valid according to mod10.r   é   éÿÿÿÿé   é
   )ÚrangeÚlenr   ÚstrÚint)r   ÚdoubleÚtotalÚiÚcr   r   r   Úis_mod103   s   zCreditCard.is_mod10c                 C   s
   | j tv S )z-Returns True if number is a test card number.)r   ÚTEST_NUMBERSr    r   r   r   Úis_test=   s   
zCreditCard.is_testc                 C   s*   t  ¡ D ]\}}| | j¡r|  S qdS )z/Return the type if it matches one of the cards.N)ÚCARDSÚitemsÚmatchr   )r   ÚcardÚpatternr   r   r   Úget_typeD   s
   ÿzCreditCard.get_typec                 C   s$   |   ¡ r|  ¡ s|  ¡ r|  ¡ S dS )z)Returns the card type if valid else None.N)r!   r0   r.   r6   r    r   r   r   r   K   s   zCreditCard.verifyN)	Ú__name__Ú
__module__Ú__qualname__r   r!   r.   r0   r6   r   r   r   r   r   r   *   s    
r   )Ú__doc__r   Úcompiler1   r/   r   r   r   r   r   r   Ú<module>   s   û	