fork download
  1. <?php
  2. class IyzicocheckoutformResultModuleFrontController extends ModuleFrontController {
  3.  
  4. public $ssl = true;
  5. public $display_column_left = false;
  6.  
  7. public function initContent() {
  8. parent::initContent();
  9.  
  10. $module_action = Tools::getValue('module_action');
  11. $action_list = array('result' => 'initResult', 'payment' => 'initPayment');
  12.  
  13. if (isset($action_list[$module_action])) {
  14. $this->{$action_list[$module_action]}();
  15. }
  16. }
  17.  
  18. public function initResult() {
  19. IyzipayBootstrap::init();
  20.  
  21. $iyzico = new Iyzicocheckoutform();
  22.  
  23. $context = Context::getContext();
  24. $language_iso_code = $this->$context->language->iso_code;
  25. $locale = ($language_iso_code == "tr") ? Iyzipay\Model\Locale::TR : Iyzipay\Model\Locale::EN;
  26. $cart = $context->cart;
  27. $error_msg = '';
  28.  
  29.  
  30. try {
  31. $token = Tools::getValue('token');
  32.  
  33. if (empty($token)) {
  34. $error_msg = ($language_iso_code == "tr") ? 'Güvenlik token bulunamadı' : 'Token not found.';
  35. }
  36.  
  37. $cart_total = 0;
  38.  
  39. $options = new \Iyzipay\Options();
  40. $options->setApiKey(Configuration::get('IYZICO_FORM_LIVE_API_ID'));
  41. $options->setSecretKey(Configuration::get('IYZICO_FORM_LIVE_SECRET'));
  42. $options->setBaseUrl("https://a...content-available-to-author-only...y.com");
  43.  
  44. $request = new \Iyzipay\Request\RetrieveCheckoutFormRequest();
  45. $request->setLocale($locale);
  46. $request->setToken($token);
  47.  
  48. Db::getInstance()->insert("iyzico_api_log", array(
  49. 'id' => Tools::getValue('id'),
  50. 'order_id' => (int) $cart->id,
  51. 'item_id' => 0,
  52. 'transaction_status' => '',
  53. 'api_request' => pSQL($request->toJsonString()),
  54. 'api_response' => '',
  55. 'request_type' => 'get_auth',
  56. 'note' => '',
  57. 'created' => date('Y-m-d H:i:s'),
  58. 'updated' => date('Y-m-d H:i:s'),
  59. ));
  60.  
  61. $last_insert_id = Db::getInstance()->Insert_ID();
  62.  
  63. $response = \Iyzipay\Model\CheckoutForm::retrieve($request, $options);
  64.  
  65. $status = $response->getStatus();
  66. if (empty($status) || (!empty($status) && 'failure' == $status)) {
  67. throw new \Exception($response->getErrorMessage());
  68. }
  69.  
  70. if ($response->getPaymentStatus() == "FAILURE") {
  71. throw new \Exception($response->getErrorMessage());
  72. }
  73.  
  74. $basket_id = pSQL($response->getBasketId());
  75.  
  76. if ((int) $cart->id != $basket_id) {
  77. $error_msg = ($language_iso_code == "tr") ? "Geçersiz istek" : "Invalid request";
  78. }
  79.  
  80. $query = 'SELECT * FROM `' . _DB_PREFIX_ . 'iyzico_order_form` WHERE `order_id`= "' . $basket_id . '"';
  81. $order = Db::getInstance()->ExecuteS($query);
  82.  
  83. if (!empty($order)) {
  84. $error_msg = ($language_iso_code == "tr") ? "Sipariş zaten var." : "Order already exists.";
  85. }
  86.  
  87. $cart_total = (float) $cart->getOrderTotal(true, Cart::BOTH);
  88. $total = pSQL($response->getPaidPrice());
  89. $payment_currency = pSQL($response->getCurrency());
  90. $currency = new Currency((int) ($cart->id_currency));
  91. $iso_code = ($currency->iso_code) ? $currency->iso_code : '';
  92.  
  93. $iyzico->validateOrder((int) $cart->id, Configuration::get('PS_OS_PAYMENT'), $cart_total, $iyzico->displayName, null, $total, (int) $currency->id, false, $cart->secure_key);
  94.  
  95. $cart->id_customer = (int) $cart->id_customer;
  96.  
  97. if (!empty($cart->id_customer)) {
  98. $cardcustomer = 'SELECT * FROM `' . _DB_PREFIX_ . 'iyzico_cart_save` WHERE `customer_id`= "' . $cart->id_customer . '"';
  99. if ($row = Db::getInstance()->getRow($cardcustomer)){
  100.  
  101. $card_user_key = pSQL($response->GetcardUserKey());
  102. $merchant_api_id = Configuration::get('IYZICO_FORM_LIVE_API_ID');
  103. $customer_id = $cart->id_customer;
  104.  
  105. $card_update_array = array(
  106. 'customer_id' => $customer_id,
  107. 'card_key' => $card_user_key,
  108. 'api_key' => $merchant_api_id,
  109.  
  110. );
  111.  
  112. Db::getInstance()->update('iyzico_cart_save', $card_update_array, 'customer_id = ' . (int) $customer_id);
  113.  
  114. }else{
  115.  
  116. $card_user_key = pSQL($response->GetcardUserKey());
  117. $merchant_api_id = Configuration::get('IYZICO_FORM_LIVE_API_ID');
  118. $customer_id = $cart->id_customer;
  119.  
  120. $card_update_array = array(
  121. 'customer_id' => $customer_id,
  122. 'card_key' => $card_user_key,
  123. 'api_key' => $merchant_api_id,
  124. );
  125.  
  126. $cardfields = '`' . implode('`,`', array_keys($card_update_array)) . '`';
  127. $cardparams = "'" . implode("','", array_values($card_update_array)) . "'";
  128. $card_query = "INSERT INTO `" . _DB_PREFIX_ . "iyzico_cart_save` ({$cardfields}) VALUES ({$cardparams})";
  129. Db::getInstance()->execute($card_query);
  130.  
  131. }
  132. }
  133.  
  134. if ($response->getInstallment()) {
  135.  
  136. $order = new Order($iyzico->currentOrder);
  137. $current_order_id = $order->id;
  138. $installment_fee = abs($response->getPaidPrice() - $response->getPrice());
  139.  
  140. $response_arr = array(
  141. 'order_id' => (int) $current_order_id,
  142. 'transaction_id' => $cart->id,
  143. 'installment_fee' => pSQL($installment_fee),
  144. 'installment_amount' => (double) $total,
  145. 'installment_no' => (int) pSQL($response->getInstallment()),
  146. 'installment_brand' => pSQL($response->getCardAssociation()),
  147. 'response_data' => pSQL($response->getRawResult()),
  148. 'created' => date('Y-m-d H:i:s'),
  149. 'processing_time' => pSQL($response->getSystemTime())
  150. );
  151. IyzicocheckoutformOrder::insertOrder($response_arr);
  152.  
  153. $order_detail = $response->getPaymentItems();
  154.  
  155. foreach ($order_detail as $detail) {
  156. $detail_arr = array(
  157. 'order_id' => (int) $current_order_id,
  158. 'item_id' => pSQL($detail->getItemId()),
  159. 'payment_transaction_id' => pSQL($detail->getPaymentTransactionId()),
  160. 'paid_price' => pSQL($detail->getPaidPrice()),
  161. 'currency' => $payment_currency,
  162. 'total_refunded_amount' => 0,
  163. 'created' => date('Y-m-d H:i:s'),
  164. 'updated' => date('Y-m-d H:i:s'),
  165. );
  166.  
  167. $dbFields = '`' . implode('`,`', array_keys($detail_arr)) . '`';
  168. $dbParams = "'" . implode("','", array_values($detail_arr)) . "'";
  169.  
  170. $detail_query = "INSERT INTO `" . _DB_PREFIX_ . "iyzico_cart_detail` ({$dbFields}) VALUES ({$dbParams})";
  171. Db::getInstance()->execute($detail_query);
  172.  
  173. $update_id_array = array(
  174. 'order_id' => (int) $current_order_id,
  175. 'updated' => date('Y-m-d H:i:s'),
  176. );
  177.  
  178. Db::getInstance()->update('iyzico_api_log', $update_id_array, 'order_id = ' . (int) $cart->id);
  179.  
  180. $update_array = array(
  181. 'order_id' => (int) $current_order_id,
  182. 'transaction_status' => 'success',
  183. 'api_response' => pSQL($response->getRawResult()),
  184. 'updated' => date('Y-m-d H:i:s'),
  185. );
  186.  
  187. Db::getInstance()->update('iyzico_api_log', $update_array, 'id = ' . (int) $last_insert_id);
  188. }
  189. }
  190. $this->context->smarty->assign(array(
  191. 'error' => $error_msg,
  192. 'total' => $total,
  193. 'currency' => $iso_code,
  194. 'locale' => $locale,
  195. ));
  196. $this->setTemplate('module:iyzicocheckoutform/views/templates/front/order_result.tpl');
  197. } catch (\Exception $ex) {
  198. $error_msg = $ex->getMessage();
  199. if(!empty($error_msg)){
  200. if($language_iso_code=='tr'){
  201. $error_msg="Bir hata oluştu, lütfen tekrar deneyin.";
  202. }else{
  203. $error_msg="Unknown Error, please try again";
  204. }
  205. }
  206. $this->context->smarty->assign(array(
  207. 'error' => $error_msg,
  208. ));
  209. $this->setTemplate('module:iyzicocheckoutform/views/templates/front/order_result.tpl');
  210. }
  211. }
  212.  
  213. public function initPayment() {
  214. $context = Context::getContext();
  215. $cart = $context->cart;
  216. $zero_total = $context->cookie->zero_total;
  217.  
  218. $iyzico = new Iyzicocheckoutform();
  219. $currency = new Currency((int) ($cart->id_currency));
  220. $iso_code = ($currency->iso_code) ? $currency->iso_code : '';
  221. $cart_total = (float) $cart->getOrderTotal(true, Cart::BOTH);
  222. $shipping_toal = (float) $cart->getOrderTotal(true, Cart::ONLY_SHIPPING);
  223. $language_iso_code = $context->language->iso_code;
  224. if ($cart_total == $shipping_toal && $zero_total) {
  225. $total = 0;
  226. $cart_total = 0;
  227. $error_msg = ($language_iso_code == "tr") ? 'Alışveriş tutarı indirim tutarına eşit olamaz.' : 'Cart total cannot be equal to discount amount.' ;
  228. $this->context->smarty->assign(array(
  229. 'error' => $error_msg,
  230. 'total' => $total,
  231. 'currency' => $iso_code,
  232. ));
  233. $iyzico->validateOrder((int) $cart->id, Configuration::get('PS_OS_PAYMENT'), $cart_total, $iyzico->displayName, null, $total, (int) $currency->id, false, $cart->secure_key);
  234. $this->setTemplate('module:iyzicocheckoutform/views/templates/front/order_result.tpl');
  235. }
  236. }
  237.  
  238. }
  239.  
Runtime error #stdin #stdout #stderr 0.02s 23504KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Class 'ModuleFrontController' not found in /home/H5YD8w/prog.php on line 2