Jump to content

Payment methods not showing on the checkout page


Rawan
 Share

Recommended Posts

Hi ..

I'm using Prestashop 1.7.4.3

Previously I had two payment methods, Bank transfer & another payment module .. both was working.
Now I have installed a new payment module and uninstall the old one.

But, the new Payment method not showing on the checkout page, only Bank transfer module is active.

Positions Hooks (displayAdminOrder  &  displayPaymentReturn  &  displayRightColumn)

I dont know what is the problem, Please help..

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 1 year later...
On 11/21/2020 at 10:50 PM, rrataj said:

Maybe module config is not correct and method is not being displayed?

Or you have it disabled in Payment -> Preferences for certain Currency, Group, Country or Carrier?

I have the same problem. And I checked and verified that the payment method that is not showing on the Checkout Page is indeed enabled for this Currency, Group, Country and Carrier.

Share this post


Link to post
Share on other sites

1 hour ago, stifler97 said:

And is that transplanted to paymentOptions too?

No, it is not transplanted to the paymentOptions hook. And so I think this may be a problem.

It is transplanted to the payment hook instead! So it's not visible on the Checkout Page.

How to retransplant it to the paymentOptions hook? :) 

Share this post


Link to post
Share on other sites

An example here from payment module of ps_checkout

    /**
     * Add payment option at the checkout in the front office (prestashop 1.7)
     *
     * @param array{cookie: Cookie, cart: Cart, altern: int} $params
     *
     * @return array
     */
    public function hookPaymentOptions(array $params)
    {
        /** @var Cart $cart */
        $cart = $params['cart'];

        if (false === Validate::isLoadedObject($cart)
            || false === $this->checkCurrency($cart)
            || false === $this->merchantIsValid()
        ) {
            return [];
        }
        /** @var \PrestaShop\Module\PrestashopCheckout\Repository\PaypalAccountRepository $paypalAccountRepository */
        $paypalAccountRepository = $this->getService('ps_checkout.repository.paypal.account');

        /** @var \PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceProvider $fundingSourceProvider */
        $fundingSourceProvider = $this->getService('ps_checkout.funding_source.provider');

        $paymentOptions = [];

        foreach ($fundingSourceProvider->getAll() as $fundingSource) {
            $paymentOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption();
            $paymentOption->setModuleName($this->name . '-' . $fundingSource->name);
            $paymentOption->setCallToActionText($fundingSource->label);
            $paymentOption->setBinary(true);

            if ('card' === $fundingSource->name && $paypalAccountRepository->cardHostedFieldsIsAvailable()) {
                $this->context->smarty->assign('modulePath', $this->getPathUri());
                $paymentOption->setForm($this->context->smarty->fetch('module:ps_checkout/views/templates/hook/paymentOptions.tpl'));
            }

            $paymentOptions[] = $paymentOption;
        }

        return $paymentOptions;
    }

As you see there is a method hookPaymentOptions which is transplanted automatically into paymentOptions hook. But in your case your payment module was not hooked to this and that is why you can not see this payment module as an option in checkout page. Because this method is responsible for sending data to FO in which to present it as a payment option.

Another thing is you said you could not transplant this module manually into the hook of paymentOptions because you do not see that in the list. That is what I understood. So, you should check if the payment module has implemented this method hookPaymentOptions or not. If it is there just check the install method of the module and use $this->register() to transplant the hook into the module. You should reset your module to take effect. If you have critical data in your payment module do not reset it. Just put this in the install method and in __construct() method. Then just reload the module lists in BO and the transplant action takes place.

Edited by stifler97 (see edit history)
  • Thanks 1

Share this post


Link to post
Share on other sites

15 minutes ago, stifler97 said:

An example here from payment module of ps_checkout

    /**
     * Add payment option at the checkout in the front office (prestashop 1.7)
     *
     * @param array{cookie: Cookie, cart: Cart, altern: int} $params
     *
     * @return array
     */
    public function hookPaymentOptions(array $params)
    {
        /** @var Cart $cart */
        $cart = $params['cart'];

        if (false === Validate::isLoadedObject($cart)
            || false === $this->checkCurrency($cart)
            || false === $this->merchantIsValid()
        ) {
            return [];
        }
        /** @var \PrestaShop\Module\PrestashopCheckout\Repository\PaypalAccountRepository $paypalAccountRepository */
        $paypalAccountRepository = $this->getService('ps_checkout.repository.paypal.account');

        /** @var \PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceProvider $fundingSourceProvider */
        $fundingSourceProvider = $this->getService('ps_checkout.funding_source.provider');

        $paymentOptions = [];

        foreach ($fundingSourceProvider->getAll() as $fundingSource) {
            $paymentOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption();
            $paymentOption->setModuleName($this->name . '-' . $fundingSource->name);
            $paymentOption->setCallToActionText($fundingSource->label);
            $paymentOption->setBinary(true);

            if ('card' === $fundingSource->name && $paypalAccountRepository->cardHostedFieldsIsAvailable()) {
                $this->context->smarty->assign('modulePath', $this->getPathUri());
                $paymentOption->setForm($this->context->smarty->fetch('module:ps_checkout/views/templates/hook/paymentOptions.tpl'));
            }

            $paymentOptions[] = $paymentOption;
        }

        return $paymentOptions;
    }

As you see there is a method hookPaymentOptions which is transplanted automatically into paymentOptions hook. But in your case your payment module was not hooked to this and that is why you can not see this payment module as an option in checkout page. Because this method is responsible for sending data to FO in which to present the it as a payment option.

Another thing is you said you could not transplant this module manually into the hook of paymentOptions because you do not see that in the list. That is what I understood. So, you should check if the payment module has implemented this method hookPaymentOptions or not. If it is there just check the install method of the module and use $this->register() to transplant the hook into the module. You should reset your module to take effect. If you have critical data in your payment module do not reset it. Just put this in the install method and in __construct() method. Then just reload the module lists in BO and the transplant action takes place.

My payment gateway provider unfortunately doesn't have a payment module for Prestashop v1.7

What they have is a payment module for Prestashop v1.6

And I am just trying to use a module developed for  Prestashop v1.6 in my Prestashop v1.7

Here is the module's PHP code:

<?php
require_once(dirname(__FILE__).'/../../config/config.inc.php');
if (!defined('_PS_VERSION_'))
	exit;
	
class Paysolutions extends PaymentModule
{
	private	$_html = '';
	private $_postErrors = array();
    const STATE_PENDING = 'PAYSOLUTIONS_OS_PENDING';
    const STATUS_PENDING = 'Paysolutions Payment Pending';
	public function __construct()
	{
		$this->name = 'paysolutions';
		$this->tab = 'payments_gateways';
		$this->version = '1.6';
		$this->author = 'PrestaShop';
		
		$this->currencies = true;
		$this->currencies_mode = 'radio';
		
        parent::__construct();
		
        /* The parent construct is required for translations */
		$this->page = basename(__FILE__, '.php');
        $this->displayName = $this->l('PAYSOLUTIONS Secure Gateway');
        $this->description = $this->l('Accepts payments by PAYSOLUTIONS Co.,Ltd (Thailand)');
		$this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
	}
	public function getPaysolutionsUrl()
	{
		return "https://www.thaiepay.com/epaylink/payment.aspx";
	}
	public function install()
	{
		if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('paymentReturn') || !$this->addOrderStates())
			return false;
		return true;
	}

    public function addOrderStates() {
        $id = $this->_addOrderState(self::STATUS_PENDING);
        Configuration::updateValue(self::STATE_PENDING, $id);

        return true;
    }


    public function removeOrderStates() {
        $this->_deleteOrderState(Configuration::get(self::CFG_STATE_INPROCESS));
        Configuration::deleteByName(self::CFG_STATE_INPROCESS);
        $this->_deleteOrderState(Configuration::get(self::CFG_STATE_PENDING));
        Configuration::deleteByName(self::CFG_STATE_PENDING);
        return true;
    }


    private function _addOrderState($name) {
        $OrderState = new OrderState();
        $OrderState->name = array_fill(0, 10, $name);
        $OrderState->send_mail = 0;
        $OrderState->invoice = 0;
        $OrderState->color = '#4169E1';
        $OrderState->unremovable = true;
        $OrderState->logable = 0;
        $OrderState->add();
        return $OrderState->id;
    }
	public function uninstall()
	{
		if (!Configuration::deleteByName('PAYSOLUTIONS_MERCHANTID')


            || !parent::uninstall())
			return false;
		return true;
	}
	public function getContent()
	{
		$this->_html = '<h2>PAYSOLUTIONS Payment Module</h2>';
		if (isset($_POST['submitPaysolutions']))
		{
			if (empty($_POST['MerchantID']))
				$this->_postErrors[] = $this->l('PAYSOLUTIONS MerchantID is required.');
			
				
			if (!sizeof($this->_postErrors))
			{
				Configuration::updateValue('PAYSOLUTIONS_MERCHANTID', $_POST['MerchantID']);
				Configuration::updateValue('PAYSOLUTIONS_VISA', isset($_POST['accept_visa']) ? $_POST['accept_visa']:0 );
				Configuration::updateValue('PAYSOLUTIONS_AMEX', isset($_POST['accept_amex']) ? $_POST['accept_amex']:0);
				//Configuration::updateValue('PAYSOLUTIONS_CHARGE', $_POST['charge']);
				if (isset($_POST['charge'])) { //Firsov
    			Configuration::updateValue('PAYSOLUTIONS_CHARGE', $_POST['charge']);
				} 				 
				 
				$this->displayConf();
			}
			else
				$this->displayErrors();
		}

		$this->displayPaysolutions();
		$this->displayFormSettings();
		return $this->_html;
	}

	public function displayConf()
	{
		$this->_html .= '
		<div class="conf confirm">
			<img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />
			'.$this->l('Settings updated').'
		</div>';
	}

	public function displayErrors()
	{
		$nbErrors = sizeof($this->_postErrors);
		$this->_html .= '
		<div class="alert error">
			<h3>'.($nbErrors > 1 ? $this->l('There are') : $this->l('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? $this->l('errors') : $this->l('error')).'</h3>
			<ol>';
		foreach ($this->_postErrors AS $error)
			$this->_html .= '<li>'.$error.'</li>';
		$this->_html .= '
			</ol>
		</div>';
	}
	
	
	public function displayPaysolutions()
	{
		$this->_html .= '
		<img src="../modules/paysolutions/paysolutions.png" style="float:left; margin-right:15px;" />
		<b>'.$this->l('This is an official PAYSOLUTIONS payment gateway for Prestashop').'</b><br /><br />
		'.$this->l('You MUST configure your PAYSOLUTIONS account first before using this module.').'
		<br /><br /><br /><br/>';
	}

	public function displayFormSettings()
	{
		$conf = Configuration::getMultiple(array('PAYSOLUTIONS_MERCHANTID','PAYSOLUTIONS_AMEX','PAYSOLUTIONS_VISA','PAYSOLUTIONS_CHARGE'));
		// E-Mail Address
		$MerchantID = array_key_exists('MerchantID', $_POST) ? $_POST['MerchantID'] : (array_key_exists('PAYSOLUTIONS_MERCHANTID', $conf) ? $conf['PAYSOLUTIONS_MERCHANTID'] : '');
		$accept_amex = array_key_exists('accept_amex', $_POST) ? $_POST['accept_amex'] : (array_key_exists('PAYSOLUTIONS_AMEX', $conf) ? $conf['PAYSOLUTIONS_AMEX'] : '');
		$accept_visa = array_key_exists('accept_visa', $_POST) ? $_POST['accept_visa'] : (array_key_exists('PAYSOLUTIONS_VISA', $conf) ? $conf['PAYSOLUTIONS_VISA'] : '');
		
		$charge = array_key_exists('charge', $_POST) ? $_POST['charge'] : (array_key_exists('PAYSOLUTIONS_CHARGE', $conf) ? $conf['PAYSOLUTIONS_CHARGE'] : '0');
		
		$this->_html .= '
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
		<fieldset>
			<legend><img src="../img/admin/contact.gif" />'.$this->l('Settings').'</legend>
			
			<label>'.$this->l('MerchantID').'</label>
			<div class="margin-form">
				<input type="text" size="33" name="MerchantID" value="'.htmlentities($MerchantID, ENT_COMPAT, 'UTF-8').'" />
			</div>
			
			<br />
			
			<center><input type="submit" name="submitPaysolutions" value="'.$this->l('Update settings').'" class="button" /></center>
		
		<br />
		
		</fieldset>		
		</form>		
		<br /><br />		
		';
	}

	public function hookPayment($params)
	{
		global $smarty;

		$address = new Address(intval($params['cart']->id_address_invoice));
		$customer = new Customer(intval($params['cart']->id_customer));
		$business = Configuration::get('PAYSOLUTIONS_MERCHANTID');
		
		$currency = $this->getCurrency();

			//if (!Validate::isEmail($business))
			//return $this->l('PAYSOLUTIONS error: (invalid or undefined account MerchantID)');

		if (!Validate::isLoadedObject($address) OR !Validate::isLoadedObject($customer) OR !Validate::isLoadedObject($currency))
			return $this->l('PAYSOLUTIONS error: (invalid address or customer)');
			
		$products = $params['cart']->getProducts();
		
		foreach ($products as $key => $product)
		{
			$products[$key]['name'] = str_replace('"', '\'', $product['name']);
			if (isset($product['attributes']))
				$products[$key]['attributes'] = str_replace('"', '\'', $product['attributes']);
			$products[$key]['name'] = htmlentities(utf8_decode($product['name']));
			$products[$key]['paysolutionsAmount'] = number_format(Tools::convertPrice($product['price_wt'], $currency), 2, '.', '');
		}
		$ChargeMultiplier = (Configuration::get('PAYSOLUTIONS_CHARGE') + 100) / 100;
		
		$smarty->assign(array(
			'address' => $address,
			'country' => new Country(intval($address->id_country)),
			'customer' => $customer,
			'business' => $business,
			'currency' => $currency,
			'accept_visa' => Configuration::get('PAYSOLUTIONS_VISA'),
			'accept_amex' => Configuration::get('PAYSOLUTIONS_AMEX'),
			'paysolutionsUrl' => $this->getPaysolutionsUrl(),
			'amount' => number_format(Tools::convertPrice($params['cart']->getOrderTotal(true, 4) * $ChargeMultiplier , $currency), 2, '.', ''),
			'shipping' =>  number_format(Tools::convertPrice(($params['cart']->getOrderShippingCost() + $params['cart']->getOrderTotal(true, 6)), $currency), 2, '.', ''),
			'discounts' => $params['cart']->getDiscounts(),
			'products' => $products,
			'total' => number_format(Tools::convertPrice($params['cart']->getOrderTotal(true, 3)* $ChargeMultiplier , $currency), 2, '.', ''),
			'id_cart' => intval($params['cart']->id),
			'postUrl' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'index.php?controller=order-confirmation&key='.$customer->secure_key.'&id_cart='.intval($params['cart']->id).'&id_module='.intval($this->id),
			'reqUrl' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/paysolutions/validation.php',
			'this_path' => $this->_path,
			'Charge' => Configuration::get('PAYSOLUTIONS_CHARGE'),
		));
		
		return $this->display(__FILE__, 'payment.tpl');
    }
	
	public function getL($key)
	{
		$translations = array(
			'mc_gross' => $this->l('Paysolutions key \'mc_gross\' not specified, can\'t control amount paid.'),
			'payment_status' => $this->l('Paysolutions key \'payment_status\' not specified, can\'t control payment validity'),
			'payment' => $this->l('Payment: '),
			'custom' => $this->l('Paysolutions key \'custom\' not specified, can\'t rely to cart'),
			'txn_id' => $this->l('Paysolutions key \'txn_id\' not specified, transaction unknown'),
			'mc_currency' => $this->l('Paysolutions key \'mc_currency\' not specified, currency unknown'),
			'cart' => $this->l('Cart not found'),
			'order' => $this->l('Order has already been placed'),
			'transaction' => $this->l('Paysolutions Transaction ID: '),
			'verified' => $this->l('The Paysolutions transaction could not be VERIFIED.'),
			'connect' => $this->l('Problem connecting to the Paysolutions server.'),
			'nomethod' => $this->l('No communications transport available.'),
			'socketmethod' => $this->l('Verification failure (using fsockopen). Returned: '),
			'curlmethod' => $this->l('Verification failure (using cURL). Returned: '),
			'curlmethodfailed' => $this->l('Connection using cURL failed'),
		);
		return $translations[$key];
	}
	public function hookPaymentReturn($params)
	{
		$payment_status	 = substr($_POST["result"], 0, 2);
		$id_order = trim(substr($_POST["result"],2));
		$amount = $_POST['amt'];

		global $smarty;
		
		$smarty->assign(array(
			'payment_status' => $payment_status,
			'id_order' => $id_order,
			'amount' => $amount,
	));
		
	return $this->display(__FILE__, 'order-confirmation.tpl');

	}
}
?>

I think I need to edit public function install()

What do you think?

Edited by Alexander Firsov
Update (see edit history)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More