ó
÷Efc           @   sÏ  d  d l  m Z m Z m Z d  d l m Z m Z m Z d  d l m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z m Z d  d l m Z d  d	 l m Z m Z d  d
 l m Z d  d l m Z d  d l m Z m Z m  Z  d  d l! m" Z" d  d l# Z# d  d l$ Z$ d  d l% m& Z& d  d l' Td  d l( Td  d l) Td  d l* Td  d l+ Td  d l, Td  d l- Td  d l. Td  d l/ Td  d l0 Td „  Z1 d „  Z2 e& d „  ƒ Z3 d „  Z4 d „  Z5 d S(   iÿÿÿÿ(   t   rendert   render_to_responset   get_object_or_404(   t   RequestContextt   loadert   Context(   t   login_requiredt   permission_required(   t   Q(   t   Site(   t   settings(   t   HttpResponseRedirectt   Http404t   HttpResponse(   t   reverse(   t   Usert   Group(   t   messages(   t   slugify(   t   datetimet   datet   time(   t   chainN(   t   csrf_exempt(   t   *c         C   sñ  y t  j j d d ƒ } Wn t } n Xy t j j d |  j ƒ } Wn t } n X| rÞ t d i | j d 6| j d 6| j	 d 6| j j
 d 6| j d	 6| j d
 6| j d 6| j d 6| j d 6| j d 6| j d 6ƒ } n	 t ƒ  } t ƒ  } |  j rÃt |  j ƒ } t |  j ƒ } | j ƒ  rÃ| j ƒ  rÃyt | j d t ƒ } t d t d ƒ | _ | j ƒ  t |  j d | ƒ} | j ƒ  | j |  j d <t t d ƒ ƒ SWqÀt j |  d ƒ qÀXqÃn  t d i | d 6| d 6| d 6d t |  ƒ ƒS(   Nt   slugs   donation-introt   usert   initialt   titlet   surnamet
   first_namet   email_addresst	   address_1t	   address_2t   townt   countyt   countryt   postcodet	   telephonet   commitid   t
   unique_keyt   instancet   donation_keyt   donation_payments   Could Not save Donations   public/donation/donation.htmlt   content_blockt   donation_formt   ga_formt   context_instance(    t   ContentBlockt   objectst   gett   Falset   MemberR   t   DonationFormR   R   t
   given_namet   emailR    R!   R"   R#   R$   R%   R&   t   GAFormt   POSTt   is_validt   savet   random_string_uniquet   DonationR(   t   sessionR   R   R   t   errorR   R   (   t   requestR,   t   current_memberR-   R.   t   donation(    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyRB   $   s6    

ƒ			

c   	      C   s‘  |  j  j d t ƒ rd t t d |  j  d ƒ} | j r„ |  j  d =t j |  d ƒ t t	 d ƒ ƒ Sn  t j |  d ƒ t t	 d ƒ ƒ St
 d d d | ƒ } | j r± | j | _ n  | j ƒ  t j r× d | j | _ n d | j | _ | j ƒ  t j } t j } d	 t j t	 d
 ƒ f } d | | | j | j | f } d d  l } | j | ƒ j ƒ  } t d i | d 6| d 6| d 6| d 6d t |  ƒ ƒS(   NR*   R(   s3   Sorry, you have already donated with these details.RB   s&   You have not started your donation yett   types   Donation_%sDs   Donation_%ss   %s%st   donation_payment_processs   %s:%s:%s:GBP:%s:%siÿÿÿÿs   public/donation/payment.htmlt   paymentt   redirect_urlt   encrypted_stringR/   (   R>   R2   R3   R   R=   t   completeR   R?   R   R   t   Paymentt   memberR;   R
   t   DEVELOPMENTt   idt   invoicet   WORLD_PAY_SECRET_KEYt   WORLD_PAY_INSTALLATION_IDt   PAYMENT_URLt   amountt   hashlibt   md5t	   hexdigestR   R   (	   R@   RB   RE   t
   secret_keyt   installation_idRF   t   stringRR   RG   (    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyRE   P   s.    	
	
	
		c   
   
   C   sá  |  j  s t ‚ n  |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } t t d | ƒ} g  } t } | s  | s  | s  | r¶ t } | j d ƒ n  | t j	 k rÛ t } | j d ƒ n  | sž| d	 k ro| j
 d
 k rSd | _
 | | _ | j ƒ  | j } t | _ | j ƒ  t j d d  d |  d | ƒ n  d t j t d ƒ f }	 qÊd | _
 | j ƒ  d t j t d ƒ f }	 n, d | _
 | j ƒ  d t j t d ƒ f }	 t |  d i |	 d 6ƒ S(   Nt
   callbackPWt    t   transStatust
   authAmountt   cartIdRM   s   Missing a Required Variables   World Pay Password Incorrectt   Yt   pendingRH   t   senderR@   RB   s   %s%st   donation_payment_completet   rejectedt   donation_payment_failures%   public/donation/payment-redirect.htmlt   next(   R9   R   R2   R   RI   R3   t   Truet   appendR
   t   WORLD_PAY_PASSWORDt   statusRQ   R;   RB   RH   t   donation_confirmation_emailt   sendt   Nonet   URLR   R    (
   R@   RX   RZ   R[   R\   RE   t   errorsR?   RB   Rc   (    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyt   payment_processq   sB    				
		
	
	
c         C   sI   y t  j j d d ƒ } Wn t } n Xt d i | d 6d t |  ƒ ƒS(   NR   s   donation-payment-completes%   public/donation/payment-complete.htmlR,   R/   (   R0   R1   R2   R3   R   R   (   R@   R,   (    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyt   payment_complete¥   s
    
c         C   s    t  j |  d ƒ t t d ƒ ƒ S(   Nsm   Sorry, your payment could not be taken at this time. If you wish to retry your payment, please proceed below.R+   (   R   R?   R   R   (   R@   (    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyt   payment_failure®   s    (6   t   django.shortcutsR    R   R   t   django.templateR   R   R   t   django.contrib.auth.decoratorsR   R   t   django.db.modelsR   t   django.contrib.sites.modelsR	   t   django.confR
   t   django.httpR   R   R   t   django.core.urlresolversR   t   django.contrib.auth.modelsR   R   t   django.contribR   t   django.template.defaultfiltersR   R   R   R   t	   itertoolsR   t   cPicklet   base64t   django.views.decorators.csrfR   t   modules.core.functionst   modules.members.functionst   modules.payments.functionst   signalst   formst   modelst   modules.blocks.modelst   modules.resources.modelst   modules.members.modelst   modules.payments.modelsRB   RE   Rm   Rn   Ro   (    (    (    s5   /var/www/svtgbi.org/svtgbi/modules/donations/views.pyt   <module>   s<   









	,	!4		