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.
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;
}
}
}
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.