HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

Payment system for a web shop

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
paymentsystemforshopweb

Problem

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)

Solution

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.

Context

StackExchange Code Review Q#7503, answer score: 4

Revisions (0)

No revisions yet.