Jota McCready Posted February 9, 2018 Share Posted February 9, 2018 ¡Hi everyone! First, thanks for giving us this forum, my name is Juan Pablo, I need some help with a payment getway module I'm developing, I'm working on a module for Prestashop 1.7, We already have a 1.6 version that runs with no problems. The new module seems to work in the back end (admin page) with no problems, nothing complex, only work with 2 fields. The problem is the catalog page, the payment method does not show up in the method payments when you reach the checkout, I'm following the steps told by the official docs, I would like know what I'm doing wrong. THIS IS THE FILE <?php /*This checks for the Prestashop existence */ if (!defined('_PS_VERSION_')){ exit; } class Fastpay extends PaymentModule { private $html = ''; private $postErrors = array(); public $serviceID; public $secretKey; public $gateway='https://www.fastpay.com/pay'; public function __construct() { $this->name = 'fastpay'; $this->tab = 'payments_gateways'; $this->version = '2.0'; $this->author = 'Fastpay SPA'; $this->need_instance = 1; $this->currencies = true; $this->currencies_mode = 'checkbox'; $this->module_key = '54e53619d6b66c26b2c4ecf54f43afcf'; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->bootstrap = true; $config = Configuration::getMultiple(array('PAYGOL_SERVICEID','PAYGOL_SECRETKEY')); // Properties serviceid and secretkey get their values from the database. if (isset($config['PAYGOL_SERVICEID'])) { $this->serviceID = $config['PAYGOL_SERVICEID']; } if (isset($config['PAYGOL_SECRETKEY'])) { $this->secretKey = $config['PAYGOL_SECRETKEY']; } parent::__construct(); $this->displayName = $this->l('Fastpay'); $this->description = $this->l('Fastpay is an online payment service provider that offers a wide variety of both worldwide and local payment methods. Additional information can be found at: https://www.fastpay.com/en https://www.fastpay.com/en/pricing'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('PAYGOL')) $this->warning = $this->l('No name provided'); } // Possible transaction statuses, also register hooks. public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('header') || !Configuration::updateValue('Fastpay', 'my friend') ) if (!Configuration::get('PAYGOL_PAYMENT_PREORDER')) { Configuration::updateValue('PAYGOL_PAYMENT_PREORDER', $this->addState('Successful (Fastpay)', '#DDEEFF')); } if (!Configuration::get('PAYGOL_WAITING_PAYMENT')) { Configuration::updateValue('PAYGOL_WAITING_PAYMENT', $this->addState('Pending (Fastpay)', '#DDEEFF')); } if (!Configuration::get('PAYGOL_PAYMENT_SUCCESS')) { Configuration::updateValue('PAYGOL_PAYMENT_SUCCESS', $this->addState('Successful (Fastpay)', '#32D600')); } if (!parent::install() || !$this->registerHook('paymentOptions') || !$this->registerHook('paymentReturn')) { return false; } return true; } public function uninstall() { if (!Configuration::deleteByName('PAYGOL_SERVICEID') || !parent::uninstall()) { return false; } if (!Configuration::deleteByName('PAYGOL_SECRETKEY') || !parent::uninstall()) { return false; } return true; } /*********************************************************************************/ public function getContent() { $output = null; if (Tools::isSubmit('submit'.$this->name)) { $pg_serviceID = trim((string)(Tools::getValue('serviceID'))); $pg_secretKey = trim((string)(Tools::getValue('secretKey'))); if (empty($pg_serviceID) || empty($pg_secretKey) || !Validate::isGenericName($pg_serviceID) || !Validate::isGenericName($pg_secretKey)){ $output .= $this->displayError($this->l('"Service ID" and "Secret Key" can not be empty!')); }else{ Configuration::updateValue('PAYGOL_SERVICEID', $pg_serviceID); Configuration::updateValue('PAYGOL_SECRETKEY', $pg_secretKey); $output .= $this->displayConfirmation($this->l('Settings Updated')); } } return $output.$this->displayForm(); } /*********************************************************************************/ public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Fastpay Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'prefix' => '<i class="icon icon-tag"></i>', 'col' => 1, 'type' => 'text', 'name' => 'serviceID', 'label' => $this->l('Service ID'), 'required' => true ), array( 'prefix' => '<i class="icon icon-tag"></i>', 'col' => 3, 'type' => 'text', 'name' => 'secretKey', 'label' => $this->l('Secret Key'), 'required' => true ), array( 'col' => 3, 'type' => 'text', 'name' => 'ipnURL', 'label' => $this->l('IPN URL'), 'disabled' => 'disabled' ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-danger pull-right' ) ); $helper = new HelperForm(); // Module, token and currentIndex $helper->module = $this; $helper->name_controller = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; // Language $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; // Title and toolbar $helper->title = $this->displayName; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen. $helper->submit_action = 'submit'.$this->name; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. '&token='.Tools::getAdminTokenLite('AdminModules') ), 'back' => array( 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); // Load current value $helper->fields_value['serviceID'] = Configuration::get('PAYGOL_SERVICEID'); $helper->fields_value['secretKey'] = Configuration::get('PAYGOL_SECRETKEY'); $helper->fields_value['ipnURL'] = _PS_BASE_URL_.__PS_BASE_URI__."modules/fastpay/fastpay_ipn.php"; return $helper->generateForm($fields_form); } public function hookPaymentOptions($params) { if (!$this->active) { return; } // Check if cart has product download if ($this->hasProductDownload($params['cart'])) { return; } $newOption = new PaymentOption(); $newOption->setModuleName($this->name) ->setCallToActionText($this->trans('Pay with Fastpay', array(), 'Modules.Fastpay.Shop')) ->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true)) ->setAdditionalInformation($this->fetch('module:fastpay/views/templates/hook/payment.tpl')); $payment_options = [ $newOption, ]; return $payment_options; } // Used by fastpay_ipn.php public function validationFastpay() { $service_id = Tools::getValue('service_id'); //$country = Tools::getValue('country'); $price = Tools::getValue('price'); $custom = Tools::getValue('custom'); //$currency = Tools::getValue('currency'); $frmprice = Tools::getValue('frmprice'); $frmcurrency = Tools::getValue('frmcurrency'); $arrayCustom = explode("-", $custom); $cart_id = $arrayCustom[0]; $customer_id = $arrayCustom[1]; $skey = $arrayCustom[2]; /// $key = Tools::getValue('key'); $sk = Tools::safeOutput(Configuration::get('PAYGOL_SECRETKEY')); $sk = trim($sk); $sid = Tools::safeOutput(Configuration::get('PAYGOL_SERVICEID')); $sid = trim($sid); if ($sk != $key) { exit; } if ($sid != $service_id) { exit; } if ((!empty($frmprice) && !empty($frmcurrency)) && (!empty($custom) && !empty($price))) { $this->context->cart = new Cart((int)$cart_id); $this->context->cart->id; $this->context->cart->id_customer; $valide_var = 'SELECT `id_order`,`id_customer`,`id_cart`,`secure_key` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int)$this->context->cart->id.''; if ($results = Db::getInstance()->ExecuteS($valide_var)) { foreach ($results as $row) { if (($skey == $row['secure_key']) && ($row['id_cart'] == $cart_id && $row['id_customer'] == $customer_id )) { if (!$this->context->cart->OrderExists()) { return false; } if (Validate::isLoadedObject($this->context->cart)) { $id_orders = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int)$this->context->cart->id.''); foreach ($id_orders as $val) { $order = new Order((int)$val['id_order']); $order->setCurrentState((int)Configuration::get('PAYGOL_PAYMENT_SUCCESS')); } } } } } } } } I would appreciate any help Thanks in advance! -Juan Pablo Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now