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 / Membership2.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
Membership2.class.php
215 lines
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class postaffiliatepro_Form_Settings_Membership2 extends postaffiliatepro_Form_Base {
5 const MEMBERSHIP2_COMMISSION_ENABLED = 'membership2-commission-enabled';
6 const MEMBERSHIP2_CONFIG_PAGE = 'membership2-config-page';
7 const MEMBERSHIP2_TRACK_REFUNDS = 'membership2-track-refunds';
8
9 public function __construct() {
10 parent::__construct(self::MEMBERSHIP2_CONFIG_PAGE, 'options.php');
11 }
12
13 protected function getTemplateFile() {
14 return WP_PLUGIN_DIR . '/postaffiliatepro/Template/Membership2Config.xtpl';
15 }
16
17 protected function initForm() {
18 $this->addCheckbox(self::MEMBERSHIP2_TRACK_REFUNDS);
19
20 $this->addSubmit();
21 }
22
23 public function initSettings() {
24 register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::MEMBERSHIP2_COMMISSION_ENABLED);
25 register_setting(self::MEMBERSHIP2_CONFIG_PAGE, self::MEMBERSHIP2_TRACK_REFUNDS);
26 }
27
28 public function addPrimaryConfigMenu() {
29 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) === 'true') {
30 add_submenu_page(
31 'integrations-config-page-handle',
32 'Membership 2 Pro',
33 'Membership 2 Pro',
34 'manage_options',
35 'membership2integration-settings-page',
36 array($this, 'printConfigPage')
37 );
38 }
39 }
40
41 public function printConfigPage() {
42 $this->render();
43 }
44
45 public function Membership2TrackSale($invoice, $subscription) {
46 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) !== 'true') {
47 return false;
48 }
49
50 $papCookie = '';
51 $accountID = '';
52 $visitorID = '';
53 if (isset($_REQUEST['pap_custom']) && (sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])) != '')) {
54 $papCookie = sanitize_text_field(wp_unslash($_REQUEST['pap_custom']));
55 }
56 $visitorID = substr($papCookie,-32);
57 $accountID = substr($papCookie,0,8);
58
59 if ($subscription->is_trial_eligible()) {
60 $total = $invoice->trial_price;
61 } else {
62 $total = $invoice->total;
63 }
64
65 $query = 'AccountId='.$accountID. '&visitorId='.$visitorID.'&TotalCost='.$total.'&ProductID='.$subscription->get_membership()->id.'&OrderID='.$subscription->id;
66
67 if (isset($_POST['payer_email'])) {
68 $user = get_user_by('email', sanitize_email(wp_unslash($_POST['payer_email'])));
69 $query .= '&Data1='.$user->ID;
70 }
71
72 if (isset($_REQUEST['pap_IP']) && ($ip = filter_var(wp_unslash($_REQUEST['pap_IP']), FILTER_VALIDATE_IP))) {
73 $query .= '&ip='.$ip;
74 }
75
76 self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
77 return true;
78 }
79
80 public function Membership2StripeTransaction($invoice, $gateway) {
81 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) !== 'true') {
82 return false;
83 }
84
85 $subscription = $invoice->get_subscription();
86 $member = $subscription->get_member();
87 $customer = $gateway->_api->find_customer($member);
88
89 $accountID = '';
90 $visitorID = '';
91 $pap_custom = '';
92 if (!empty($customer)) {
93 $pap_custom = $customer->description;
94 }
95
96 if (isset($pap_custom) && ($pap_custom != '')) {
97 $visitorID = substr($pap_custom,-32);
98 $accountID = substr($pap_custom,0,8);
99 }
100
101 if ($subscription->is_trial_eligible()) {
102 $total = $invoice->trial_price;
103 } else {
104 $total = $invoice->total;
105 }
106
107 $query = 'AccountId='.$accountID.'&visitorId='.$visitorID.'&TotalCost='.$total.'&ProductID='.$subscription->get_membership()->id.'&OrderID='.$subscription->id;
108
109 $user = get_user_by('email', $member->email);
110 $query .= '&Data1='.$user->ID;
111
112 self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
113 return true;
114 }
115
116 public function Membership2TrackRefund($invoice, $subscription) {
117 if (get_option(self::MEMBERSHIP2_TRACK_REFUNDS) !== 'true') {
118 return false;
119 }
120
121 $session = $this->getApiSession();
122 if ($session === null || $session === '0') {
123 $this->_log('We have no session to PAP installation! Transaction status change failed.');
124 return false;
125 }
126 $ids = $this->getTransactionIDsByOrderID($subscription->id, $session, 'A,P', 1);
127 if (empty($ids)) {
128 $this->_log('Nothing to change, the commission does not exist in PAP');
129 return true;
130 }
131
132 $request = new Gpf_Rpc_FormRequest('Pap_Merchants_Transaction_TransactionsForm', 'makeRefundChargeback', $session);
133 $request->addParam('ids', new Gpf_Rpc_Array($ids));
134 $request->addParam('status', 'R');
135 $request->addParam('merchant_note', 'Refunded automatically from WooCommerce');
136 try {
137 $request->sendNow();
138 } catch (Exception $e) {
139 $this->_log('A problem occurred while transaction status change with API: ' . $e->getMessage());
140 return false;
141 }
142
143 return true;
144 }
145
146 public function Membership2PayPalButton($html, $subscription, $gateway) {
147 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) !== 'true') {
148 return false;
149 }
150
151 $ip = 'pap_IP='.postaffiliatepro::getRemoteIp().'&';
152 $snippet = '<!-- Post Affiliate Pro integration snippet -->';
153
154 $contentToAsync = 'PostAffTracker.setAccountId(\''.postaffiliatepro_Base::getAccountName().'\');
155 PostAffTracker.writeCookieToCustomField(\'notify_url\', \'\', \''.$ip.'pap_custom\');';
156
157 if (get_option(postaffiliatepro::ASYNC_ENABLED) != 'true') {
158 $result = postaffiliatepro::getPAPTrackJSDynamicCode().'<script type="text/javascript">';
159 $result .= $contentToAsync . "</script>\n";
160 } else {
161 $result = postaffiliatepro::getPAPTrackJSAsyncCode($contentToAsync);
162 }
163
164 $snippet .= $result.'<!-- /Post Affiliate Pro integration snippet -->';
165
166 return str_replace('</form>', '</form>'.$snippet, $html);
167 }
168
169 public function Membership2StripeButton($html, $subscription, $gateway) {
170 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) !== 'true') {
171 return false;
172 }
173
174 $snippet = postaffiliatepro::addHiddenFieldToPaymentForm(true);
175 $html = str_replace('</form>', $snippet.'</form>', $html);
176 return $html;
177 }
178
179 public function Membership2StripeCustomer($customer, $member, $gateway) {
180 if (get_option(self::MEMBERSHIP2_COMMISSION_ENABLED) !== 'true') {
181 return false;
182 }
183
184 $desc = '';
185 if (isset($_REQUEST['pap_custom'])) {
186 $desc = sanitize_text_field(wp_unslash($_REQUEST['pap_custom']));
187 }
188 if (empty($customer)) {
189 $customer = Stripe_Customer::create(
190 array(
191 'card' => $token,
192 'email' => $member->email,
193 'description' => $desc
194 )
195 );
196 $member->set_gateway_profile($gateway::ID, 'customer_id', $customer->id);
197 $member->save();
198 }
199 return $customer;
200 }
201 }
202
203 $papSubmenuPriority = 23;
204 $papIntegrationMembership2 = new postaffiliatepro_Form_Settings_Membership2();
205 add_action('admin_init', array($papIntegrationMembership2, 'initSettings'), 99);
206 add_action('admin_menu', array($papIntegrationMembership2, 'addPrimaryConfigMenu'), $papSubmenuPriority);
207
208 add_action('ms_gateway_paypalstandard_payment_processed_', array($papIntegrationMembership2, 'Membership2TrackSale'), 99, 2);
209 add_action('ms_gateway_paypalstandard_payment_processed_paid', array($papIntegrationMembership2, 'Membership2TrackSale'), 99, 2);
210 add_action('ms_gateway_paypalstandard_payment_processed_denied', array($papIntegrationMembership2, 'Membership2TrackRefund'), 99, 2);
211 add_filter('ms_controller_gateway_purchase_button_paypalstandard', array($papIntegrationMembership2, 'Membership2PayPalButton'), 99, 3);
212 add_filter('ms_controller_gateway_purchase_button_stripeplan', array($papIntegrationMembership2, 'Membership2StripeButton'), 99, 3);
213 add_filter('ms_gateway_stripe_find_customer', array($papIntegrationMembership2, 'Membership2StripeCustomer'), 1, 3);
214 add_filter('ms_gateway_stripe_process_purchase', array($papIntegrationMembership2, 'Membership2StripeTransaction'), 1, 2);
215