<s> from billing import Integration , IntegrationNotConfigured <EOL> from billing . forms . authorize_net_forms import AuthorizeNetDPMForm <EOL> from billing . signals import transaction_was_successful , transaction_was_unsuccessful <EOL> from django . conf import settings <EOL> from django . conf . urls import patterns , url <EOL> from django . views . decorators . csrf import csrf_exempt <EOL> from django . views . decorators . http import require_POST <EOL> from django . utils . decorators import method_decorator <EOL> from django . http import HttpResponseForbidden <EOL> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext <EOL> from django . core . urlresolvers import reverse <EOL> import hashlib <EOL> import hmac <EOL> import urllib <EOL> csrf_exempt_m = method_decorator ( csrf_exempt ) <EOL> require_POST_m = method_decorator ( require_POST ) <EOL> class AuthorizeNetDpmIntegration ( Integration ) : <EOL> display_name = "<STR_LIT>" <EOL> template = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> super ( AuthorizeNetDpmIntegration , self ) . __init__ ( ) <EOL> merchant_settings = getattr ( settings , "<STR_LIT>" ) <EOL> if not merchant_settings or not merchant_settings . get ( "<STR_LIT>" ) : <EOL> raise IntegrationNotConfigured ( "<STR_LIT>" <EOL> "<STR_LIT>" % self . display_name ) <EOL> self . authorize_net_settings = merchant_settings [ "<STR_LIT>" ] <EOL> def form_class ( self ) : <EOL> return AuthorizeNetDPMForm <EOL> def generate_form ( self ) : <EOL> transaction_key = self . authorize_net_settings [ "<STR_LIT>" ] <EOL> login_id = self . authorize_net_settings [ "<STR_LIT>" ] <EOL> initial_data = self . fields <EOL> x_fp_hash = hmac . new ( transaction_key , "<STR_LIT>" % ( login_id , <EOL> initial_data [ '<STR_LIT>' ] , <EOL> initial_data [ '<STR_LIT>' ] , <EOL> initial_data [ '<STR_LIT>' ] ) , <EOL> hashlib . md5 ) <EOL> initial_data . update ( { '<STR_LIT>' : login_id , <EOL> '<STR_LIT>' : x_fp_hash . hexdigest ( ) } ) <EOL> form = self . form_class ( ) ( initial = initial_data ) <EOL> return form <EOL> @ property <EOL> def service_url ( self ) : <EOL> if self . test_mode : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" <EOL> def verify_response ( self , request ) : <EOL> data = request . POST . copy ( ) <EOL> md5_hash = self . authorize_net_settings [ "<STR_LIT>" ] <EOL> login_id = self . authorize_net_settings [ "<STR_LIT>" ] <EOL> hash_str = "<STR_LIT>" % ( md5_hash , login_id , <EOL> data . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> data . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> return hashlib . md5 ( hash_str ) . hexdigest ( ) == data . get ( "<STR_LIT>" ) . lower ( ) <EOL> @ csrf_exempt_m <EOL> @ require_POST_m <EOL> def authorizenet_notify_handler ( self , request ) : <EOL> response_from_authorize_net = self . verify_response ( request ) <EOL> if not response_from_authorize_net : <EOL> return HttpResponseForbidden ( ) <EOL> post_data = request . POST . copy ( ) <EOL> result = post_data [ "<STR_LIT>" ] <EOL> if request . POST [ '<STR_LIT>' ] == '<STR_LIT:1>' : <EOL> transaction_was_successful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = post_data ) <EOL> redirect_url = "<STR_LIT>" % ( request . build_absolute_uri ( reverse ( "<STR_LIT>" ) ) , <EOL> urllib . urlencode ( { "<STR_LIT>" : result , <EOL> "<STR_LIT>" : request . POST [ "<STR_LIT>" ] } ) ) <EOL> return render_to_response ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : redirect_url } ) <EOL> redirect_url = "<STR_LIT>" % ( request . build_absolute_uri ( reverse ( "<STR_LIT>" ) ) , <EOL> urllib . urlencode ( { "<STR_LIT>" : result } ) ) <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = post_data ) <EOL> return render_to_response ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : redirect_url } ) <EOL> def authorize_net_success_handler ( self , request ) : <EOL> response = request . GET <EOL> return render_to_response ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : response } , <EOL> context_instance = RequestContext ( request ) ) <EOL> def authorize_net_failure_handler ( self , request ) : <EOL> response = request . GET <EOL> return render_to_response ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : response } , <EOL> context_instance = RequestContext ( request ) ) <EOL> def get_urls ( self ) : <EOL> urlpatterns = patterns ( '<STR_LIT>' , <EOL> url ( '<STR_LIT>' , self . authorizenet_notify_handler , name = "<STR_LIT>" ) , <EOL> url ( '<STR_LIT>' , self . authorize_net_success_handler , name = "<STR_LIT>" ) , <EOL> url ( '<STR_LIT>' , self . authorize_net_failure_handler , name = "<STR_LIT>" ) , ) <EOL> return urlpatterns </s>
