Advertisement
Guest User

Untitled

a guest
Mar 9th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Loader)
  6. *
  7. * @ Version : 2.0.0.3
  8. * @ Author : DeZender
  9. * @ Release on : 06.05.2013
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. if (!(defined("_JEXEC")))
  15. {
  16. exit("Restricted access");
  17. }
  18. if (!class_exists("vmPSPlugin"))
  19. {
  20. require JPATH_VM_PLUGINS . DS . "vmpsplugin.php";
  21. }
  22. class plgVmPaymentHellaspay extends vmPSPlugin {
  23.  
  24. public static $_this = false;
  25. private $_vivinstalments = "";
  26. private $_vivinstalmentsamount = "";
  27. private $instalmentoptions = "";
  28. private $instalmentcharge = "";
  29. private $split_instal_hellaspay = "";
  30. private $merchant_ref = "";
  31. private $hellaspay_amount = "";
  32. private $hellaspay_lang = "";
  33. private $hellaspay_period = "";
  34. private $hellaspay_period_note = "";
  35. private $tm_private_key = "QzIwMTJfVC5DLiB2YW4gZGVyIFZlZXJfd2ViaXQuYno=";
  36. public function __construct(&$subject, $config) {
  37.  
  38. parent::__construct($subject, $config);
  39. $this->_loggable = true;
  40. $this->tableFields = array_keys($this->getTableSQLFields());
  41. $this->_tablepkey = "id";
  42. $this->_tableId = "id";
  43. $varsToPush = array("hellaspay_merchant_id" => array("", "char"), "hellaspay_merchant_pass" => array("", "char"), "hellaspay_source" => array("", "char"), "hellaspay_instalments" => array("", "char"), "hellaspay_instalments_charge" => array("", "char"), "hellaspay_production" => array("", "int"), "payment_currency" => array("", "int"), "payment_logos" => array("", "char"), "debug" => array(0, "int"), "status_pending" => array("", "char"), "status_success" => array("", "char"), "status_canceled" => array("", "char"), "language" => array("", "char"), "countries" => array("", "char"), "min_amount" => array("", "int"), "max_amount" => array("", "int"), "cost_per_transaction" => array("", "int"), "cost_percent_total" => array("", "int"), "tax_id" => array(0, "int"));
  44. $this->setConfigParameterable($this->_configTableFieldName, $varsToPush);
  45. return;
  46. }
  47.  
  48. public function getVmPluginDropTableSQL() {
  49.  
  50. $db = JFactory::getdbo();
  51. $config = JFactory::getconfig();
  52. $table = $config->getValue("config.dbprefix") . "virtuemart_payment_plg_hellaspay";
  53. $db->setQuery("DROP TABLE " . $table);
  54. return $db->query();
  55. }
  56.  
  57. public function getVmPluginCreateTableSQL() {
  58.  
  59. $this->getVmPluginDropTableSQL();
  60. return $this->createTableSQL("Payment HellasPay Table");
  61. }
  62.  
  63. public function getTableSQLFields() {
  64.  
  65. $SQLfields = array("id" => " INT(11) unsigned NOT NULL AUTO_INCREMENT ", "virtuemart_order_id" => " int(1) UNSIGNED DEFAULT NULL", "order_number" => " char(32) DEFAULT NULL", "virtuemart_paymentmethod_id" => " mediumint(1) UNSIGNED DEFAULT NULL", "payment_name" => "varchar(5000)", "payment_order_total" => "decimal(15,5) NOT NULL DEFAULT '0.00000' ", "payment_currency" => "char(3) ", "cost_per_transaction" => " decimal(10,2) DEFAULT NULL ", "cost_percent_total" => " decimal(10,2) DEFAULT NULL ", "tax_id" => " smallint(1) DEFAULT NULL", "hellaspay_custom" => " varchar(255) ", "hellaspay_OrderCode" => " varchar(255) ", "hellaspay_ErrorCode" => " varchar(255) ", "hellaspay_ErrorText" => " varchar(255) ", "hellaspay_ref" => " varchar(255) ", "hellaspay_order_state" => " char(1) DEFAULT NULL", "hellaspay_instalments" => " varchar(5) DEFAULT NULL", "hellaspayresponse_raw" => " varchar(512) DEFAULT NULL");
  66. return $SQLfields;
  67. }
  68.  
  69. public function plgVmConfirmedOrder($cart, $order) {
  70.  
  71. if (!($this->_currentMethod = $this->getVmPluginMethod($order["details"]["BT"]->virtuemart_paymentmethod_id)))
  72. {
  73. return NULL;
  74. }
  75. if (!$this->selectedThisElement($this->_currentMethod->payment_element))
  76. {
  77. return FALSE;
  78. }
  79. $session = JFactory::getsession();
  80. $return_context = $session->getId();
  81. if (!class_exists("VirtueMartModelOrders"))
  82. {
  83. require VMPATH_ADMIN . DS . "models" . DS . "orders.php";
  84. }
  85. if (!class_exists("VirtueMartModelCurrency"))
  86. {
  87. require VMPATH_ADMIN . DS . "models" . DS . "currency.php";
  88. }
  89. $new_status = "";
  90. $usrBT = $order["details"]["BT"];
  91. $address = isset($order["details"]["ST"]) ? ($order["details"]["ST"]) : ($order["details"]["BT"]);
  92. if (!class_exists("TableVendors"))
  93. {
  94. require VMPATH_ADMIN . DS . "table" . DS . "vendors.php";
  95. }
  96. $vendorModel = VmModel::getmodel("Vendor");
  97. $vendorModel->setId(1);
  98. $vendor = $vendorModel->getVendor();
  99. $vendorModel->addImages($vendor, 1);
  100. $this->getPaymentCurrency($this->_currentMethod);
  101. $q = "SELECT `currency_code_3` FROM `#__virtuemart_currencies` WHERE `virtuemart_currency_id`=\"" . $this->_currentMethod->payment_currency . "\" ";
  102. $db = &JFactory::getdbo();
  103. $db->setQuery($q);
  104. $currency_code_3 = $db->loadResult();
  105. $paymentCurrency = CurrencyDisplay::getinstance($this->_currentMethod->payment_currency);
  106. $totalInPaymentCurrency = round($paymentCurrency->convertCurrencyTo($this->_currentMethod->payment_currency, $order["details"]["BT"]->order_total, false), 2);
  107. $cd = CurrencyDisplay::getinstance($cart->pricesCurrency);
  108. $merchant_id = $this->_getMerchantId($this->_currentMethod);
  109. if (empty($merchant_id))
  110. {
  111. vmInfo(vmText::_("VMPAYMENT_HELLASPAY_MERCHANT_ID_NOT_SET"));
  112. return false;
  113. }
  114. $merchant_pass = $this->_getMerchantPass($this->_currentMethod);
  115. if (empty($merchant_pass))
  116. {
  117. vmInfo(vmText::_("VMPAYMENT_HELLASPAY_MERCHANT_PASS_NOT_SET"));
  118. return false;
  119. }
  120. $merchant_ref = "REF" . substr(md5(uniqid(rand(), true)), 0, 9);
  121. $TmSecureKey = "d2ViaXQuYnovbGljZW5zZS50eHQ=";
  122. $hellaspay_amount = number_format($totalInPaymentCurrency, 2, ".", "") * 100;
  123. $lang = JFactory::getlanguage();
  124. $this->lang_tag = $lang->getTag();
  125. if (strtolower($this->lang_tag) == "el-gr")
  126. {
  127. $hellaspay_lang = "el-GR";
  128. }
  129. else
  130. {
  131. $hellaspay_lang = "en-US";
  132. }
  133. $this->_getHellaspayIntoSession();
  134. if (1 < $this->_vivinstalments)
  135. {
  136. $hellaspay_period = $this->_vivinstalments;
  137. $hellaspay_period_note = "- Instalments: " . $this->_vivinstalments;
  138. }
  139. else
  140. {
  141. $hellaspay_period = "0";
  142. $hellaspay_period_note = "";
  143. }
  144. if (0 < $hellaspay_period)
  145. {
  146. $Installments = (int)$hellaspay_period;
  147. }
  148. else
  149. {
  150. $Installments = "1";
  151. }
  152. $postargs = "Amount=" . urlencode($hellaspay_amount) . "&RequestLang=" . urlencode($hellaspay_lang) . "&Email=" . urlencode($order["details"]["BT"]->email) . "&MaxInstallments=" . urlencode($Installments) . "&MerchantTrns=" . urlencode($order["details"]["BT"]->order_number) . "&SourceCode=" . urlencode($this->_currentMethod->hellaspay_source) . "&PaymentTimeOut=300";
  153. if ($this->_currentMethod->hellaspay_production == "1")
  154. {
  155. $curl = curl_init("http://demo.vivapayments.com/api/orders");
  156. }
  157. else
  158. {
  159. $curl = curl_init("https://www.vivapayments.com/api/orders");
  160. }
  161. curl_setopt($curl, CURLOPT_POST, true);
  162. curl_setopt($curl, CURLOPT_POSTFIELDS, $postargs);
  163. curl_setopt($curl, CURLOPT_HEADER, false);
  164. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  165. curl_setopt($curl, CURLOPT_USERPWD, $this->_currentMethod->hellaspay_merchant_id . ":" . $this->_currentMethod->hellaspay_merchant_pass);
  166. $curlversion = curl_version();
  167. if (!preg_match("/NSS/", $curlversion["ssl_version"]))
  168. {
  169. curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");
  170. }
  171. if ($this->_currentMethod->hellaspay_production != "1");
  172. if (!($response = curl_exec($curl)))
  173. {
  174. die(curl_error($curl));
  175. }
  176. curl_close($curl);
  177. try
  178. {
  179. $resultObj = json_decode($response);
  180. }
  181. catch (Exception $e)
  182. {
  183. throw new Exception("Result is not a json object (" . $e->getMessage() . ")");
  184. }
  185. if ($resultObj->ErrorCode == 0)
  186. {
  187. $OrderCode = $resultObj->OrderCode;
  188. $ErrorCode = $resultObj->ErrorCode;
  189. $ErrorText = $resultObj->ErrorText;
  190. }
  191. else
  192. {
  193. throw new Exception("Unable to create order code (" . $resultObj->ErrorText . ")");
  194. }
  195. $dbValues["order_number"] = $order["details"]["BT"]->order_number;
  196. $dbValues["payment_name"] = parent::renderpluginname($this->_currentMethod);
  197. $dbValues["virtuemart_paymentmethod_id"] = $cart->virtuemart_paymentmethod_id;
  198. $dbValues["hellaspay_custom"] = $return_context;
  199. $dbValues["hellaspay_instalments"] = $Installments;
  200. $dbValues["hellaspay_OrderCode"] = '' . $OrderCode;
  201. $dbValues["hellaspay_ErrorCode"] = '' . $ErrorCode;
  202. $dbValues["hellaspay_ErrorText"] = '' . $ErrorText;
  203. $dbValues["cost_per_transaction"] = $this->_currentMethod->cost_per_transaction;
  204. $dbValues["cost_percent_total"] = $this->_currentMethod->cost_percent_total;
  205. $dbValues["payment_currency"] = "978";
  206. $dbValues["payment_order_total"] = $totalInPaymentCurrency;
  207. $dbValues["tax_id"] = $this->_currentMethod->tax_id;
  208. $this->storePSPluginInternalData($dbValues);
  209. $post_variables = array("Ref" => $OrderCode);
  210. if ($this->_currentMethod->hellaspay_production == "1")
  211. {
  212. $url = "http://demo.vivapayments.com/web/newtransaction.aspx";
  213. }
  214. else
  215. {
  216. $url = "https://www.vivapayments.com/web/newtransaction.aspx";
  217. }
  218. $html = "<html><head><title>Redirection</title></head><body><div style=\"margin: auto; text-align: center;\">";
  219. $html .= "<form action=\"" . $url . "\" method=\"get\" name=\"vm_hellaspay_form\" >";
  220. $html .= "<input type=\"submit\" value=\"" . vmText::_("VMPAYMENT_HELLASPAY_REDIRECT_MESSAGE") . "\" />";
  221. foreach ($post_variables as $name => $value)
  222. {
  223. $html .= "<input type=\"hidden\" name=\"" . $name . "\" value=\"" . htmlspecialchars($value) . "\" />";
  224. continue;
  225. }
  226. $html .= "</form></div>";
  227. $html .= " <script type=\"text/javascript\">";
  228. $html .= " document.vm_hellaspay_form.submit();";
  229. $html .= " </script></body></html>";
  230. return $this->processConfirmedOrderPaymentResponse(2, $cart, $order, $html, $dbValues["payment_name"], $new_status);
  231. }
  232.  
  233. public function plgVmgetPaymentCurrency($virtuemart_paymentmethod_id, &$paymentCurrencyId) {
  234.  
  235. if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id)))
  236. {
  237. return NULL;
  238. }
  239. if (!$this->selectedThisElement($this->_currentMethod->payment_element))
  240. {
  241. return FALSE;
  242. }
  243. $this->getPaymentCurrency($this->_currentMethod);
  244. $paymentCurrencyId = $this->_currentMethod->payment_currency;
  245. return;
  246. }
  247.  
  248. public function _getHtmlPaymentResponse($msg, $is_success = true, $order_id = null, $order_nr = null, $amount = null, $txid = null, $period = null, $date = null, $paymethodid = null) {
  249.  
  250. if (!$is_success)
  251. {
  252. ..........................................................................
  253. ..............................
  254. ........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement