Payment system for a web shop I've tried making a payment system for an API called Payson, which is a European company similar to PayPal.

I get the right response when I press the button so it seems to work, and I wonder if you can look at my code to see if it looks OK. I didn't test the part receive but the part send i.e. the first part I've testet and it appears to work:

class PaysonHandler(webapp2.RequestHandler):

    def get(self):
        """
............Returns a simple HTML form for Payson
........"""
        logging.info('in payson')
        SellerEmail = 'niklas...@gmail.com'
        Cost = 250
        ExtraCost=0
        GuaranteeOffered=2
        OkUrl = self.request.host+"/payson_okurl" # TO DO
        Key = '319033-6152-402-b95a-37430de6b6'
        text = SellerEmail + ':' + str(Cost) + ':' + str(ExtraCost) + ':' + OkUrl + ':' + str(GuaranteeOffered) + Key
        logging.info('mdtext5: '+text)
        m = hashlib.md5()
        Generated_MD5_Hash_Value = hashlib.md5(text).hexdigest()
        BuyerEmail = 'niklas@.....se'
        AgentID = 11366
        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'payson.html')
        self.response.out.write(template.render(path, {
            'SellerEmail':SellerEmail, 'Cost':Cost,  'Cost':Cost, 'AgentID':AgentID,
                  'ExtraCost':ExtraCost, 'GuaranteeOffered':GuaranteeOffered,  'OkUrl':OkUrl, 'Key':Key,  'Generated_MD5_Hash_Value':Generated_MD5_Hash_Value,  'BuyerEmail':BuyerEmail,    }))

class PaysonReceiveHandler(webapp2.RequestHandler):

    def get(self):
        """
............Receives Payson messages. Not tested
........"""
        logging.info('in payson')
        SellerEmail = 'niklas....@gmail.com'
        Cost = 10
        ExtraCost=0
        GuaranteeOffered=2
        OkUrl = self.request.host+'/payson_okurl' # TO DO
        text = SellerEmail + ':' + str(Cost) + ':' + str(ExtraCost) + ':' + OkUrl + ':' + str(GuaranteeOffered) + Key
        logging.info('mdtext5: '+text)
        m = hashlib.md5()
        Generated_MD5_Hash_Value = hashlib.md5(text).hexdigest()
        AgentID = 11366

        strYourSecretKey = "3190fb33-6152-4052-b95a-379b430de6b6";
        strOkURL = self.request.GET.get('OkURL')
        strRefNr = self.request.GET.get('RefNr')
        strPaysonRef = self.request.GET.get('Paysonref')

        strTestMD5String = strOkURL + strPaysonRef + strYourSecretKey
        strMD5Hash = hashlib.md5(strTestMD5String).hexdigest()  

        logging.info('testing MD5 value')
        if strMD5Hash == self.request.GET.get('MD5'):
            logging.info('Korrekt anrop från Payson')
            logging.info('Rätt!')
            logging.info('OkUrl: ') + strOkURL
            logging.info('RefNr: ') + strRefNr
            logging.info('PaysonRef: ') + strPaysonRef
        else:
            #Felaktigt anrop från någon annan.
            logging.info("Felaktig MD5-summa!")
First of all, please make sure that your indentation is correct, especially when posting Python code.  Also, take a look at PEP 8.   You are violating it in at least the following places:


You have tabs, not spaces
Comments should be in English
It is apparently not directly against PEP 8, but giving locals CapsWords names makes the code harder to understand, in my opinion (especially seeing as SE highlights them a different colour).


You also seem to have an awful lot of duplicate code.  Try to factor common operations (such as setting up all those members) into separate functions.

Speaking of which, your functions aren't particularly clear.  Why does a method called get not return anything?  What is it supposed to get?

You've got plenty of hard-coded values in there.  I hope that strYourSecretKey is a placeholder value; the other ones should be passed in as parameters.  Could you make it determine the agent ID based on the email?  As things are, it seems like this is prone to incorrect combinations of input if anything is changed.