API provides a way to register sales using PHP. This is an alternative to the General solution you can find in Integration methods.
Please make sure that you include the PapApi.class.php before you use this code. In case you have click tracking code on different domain then sale tracking code, then make sure you pass the PAPVisitorId cookie content to the sale tracking code. Use then setVisitorId($visitorId) in such case.
Example of registering sale:
include_once('PapApi.class.php'); $saleTracker = new Pap_Api_SaleTracker('URL_TO_PAP/scripts/sale.php'); $saleTracker->setAccountId('default1'); //if you need to set customer's IP use this row, otherwise is used IP recognized from $_SERVER['REMOTE_ADDR'] //$saleTracker->setIp('123.456.789.1'); $sale1 = $saleTracker->createSale(); $sale1->setTotalCost('100'); $sale1->setOrderID('oid'); $sale2 = $saleTracker->createSale(); $sale2->setTotalCost('10'); $sale2->setOrderID('oid'); $sale2->setProductID('pid'); $saleTracker->register();
Example above will register two sales with order ID 'oid'. First one with total cost of 100 and second one with total cost of 10. The second sale will also have product id set to 'pid'.
For PAN you need to set right account Id into sale tracker by using function setAccountId($accountId). Each merchant account in PAN has its own ID, you can find it in the section Accounts>Account manager when you are logged in as a network owner.
SaleTracker allows you to create as many sales / leads / actions as you wish. After creating them and setting all values you need to call register() method to finish the sale tracking.
If you want to register action instead of sale, use createAction($actionCode) method instead of createSale() method. Actions will work only if you have Action commissions feature enabled in PAP and the $actionCode is a valid code of some action commission.
You can force visitorId in sale tracker by calling $saleTracker->setVisitorId($visitorId) method.
Debug mode: if you want to see tracking debug messages, you can enable debug mode by using value true as second parameter in constructor of Pap_Api_SaleTracler(), example:
$saleTracker = new Pap_Api_SaleTracker('URL_TO_PAP/scripts/sale.php', true);
Sale / lead / action parameters
setTotalCost($value) total cost of the order. It is required for percentage commissions campaigns, otherwise optional
setOrderID($value) ID of the order. Can be used for recognizing duplicate transactions
setProductID($value) ID of the product
setCouponCode($value) coupon code used by the sale
setAffiliateID($value) ID or referral ID of the affiliate. With this parameter you can force to register commission to this affiliate
setBannerID($value) ID of the banner which was clicked by the customer to refer the sale. With this parameter you can fill in the banner for the commission you will save and it might also affect the campaign under which the commission will be saved if none of the higher priority parameters like CampaignID isn't used. This parameter was missing from this guide and was added here thanks to our customer Ali Gajani who pointed that out.
setCampaignID($value) ID of the campaign. With this parameter you can force to register commission using this campaign
setChannelID($value) ID of the channel. With this parameter you can force to register commission for this channel
setCustomCommission($value) value of custom commissions. You can force to use these commissions value instead of commissions set in a campaign. If you put % in front of the number, the commission will be computed as percentage, for tiers separator use ';' e.g.: 10;5;3;1
setCustomCommissionNextTiersFromCampaign('Y') use this if you want to generate other default tiers by campaign settings, without this setting only custom commission tiers would be generated and campaign would be completely ignored.
setStatus($value) force to set this status for this commission. You can use these states:
'A' - approved
'P' - pending
'D' - declined
setCurrency($value) set currency of sale (you must have active the feature Multiple currencies).
setData1($value) set custom data for this transaction. You have up to five fields.
setData2($value) set additional custom data for this transaction
setData3($value) set additional custom data for this transaction
setData4($value) set additional custom data for this transaction
setData5($value) set additional custom data for this transaction