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 / RestrictContentPro.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
RestrictContentPro.class.php
182 lines
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class postaffiliatepro_Form_Settings_RestrictContentPro extends postaffiliatepro_Form_Base {
5 const RESTRICTCP_COMMISSION_ENABLED = 'rcppap-commission-enabled';
6 const RESTRICTCP_CONFIG_PAGE = 'rcppap-config-page';
7 const RESTRICTCP_REGISTRATION = 'rcppap-track-registration';
8 const RESTRICTCP_REGISTRATION_ACTION_NAME = 'rcppap-registration-action-name';
9 const RESTRICTCP_PAYMENTS = 'rcppap-track-payments';
10 const RESTRICTCP_UPDATE_COMM_STATUS = 'rcppap-update-comm-status';
11
12 public function __construct() {
13 parent::__construct(self::RESTRICTCP_CONFIG_PAGE, 'options.php');
14 }
15
16 public function initSettings() {
17 register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::RESTRICTCP_COMMISSION_ENABLED);
18 register_setting(self::RESTRICTCP_CONFIG_PAGE, self::RESTRICTCP_REGISTRATION);
19 register_setting(self::RESTRICTCP_CONFIG_PAGE, self::RESTRICTCP_REGISTRATION_ACTION_NAME, ['sanitize_callback' => 'sanitize_text_field']);
20 register_setting(self::RESTRICTCP_CONFIG_PAGE, self::RESTRICTCP_PAYMENTS);
21 register_setting(self::RESTRICTCP_CONFIG_PAGE, self::RESTRICTCP_UPDATE_COMM_STATUS);
22 }
23
24 public function addPrimaryConfigMenu() {
25 if (get_option(postaffiliatepro_Form_Settings_RestrictContentPro::RESTRICTCP_COMMISSION_ENABLED) === 'true') {
26 add_submenu_page(
27 'integrations-config-page-handle',
28 'Restrict Content Pro',
29 'Restrict Content Pro',
30 'manage_options',
31 'rcppapintegration-settings-page',
32 array($this, 'printConfigPage')
33 );
34 }
35 }
36
37 public function printConfigPage() {
38 $this->render();
39 }
40
41 protected function getTemplateFile() {
42 return WP_PLUGIN_DIR . '/postaffiliatepro/Template/RestrictContentProConfig.xtpl';
43 }
44
45 protected function initForm() {
46 $this->addCheckbox(self::RESTRICTCP_REGISTRATION);
47 $this->addTextBox(self::RESTRICTCP_REGISTRATION_ACTION_NAME);
48 $this->addCheckbox(self::RESTRICTCP_PAYMENTS);
49 $this->addCheckbox(self::RESTRICTCP_UPDATE_COMM_STATUS);
50
51 $this->addSubmit();
52 }
53
54 public function customFieldsToRestrictSignupForm() {
55 postaffiliatepro::addHiddenFieldToPaymentForm();
56 }
57
58 public function updateStatus($newStatus, $paymentId) {
59 if (get_option(self::RESTRICTCP_UPDATE_COMM_STATUS) !== 'true') {
60 return false;
61 }
62
63 $this->_log('Received status: ' . $newStatus);
64
65 switch ($newStatus) {
66 case 'complete':
67 $status = 'A';
68 break;
69 case 'pending':
70 $status = 'P';
71 break;
72 case 'failed':
73 $status = 'D';
74 break;
75 case 'refunded':
76 return $this->refundTransaction($paymentId);
77 default:
78 $status = '';
79 }
80
81 if ($status == '') {
82 $this->_log('Unsupported status ' . $newStatus);
83 return false;
84 }
85
86 return $this->changeOrderStatus($paymentId, $status);
87 }
88
89 private function refundTransaction($orderId) {
90 $limit = 100;
91 $session = $this->getApiSession();
92 if ($session === null || $session === '0') {
93 $this->_log('We have no session to PAP installation! Transaction status change failed.');
94 return;
95 }
96 $ids = $this->getTransactionIDsByOrderID($orderId, $session, 'A,P', $limit);
97 if (empty($ids)) {
98 $this->_log('Nothing to change, the commission does not exist in PAP.');
99 return true;
100 }
101
102 $request = new Gpf_Rpc_FormRequest('Pap_Merchants_Transaction_TransactionsForm', 'makeRefundChargeback', $session);
103 $request->addParam('ids', new Gpf_Rpc_Array($ids));
104 $request->addParam('status', 'R');
105 $request->addParam('merchant_note', 'Refunded automatically from WP RestrictContentPro');
106 try {
107 $request->sendNow();
108 } catch (Exception $e) {
109 $this->_log('A problem occurred while transaction status change with API: ' . $e->getMessage());
110 return false;
111 }
112
113 return true;
114 }
115
116 public function trackRcpRegistration($POST, $userId, $price, $paymentId, $customer, $membershipId, $previousMembership, $registrationType) {
117 if (get_option(self::RESTRICTCP_REGISTRATION) !== 'true') {
118 return;
119 }
120
121 $action = '';
122 if (get_option(self::RESTRICTCP_REGISTRATION_ACTION_NAME) != '') {
123 $action = get_option(self::RESTRICTCP_REGISTRATION_ACTION_NAME);
124 }
125
126 $wpuser = new WP_User($userId);
127
128 $query = 'TotalCost='.$price.'&OrderID='.$membershipId.'&Data1='.$wpuser->user_email;
129
130 try {
131 $reg = rcp_get_registration();
132 $lvlId = $reg->get_membership_level_id();
133 $membershipLevel = rcp_get_membership_level($lvlId);
134
135 $query .= '&ProductID='.urlencode($membershipLevel->get_name());
136 } catch (Exception $e) {
137 $this->_log('Error loading membership level: ' . $e->getMessage());
138 }
139
140 if ($action != '') {
141 $query .= '&ActionCode='.$action;
142 }
143
144 if (isset($_REQUEST['pap_custom']) && (sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])) != '')) {
145 $query .= '&AccountId='.substr(sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])),0,8);
146 $query .= '&visitorId='.substr(sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])),-32);
147 }
148
149 postaffiliatepro::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
150 }
151
152 public function trackRcpPayment($paymentId, $params) {
153 if (get_option(self::RESTRICTCP_UPDATE_COMM_STATUS) !== 'true') {
154 return;
155 }
156 $this->_log('RCP payment details received: '.print_r($params, true));
157
158 $level = rcp_get_membership_level($params['object_id']);
159 $wpuser = new WP_User($params['user_id']);
160
161 $query = 'TotalCost='.$params['amount'].'&OrderID='.$params['membership_id'];
162 $query .= '&ProductID='.urlencode($level->get_name());
163 $query .= '&Data1='.$wpuser->user_email;
164
165 if (isset($_REQUEST['pap_custom']) && sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])) != '') {
166 $query .= '&AccountId='.substr(sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])),0,8);
167 $query .= '&visitorId='.substr(sanitize_text_field(wp_unslash($_REQUEST['pap_custom'])),-32);
168 }
169
170 postaffiliatepro::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query);
171 }
172 }
173
174 $papSubmenuPriority = 35;
175 $papIntegrationRestrictContentPro = new postaffiliatepro_Form_Settings_RestrictContentPro();
176 add_action('admin_init', array($papIntegrationRestrictContentPro, 'initSettings'), 99);
177 add_action('admin_menu', array($papIntegrationRestrictContentPro, 'addPrimaryConfigMenu'), $papSubmenuPriority);
178
179 add_action('rcp_create_payment', array($papIntegrationRestrictContentPro, 'trackRcpPayment'), 99, 2);
180 add_action('rcp_form_processing', array($papIntegrationRestrictContentPro, 'trackRcpRegistration'), 99, 8);
181 add_action('rcp_update_payment_status', array($papIntegrationRestrictContentPro, 'updateStatus'), 99, 2);
182 add_action('rcp_before_register_form_fields', array($papIntegrationRestrictContentPro, 'customFieldsToRestrictSignupForm'));