OK, this was hellish for me because I was a PHP noob. (Note the past tense.)
What I finally did is steeped in a healthy dose of PHP superstition, but it works.
Nothing I did worked on the JAM PHP integration, and I still don't know why, and maybe I never will. I ended up going with the image tag implementation, but that was meant for an HTML page, not a PHP page, but I adjusted it to work on a PHP page.
First, I found that JAM has good code to avoid duplicate commissions, so putting the image tag on the checkout_success.php page is just fine.
I did set the necessary variables as my own session variables over in the /webassist/plugins/shopping_cart/cart_readonly.php page, and there I did the math that Jason provided. I put this right before the final <script> tag:
<?php
// Affiliate Code Math Here
$_SESSION['EPCtrans_id']=$_SESSION['OrderID'];
$_SESSION['EPCamount']=$WA_Store_Cart->TotalColumn("TotalPrice")-$WA_Store_Cart->GetDiscounts();
?>
(My initials are EPC.)
Then, on the checkout_success.php, I put this code right after this line:
</h1>
<div class="contentBox ps_pod1 borderColor">
(this is the inserted code now):
<?php
$FINALtrans_id=$_SESSION['EPCtrans_id'];
$FINALamount=$_SESSION['EPCamount'];
?>
<?php
echo ('<img border="0" src="https://mydomain.com/affiliate_folder/sale.php?amount='.$FINALamount.'&trans_id='.$FINALtrans_id.'" width="1" height="1">')
?>
As I said, superstitious, but this went on for 4 days for me. Then I learned about escaping the quotes. I could have just written--
<?php
echo ('<img border="0" src="https://mydomain.com/affiliate_folder/sale.php?amount='.$_SESSION['EPCamount'].'&trans_id='.$_SESSION['EPCtrans_id'].'" width="1" height="1">')
?>
-- and done it in one line. Maybe I could have done the "math" here as well (probably), but I went through a bit of hell with this, so I hope it helps you if you need it. It works!
Also, note the "https://" action. My PowerStore is secure, but if your's isn't, drop the "s" and make it "http://". Good luck!