first succesfull transfer of form to PayWay
[indico-PayWay] / MaKaC / plugins / EPayment / payWay / epayment.py
index 435c20e..0fd4a75 100644 (file)
@@ -25,14 +25,17 @@ from MaKaC.webinterface.common.tools import strip_ml_tags
 from MaKaC.plugins.EPayment.payWay.webinterface import urlHandlers as localUrlHandlers
 from MaKaC.plugins.EPayment.payWay import MODULE_ID
 
+import unicodedata
+import hashlib
+
 class PayWayMod(BaseEPayMod):
 
     def __init__(self, data=None):
         BaseEPayMod.__init__(self)
         self._title = "payway"
 
-        self._url="https://www.payway.com/cgi-bin/webscr"
-        self._business= ""
+        self._url="https://pgwtest.ht.hr/services/payment/api/authorize-form"
+        self._business= "please fill in private key here"
 
         if data is not None:
             setValue(data)
@@ -63,24 +66,110 @@ class PayWayMod(BaseEPayMod):
     def setBusiness(self,business):
         self._business= business
 
+    def strip_accents(self,text):
+        """
+        Strip accents from input String.
+    
+        :param text: The input string.
+        :type text: String.
+    
+        :returns: The processed String.
+        :rtype: String.
+        """
+        try:
+            text = unicode(text, 'utf-8')
+        except NameError: # unicode is a default on python 3 
+            pass
+        text = unicodedata.normalize('NFD', text)
+        text = text.encode('ascii', 'ignore')
+        text = text.decode("utf-8")
+        return str(text)
+
     def getFormHTML(self,prix,Currency,conf,registrant,lang = "en_GB", secure=False):
-        url_return=localUrlHandlers.UHPayConfirmPayWay.getURL(registrant)
-        url_cancel_return=localUrlHandlers.UHPayCancelPayWay.getURL(registrant)
+
+       pgw_shop_id=str(20000573)
+       pgw_order_id=str(registrant.getId())
+       pgw_amount=str(int(prix * 100))
+
+        pgw_success_url=str(localUrlHandlers.UHPayConfirmPayWay.getURL(registrant))
+        pgw_failure_url=str(localUrlHandlers.UHPayCancelPayWay.getURL(registrant))
         url_notify=localUrlHandlers.UHPayParamsPayWay.getURL(registrant)
-        s=""" <form action="%s" method="POST" id="%s">
-                        <input type="hidden" name="cmd" value="_xclick">
-                        <input type="hidden" name="business" value="%s">
-                        <input type="hidden" name="item_name" value="%s">
-                        <input type="hidden" name="amount" value="%s">
-                        <INPUT TYPE="hidden" NAME="currency_code" value="%s">
-                        <input type="hidden" name="charset" value="utf-8">
-                        <input type="hidden" name="return" value="%s">
-                        <input type="hidden" name="cancel_return" value="%s">
-                        <input type="hidden" name="notify_url" value="%s">
-                   </form>
-                       """%(self.getUrl(),self.getId(),self.getBusiness(), "%s: registration for %s"%(registrant.getFullName(),strip_ml_tags(conf.getTitle())),prix,Currency,\
-                            url_return,url_cancel_return,url_notify)
-        #s=cgi.escape(s)
+
+        pgw_first_name=self.strip_accents(registrant.getFirstName())
+        pgw_last_name=self.strip_accents(registrant.getSurName())
+
+       pgw_telephone=registrant.getPhone()
+       pgw_email=registrant.getEmail()
+
+       secret_key=self.getBusiness()
+       pgw_signature= \
+'authorize-form' + secret_key + \
+pgw_shop_id + secret_key + \
+pgw_order_id + secret_key + \
+pgw_amount + secret_key + \
+'0' + secret_key + \
+'en' + secret_key + \
+pgw_success_url + secret_key + \
+pgw_failure_url + secret_key + \
+pgw_first_name + secret_key + \
+pgw_last_name + secret_key + \
+pgw_telephone + secret_key + \
+pgw_email + secret_key
+
+       """
+gnature = SHA512 (
+naziv_metode + secret_key +
+pgw_shop_id + secret_key +
+pgw_order_id + secret_key +
+pgw_amount + secret_key +
+#pgw_installments + secret_key +
+pgw_authorization_type + secret_key +
+#pgw_authorization_token + secret_key +
+pgw_language + secret_key +
+#pgw_return_method + secret_key +
+pgw_success_url + secret_key +
+pgw_failure_url + secret_key +
+#pgw_card_number + secret_key +
+#pgw_card_expiration_date + secret_key +
+#pgw_card_verification_data + secret_key +
+pgw_first_name + secret_key +
+pgw_last_name + secret_key +
+#pgw_street + secret_key +
+#pgw_city + secret_key +
+#pgw_post_code + secret_key +
+#pgw_country + secret_key +
+pgw_telephone + secret_key +
+pgw_email + secret_key +
+#pgw_merchant_data + secret_key
+"""
+
+       pgw_signature=hashlib.sha512(pgw_signature).hexdigest()
+
+        s="""<form name="Button" action="%s" method="post" id="%s">
+             <input type="hidden" name="pgw_shop_id" value="%s" />
+             <input type="hidden" name="pgw_order_id" value="%s" />
+             <input type="hidden" name="pgw_amount" value="%s" />
+
+             <input type="hidden" name="pgw_authorization_type" value="0" />
+             <input type="hidden" name="pgw_language" value="en" />
+
+             <input type="hidden" name="pgw_success_url" value="%s" />
+             <input type="hidden" name="pgw_failure_url" value="%s" />
+
+             <input type="hidden" name="pgw_first_name" value="%s" />
+             <input type="hidden" name="pgw_last_name" value="%s" />
+
+             <input type="hidden" name="pgw_telephone" value="%s" />
+             <input type="hidden" name="pgw_email" value="%s" />
+             
+             <input type="hidden" name="pgw_signature" value="%s" />
+
+             </form>""" % (self.getUrl(), self.getId(), \
+               pgw_shop_id, pgw_order_id, pgw_amount, \
+               pgw_success_url, pgw_failure_url, \
+               pgw_first_name, pgw_last_name, pgw_telephone, pgw_email, \
+               pgw_signature)
+
         return s
 
     def getConfModifEPaymentURL(self, conf):