function tiaop_process_saved_purchases($is_test = false) { // Get the referral information if ($is_test) { $affiliateId = 1; } else { $affiliateId = affiliate_wp()->tracking->get_affiliate_id(); } if (empty($affiliateId)) { return; } // Check the database for saved purchases $savedPurchase = tiaop_get_saved_purchase(); if (!$savedPurchase) { return; } // Tell the log that we found a saved purchase and are attempting to process it if (WP_DEBUG === true) { error_log("tiaop_add_referral: Found a saved purchase; attempting to process it"); error_log(print_r($savedPurchase, true)); } $amount = $savedPurchase[2]; $description = $savedPurchase[3]; $reference = $savedPurchase[4]; $expiration = $savedPurchase[5]; // Get the visit id if ($is_test) { $visitId = 2; } else { $visitId = affiliate_wp()->tracking->get_visit_id(); } // Call the function that adds the referral tiaop_add_referral($affiliateId, $amount, $description, $reference, "", $visitId, $is_test); // Log the link tiaop_add_history(tiaop_get_user_ip(), $amount, $description, $reference, $expiration, "Visit ID " . $visitId . " linked to Affiliate ID " . $affiliateId, $is_test); // Update the conversion stats if (!is_test) { tiaop_increment_ac($amount); } // Delete this entry now that it was processed tiaop_delete_current_ip(); }
function tiaop_paypal_notify($false, $args) { // Delete any expired purchases tiaop_delete_expired(); // Don't proceed if the notification arguments weren't passed if (!$args) { if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: second argument set empty"); } return; } // Don't proceed if the paypal array isn't available if (!$args["paypal"]) { if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: paypal array not found"); } return; } // Show the available args in the debug file if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: args value = "); if (is_array($args) || is_object($args)) { error_log(print_r($args, true)); } else { error_log($args); } } // Get the referral information $affiliateId = affiliate_wp()->tracking->get_affiliate_id(); $amount = $args["paypal"]["mc_gross"]; $description = $args["paypal"]["transaction_subject"]; $reference = $args["paypal"]["payer_email"]; $payerIpAddress = $args["paypal"]["option_selection2"]; // If the affiliateId wasn't found using get_affiliate_id(), save to try later if (empty($affiliateId)) { if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: affiliate_wp()->tracking->get_affiliate_id() did not obtain affiliateId, storing in database to try later"); } // Save purchase tiaop_save_purchase($payerIpAddress, $amount, $description, $reference); return; } // If the affiliateId wasn't found, log and return if (empty($affiliateId)) { if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: affiliate id was not found"); } return; } // If the affiliateId isn't valid, log and return if (!affiliate_wp()->tracking->is_valid_affiliate($affiliate_id)) { if (WP_DEBUG === true) { error_log("tiaop_paypal_notify: affiliate id was not valid"); } return; } // Get the visit id $visitId = affiliate_wp()->tracking->get_visit_id(); // Call the function that adds the referral tiaop_add_referral($affiliateId, $amount, $description, $reference, "", $visitId); }