VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: rejoan on October 06, 2020, 19:06:15 PM

Title: cancel url calling from wrong plugin
Post by: rejoan on October 06, 2020, 19:06:15 PM
Hi,
I am developing a payment plugin for virtumart. It is working fine but one issue raised. I have created a new method called plgVmOnUserPaymentCancel in my "amarpay.php" (amarpay plugin). But this method not calling on user cancel. plgVmOnUserPaymentCancel is being called from "tco(2checkout)" plugin. My new plugin same name method not calling.
When I remove/uninstall 2chekout plugin then start working new plugin plgVmOnUserPaymentCancel method

How to resolve this issue? please help.  have seen there are many same name method/event available across the payment plugin & calling/triggering corresponding right method but mine is not working
Title: Re: cancel url calling from wrong plugin
Post by: Jörgen on October 06, 2020, 19:58:45 PM
Your plugin is badly written...
It is your responsibility to make sure that the call is for your plugin. Look att the existing plugins...

Jörgen
Title: Re: cancel url calling from wrong plugin
Post by: rejoan on October 06, 2020, 20:02:37 PM
I have copied the standard plugin and modified as required.
Title: Re: cancel url calling from wrong plugin
Post by: Jörgen on October 06, 2020, 20:52:18 PM
Then You have not understood the code in the beginning of each trigger function...
Without any real code example, this is what I think.

Jörgen @ Kreativ Fotografi
Title: Re: cancel url calling from wrong plugin
Post by: Jörgen on October 06, 2020, 20:54:19 PM
Maybe to old VM version, who knows ?

Jörgen @ Kreativ Fotografi
Title: Re: cancel url calling from wrong plugin
Post by: rejoan on October 07, 2020, 01:24:34 AM
My Joomla version is 3.9.21 & my virtumart version is 3.8. I have called cancel url in my plgVmConfirmedOrder like this

$cancelUrl = JURI::root() . 'index.php/shop/pluginresponse/pluginUserPaymentCancel?on=' . $order['details']['BT']->order_number . ',' . $order['details']['BT']->virtuemart_paymentmethod_id;
$post_data['cancel_url'] = $cancelUrl;
$response = $this->_sendRequest($method, $post_data);


and at com_virtumart/controllers/vmplg.php the pluginUserPaymentCancel method I do not touch anything

Finally my plugin construct method like this

if (!class_exists('vmPSPlugin')) {
    require(VMPATH_PLUGINLIBS . DS . 'vmpsplugin.php');
}

class plgVmPaymentAmarpay extends vmPSPlugin {

    function __construct(& $subject, $config) {

        parent::__construct($subject, $config);
        $this->_loggable = TRUE;
        $this->tableFields = array_keys($this->getTableSQLFields());
        $this->_tablepkey = 'id';
        $this->_tableId = 'id';
        $varsToPush = $this->getVarsToPush();
        $this->addVarsToPushCore($varsToPush, 1);
        $this->setConfigParameterable($this->_configTableFieldName, $varsToPush);
    }

function plgVmOnUserPaymentCancel() {
        $reqData = vRequest::getString('on', '');
        $reqDataArr = explode(',', $reqData);
        $order_number = trim($reqDataArr[0]);

        $virtuemart_paymentmethod_id = trim($reqDataArr[1]);
...




Title: Re: cancel url calling from wrong plugin
Post by: Jörgen on October 07, 2020, 10:46:05 AM
You have to look for this kind of construct !


if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
return NULL; // Another method was selected, do nothing


Jörgen
Title: Re: cancel url calling from wrong plugin
Post by: rejoan on October 07, 2020, 12:18:23 PM
After providing unique order number for each payment method when payment method created. It is working
Title: Re: cancel url calling from wrong plugin
Post by: AH on October 07, 2020, 14:44:54 PM
That means your code for your new plugin is wrong - each payment method does not require a unique order_id
Payment plugins should test to see if the order being "updated" by the plugin was actually created by that plugin