News:

Support the VirtueMart project and become a member

Main Menu

VMPayment Plugin: How to validate input data from user?

Started by ndaumalle, July 28, 2016, 00:54:27 AM

Previous topic - Next topic

ndaumalle

Hello,

We are actually updating our payment plugins for Virtuemart. But we need help.
For some of our payment methods, it is required that the user write a bank code (bic) from a text field in the checkout page.
We would like to validate this bank code, verifying that it is not empty and valid.

We are using this function: plgVmOnSelectCheckPayment

The problem is that even if we return false in this function, the next function plgVmConfirmedOrder is called anyway, instead of showing the checkout page with an error message.

For example:
public function plgVmOnSelectCheckPayment(VirtueMartCart $cart, &$msg) {
       
        if (!$this->selectedThisByMethodId($cart->virtuemart_paymentmethod_id)) {
            return NULL; // Another method was selected, do nothing
        }

        if (!($this->_currentMethod = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {
            return FALSE;
        }
       
        // load payment method
        $method = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id);

        $this->_gc_giropay_bic = vRequest::getVar('gc_giropay_bic_' . $cart->virtuemart_paymentmethod_id, '');

        $this->_gc_giropay_bic = isset($this->_gc_giropay_bic) ? (is_string($this->_gc_giropay_bic) ? trim($this->_gc_giropay_bic) : '') : '';

        if ($this->_gc_giropay_bic) {
           //More code to validate the bank code..
        } else {
                $msg = "Bank code empty.";
              return false;

        }
    }

Any help would be very apreciated.
Thanks.

GJC Web Design

study the function in components\com_virtuemart\helpers\cart.php ~ line  860

the return is an array.. is something else returning true before yours?

//Add a hook here for other payment methods, checking the data of the choosed plugin
$msg = '';
$_dispatcher = JDispatcher::getInstance();
$_retValues = $_dispatcher->trigger('plgVmOnSelectCheckPayment', array( $this, &$msg));
$dataValid = true;
foreach ($_retValues as $_retVal) {
if ($_retVal === true ) {
$this->setCartIntoSession();
// Plugin completed succesfull; nothing else to do
break;
} else if ($_retVal === false ) {
if ($redirect) {
$app = JFactory::getApplication();
$app->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=editpayment',$this->useXHTML,$this->useSSL), $msg);
break;
} else {
return;
}
}
}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ndaumalle

Thanks for the reply. We were observing this function and we can see that the value of $_retValues is  Array(   
  • => ) which we think it is fine.
    But what we don't understand is why $redirect = false in this function... Which is in our opinion why the user is not redirected to the checkout page...

    We don't think that there is something else returning true.