Okay so im working on a store system, and we are adding our second gateway which will be paymentwall, however im struggling to find a good way to add more than one gateway.
The issue is that Paypal our first gateway which we added just uses a post form so it was easy to add by just dropping the html into the template, however Paymentwall you actually recieve the html by request and of course not ever store is going to use both.
So i need to loop over there gateways and add the correct html into there checkout pages however this is not a issue really for Paymentwall but for paypal it is since it means i have to take the post form and replace certain things based on the store and user checking out.
def multiwordReplace(text, wordDic):
"""
take a text and replace words that match a key in a dictionary with
the associated value, return the changed text
"""
rc = re.compile('|'.join(map(re.escape, wordDic)))
def translate(match):
return wordDic[match.group(0)]
return rc.sub(translate, text)
def PaypalAPI(marketid, cartid, username, cart_total):
try:
print("Getting paypal form")
gateway = Gateway.objects.get(marketid=marketid, type=1)
print(marketid)
print(cartid)
print(username)
print(cart_total)
dict = {'email':gateway.ppemail, 'currencycode':gateway.ppcurrency.code, 'cartid':str(cartid), 'user':str(username), 'cart_total':str(cart_total)}
postform = '<form action="https://www.paypal.com/cgi-bin/webscr" target="_new" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="email"><input type="hidden" name="currency_code" value="currencycode"><input type="hidden" name="item_name" value="MinecraftMarket Purchase"><input type="hidden" name="on0" value="Minecraft Username"><input type="hidden" name="os0" value="user"><input type="hidden" name="custom" value="cartid"><input type="hidden" name="amount" value="cart_total"><input type="hidden" name="notify_url" value="http://www.minecraftmarket.com/paycart/"><input type="submit" name="submit" class="btn btn-success btn-block" value="Continue"></form>'
paypalform = multiwordReplace(postform, dict)
return paypalform
except Exception, e:
print(e)
I have tried various ways via, context_proccessor, template tag and now i have gone back to view based.
And it still feels wrong having to hack that post form together, what could be a better way to do it and would a redirect page be a better option so technically no-one would see the post form and instead i post it within a function?