name = 'imoje'; $this->displayName = 'imoje'; $this->tab = 'payments_gateways'; $this->version = '1.11.0'; $this->author = 'imoje'; $this->need_instance = 1; $this->currencies = true; $this->currencies_mode = 'checkbox'; $this->ps_versions_compliancy = [ 'min' => '1.7', 'max' => '1.7', ]; $this->is_eu_compatible = 1; parent::__construct(); $this->displayName = $this->l('imoje'); $this->description = $this->l('Visa, MasterCard, BLIK ect.'); $this->confirm_uninstall = $this->l('Are you sure you want to uninstall imoje module?'); } /** * @param $name * @param $type * * @return string */ public static function buildTemplatePath($name, $type) { return 'module:imoje/views/templates/' . $type . '/' . $name . '.tpl'; } /** * This function installs the imoje Module * * @return boolean * @throws PrestaShopDatabaseException * @throws PrestaShopException */ public function install() { if (extension_loaded('curl') == false) { $this->_errors[] = $this->l('You have to enable the cURL extension on your server to install this module'); return false; } include(dirname(__FILE__) . '/sql/ImojeSql.php'); if(!ImojeSql::install()){ $this->_errors[] = $this->l('Something went wrong with creating table imoje_transaction_list.'); return false; } if (!( parent::install() && $this->registerHook('paymentOptions') && $this->registerHook('orderConfirmation') && $this->registerHook('paymentReturn') && $this->registerHook('displayBackOfficeHeader') && $this->registerHook('displayHeader') && $this->registerHook('displayReassurance') && Configuration::updateValue('IMOJE_SANDBOX', 0) && Configuration::updateValue('IMOJE_DEBUG_MODE', 0) && Configuration::updateValue('IMOJE_CREATE_ORDER_ARRANGEMENT', 0) && Configuration::updateValue('IMOJE_SERVICE_ID', '') && Configuration::updateValue('IMOJE_SERVICE_KEY', '') && Configuration::updateValue('IMOJE_MERCHANT_ID', '') && Configuration::updateValue('IMOJE_GA_KEY', '') && Configuration::updateValue('IMOJE_IMOJE_BUTTON', 1) && Configuration::updateValue('IMOJE_PAYMENT_TITLE', '') && Configuration::updateValue('IMOJE_CURRENCIES', []) && Configuration::updateValue('IMOJE_HIDE_BRAND', 0) && Configuration::updateValue('IMOJE_BLIK_BUTTON', 0) && Configuration::updateValue('IMOJE_BLIK_PAYMENT_TITLE', '') && Configuration::updateValue('IMOJE_BLIK_HIDE_BRAND', 0) && Configuration::updateValue('IMOJE_BLIK_CODE_CHECKOUT', 0) && Configuration::updateValue('IMOJE_BLIK_CURRENCIES', []) // && Configuration::updateValue('IMOJE_BLIK_ONECLICK', 0) && Configuration::updateValue('IMOJE_PBL_BUTTON', 0) && Configuration::updateValue('IMOJE_PBL_PAYMENT_TITLE', '') && Configuration::updateValue('IMOJE_PBL_HIDE_BRAND', 0) && Configuration::updateValue('IMOJE_PBL_CURRENCIES', []) && Configuration::updateValue('IMOJE_CARDS_BUTTON', 0) && Configuration::updateValue('IMOJE_CARDS_PAYMENT_TITLE', '') && Configuration::updateValue('IMOJE_CARDS_HIDE_BRAND', 0) && Configuration::updateValue('IMOJE_CARDS_CURRENCIES', []) && Configuration::updateValue('IMOJE_PAYLATER_BUTTON', 0) && Configuration::updateValue('IMOJE_PAYLATER_PAYMENT_TITLE', '') && Configuration::updateValue('IMOJE_PAYLATER_HIDE_BRAND', 0) && Configuration::updateValue('IMOJE_PAYLATER_CURRENCIES', []) && Configuration::updateValue('IMOJE_TOKEN', '') )) { return false; } if (Validate::isInt(Configuration::get('PAYMENT_IMOJE_NEW_STATUS')) xor (Validate::isLoadedObject($orderStateNew = new OrderState(Configuration::get('PAYMENT_IMOJE_NEW_STATUS'))))) { $orderStateNew = new OrderState(); $missingLang = true; $langs = [ 'en' => 'Payment imoje: awaiting for confirmation', 'pl' => 'Płatność imoje: oczekuje na potwierdzenie', ]; foreach ($langs as $lang => $message) { $langId = Language::getIdByIso($lang); if (isset($langId)) { $orderStateNew->name[$langId] = $message; $missingLang = false; } } if ($missingLang) { $langId = (int) $this->context->language->id; $orderStateNew->name[$langId] = $langs['en']; } $orderStateNew->send_email = false; $orderStateNew->invoice = false; $orderStateNew->unremovable = false; $orderStateNew->color = "lightblue"; if (!$orderStateNew->add()) { $this->_errors[] = $this->l('There was an Error installing the module. Cannot add new order state.'); return false; } if (!Configuration::updateValue('PAYMENT_IMOJE_NEW_STATUS', $orderStateNew->id)) { $this->_errors[] = $this->l('There was an Error installing the module. Cannot update new order state.'); return false; } copy(_PS_MODULE_DIR_ . $this->name . '/imoje.gif', _PS_IMG_DIR_ . 'os/' . $orderStateNew->id . '.gif'); } return true; } /** * This function uninstalls the imoje Module * * @return boolean */ public function uninstall() { return Configuration::deleteByName('IMOJE_SANDBOX') && Configuration::deleteByName('IMOJE_DEBUG_MODE') && Configuration::deleteByName('IMOJE_CREATE_ORDER_ARRANGEMENT') && Configuration::deleteByName('IMOJE_SERVICE_ID') && Configuration::deleteByName('IMOJE_SERVICE_KEY') && Configuration::deleteByName('IMOJE_MERCHANT_ID') && Configuration::deleteByName('IMOJE_GA_KEY') && Configuration::deleteByName('IMOJE_IMOJE_BUTTON') && Configuration::deleteByName('IMOJE_PAYMENT_TITLE') && Configuration::deleteByName('IMOJE_HIDE_BRAND') && Configuration::deleteByName('IMOJE_CURRENCIES') && Configuration::deleteByName('IMOJE_PAYLATER_BUTTON') && Configuration::deleteByName('IMOJE_PAYLATER_HIDE_BRAND') && Configuration::deleteByName('IMOJE_PAYLATER_PAYMENT_TITLE') && Configuration::deleteByName('IMOJE_PAYLATER_CURRENCIES') && Configuration::deleteByName('IMOJE_BLIK_BUTTON') && Configuration::deleteByName('IMOJE_BLIK_PAYMENT_TITLE') && Configuration::deleteByName('IMOJE_BLIK_HIDE_BRAND') && Configuration::deleteByName('IMOJE_BLIK_CODE_CHECKOUT') && Configuration::deleteByName('IMOJE_BLIK_CURRENCIES') // && Configuration::deleteByName('IMOJE_BLIK_ONECLICK') && Configuration::deleteByName('IMOJE_PBL_BUTTON') && Configuration::deleteByName('IMOJE_PBL_PAYMENT_TITLE') && Configuration::deleteByName('IMOJE_PBL_HIDE_BRAND') && Configuration::deleteByName('IMOJE_PBL_CURRENCIES') && Configuration::deleteByName('IMOJE_CARDS_BUTTON') && Configuration::deleteByName('IMOJE_CARDS_PAYMENT_TITLE') && Configuration::deleteByName('IMOJE_CARDS_HIDE_BRAND') && Configuration::deleteByName('IMOJE_CARDS_CURRENCIES') && Configuration::deleteByName('IMOJE_TOKEN') && parent::uninstall(); } /** * Display configuration form. * * @return mixed */ public function getContent() { $msg = ''; if (Tools::isSubmit('submitiMoje')) { if ($this->saveConfiguration()) { $msg = [ 'type' => 'success', 'message' => $this->l('Configuration updated successfully'), ]; } else { $msg = [ 'type' => 'error', 'message' => $this->l('There was an error saving your configuration'), ]; } } $this->context->smarty->assign([ 'imoje_form' => './index.php?tab=AdminModules&configure=imoje&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=imoje', 'imoje_enabled' => Configuration::get('IMOJE_ENABLED'), 'imoje_token' => Configuration::get('IMOJE_TOKEN'), 'imoje_debug_mode' => Configuration::get('IMOJE_DEBUG_MODE'), 'imoje_sandbox' => Configuration::get('IMOJE_SANDBOX'), 'imoje_create_order_arrangement' => Configuration::get('IMOJE_CREATE_ORDER_ARRANGEMENT'), 'imoje_service_id' => Configuration::get('IMOJE_SERVICE_ID'), 'imoje_service_key' => Configuration::get('IMOJE_SERVICE_KEY'), 'imoje_merchant_id' => Configuration::get('IMOJE_MERCHANT_ID'), 'imoje_notification_url' => $this->context->link->getModuleLink('imoje', 'notification'), 'imoje_msg' => $msg, 'imoje_ga_key' => Configuration::get('IMOJE_GA_KEY'), 'imoje_available_currencies' => Util::getSupportedCurrencies(), 'imoje_imoje_button' => Configuration::get('IMOJE_IMOJE_BUTTON'), 'imoje_hide_brand' => Configuration::get('IMOJE_HIDE_BRAND'), 'imoje_payment_title' => Configuration::get('IMOJE_PAYMENT_TITLE'), 'imoje_payment_title_default' => $this->getPaymentTitleDefault(), 'imoje_currencies' => explode(",", Configuration::get('IMOJE_CURRENCIES')), 'imoje_paylater_button' => Configuration::get('IMOJE_PAYLATER_BUTTON'), 'imoje_paylater_hide_brand' => Configuration::get('IMOJE_PAYLATER__HIDE_BRAND'), 'imoje_paylater_payment_title' => Configuration::get('IMOJE_PAYLATER_PAYMENT_TITLE'), 'imoje_paylater_payment_title_default' => $this->getPaylaterPaymentTitleDefault(), 'imoje_paylater_currencies' => explode(",", Configuration::get('IMOJE_PAYLATER_CURRENCIES')), 'imoje_is_token' => Configuration::get('IMOJE_TOKEN'), 'imoje_blik_button' => Configuration::get('IMOJE_BLIK_BUTTON'), 'imoje_blik_hide_brand' => Configuration::get('IMOJE_BLIK_HIDE_BRAND'), 'imoje_blik_code_checkout' => Configuration::get('IMOJE_BLIK_CODE_CHECKOUT'), 'imoje_blik_payment_title' => Configuration::get('IMOJE_BLIK_PAYMENT_TITLE'), // 'imoje_blik_oneclick' => Configuration::get('IMOJE_BLIK_ONECLICK'), 'imoje_blik_oneclick' => false, 'imoje_blik_payment_title_default' => $this->getBlikPaymentTitleDefault(), 'imoje_blik_currencies' => explode(",", Configuration::get('IMOJE_BLIK_CURRENCIES')), 'imoje_cards_button' => Configuration::get('IMOJE_CARDS_BUTTON'), 'imoje_cards_hide_brand' => Configuration::get('IMOJE_CARDS_HIDE_BRAND'), 'imoje_cards_payment_title' => Configuration::get('IMOJE_CARDS_PAYMENT_TITLE'), 'imoje_cards_payment_title_default' => $this->getCardsPaymentTitleDefault(), 'imoje_cards_currencies' => explode(",", Configuration::get('IMOJE_CARDS_CURRENCIES')), 'imoje_pbl_button' => Configuration::get('IMOJE_PBL_BUTTON'), 'imoje_pbl_hide_brand' => Configuration::get('IMOJE_PBL_HIDE_BRAND'), 'imoje_pbl_payment_title' => Configuration::get('IMOJE_PBL_PAYMENT_TITLE'), 'imoje_pbl_payment_title_default' => $this->getPblPaymentTitleDefault(), 'imoje_pbl_currencies' => explode(",", Configuration::get('IMOJE_PBL_CURRENCIES')), ]); return $this->fetchTemplate('admin.tpl'); } /** * @return bool */ private function saveConfiguration() { Configuration::updateValue('IMOJE_DEBUG_MODE', pSQL(Tools::getValue('imoje_debug_mode'))); Configuration::updateValue('IMOJE_SANDBOX', pSQL(Tools::getValue('imoje_sandbox'))); Configuration::updateValue('IMOJE_CREATE_ORDER_ARRANGEMENT', pSQL(Tools::getValue('imoje_create_order_arrangement'))); Configuration::updateValue('IMOJE_SERVICE_ID', pSQL(Tools::getValue('imoje_service_id'))); Configuration::updateValue('IMOJE_SERVICE_KEY', pSQL(Tools::getValue('imoje_service_key'))); Configuration::updateValue('IMOJE_MERCHANT_ID', pSQL(Tools::getValue('imoje_merchant_id'))); Configuration::updateValue('IMOJE_TOKEN', pSQL(Tools::getValue('imoje_token'))); Configuration::updateValue('IMOJE_GA_KEY', pSQL(Tools::getValue('imoje_ga_key'))); Configuration::updateValue('IMOJE_IMOJE_BUTTON', pSQL(Tools::getValue('imoje_imoje_button'))); Configuration::updateValue('IMOJE_HIDE_BRAND', pSQL(Tools::getValue('imoje_hide_brand'))); Configuration::updateValue('IMOJE_PAYMENT_TITLE', pSQL(Tools::getValue('imoje_payment_title'))); Configuration::updateValue('IMOJE_PAYLATER_BUTTON', pSQL(Tools::getValue('imoje_paylater_button'))); Configuration::updateValue('IMOJE_PAYLATER_HIDE_BRAND', pSQL(Tools::getValue('imoje_paylater_hide_brand'))); Configuration::updateValue('IMOJE_PAYLATER_PAYMENT_TITLE', pSQL(Tools::getValue('imoje_paylater_payment_title'))); Configuration::updateValue('IMOJE_BLIK_BUTTON', pSQL(Tools::getValue('imoje_blik_button'))); Configuration::updateValue('IMOJE_BLIK_HIDE_BRAND', pSQL(Tools::getValue('imoje_blik_hide_brand'))); Configuration::updateValue('IMOJE_BLIK_CODE_CHECKOUT', pSQL(Tools::getValue('imoje_blik_code_checkout'))); // Configuration::updateValue('IMOJE_BLIK_ONECLICK', pSQL(Tools::getValue('imoje_blik_oneclick'))); Configuration::updateValue('IMOJE_BLIK_PAYMENT_TITLE', pSQL(Tools::getValue('imoje_blik_payment_title'))); Configuration::updateValue('IMOJE_PBL_BUTTON', pSQL(Tools::getValue('imoje_pbl_button'))); Configuration::updateValue('IMOJE_PBL_HIDE_BRAND', pSQL(Tools::getValue('imoje_pbl_hide_brand'))); Configuration::updateValue('IMOJE_PBL_PAYMENT_TITLE', pSQL(Tools::getValue('imoje_pbl_payment_title'))); Configuration::updateValue('IMOJE_CARDS_BUTTON', pSQL(Tools::getValue('imoje_cards_button'))); Configuration::updateValue('IMOJE_CARDS_HIDE_BRAND', pSQL(Tools::getValue('imoje_cards_hide_brand'))); Configuration::updateValue('IMOJE_CARDS_PAYMENT_TITLE', pSQL(Tools::getValue('imoje_cards_payment_title'))); if (is_array($imojeBlikCurrencies = Tools::getValue('imoje_blik_currencies'))) { Configuration::updateValue('IMOJE_BLIK_CURRENCIES', pSQL(implode(',', $imojeBlikCurrencies))); } if (is_array($imojeCurrencies = Tools::getValue('imoje_currencies'))) { Configuration::updateValue('IMOJE_CURRENCIES', pSQL(implode(',', $imojeCurrencies))); } if (is_array($imojePaylaterCurrencies = Tools::getValue('imoje_paylater_currencies'))) { Configuration::updateValue('IMOJE_PAYLATER_CURRENCIES', pSQL(implode(',', $imojePaylaterCurrencies))); } if (is_array($imojeCardsCurrencies = Tools::getValue('imoje_cards_currencies'))) { Configuration::updateValue('IMOJE_CARDS_CURRENCIES', pSQL(implode(',', $imojeCardsCurrencies))); } if (is_array($imojePblCurrencies = Tools::getValue('imoje_pbl_currencies'))) { Configuration::updateValue('IMOJE_PBL_CURRENCIES', pSQL(implode(',', $imojePblCurrencies))); } return true; } /** * @return string */ private function getPaymentTitleDefault() { return $this->l('Pay for purchases using the most convenient online payment methods - PayByLink, cards, BLIK.'); } /** * @return string */ private function getPaylaterPaymentTitleDefault() { return $this->l('Twisto - imoje pay later'); } /** * @return string */ private function getBlikPaymentTitleDefault() { return $this->l('BLIK'); } /** * @return string */ private function getCardsPaymentTitleDefault() { return $this->l('Payment cards'); } /** * @return string */ private function getPblPaymentTitleDefault() { return $this->l('Pay-By-Link with imoje'); } /** * @param string $name * * @return mixed */ public function fetchTemplate($name) { return $this->display(__FILE__, $name); } /** * Hook that run on mobile version of Prestashop. */ public function hookDisplayMobileHeader() { $this->hookHeader(); } /** * Hook that adds css for old versions of Prestashop. */ public function hookHeader() { $this->context->controller->addCSS(($this->_path) . 'assets/css/imoje-legacy-front.min.css', 'all'); } /** * Hook that adds css and js in admin panel. For newer version of PrestaShop. */ public function hookBackOfficeHeader() { $this->context->controller->addJquery(); $this->context->controller->addCSS($this->_path . 'assets/css/imoje-admin.min.css', 'all'); $this->context->controller->addCSS($this->_path . 'assets/css/font-awesome.min.css', 'all'); if (!Configuration::get('IMOJE_TOKEN') || !Configuration::get('IMOJE_MERCHANT_ID') || !Configuration::get('IMOJE_SERVICE_ID')) { return ''; } $orderId = Tools::getValue('id_order'); if ($orderId === false) { return ''; } $order = new Order($orderId); $orderCurrentState = $order->getCurrentState(); if ($order->module !== 'imoje' || ($orderCurrentState === Configuration::get('PAYMENT_IMOJE_NEW_STATUS')) ) { return ''; } include(dirname(__FILE__) . '/sql/ImojeSql.php'); $idTransaction = ImojeSql::getTransactionId($orderId); if(!$idTransaction){ return ''; } $api = new Api( Configuration::get('IMOJE_TOKEN'), Configuration::get('IMOJE_MERCHANT_ID'), Configuration::get('IMOJE_SERVICE_ID'), Configuration::get('IMOJE_SANDBOX') ? Util::ENVIRONMENT_SANDBOX : Util::ENVIRONMENT_PRODUCTION ); $apiTransaction = $api->getTransaction($idTransaction); if (!$apiTransaction['success']) { return ''; } $amountToRefund = Util::calculateAmountToRefund($apiTransaction); $msg = ''; $refundError = ''; $imojeSubmitRefund = Tools::getValue('imoje_submit_refund'); $imojeRefundAmount = Tools::getValue('imoje_refund_amount'); $this->context->smarty->assign('imoje_amount_refundable', Util::convertAmountToMain($amountToRefund)); $this->context->smarty->assign('ps_version', (int) str_replace('.', '', _PS_VERSION_)); if (!$imojeSubmitRefund || !$imojeRefundAmount) { $this->context->smarty->assign('imoje_can_refund', $amountToRefund); $this->context->smarty->assign('imoje_refund_message', $msg); $this->context->smarty->assign('imoje_refund_error', $refundError); return $this->fetchTemplate('/views/templates/admin/refunds.tpl'); } $imojeChangeStatus = Tools::getValue('imoje_change_status'); $currencyInfo = Currency::getCurrency($order->id_currency); $refund = $api->createRefund( $api->prepareRefundData( Util::convertAmountToFractional($imojeRefundAmount) ), $idTransaction ); if (!$refund['success'] || (isset($refund['body']['transaction']['status']) && $refund['body']['transaction']['status'] !== 'settled')) { if (isset($refund['data']['body']) && $refund['data']['body']) { $refundError = $this->l('Refund error:') . ' ' . $refund['data']['body']; } else { $refundError = $this->l('Refund error.'); } PrestaShopLogger::addLog($refundError . ' ' . $this->l('order ID:') . ' ' . $orderId); $this->context->smarty->assign('imoje_can_refund', $amountToRefund); $this->context->smarty->assign('imoje_refund_message', $msg); $this->context->smarty->assign('imoje_refund_error', $refundError); return $this->fetchTemplate('/views/templates/admin/refunds.tpl'); } $msg = $this->l('Refund for amount:') . ' ' . round($imojeRefundAmount, 2) . ' ' . $currencyInfo['iso_code'] . ' ' . $this->l('has been created.') . ' ' . $this->l('order ID:') . ' ' . $orderId . '. ' . $this->l('Refund ID') . ': ' . $refund['body']['transaction']['id']; PrestaShopLogger::addLog($msg); if ($imojeChangeStatus || Util::convertAmountToFractional($imojeRefundAmount) === $amountToRefund) { $history = new OrderHistory(); $history->id_order = $orderId; $history->changeIdOrderState(Configuration::get('PS_OS_REFUND'), $orderId); $history->addWithemail(true, []); } $apiTransaction = $api->getTransaction($idTransaction); if (!$apiTransaction['success']) { return ''; } $amountToRefund = Util::calculateAmountToRefund($apiTransaction); $this->context->smarty->assign('imoje_amount_refundable', Util::convertAmountToMain($amountToRefund)); $this->context->smarty->assign('imoje_can_refund', true); $this->context->smarty->assign('imoje_refund_message', $msg); $this->context->smarty->assign('imoje_refund_error', $refundError); return $this->fetchTemplate('/views/templates/admin/refunds.tpl'); } /** * Hook that adds css and js in admin panel. */ public function hookBackOfficeFooter() { echo ''; echo ''; echo ''; } /** * @param array $params * * @return array|bool * @throws SmartyException * @throws Exception */ public function hookPaymentOptions($params) { if ( !Configuration::get('IMOJE_MERCHANT_ID') || !Configuration::get('IMOJE_SERVICE_ID') || !Configuration::get('IMOJE_SERVICE_KEY') || !$this->active ) { return false; } $environment = Configuration::get('IMOJE_SANDBOX') == 1 ? Util::ENVIRONMENT_SANDBOX : Util::ENVIRONMENT_PRODUCTION; $paymentOptions = []; $currency = Currency::getCurrency($params['cart']->id_currency); if (!Util::canUseForCurrency($currency['iso_code'])) { return $paymentOptions; } $imojeToken = Configuration::get('IMOJE_TOKEN'); if ( Configuration::get('IMOJE_BLIK_BUTTON') && $imojeToken && in_array( $currency['iso_code'], explode( ',', Configuration::get('IMOJE_BLIK_CURRENCIES') ) ) ) { $paymentOptionBlik = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $paymentOptions[] = $paymentOptionBlik->setCallToActionText( (Configuration::get('IMOJE_BLIK_PAYMENT_TITLE') ?: $this->getBlikPaymentTitleDefault()) . ($environment === Util::ENVIRONMENT_SANDBOX ? ' ' . $this->l('Sandbox is enabled.') : '')) ->setLogo($this->getLogoPath( Util::getPaymentMethod('blik'), Configuration::get('IMOJE_BLIK_HIDE_BRAND') )) ->setModuleName($this->name) ->setAction($this->context->link->getModuleLink('imoje', 'paymentblik')) ->setAdditionalInformation( $this->context->smarty->fetch('module:imoje/views/templates/hook/payment_imoje_terms.tpl') ); } if ( Configuration::get('IMOJE_IMOJE_BUTTON') && in_array( $currency['iso_code'], explode( ',', Configuration::get('IMOJE_CURRENCIES') ) ) ) { $paymentOptionImoje = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $paymentOptions[] = $paymentOptionImoje->setCallToActionText( (Configuration::get('IMOJE_PAYMENT_TITLE') ?: $this->getPaymentTitleDefault()) . ($environment === Util::ENVIRONMENT_SANDBOX ? ' ' . $this->l('Sandbox is enabled.') : '')) ->setModuleName($this->name) ->setAction($this->context->link->getModuleLink('imoje', 'payment')) ->setLogo($this->getLogoPath( 'imoje', Configuration::get('IMOJE_HIDE_BRAND') )); } if ( Configuration::get('IMOJE_PAYLATER_BUTTON') && in_array( $currency['iso_code'], explode( ',', Configuration::get('IMOJE_PAYLATER_CURRENCIES') ) ) ) { $paymentOptionPaylater = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $paymentOptions[] = $paymentOptionPaylater->setCallToActionText( (Configuration::get('IMOJE_PAYLATER_PAYMENT_TITLE') ?: $this->getPaylaterPaymentTitleDefault()) . ($environment === Util::ENVIRONMENT_SANDBOX ? ' ' . $this->l('Sandbox is enabled.') : '')) ->setLogo($this->getLogoPath( 'paylater', Configuration::get('IMOJE_PAYLATER_HIDE_BRAND') )) ->setModuleName('paylater') ->setAction($this->context->link->getModuleLink('imoje', 'paymentpaylater')); } if ( Configuration::get('IMOJE_CARDS_BUTTON') && in_array( $currency['iso_code'], explode( ',', Configuration::get('IMOJE_CARDS_CURRENCIES') ) ) ) { $paymentOptionCards = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $paymentOptions[] = $paymentOptionCards->setCallToActionText( (Configuration::get('IMOJE_CARDS_PAYMENT_TITLE') ?: $this->getCardsPaymentTitleDefault()) . ($environment === Util::ENVIRONMENT_SANDBOX ? ' ' . $this->l('Sandbox is enabled.') : '')) ->setLogo($this->getLogoPath( Util::getPaymentMethod('card'), Configuration::get('IMOJE_CARDS_HIDE_BRAND') )) ->setModuleName($this->name) ->setAction($this->context->link->getModuleLink('imoje', 'paymentcards')); } if ( Configuration::get('IMOJE_PBL_BUTTON') && $imojeToken && in_array( $currency['iso_code'], explode( ',', Configuration::get('IMOJE_PBL_CURRENCIES') ) ) ) { $paymentOptionPbl = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $paymentOptions[] = $paymentOptionPbl->setCallToActionText( (Configuration::get('IMOJE_PBL_PAYMENT_TITLE') ?: $this->getPblPaymentTitleDefault()) . ($environment === Util::ENVIRONMENT_SANDBOX ? ' ' . $this->l('Sandbox is enabled.') : '')) ->setLogo($this->getLogoPath( Util::getPaymentMethod('pbl'), Configuration::get('IMOJE_PBL_HIDE_BRAND') )) ->setModuleName($this->name) ->setAction($this->context->link->getModuleLink('imoje', 'pbl')) ->setAdditionalInformation( $this->context->smarty->fetch('module:imoje/views/templates/hook/payment_imoje_terms.tpl') ); } return $paymentOptions; } /** * @param $paymentOption * @param $isHidden * * @return array|bool|mixed|string */ public function getLogoPath($paymentOption, $isHidden) { if ($isHidden) { return ''; } if ($paymentOption === 'imoje') { return Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/assets/img/imoje.png'); } switch ($paymentOption) { case 'blik': return Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/assets/img/blik-mini.png'); case 'paylater': return Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/assets/img/paylater-mini.png'); case 'card': return Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/assets/img/cards.png'); case 'pbl': return Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/assets/img/pbl.png'); default: return ''; } } /** * @param Cart $cart * * @return CartData */ public function getCart($cart) { $cartData = new CartData(); foreach ($cart->getProducts() as $product) { $cartData->addItem( $product['id_product'] . (isset($product['attributes_small']) && !empty($product['attributes_small']) ? ' - ' . $product['attributes_small'] : ''), (float) $product['rate'], $product['name'], Util::convertAmountToFractional(round($product['total_wt'], 2) / $product['quantity']), (float) $product['quantity'] ); } $cartData->setAmount(Util::convertAmountToFractional($cart->getOrderTotal())); $cartData->setCreatedAt(strtotime($cart->date_add)); $carrier = new Carrier($cart->id_carrier); $addressBilling = new Address((int) $cart->id_address_invoice); $cartData->setAddressBilling( $addressBilling->city, $addressBilling->firstname . ' ' . $addressBilling->lastname, empty($addressBilling->phone_mobile) ? (empty($addressBilling->phone) ? '' : $addressBilling->phone) : $addressBilling->phone_mobile, empty($addressBilling->address2) ? $addressBilling->address1 : $addressBilling->address1 . ', ' . $addressBilling->address2, CountryCore::getIsoById($addressBilling->id_country), $addressBilling->postcode); $addressDelivery = new Address((int) $cart->id_address_delivery); $cartData->setAddressDelivery( $addressDelivery->city, $addressDelivery->firstname . ' ' . $addressDelivery->lastname, empty($addressDelivery->phone_mobile) ? (empty($addressDelivery->phone) ? '' : $addressDelivery->phone) : $addressDelivery->phone_mobile, empty($addressDelivery->address2) ? $addressDelivery->address1 : $addressDelivery->address1 . ', ' . $addressDelivery->address2, CountryCore::getIsoById($addressDelivery->id_country), $addressDelivery->postcode); $cartData->setShipping( $carrier->getTaxesRate(new Address((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})), $carrier->name, Util::convertAmountToFractional($cart->getTotalShippingCost()) ); $discount = $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS); if ($discount > 0) { $cartData->setDiscount( 0, 'discount', Util::convertAmountToFractional($discount) ); } return $cartData; } /** * @return mixed */ public function hookPaymentReturn() { return null; } /** * Prepares data for form that is send to imoje. * * @param Cart $cart * @param string $cartData * * @return array * @throws Exception */ public function getDataForRequestToPaywall($cart, $cartData = '', $visibleMethod = '') { $cartId = $cart->id; $customer = new Customer(intval($cart->id_customer)); $addressBilling = new Address((int) $cart->id_address_invoice); $addressDelivery = new Address((int) $cart->id_address_delivery); $currencyInfo = Currency::getCurrency($cart->id_currency); $total = $cart->getOrderTotal(); $failureUrl = $this->context->link->getModuleLink('imoje', 'failure'); $confirmationUrl = $this->context->link->getModuleLink('imoje', 'confirmation'); $imojeVersion = $this->version . ';prestashop_' . _PS_VERSION_; $customerPhone = ($addressDelivery->phone_mobile ?: ($addressBilling->phone_mobile ?: '')); // 0 - after checkout(order), 1 - after ipn(cart) if (Configuration::get('IMOJE_CREATE_ORDER_ARRANGEMENT')) { return Util::prepareData( $total, $currencyInfo['iso_code'], intval($cartId), null, $customer->firstname, $customer->lastname, $customer->email, $customerPhone, Configuration::get('IMOJE_GA_KEY') ? $this->context->link->getModuleLink('imoje', 'success', [ 'ga_cart_id' => $cartId, 'ga_hash' => hash('sha256', $cartId . $cart->secure_key), ]) : $this->context->link->getModuleLink('imoje', 'success'), $failureUrl, $confirmationUrl, $imojeVersion, $cartData, $visibleMethod ); } $this->validateOrder($cartId, Configuration::get('PAYMENT_IMOJE_NEW_STATUS'), $total, $this->displayName, null, [], null, false, $customer->secure_key ); $orderId = Order::getIdByCartId(($cart->id)); return Util::prepareData( $total, $currencyInfo['iso_code'], $orderId, null, $customer->firstname, $customer->lastname, $customer->email, $customerPhone, _PS_BASE_URL_ . __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $orderId . '&key=' . $customer->secure_key, $failureUrl, $confirmationUrl, $imojeVersion, $cartData, $visibleMethod ); } /** * Prepares data for form that is send to imoje. * * @param Cart $cart * @param string $paymentMethod * @param string $paymentMethodCode * @param string $blikCode * * @return string * @throws Exception */ public function getDataForRequestToApi($cart, $paymentMethod, $paymentMethodCode, $blikCode = '') { $customer = new Customer($cart->id_customer); $currencyInfo = Currency::getCurrency($cart->id_currency); $cartId = (string) $cart->id; $isBlik = $paymentMethod === Util::getPaymentMethod('blik') && ($paymentMethodCode === Util::getPaymentMethodCode('blik') || $paymentMethodCode === Util::getPaymentMethodCode('blik_oneclick')); $imojeApi = new Api( Configuration::get('IMOJE_AUTHORIZATION_TOKEN'), Configuration::get('IMOJE_MERCHANT_ID'), Configuration::get('IMOJE_SERVICE_ID'), Configuration::get('IMOJE_SANDBOX') ? Util::ENVIRONMENT_SANDBOX : Util::ENVIRONMENT_PRODUCTION ); $total = $cart->getOrderTotal(); $currency = $currencyInfo['iso_code']; $failureUrl = $this->context->link->getModuleLink('imoje', 'failure'); $address = $this->getAddressData($cart); $cid = $this->context->customer->isLogged() ? hash('md5', $this->context->customer->id . $this->context->customer->email) : ''; // 0 - after checkout(order), 1 - after ipn(cart) if (Configuration::get('IMOJE_CREATE_ORDER_ARRANGEMENT')) { return $imojeApi->prepareData( $total, $currency, $cartId, $paymentMethod, $paymentMethodCode, Configuration::get('IMOJE_GA_KEY') ? $this->context->link->getModuleLink('imoje', 'success', [ 'ga_cart_id' => $cartId, 'ga_hash' => hash('sha256', $cartId . $cart->secure_key), ]) : $this->context->link->getModuleLink('imoje', 'success'), $failureUrl, $customer->firstname, $customer->lastname, $customer->email, Api::TRANSACTION_TYPE_SALE, '', ($blikCode && $isBlik) ? $blikCode : '', $address, $cid ); } $imoje = new iMoje(); $imoje->validateOrder($cartId, Configuration::get('PAYMENT_IMOJE_NEW_STATUS'), $total, $imoje->displayName, null, [], null, false, $customer->secure_key ); $orderId = (string) Order::getIdByCartId((int) $cartId); return $imojeApi->prepareData( $total, $currency, $orderId, $paymentMethod, $paymentMethodCode, _PS_BASE_URL_ . __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $imoje->id . '&id_order=' . $orderId . '&key=' . $customer->secure_key, $failureUrl, $customer->firstname, $customer->lastname, $customer->email, Api::TRANSACTION_TYPE_SALE, '', ($blikCode && $isBlik) ? $blikCode : '', $address, $cid ); } /** * @param object $cart * * @return array */ private static function getAddressData($cart) { $addressBilling = new Address((int) $cart->id_address_invoice); $addressDelivery = new Address((int) $cart->id_address_delivery); return [ 'billing' => Api::prepareAddressData( $addressBilling->firstname, $addressBilling->lastname, empty($addressBilling->address2) ? $addressBilling->address1 : $addressBilling->address1 . ', ' . $addressBilling->address2, $addressBilling->city, State::getNameById($addressBilling->id_state), $addressBilling->postcode, CountryCore::getIsoById($addressBilling->id_country) ), 'shipping' => Api::prepareAddressData( $addressDelivery->firstname, $addressDelivery->lastname, empty($addressDelivery->address2) ? $addressDelivery->address1 : $addressDelivery->address1 . ', ' . $addressDelivery->address2, $addressDelivery->city, State::getNameById($addressDelivery->id_state), $addressDelivery->postcode, CountryCore::getIsoById($addressDelivery->id_country) ), ]; } }