<s> from __future__ import absolute_import , unicode_literals <EOL> import random <EOL> import sys <EOL> import string <EOL> import time <EOL> import base64 <EOL> import platform <EOL> from hashlib import sha1 <EOL> import django <EOL> from django import forms <EOL> from django . core . exceptions import ValidationError <EOL> from . models import Payment <EOL> from . import config , get_version <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> <EOL> class PaymentCallbackForm ( forms . ModelForm ) : <EOL> testing = forms . CharField ( required = False ) <EOL> def clean ( self ) : <EOL> key = config . FUTUPAYMENTS_SECRET_KEY <EOL> data = dict ( self . data . items ( ) ) <EOL> signature = data . pop ( '<STR_LIT>' ) if '<STR_LIT>' in self . data else None <EOL> if signature != get_signature ( key , data ) : <EOL> raise ValidationError ( '<STR_LIT>' ) <EOL> self . cleaned_data [ '<STR_LIT>' ] = self . cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT:1>' <EOL> return self . cleaned_data <EOL> class Meta : <EOL> model = Payment <EOL> fields = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:state>' , <EOL> '<STR_LIT:message>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> class PaymentForm ( forms . Form ) : <EOL> MAX_DESCRIPTION_LENGTH = <NUM_LIT> <EOL> @ classmethod <EOL> def create ( <EOL> cls , <EOL> request , <EOL> amount , <EOL> order_id , <EOL> description , <EOL> client_email = '<STR_LIT>' , <EOL> client_phone = '<STR_LIT>' , <EOL> client_name = '<STR_LIT>' , <EOL> meta = None , <EOL> cancel_url = None , <EOL> testing = None , <EOL> ) : <EOL> if cancel_url is not None and not cancel_url . lower ( ) . startswith ( ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> cancel_url = request . build_absolute_uri ( cancel_url ) <EOL> if testing is None : <EOL> testing = config . FUTUPAYMENTS_TEST_MODE <EOL> data = { <EOL> '<STR_LIT>' : str ( int ( testing ) ) , <EOL> '<STR_LIT>' : amount , <EOL> '<STR_LIT:description>' : description [ : cls . MAX_DESCRIPTION_LENGTH ] , <EOL> '<STR_LIT>' : str ( order_id ) , <EOL> '<STR_LIT>' : cancel_url or request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : meta or '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_email , <EOL> '<STR_LIT>' : client_phone , <EOL> '<STR_LIT>' : client_name , <EOL> '<STR_LIT>' : '<STR_LIT>' . join ( <EOL> random . choice ( string . ascii_letters ) <EOL> for _ in range ( <NUM_LIT:32> ) <EOL> ) , <EOL> '<STR_LIT>' : int ( time . time ( ) ) , <EOL> '<STR_LIT>' : config . FUTUPAYMENTS_MERCHANT_ID , <EOL> '<STR_LIT>' : request . build_absolute_uri ( <EOL> config . FUTUPAYMENTS_FAIL_URL , <EOL> ) , <EOL> '<STR_LIT>' : request . build_absolute_uri ( <EOL> config . FUTUPAYMENTS_SUCCESS_URL , <EOL> ) , <EOL> '<STR_LIT>' : '<STR_LIT:{>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + platform . python_version ( ) + '<STR_LIT>' + <EOL> '<STR_LIT>' + get_version ( ) + '<STR_LIT>' + <EOL> '<STR_LIT>' + django . get_version ( ) + '<STR_LIT:">' + <EOL> '<STR_LIT:}>' , <EOL> } <EOL> key = config . FUTUPAYMENTS_SECRET_KEY <EOL> data [ '<STR_LIT>' ] = get_signature ( key , data ) <EOL> form = cls ( data ) <EOL> form . action = config . FUTUPAYMENTS_HOST + '<STR_LIT>' <EOL> assert form . is_valid ( ) , form . as_p ( ) <EOL> return form <EOL> testing = forms . CharField ( widget = forms . HiddenInput ) <EOL> merchant = forms . CharField ( widget = forms . HiddenInput ) <EOL> amount = forms . DecimalField ( widget = forms . HiddenInput ) <EOL> currency = forms . CharField ( widget = forms . HiddenInput ) <EOL> description = forms . CharField ( widget = forms . HiddenInput , required = False , <EOL> max_length = MAX_DESCRIPTION_LENGTH ) <EOL> meta = forms . CharField ( widget = forms . HiddenInput , required = False ) <EOL> order_id = forms . CharField ( widget = forms . HiddenInput ) <EOL> success_url = forms . URLField ( widget = forms . HiddenInput ) <EOL> fail_url = forms . URLField ( widget = forms . HiddenInput ) <EOL> cancel_url = forms . URLField ( widget = forms . HiddenInput ) <EOL> unix_timestamp = forms . IntegerField ( widget = forms . HiddenInput ) <EOL> salt = forms . CharField ( widget = forms . HiddenInput ) <EOL> client_email = forms . EmailField ( widget = forms . HiddenInput , required = False ) <EOL> client_phone = forms . CharField ( widget = forms . HiddenInput , required = False , max_length = <NUM_LIT:30> ) <EOL> client_name = forms . CharField ( widget = forms . HiddenInput , required = False ) <EOL> sysinfo = forms . CharField ( max_length = <NUM_LIT:255> , widget = forms . HiddenInput , required = False ) <EOL> signature = forms . CharField ( widget = forms . HiddenInput ) <EOL> def get_signature ( secret_key , params ) : <EOL> return double_sha1 ( secret_key , '<STR_LIT:&>' . join ( <EOL> '<STR_LIT>' . format ( force_encode ( k ) . decode ( '<STR_LIT:utf-8>' ) , base64 . b64encode ( force_encode ( params [ k ] ) ) . decode ( '<STR_LIT:utf-8>' ) ) <EOL> for k in sorted ( params ) <EOL> if params [ k ] and k != '<STR_LIT>' <EOL> ) ) <EOL> def force_encode ( v ) : <EOL> if PY2 : <EOL> return v . encode ( '<STR_LIT:utf-8>' ) if isinstance ( v , unicode ) else str ( v ) <EOL> return str ( v ) . encode ( '<STR_LIT:utf-8>' ) <EOL> def double_sha1 ( secret_key , s ) : <EOL> secret_key = secret_key . encode ( '<STR_LIT:utf-8>' ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> s = sha1 ( secret_key + s ) . hexdigest ( ) <EOL> return s </s>
