This integration method is for Virtue Mart version 2. If you have lower version, please navigate to the integration method named "Virtue Mart".

1.

Virtue Mart with PayPal in Joomla

First step is to edit file /plugins/vmpayment/paypal/paypal.php of your Joomla installation. Find function plgVmConfirmedOrder($cart, $order) and in the function find line
$html.= '</form>';

It can also be like this:
$html .= '</form></div>';

Now add this code right after the above:

$html.= '<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/salejs.php" type="text/javascript">
</script>
<script type="text/javascript">'."
PostAffTracker.setAccountId('Account_ID');
PostAffTracker.setAppendValuesToField('&pap_custom=');
PostAffTracker.writeCookieToCustomField('pap_ab78y5t4a');
</script>";

2.

Virtue Mart with PayPal in Joomla

Now one more change is needed - find the line

$html.= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';

and replace it with this:

if ($name == "notify_url") {$id='id="pap_ab78y5t4a"';} else {$id="";}
$html.= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" '.$id." />n";

Now save your work, there is another step to be done.

3.

Virtue Mart with PayPal in Joomla

Final step is to resend response from PayPal to Post Affiliate Pro. To do this, find this line in the same file:
function _processIPN($paypal_data, $method) {
Add this code right below this line (create a new blank line) and past the code there:

// Post Affiliate Pro integration snippet
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://URL_TO_PostAffiliatePro/plugins/PayPal/paypal.php?pap_custom=".$_GET['pap_custom']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
// /Post Affiliate Pro integration snippet

This is it. Now save your file and upload it back to the server. Do not forget to enable PayPal plugin in your Post Affiliate Pro.

4.

Virtue Mart with COD in Joomla

In case of Cash on delivery (COD) you have to modify the file /plugins/vmpayment/standard/standard.php and insert the sale tracking code there.
Find the line:
$cart->emptyCart ();
and paste this code above that line:

$html.= '<!-- Post Affiliate Pro sale tracking code -->
<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/salejs.php" type="text/javascript"></script>
<script type="text/javascript">'
."PostAffTracker.setAccountId('Account_ID');"
.'var sale = PostAffTracker.createSale();
sale.setTotalCost(''.$order['details']['BT']->order_subtotal.'');
sale.setOrderID(''.$order['details']['BT']->order_number.'');
PostAffTracker.register();
</script>';

That's it. Save your work and upload it back to the server.

Here is a list of all variables you can use:

$order['details']['BT']->order_total  
$order['details']['BT']->order_subtotal  
$order['details']['BT']->tax  
$order['details']['BT']->coupon_discount  
$order['details']['BT']->coupon_code  
$order['details']['BT']->order_status  

5.

Virtue Mart with Cheque in Joomla

In case of Cheque payment method you have to modify the file /plugins/vmpayment/standard/standard.php and insert the sale tracking code there.
Find the line:

$modelOrder->updateStatusForOneOrder ($order['details']['BT']->virtuemart_order_id, $order, TRUE);

and paste this code below that line:

/* Post Affiliate Pro integration snippet */
$html .= '<script type="text/javascript">
  document.write(unescape("%3Cscript id=%27pap_x2s6df8d%27 src=%27" + (("https:" == document.location.protocol) ? "https://" : "http://") + "URL_TO_PostAffiliatePro/scripts/trackjs.js%27 type=%27text/javascript%27%3E%3C/script%3E"));
  </script>
  <script type="text/javascript">
  PostAffTracker.setAccountId('default1');
  var sale = PostAffTracker.createSale();
  sale.setTotalCost(''.$order['details']['BT']->order_subtotal.'');
  sale.setOrderID(''.$order['details']['BT']->order_number.'');

  PostAffTracker.register();
  </script>';
/* /Post Affiliate Pro integration snippet */

Save your work and you are done. You can use the same extra variables described in step 10.

6.

Virtue Mart with GoogleCheckout in Joomla

The first step is to edit file /plugins/vmpayment/osegooglecheckout/osegooglecheckout.php and to find function plgVmConfirmedOrder. Now, find line (in the end of the function):

$html.= '</form>';

Now change this line to these lines instead:

/* Post Affiliate Pro integration snippet */
$html.= '<input id="pap_dx8vc2s5" type="hidden" name="shopping-cart.items.item-1.merchant-private-item-data" value="" />';
$html.= '<script id="pap_x2s6df8d" src="//URL_TO_PostAffiliatePro/scripts/notifysale.php" type="text/javascript">'."n".'</script>';
$html.= '</form>';
/* /Post Affiliate Pro integration snippet */

Additionally, change line:

$html.= ' document.vm_google_form.submit();';

to this line:

$html.= ' setTimeout("document.vm_google_form.submit()",3600);';

This will ensure the tracking will work with GoogleCheckout buttons.

7.

Virtue Mart with GoogleCheckout in Joomla

The second and the last step of GoogleCheckout integration is to place cURL code to its correct place - find the function plgVmOnPaymentResponseReceived and place the following code to the start of the function:

/* Post Affiliate Pro integration snippet */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://URL_TO_PostAffiliatePro/plugins/GoogleCheckout/googlecheckout.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
/* /Post Affiliate Pro integration snippet */

Note: URL https://URL_TO_PostAffiliatePro/plugins/GoogleCheckout/googlecheckout.php must be on secure domain (More on Google documentation).


Do not forget to integrate the click tracking code, to make the sale tracking work correctly.