PluginProbe ʕ •ᴥ•ʔ
Post Affiliate Pro / trunk
Post Affiliate Pro vtrunk
1.29.5 1.29.4 1.29.3 1.29.0 1.29.1 1.29.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.5.0 1.5.1 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 trunk 1.0.1 1.0.10 1.0.11 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.10.1 1.10.2 1.10.3 1.10.4 1.11.1 1.11.2 1.12.1 1.12.2 1.12.3 1.12.4 1.12.5 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.14.0 1.14.1 1.14.2 1.15.0 1.15.1 1.15.2 1.15.3 1.15.4 1.15.5 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.17.0 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.19.0 1.19.1 1.19.10 1.19.11 1.19.12 1.19.13 1.19.14 1.19.15 1.19.16 1.19.17 1.19.2 1.19.3 1.19.4 1.19.5 1.19.6 1.19.7 1.19.8 1.19.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.28 1.2.3 1.2.31 1.2.32 1.2.33 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.20.0 1.20.1 1.21.0 1.21.1 1.21.2 1.21.3 1.21.4 1.21.5 1.21.6 1.21.7 1.22.0 1.22.1 1.22.2 1.23.0 1.23.1 1.23.2 1.23.3 1.23.4 1.23.5 1.23.6 1.23.7 1.23.8 1.24.1 1.24.2 1.24.3 1.24.4 1.24.5 1.24.6 1.24.7 1.24.8 1.24.9 1.25.0 1.26.0 1.26.1 1.26.10 1.26.11 1.26.2 1.26.3 1.26.4 1.26.5 1.26.6 1.26.7 1.26.8 1.26.9 1.27.0 1.27.1 1.27.10 1.27.11 1.27.12 1.27.13 1.27.14 1.27.15 1.27.2 1.27.3 1.27.5 1.27.6 1.27.7 1.27.8 1.27.9 1.28.0 1.28.1 1.28.2 1.28.3
postaffiliatepro / Form / Settings / EDD.class.php
postaffiliatepro / Form / Settings Last commit date
AdditionalOptions.class.php 3 months ago CampaignInfo.class.php 3 months ago Campaigns.class.php 3 months ago ClickTracking.class.php 3 months ago ContactForm7.class.php 3 months ago Debugging.class.php 2 months ago EDD.class.php 2 months ago General.class.php 2 months ago Integrations.class.php 3 months ago LifterLMS.class.php 3 months ago Marketpress.class.php 2 months ago MemberPress.class.php 3 months ago Membership2.class.php 3 months ago PMPro.class.php 3 months ago PPBuyNowButton.class.php 3 months ago RestrictContentPro.class.php 3 months ago S2Member.class.php 3 months ago Signup.class.php 3 months ago SimplePayPro.class.php 3 months ago StripePayments.class.php 2 months ago SureCart.class.php 3 months ago WPEasyCart.class.php 3 months ago WPPayForms.class.php 3 months ago WishListMember.class.php 3 months ago WooComm.class.php 2 months ago
EDD.class.php
272 lines
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class postaffiliatepro_Form_Settings_EDD extends postaffiliatepro_Form_Base {
5 const EDD_COMMISSION_ENABLED = 'edd-commission-enabled';
6 const EDD_CONFIG_PAGE = 'edd-config-page';
7 const EDD_PERPRODUCT = 'edd-per-product';
8 const EDD_PRODUCT_ID = 'edd-product-id';
9 const EDD_TRACK_FEE = 'edd-track-fee';
10 const EDD_DATA1 = 'edd-data1';
11 const EDD_CAMPAIGN = 'edd-campaign';
12 const EDD_STATUS_UPDATE = 'edd-status-update';
13
14 public function __construct() {
15 parent::__construct(self::EDD_CONFIG_PAGE, 'options.php');
16 }
17
18 protected function getTemplateFile() {
19 return WP_PLUGIN_DIR . '/postaffiliatepro/Template/EDD.xtpl';
20 }
21
22 protected function initForm() {
23 $this->addCheckbox(self::EDD_PERPRODUCT);
24 $this->addCheckbox(self::EDD_TRACK_FEE);
25 $this->addSelect(self::EDD_PRODUCT_ID, array(
26 '0' => ' ',
27 'id' => 'product ID',
28 'name' => 'product name'
29 ));
30 $this->addSelect(self::EDD_DATA1, array(
31 '0' => ' ',
32 'id' => 'customer ID',
33 'email' => 'customer email'
34 ));
35
36 $campaignHelper = new postaffiliatepro_Util_CampaignHelper();
37 $campaignList = $campaignHelper->getCampaignsList();
38
39 $campaigns = array('0' => ' ');
40 foreach ($campaignList as $row) {
41 $campaigns[$row->get('campaignid')] = htmlspecialchars($row->get('name'));
42 }
43 $this->addSelect(self::EDD_CAMPAIGN, $campaigns);
44
45 $this->addSubmit();
46 }
47
48 public function initSettings() {
49 register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::EDD_COMMISSION_ENABLED);
50 register_setting(self::EDD_CONFIG_PAGE, self::EDD_PERPRODUCT);
51 register_setting(self::EDD_CONFIG_PAGE, self::EDD_TRACK_FEE);
52 register_setting(self::EDD_CONFIG_PAGE, self::EDD_PRODUCT_ID);
53 register_setting(self::EDD_CONFIG_PAGE, self::EDD_DATA1);
54 register_setting(self::EDD_CONFIG_PAGE, self::EDD_STATUS_UPDATE);
55 register_setting(self::EDD_CONFIG_PAGE, self::EDD_CAMPAIGN);
56 }
57
58 public function addPrimaryConfigMenu() {
59 if (get_option(self::EDD_COMMISSION_ENABLED) === 'true') {
60 add_submenu_page('integrations-config-page-handle', 'Easy Digital Downloads', 'Easy Digital Downloads', 'manage_options', 'eddintegration-settings-page', array(
61 $this,
62 'printConfigPage'
63 ));
64 }
65 }
66
67 public function printConfigPage() {
68 $this->render();
69 }
70
71 public function eddAddThankYouPageTrackSale($payment, $edd_receipt_args) {
72 if (get_option(self::EDD_COMMISSION_ENABLED) !== 'true') {
73 echo "<!-- Post Affiliate Pro sale tracking error - tracking not enabled -->\n";
74 return;
75 }
76
77 $payment = new EDD_Payment($payment->ID);
78 $cart_details = $payment->cart_details;
79
80 if (is_array($cart_details) && get_option(self::EDD_PERPRODUCT) === 'true') {
81 $count = count($cart_details);
82 $i = 1;
83 $deleteCookiesAfterFee = false;
84 foreach ($cart_details as $n => $download) {
85 $deleteCookies = false;
86 $orderId = ($this->eddIsRecurringProduct($download)) ? $payment->ID . '-' . $download['id'] : $payment->ID.'('.($i).')';
87 $order['id'] = $orderId;
88 $order['total'] = $download['subtotal'];
89 $order['product'] = $this->getProductID($download);
90 $order['data1'] = $this->getTrackingData1($payment);
91 $order['currency'] = $payment->currency;
92 if ($count == $i) {
93 $deleteCookies = true;
94 if (get_option(self::EDD_TRACK_FEE) === 'true') {
95 $deleteCookies = false;
96 $deleteCookiesAfterFee = true;
97 }
98 }
99 $this->trackOrder($order, $deleteCookies);
100 $i++;
101 if (get_option(self::EDD_TRACK_FEE) === 'true') {
102 $this->trackSignupFee($payment, $download, $i, $deleteCookiesAfterFee);
103 $i++;
104 }
105 }
106 } else {
107 // per order
108 $order['id'] = $payment->ID;
109 $totalCost = (get_option(self::EDD_TRACK_FEE) === 'true') ? $payment->subtotal + $this->getSignupFee($payment) : $payment->subtotal;
110 $order['total'] = $totalCost;
111 $order['product'] = '';
112 $order['data1'] = $this->getTrackingData1($payment);
113 $order['currency'] = $payment->currency;
114 $this->trackOrder($order);
115 }
116 }
117
118 public function eddTrackRecurring($payment, $extraDetails) {
119 if (get_option(self::EDD_COMMISSION_ENABLED) !== 'true') {
120 return;
121 }
122 self::_log('EDD Tracking of recurring order: ' . $payment->parent_payment);
123
124 $session = $this->getApiSession();
125 if ($session === null || $session === '0') {
126 self::_log('We have no session to PAP installation! Recurring commission failed. Trying to create a regular commission.');
127 $this->eddTrackRecurringAsRegularSale($payment, $extraDetails);
128 return;
129 }
130
131 if (!$this->fireRecurringCommissions($session, $payment->parent_payment . '-' . $extraDetails->product_id, $payment->total)) {
132 self::_log('Recurring commission for order ID ' . $payment->parent_payment . ' failed, trying to create a regular commission.');
133 $this->eddTrackRecurringAsRegularSale($payment, $extraDetails);
134 }
135 }
136
137 private function trackOrder($order, $deleteCookie = false) {
138 $result = "<!-- Post Affiliate Pro sale tracking -->\n";
139
140 $contentToAsync = 'PostAffTracker.setAccountId(\'' . postaffiliatepro::getAccountName() . '\');';
141 $contentToAsync .= "var sale = PostAffTracker.createSale();\n";
142 $contentToAsync .= "sale.setTotalCost('" . esc_js($order['total']) . "');\n";
143 $contentToAsync .= "sale.setOrderID('" . esc_js($order['id']) . "');\n";
144 $contentToAsync .= "sale.setProductID('" . esc_js($order['product']) . "');\n";
145 $contentToAsync .= "sale.setData1('" . esc_js($order['data1']) . "');\n";
146 $contentToAsync .= "sale.setCurrency('" . esc_js($order['currency']) . "');\n";
147
148 if (!$deleteCookie) {
149 $contentToAsync .= "if (typeof sale.doNotDeleteCookies === 'function') {sale.doNotDeleteCookies();}\n";
150 }
151 if (get_option(self::EDD_CAMPAIGN) !== '' && get_option(self::EDD_CAMPAIGN) !== null && get_option(self::EDD_CAMPAIGN) !== 0 && get_option(self::EDD_CAMPAIGN) !== '0') {
152 $contentToAsync .= "sale.setCampaignID('" . get_option(self::EDD_CAMPAIGN) . "');\n";
153 }
154 $contentToAsync .= "PostAffTracker.register();\n";
155
156 if (get_option(postaffiliatepro::ASYNC_ENABLED) !== 'true') {
157 $result .= postaffiliatepro::getPAPTrackJSDynamicCode().'<script type="text/javascript">';
158 $result .= $contentToAsync . "</script>\n";
159 } else {
160 $result .= postaffiliatepro::getPAPTrackJSAsyncCode($contentToAsync);
161 }
162
163 echo $result;
164 return true;
165 }
166
167 private function getProductID($order) {
168 switch (get_option(self::EDD_PRODUCT_ID)) {
169 case 'id':
170 return $order['id'];
171 case 'name':
172 return $order['name'];
173 default: return '';
174 }
175 }
176
177 private function getTrackingData1($payment) {
178 switch (get_option(self::EDD_DATA1)) {
179 case 'id':
180 if ($payment->user_id != '') {
181 return $payment->user_id;
182 }
183 return crc32($payment->email);
184 case 'email': return $payment->email;
185 default: return '';
186 }
187 }
188
189 private function getSignupFee($payment) {
190 if (isset($payment->fees)) {
191 foreach ($payment->fees as $fee) {
192 if ($fee['id'] === 'signup_fee') {
193 return $fee['amount'];
194 }
195 }
196 }
197 return 0;
198 }
199
200 private function getSignupFeeFromDownload($download) {
201 if (isset($download['options']['recurring']['signup_fee'])) {
202 return $download['options']['recurring']['signup_fee'];
203 }
204 if (isset($download['item_number']['options']['recurring']['signup_fee'])) {
205 return $download['item_number']['options']['recurring']['signup_fee'];
206 }
207 return 0;
208 }
209
210 private function trackSignupFee($payment, $download, $i, $deleteCookies) {
211 $order['id'] = $payment->ID.'('.($i).')';
212 $order['total'] = $this->getSignupFeeFromDownload($download);
213 $order['product'] = $this->getProductID($download) . ' Signup Fee';
214 $order['data1'] = $this->getTrackingData1($payment);
215 $order['currency'] = $payment->currency;
216 $this->trackOrder($order, $deleteCookies);
217 }
218
219 private function eddTrackRecurringAsRegularSale($payment, $extraDetails) {
220 $query = 'AccountId=' . postaffiliatepro::getAccountName();
221 $campaignId = get_option(self::EDD_CAMPAIGN);
222 if ($campaignId != '' && $campaignId !== '0') {
223 $query .= '&CampaignID=' . $campaignId;
224 }
225 $productId = $extraDetails->product_id;
226 if (get_option(self::EDD_PRODUCT_ID) === 'name' && function_exists('edd_get_payment')) {
227 $parentPayment = edd_get_payment($payment->parent_payment);
228 if (isset($parentPayment->cart_details)) {
229 foreach ( $parentPayment->cart_details as $cart_item ) {
230 if ( (int) $extraDetails->product_id === (int) $cart_item['id'] ) {
231 $productId = $cart_item['name'];
232 }
233 }
234 }
235 }
236 $orderId = $payment->ID . '-' . $extraDetails->product_id;
237 $query .= "&TotalCost=$payment->total&OrderID=$orderId&ProductID=$productId";
238 $query .= "&Currency=$payment->currency";
239 $query .= "&Data1=" . urlencode($this->getTrackingData1($payment));
240 self::_log('EDD Sending a tracking request with these details: ' . print_r($query, true));
241 self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
242 }
243
244 private function eddIsRecurringProduct($download) {
245 if(isset($download['options']['recurring'])) {
246 return true;
247 }
248 if(isset($download['item_number']['options']['recurring'])) {
249 return true;
250 }
251 return false;
252 }
253 }
254
255 $papSubmenuPriority = 12;
256 $papIntegrationEDD = new postaffiliatepro_Form_Settings_EDD();
257 add_action('admin_init', array(
258 $papIntegrationEDD,
259 'initSettings'
260 ), 99);
261 add_action('admin_menu', array(
262 $papIntegrationEDD,
263 'addPrimaryConfigMenu'
264 ), $papSubmenuPriority);
265 add_action('edd_payment_receipt_after_table', array(
266 $papIntegrationEDD,
267 'eddAddThankYouPageTrackSale'
268 ), 99, 2);
269 add_action('edd_recurring_add_subscription_payment', array(
270 $papIntegrationEDD,
271 'eddTrackRecurring'
272 ), 99, 2);