How to capture authorized transaction

  • Posts: 21
  • Thank you received: 0
3 years 9 months ago #321866

-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3

Hello,

I am implementing a third party payment gateway which has authorize and sale feature. So when I use Sale while making payment then it works fine but when I use authorize, payment functionality works fine but after that I don't see any option in order details page to Capture this transaction.

I also checked Authorize payment gateway but I did not find any code or button to capture authorized payment.
So please let me know how to achieve Capture feature for authorized transaction.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
3 years 9 months ago #321895

Hi,

There is nothing specific for that. It's up to the payment plugin to implement it how ever it wants.
Normally, I would guess that you would add a function onAfterOrderUpdate(&$order) and check the status of the order in $order->order_status and in $order->old->order_status so that you see that the order status is being changed from one status to another so that you would launch the cURL request to the payment gateway to capture the payment.
In most cases, merchants want to capture the payments directly when the payment is made by the customer so all the plugins I saw so far work like that and don't have an extra step to manually do the capture.

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
3 years 9 months ago #321896

Okay, I’ll try your suggestion.

Also I want to add a custom button on order detail page through my payment plugin and when this button is hit, I want to execute some code written in my plugin.

So please let me know the way to add custom button.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
3 years 9 months ago #321898

Hi,

You want to implement the onHikashopBeforeDisplayView(&$view) function in your plugin.
In it, you need to check the task and layout of the view ( $view->getLayout() and $view->ctrl ) so that you only add the button for the view you're targeting.
Then, you want to push an array with the correct parameters in the variable $this->toolbar.
For example:

		if($viewName == 'order' && $layout == 'show' && !empty($view->order->order_id)) {
			$url = hikashop_completeLink('xxx&task=yyy&order_id='.$view->order->order_id);
			$button = array('name' => 'popup','icon'=>'upload','alt'=>JText::_('zzz'),'url'=>$url);
			array_unshift($view->toolbar, $button);
		}
And you can also implement such function in your plugin to register your controller:
public function onHikashopPluginController($ctrl) {
		if(hikashop_isClient('administrator')) {
			return array(
				'type' => 'hikashop',
				'name' => 'xxx',
				'prefix' => 'ctrl'
			);
		}
	}
and then you can have the file xxx.php in your plugin to act as a controller.
You can find an example of that in plugins/hikashop/email_history/
Please note that all these are for a plugin of the group "hikashop". If your plugin is of the group "hikashoppayment", it mgith not be triggered by some of these. So in that case, two plugins might be needed, or a system plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
3 years 9 months ago #321918

Hello,

I tried below code to add custom button but when clicking on button nothing is happening. It is just giving error "Page not found : invoice".

Here is the my code :

class plgHikashopMygateway_invoice extends JPlugin {

	public function __construct(&$subject, $config) {
		parent::__construct($subject, $config);
	}
        
        public function onHikashopBeforeDisplayView(&$view) {
            if($view->request['ctrl'] == 'order' && $view->request['task'] == 'show') {
                $url = hikashop_completeLink('invoice&task=generate&order_id=134');
                $button = array('name' => 'popup','icon'=>'upload','alt'=>JText::_('Generate Invoice'),'url'=>$url);
                array_unshift($view->toolbar, $button);
            }
        }
        
        public function onHikashopPluginController($ctrl) {
		if(hikashop_isClient('administrator')) {
			return array(
				'type' => 'hikashop',
				'name' => 'invoice',
				'prefix' => 'ctrl'
			);
		}
	}
}

And here the controller file invoice.php, I tried to name it invoice_ctrl.php an invoice.php but none of worked :
class invoiceController extends hikashopController {
	public $modify = array();
	public $delete = array();
	public $modify_views = array();


	public function __construct($config = array(), $skip = false) {
		parent::__construct($config, $skip);
                $this->display = array_merge($this->display, array(
			'generate'
		));
	}

	public function generate() {
		$this->writeToLog("Test");
	}
        
        function writeToLog($data = null) {
		if(!empty($data)) {
			hikashop_writeToLog($data, $this->name);
			if(is_array($data) || is_object($data))
				$data = str_replace(array("\r","\n","\r\n"),"\r\n",print_r($data, true))."\r\n\r\n";
			$this->cachedDebug .= $data;
		}
		return $this->cachedDebug;
	}
	
}

And here is the xml file :
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="2.5" method="upgrade" group="hikashop">
	<name>Hikashop Mygateway Invoice Plugin</name>
	<creationDate>17 juin 2020</creationDate>
	<version>4.3.0</version>
	<author>Hikashop</author>
	<authorEmail>dev@hikashop.com</authorEmail>
	<authorUrl>http://www.hikashop.com</authorUrl>
	<copyright>(C) 2010-2020 HIKARI SOFTWARE. All rights reserved.</copyright>
	<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
	<description>This plugin enables you to download invoice</description>
	<files>
		<filename plugin="mygateway_invoice">mygateway_invoice.php</filename>
		<filename>invoice.php</filename>
	</files>
</extension>

Please let me know if I am doing something wrong.
Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
3 years 9 months ago #321934

Hi,

Since your plugin name is mygateway_invoice I think that xxx should be replaced by mygateway_invoice
and thus the file invoice.php should be mygateway_invoice_ctrl.php etc

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
3 years 9 months ago #321948

I tried the same way you told but still getting mygateway_invoice file not found. I don't know why this is not working for me.

if you have sample code then please let me know.
Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
3 years 9 months ago #321957

Hi,

Well, as I said in a previous message, in the folder plugins/hikashop/email_history you have a full example. That plugin adds the menu Customers>Emails history in your backend and has a controller to for the different tasks.
Also, when looking at this plugin, I just remebered that you also need to have a views folder with a xxx folder inside and inside it a file view.html.php (that's the file which will handle the display if your controller needs any). I suspect it might be why it's not working.

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds
Powered by Kunena Forum