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 / MemberPress.class.php
postaffiliatepro / Form / Settings Last commit date
AdditionalOptions.class.php 2 months ago CampaignInfo.class.php 2 months ago Campaigns.class.php 2 months ago ClickTracking.class.php 2 months ago ContactForm7.class.php 2 months ago Debugging.class.php 4 weeks ago EDD.class.php 4 weeks ago General.class.php 4 weeks ago Integrations.class.php 2 months ago LifterLMS.class.php 2 months ago Marketpress.class.php 4 weeks ago MemberPress.class.php 2 months ago Membership2.class.php 2 months ago PMPro.class.php 2 months ago PPBuyNowButton.class.php 2 months ago RestrictContentPro.class.php 2 months ago S2Member.class.php 2 months ago Signup.class.php 2 months ago SimplePayPro.class.php 2 months ago StripePayments.class.php 4 weeks ago SureCart.class.php 2 months ago WPEasyCart.class.php 2 months ago WPPayForms.class.php 2 months ago WishListMember.class.php 2 months ago WooComm.class.php 4 weeks ago
MemberPress.class.php
204 lines
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class postaffiliatepro_Form_Settings_MemberPress extends postaffiliatepro_Form_Base {
5 const MEMBERPRESS_COMMISSION_ENABLED = 'memberpress-commission-enabled';
6 const MEMBERPRESS_CONFIG_PAGE = 'memberpress-config-page';
7 const MEMBERPRESS_TRACK_RECURRING = 'memberpress-track-refurring';
8 const MEMBERPRESS_TRACK_RECURRING_TOTAL = 'memberpress-track-recurring-total';
9 const MEMBERPRESS_DATA1 = 'memberpress-data1';
10 const MEMBERPRESS_DATA2 = 'memberpress-data2';
11 const MEMBERPRESS_DATA3 = 'memberpress-data3';
12 const MEMBERPRESS_DATA4 = 'memberpress-data4';
13 const MEMBERPRESS_DATA5 = 'memberpress-data5';
14
15 public function __construct() {
16 parent::__construct(self::MEMBERPRESS_CONFIG_PAGE, 'options.php');
17 }
18
19 protected function getTemplateFile() {
20 return WP_PLUGIN_DIR . '/postaffiliatepro/Template/MemberPressConfig.xtpl';
21 }
22
23 protected function initForm() {
24 $this->addCheckbox(self::MEMBERPRESS_TRACK_RECURRING);
25 $this->addCheckbox(self::MEMBERPRESS_TRACK_RECURRING_TOTAL);
26
27 $additionalData = array(
28 '0' => ' ',
29 'u_ID' => 'user ID',
30 'u_user_login' => 'user login',
31 'u_user_nicename' => 'user nice name',
32 'u_display_name' => 'user display name',
33 'u_user_email' => 'user email',
34 'u_user_url' => 'user URL',
35 'u_first_name' => 'user first name',
36 'u_last_name' => 'user last name',
37 'u_user_ip' => 'user IP address',
38 'p_price' => 'membership price',
39 'p_period_type' => 'membership period type',
40 'p_pricing_title' => 'membership pricing title'
41 );
42 $this->addSelect(self::MEMBERPRESS_DATA1, $additionalData);
43 $this->addSelect(self::MEMBERPRESS_DATA2, $additionalData);
44 $this->addSelect(self::MEMBERPRESS_DATA3, $additionalData);
45 $this->addSelect(self::MEMBERPRESS_DATA4, $additionalData);
46 $this->addSelect(self::MEMBERPRESS_DATA5, $additionalData);
47
48 $this->addSubmit();
49 }
50
51 public function initSettings() {
52 register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::MEMBERPRESS_COMMISSION_ENABLED);
53 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_TRACK_RECURRING);
54 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_TRACK_RECURRING_TOTAL);
55 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_DATA1);
56 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_DATA2);
57 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_DATA3);
58 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_DATA4);
59 register_setting(self::MEMBERPRESS_CONFIG_PAGE, self::MEMBERPRESS_DATA5);
60 }
61
62 public function addPrimaryConfigMenu() {
63 if (get_option(self::MEMBERPRESS_COMMISSION_ENABLED) === 'true') {
64 add_submenu_page(
65 'integrations-config-page-handle',
66 'MemberPress',
67 'MemberPress',
68 'manage_options',
69 'memberpressintegration-settings-page',
70 array($this, 'printConfigPage')
71 );
72 }
73 }
74
75 public function printConfigPage() {
76 $this->render();
77 return;
78 }
79
80 public function MemberPressTrackSale($txn) {
81 if (get_option(self::MEMBERPRESS_COMMISSION_ENABLED) !== 'true') {
82 return $txn;
83 }
84
85 // START hacky fix for recurring subscriptions with no free trial comming in as $0 amount and few seconds afterwards triggering MemberPressRecurringSale with correct amount
86 $price = $txn->amount;
87 if ($price == '0.00' || $price == 0) {
88 $product = $txn->product();
89 if (isset($product->trial_days) && isset($product->trial_amount)) {
90 if ($product->trial_days == '0' || $product->trial_amount != '0') {
91 $this->_log('Subscription product with incorrect amount received, saving cookie to user\'s meta and waiting for recurring notification with actual paid amount.');
92 if (isset($_REQUEST['pap_custom']) && (sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])) != '')) {
93 $wp_user_obj = MeprUtils::get_user_by('id', $txn->user_id);
94 update_user_meta($wp_user_obj->ID, 'pap_custom', sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])));
95 }
96 return $txn;
97 }
98 }
99 }
100 // END
101
102 $accountID = '';
103 $visitorID = '';
104 if (isset($_REQUEST['pap_custom']) && (sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])) != '')) {
105 $papCookie = sanitize_text_field(wp_unslash($_REQUEST['pap_custom']));
106 } else {
107 $wp_user_obj = MeprUtils::get_user_by('id', $txn->user_id);
108 $papCookie = get_user_meta($wp_user_obj->ID, 'pap_custom', true);
109 }
110 if ($papCookie !== '') {
111 $visitorID = substr($papCookie, -32);
112 $accountID = substr($papCookie, 0, 8);
113 }
114
115 $query = 'AccountId='.$accountID. '&visitorId='.$visitorID.'&TotalCost='.$txn->amount.'&ProductID='.$txn->product_id.'&OrderID=';
116
117 if (isset($txn->subscription_id) && $txn->subscription_id != '0' && $txn->subscription_id != 0) {
118 $query .= $txn->subscription_id;
119 } else {
120 $query .= $txn->id;
121 }
122
123 $query = $this->addExtraDataToQuery($query, $txn);
124
125 if (isset($_REQUEST['pap_IP']) && ($ip = filter_var(wp_unslash($_REQUEST['pap_IP']), FILTER_VALIDATE_IP))) {
126 $query .= '&ip='.$ip;
127 }
128
129 $this->_log('MemberPress integration sending a tracking request with the following details: ' . $query);
130 self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
131 return $txn;
132 }
133
134 public function addHiddenFieldToPaymentForm($productId) {
135 postaffiliatepro::addHiddenFieldToPaymentForm();
136 return $productId;
137 }
138
139 public function MemberPressRecurringSale(MeprEvent $event) {
140 $txn = new MeprTransaction($event->evt_id);
141 if (get_option(self::MEMBERPRESS_TRACK_RECURRING) !== 'true') {
142 $this->_log('Recurring commissions are not enabled, ending');
143 return;
144 }
145
146 // try to recur a commission with order ID $txn->subscription_id
147 $session = $this->getApiSession();
148 if ($session === null || $session === '0') {
149 $this->_log('We have no session to PAP installation! Recurring commission failed.');
150 return;
151 }
152
153 $recurringTotal = false;
154 if (get_option(self::MEMBERPRESS_TRACK_RECURRING_TOTAL) === 'true') {
155 $recurringTotal = $txn->amount;
156 }
157 $this->_log('MemberPress integration trying to trigger a recurring commission for subscription ' . $txn->subscription_id . ' with value ' . $recurringTotal);
158 if (!$this->fireRecurringCommissions($session, $txn->subscription_id, $recurringTotal)) {
159 // creating recurring commissions failed, create a new commission instead
160 $this->_log('Creating a new commission with order ID '.$txn->subscription_id);
161 $this->MemberPressTrackSale($txn);
162 }
163 }
164
165 private function addExtraDataToQuery($query, $txn) {
166 for ($i = 1; $i <= 5; $i++) {
167 if (get_option(constant('self::MEMBERPRESS_DATA'. $i)) === '0') {
168 continue;
169 }
170 if (substr(get_option(constant('self::MEMBERPRESS_DATA'. $i)), 0, 2) === 'u_') {
171 $data = $this->getUserDetail($txn->user_id, substr(get_option(constant('self::MEMBERPRESS_DATA'. $i)), 2));
172 } else {
173 $data = $this->getProductDetail($txn->product_id, substr(get_option(constant('self::MEMBERPRESS_DATA'. $i)), 2));
174 }
175 $query .= '&data' . $i . '=' . $data;
176 }
177 return $query;
178 }
179
180 private function getUserDetail($id, $detail) {
181 $user = new MeprUser($id);
182 if (isset($user->$detail)) {
183 return urlencode($user->$detail);
184 }
185 return '';
186 }
187
188 private function getProductDetail($id, $detail) {
189 $product = new MeprProduct($id);
190 if (isset($product->$detail)) {
191 return urlencode($product->$detail);
192 }
193 return '';
194 }
195 }
196
197 $papSubmenuPriority = 22;
198 $papIntegrationMemberPress = new postaffiliatepro_Form_Settings_MemberPress();
199 add_action('admin_init', array($papIntegrationMemberPress, 'initSettings'), 99);
200 add_action('admin_menu', array($papIntegrationMemberPress, 'addPrimaryConfigMenu'), $papSubmenuPriority);
201
202 add_action('mepr-signup', array($papIntegrationMemberPress, 'MemberPressTrackSale'));
203 add_action('mepr-checkout-before-submit', array($papIntegrationMemberPress, 'addHiddenFieldToPaymentForm'));
204 add_action('mepr-event-recurring-transaction-completed', array($papIntegrationMemberPress, 'MemberPressRecurringSale'), 99, 1);