Hello,
I am testing my custom payment gateway and this URL
index.php?option=com_payplans&view=payment&task=complete&gateway=mygateway&action=error
gives me an error
Call to undefined method PayPlansViewPayment::setTemplate()
 
Here is my code for 
onPayplansPaymentAfter event
public function onPayplansPaymentAfter(PPPayment $payment, &$action, &$data, $controller)
{
	$logs   = PPLog::getLog($payment, PPLogger::LEVEL_ERROR);
	$record = array_pop($logs);
	if ($record && !empty($record))
	{
		$action = 'error';
	}
	return parent:
nPayplansPaymentAfter($payment, $action, $data, $controller);
}
The problem is that you are passing 
$this (View object) on dispatch of the 
onPayplansPaymentAfter event in Payment view and 
onPayplansPaymentAfter is expecting controller:
// Trigger apps, so they can perform post payment work
$args = array($payment, &$action, &$post, $this);
$html = PP::event()->trigger('onPayplansPaymentAfter', $args, 'payment', $payment);
Best regards,
Artem