Jump to content

Conversion tracking code, complete.tpl and viewinvoice.php?id=xxx


Recommended Posts

My goal is to print a conversion tracking code after a Paypal payment.

 

It seemed easy to put the conversion tracking code in complete.tpl between {if $ispaid} and {/if}, even if a required var "amount" was missing.

 

{if $ispaid}
<!-- Enter any HTML code which needs to be displayed once a user has completed the checkout of their order here - for example conversion tracking and affiliate tracking scripts -->
{/if}

 

The problem is that after a Paypal payment on paypal.com, I'm not taken back to /cart.php?a=complete , but to the invoice /viewinvoice.php?id=xxxx , even if the "Automatically forward the user to the payment gateway" is checked in Options. Well, it's true I'm forwarded to the payment gateway, Paypal in this case, but after the payment I'm taken to the invoice rather to the complete/thank you page.

 

In desperation, I tried to hook into InvoicePaid and made a function to echo the code there, in the invoice. But it doesn't work either, nothing is echoed.

 

/includes/hooks/csw.php (custom file):

// copy paste of function found in whmcs docs online
function csw_xml_parser($rawxml) {
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $rawxml, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
$alreadyused = array();
$x=0;
foreach ($vals as $xml_elem) {
	if ($xml_elem['type'] == 'open') {
		if (in_array($xml_elem['tag'],$alreadyused)) {
			$x++;
			$xml_elem['tag'] = $xml_elem['tag'].$x;
		}
		$level[$xml_elem['level']] = $xml_elem['tag'];
		$alreadyused[] = $xml_elem['tag'];
	}
	if ($xml_elem['type'] == 'complete') {
		$start_level = 1;
		$php_stmt = '$params';
		while($start_level < $xml_elem['level']) {
			$php_stmt .= '[$level['.$start_level.']]';
			$start_level++;
		}
		$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
		@eval($php_stmt);
	}
}
return($params);
}

function csw_InvoicePaid( $vars )
{
$invoiceid = $vars['invoiceid'];
$invoiceXML = localAPI('getinvoice',array('invoiceid'=>"$invoiceid"),'admin');
$invoice = csw_xml_parser($invoiceXML);
// debug to see what invoice looks like
return '<pre>'.print_r( $invoice, true ).'</pre>';
}
add_hook("InvoicePaid",1,"csw_InvoicePaid");

 

Could anybody kindly shed some light on this thing please?

 

Thank you in advance.

Link to comment
Share on other sites

  • 3 weeks later...

Were you able to find a solution? Customers are redirected from Paypal to the invoice paid page bypassing the tracking code in the complete.tpl template. Surely this must be a common issue with Paypal being the most popular payment gateway and ecommerce tracking a necessity for most?

Link to comment
Share on other sites

  • 8 months later...
  • 7 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated