PluginProbe
Passster – Password Protect Pages and Content / 4.3.17
Passster – Password Protect Pages and Content v4.3.17
4.3.17 4.3.16 4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 All 49 releases
← All changes | inc/freemius/includes/managers/class-fs-checkout-manager.php +285 -242 4.2.10 → 4.3.17 View file →
@@ -1,242 +1,285 @@
1 -<?php
2 - /**
3 - * @package Freemius
4 - * @copyright Copyright (c) 2024, Freemius, Inc.
5 - * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 - * @since 2.9.0
7 - */
8 -
9 - if ( ! defined( 'ABSPATH' ) ) {
10 - exit;
11 - }
12 -
13 - class FS_Checkout_Manager {
14 -
15 - # region Singleton
16 -
17 - /**
18 - * @var FS_Checkout_Manager
19 - */
20 - private static $_instance;
21 -
22 - /**
23 - * @return FS_Checkout_Manager
24 - */
25 - static function instance() {
26 - if ( ! isset( self::$_instance ) ) {
27 - self::$_instance = new FS_Checkout_Manager();
28 - }
29 -
30 - return self::$_instance;
31 - }
32 -
33 - private function __construct() {
34 - }
35 -
36 - #endregion
37 -
38 - /**
39 - * Retrieves the query params needed to load the Freemius Checkout in the context of the plugin.
40 - *
41 - * @param Freemius $fs
42 - * @param number $plugin_id
43 - * @param number $plan_id
44 - * @param number $licenses
45 - *
46 - * @return array
47 - */
48 - public function get_query_params( Freemius $fs, $plugin_id, $plan_id, $licenses ) {
49 - $timestamp = time();
50 -
51 - $context_params = array(
52 - 'plugin_id' => $fs->get_id(),
53 - 'public_key' => $fs->get_public_key(),
54 - 'plugin_version' => $fs->get_plugin_version(),
55 - 'mode' => 'dashboard',
56 - 'trial' => fs_request_get_bool( 'trial' ),
57 - 'is_ms' => ( fs_is_network_admin() && $fs->is_network_active() ),
58 - );
59 -
60 - if ( FS_Plugin_Plan::is_valid_id( $plan_id ) ) {
61 - $context_params['plan_id'] = $plan_id;
62 - }
63 -
64 - if ( $licenses === strval( intval( $licenses ) ) && $licenses > 0 ) {
65 - $context_params['licenses'] = $licenses;
66 - }
67 -
68 - if ( $plugin_id == $fs->get_id() ) {
69 - $is_premium = $fs->is_premium();
70 -
71 - $bundle_id = $fs->get_bundle_id();
72 - if ( ! is_null( $bundle_id ) ) {
73 - $context_params['bundle_id'] = $bundle_id;
74 - }
75 - } else {
76 - // Identify the module code version of the checkout context module.
77 - if ( $fs->is_addon_activated( $plugin_id ) ) {
78 - $fs_addon = Freemius::get_instance_by_id( $plugin_id );
79 - $is_premium = $fs_addon->is_premium();
80 - } else {
81 - // If add-on isn't activated assume the premium version isn't installed.
82 - $is_premium = false;
83 - }
84 - }
85 -
86 - // Get site context secure params.
87 - if ( $fs->is_registered() ) {
88 - $site = $fs->get_site();
89 -
90 - if ( $plugin_id != $fs->get_id() ) {
91 - if ( $fs->is_addon_activated( $plugin_id ) ) {
92 - $fs_addon = Freemius::get_instance_by_id( $plugin_id );
93 - $addon_site = $fs_addon->get_site();
94 - if ( is_object( $addon_site ) ) {
95 - $site = $addon_site;
96 - }
97 - }
98 - }
99 -
100 - $context_params = array_merge(
101 - $context_params,
102 - FS_Security::instance()->get_context_params(
103 - $site,
104 - $timestamp,
105 - 'checkout'
106 - )
107 - );
108 - } else {
109 - $current_user = Freemius::_get_current_wp_user();
110 -
111 - // Add site and user info to the request, this information
112 - // is NOT being stored unless the user complete the purchase
113 - // and agrees to the TOS.
114 - $context_params = array_merge( $context_params, array(
115 - 'user_firstname' => $current_user->user_firstname,
116 - 'user_lastname' => $current_user->user_lastname,
117 - 'user_email' => $current_user->user_email,
118 - 'home_url' => home_url(),
119 - ) );
120 -
121 - $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
122 -
123 - if ( is_object( $fs_user ) && $fs_user->is_verified() ) {
124 - $context_params = array_merge(
125 - $context_params,
126 - FS_Security::instance()->get_context_params(
127 - $fs_user,
128 - $timestamp,
129 - 'checkout'
130 - )
131 - );
132 - }
133 - }
134 -
135 - if ( $fs->is_payments_sandbox() ) {
136 - // Append plugin secure token for sandbox mode authentication.
137 - $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
138 - $fs->get_plugin(),
139 - $timestamp,
140 - 'checkout'
141 - );
142 -
143 - /**
144 - * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
145 - */
146 - if ( empty( $context_params['s_ctx_ts'] ) ) {
147 - $context_params['s_ctx_ts'] = $timestamp;
148 - }
149 - }
150 -
151 - $can_user_install = (
152 - ( $fs->is_plugin() && current_user_can( 'install_plugins' ) ) ||
153 - ( $fs->is_theme() && current_user_can( 'install_themes' ) )
154 - );
155 -
156 - return array_merge( $context_params, $_GET, array(
157 - // Current plugin version.
158 - 'plugin_version' => $fs->get_plugin_version(),
159 - 'sdk_version' => WP_FS__SDK_VERSION,
160 - 'is_premium' => $is_premium ? 'true' : 'false',
161 - 'can_install' => $can_user_install ? 'true' : 'false',
162 - ) );
163 - }
164 -
165 - /**
166 - * The return URL to pass to the checkout when the checkout is loaded in "redirect" mode.
167 - *
168 - * @param Freemius $fs
169 - *
170 - * @return string
171 - */
172 - public function get_checkout_redirect_return_url( Freemius $fs ) {
173 - $request_url = remove_query_arg( '_wp_http_referer' );
174 -
175 - return fs_nonce_url(
176 - $fs->checkout_url(
177 - fs_request_get( 'billing_cycle' ),
178 - fs_request_get_bool( 'trial' ),
179 - array(
180 - 'process_redirect' => 'true',
181 - '_wp_http_referer' => $request_url,
182 - )
183 - ),
184 - $this->get_checkout_redirect_nonce_action( $fs )
185 - );
186 - }
187 -
188 - /**
189 - * @param array $query_params
190 - * @param string $base_url
191 - *
192 - * @return string
193 - */
194 - public function get_full_checkout_url( array $query_params, $base_url = FS_CHECKOUT__ADDRESS ) {
195 - return $base_url . '/?' . http_build_query( $query_params );
196 - }
197 -
198 - /**
199 - * Verifies the redirect after a checkout with the nonce.
200 - *
201 - * @param Freemius $fs
202 - */
203 - public function verify_checkout_redirect_nonce( Freemius $fs ) {
204 - check_admin_referer( $this->get_checkout_redirect_nonce_action( $fs ) );
205 - }
206 -
207 - /**
208 - * Get the URL to process a new install after the checkout.
209 - *
210 - * @param Freemius $fs
211 - * @param number $plugin_id
212 - *
213 - * @return string
214 - */
215 - public function get_install_url( Freemius $fs, $plugin_id ) {
216 - return fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
217 - 'fs_action' => $fs->get_unique_affix() . '_activate_new',
218 - 'plugin_id' => $plugin_id,
219 - ) ), $fs->get_unique_affix() . '_activate_new' );
220 - }
221 -
222 - /**
223 - * Get the URL to process a pending activation after the checkout.
224 - *
225 - * @param Freemius $fs
226 - * @param number $plugin_id
227 - *
228 - * @return string
229 - */
230 - public function get_pending_activation_url( Freemius $fs, $plugin_id ) {
231 - return fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
232 - 'fs_action' => $fs->get_unique_affix() . '_activate_new',
233 - 'plugin_id' => $plugin_id,
234 - 'pending_activation' => true,
235 - 'has_upgrade_context' => true,
236 - ) ), $fs->get_unique_affix() . '_activate_new' );
237 - }
238 -
239 - private function get_checkout_redirect_nonce_action( Freemius $fs ) {
240 - return $fs->get_unique_affix() . '_checkout_redirect';
241 - }
242 - }
1 +<?php
2 + /**
3 + * @package Freemius
4 + * @copyright Copyright (c) 2024, Freemius, Inc.
5 + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 + * @since 2.9.0
7 + */
8 +
9 + if ( ! defined( 'ABSPATH' ) ) {
10 + exit;
11 + }
12 +
13 + class FS_Checkout_Manager {
14 +
15 + /**
16 + * Allowlist of query parameters for checkout.
17 + */
18 + private $_allowed_custom_params = array(
19 + // currency
20 + 'currency' => true,
21 + 'default_currency' => true,
22 + // cart
23 + 'always_show_renewals_amount' => true,
24 + 'annual_discount' => true,
25 + 'billing_cycle' => true,
26 + 'billing_cycle_selector' => true,
27 + 'bundle_discount' => true,
28 + 'maximize_discounts' => true,
29 + 'multisite_discount' => true,
30 + 'show_inline_currency_selector' => true,
31 + 'show_monthly' => true,
32 + // appearance
33 + 'form_position' => true,
34 + 'is_bundle_collapsed' => true,
35 + 'layout' => true,
36 + 'refund_policy_position' => true,
37 + 'show_refund_badge' => true,
38 + 'show_reviews' => true,
39 + 'show_upsells' => true,
40 + 'title' => true,
41 + );
42 +
43 +
44 + # region Singleton
45 +
46 + /**
47 + * @var FS_Checkout_Manager
48 + */
49 + private static $_instance;
50 +
51 + /**
52 + * @return FS_Checkout_Manager
53 + */
54 + static function instance() {
55 + if ( ! isset( self::$_instance ) ) {
56 + self::$_instance = new FS_Checkout_Manager();
57 + }
58 +
59 + return self::$_instance;
60 + }
61 +
62 + private function __construct() {
63 + }
64 +
65 + #endregion
66 +
67 + /**
68 + * Retrieves the query params needed to load the Freemius Checkout in the context of the plugin.
69 + *
70 + * @param Freemius $fs
71 + * @param number $plugin_id
72 + * @param number $plan_id
73 + * @param number $licenses
74 + *
75 + * @return array
76 + */
77 + public function get_query_params( Freemius $fs, $plugin_id, $plan_id, $licenses ) {
78 + $timestamp = time();
79 +
80 + $context_params = array(
81 + 'plugin_id' => $fs->get_id(),
82 + 'public_key' => $fs->get_public_key(),
83 + 'plugin_version' => $fs->get_plugin_version(),
84 + 'mode' => 'dashboard',
85 + 'trial' => fs_request_get_bool( 'trial' ),
86 + 'is_ms' => ( fs_is_network_admin() && $fs->is_network_active() ),
87 + );
88 +
89 + if ( FS_Plugin_Plan::is_valid_id( $plan_id ) ) {
90 + $context_params['plan_id'] = $plan_id;
91 + }
92 +
93 + if ( $licenses === strval( intval( $licenses ) ) && $licenses > 0 ) {
94 + $context_params['licenses'] = $licenses;
95 + }
96 +
97 + if ( $plugin_id == $fs->get_id() ) {
98 + $is_premium = $fs->is_premium();
99 +
100 + $bundle_id = $fs->get_bundle_id();
101 + if ( ! is_null( $bundle_id ) ) {
102 + $context_params['bundle_id'] = $bundle_id;
103 + }
104 + } else {
105 + // Identify the module code version of the checkout context module.
106 + if ( $fs->is_addon_activated( $plugin_id ) ) {
107 + $fs_addon = Freemius::get_instance_by_id( $plugin_id );
108 + $is_premium = $fs_addon->is_premium();
109 + } else {
110 + // If add-on isn't activated assume the premium version isn't installed.
111 + $is_premium = false;
112 + }
113 +
114 + // Override the checkout context with the add-on's purchase details so the checkout flow is initialized for the selected add-on instead of the parent product.
115 + $context_params['plugin_id'] = $plugin_id;
116 +
117 + foreach ( array( 'plan_id', 'pricing_id', 'billing_cycle', 'is_trial' ) as $param ) {
118 + if ( fs_request_has( $param ) ) {
119 + $context_params[ $param ] = fs_request_get( $param );
120 + }
121 + }
122 + }
123 +
124 + // Get site context secure params.
125 + if ( $fs->is_registered() ) {
126 + $site = $fs->get_site();
127 +
128 + if ( $plugin_id != $fs->get_id() ) {
129 + if ( $fs->is_addon_activated( $plugin_id ) ) {
130 + $fs_addon = Freemius::get_instance_by_id( $plugin_id );
131 + $addon_site = $fs_addon->get_site();
132 + if ( is_object( $addon_site ) ) {
133 + $site = $addon_site;
134 + }
135 + }
136 + }
137 +
138 + $context_params = array_merge(
139 + $context_params,
140 + FS_Security::instance()->get_context_params(
141 + $site,
142 + $timestamp,
143 + 'checkout'
144 + )
145 + );
146 + } else {
147 + $current_user = Freemius::_get_current_wp_user();
148 +
149 + // Add site and user info to the request, this information
150 + // is NOT being stored unless the user complete the purchase
151 + // and agrees to the TOS.
152 + $context_params = array_merge( $context_params, array(
153 + 'user_firstname' => $current_user->user_firstname,
154 + 'user_lastname' => $current_user->user_lastname,
155 + 'user_email' => $current_user->user_email,
156 + 'home_url' => home_url(),
157 + ) );
158 +
159 + $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
160 +
161 + if ( is_object( $fs_user ) && $fs_user->is_verified() ) {
162 + $context_params = array_merge(
163 + $context_params,
164 + FS_Security::instance()->get_context_params(
165 + $fs_user,
166 + $timestamp,
167 + 'checkout'
168 + )
169 + );
170 + }
171 + }
172 +
173 + if ( $fs->is_payments_sandbox() ) {
174 + // Append plugin secure token for sandbox mode authentication.
175 + $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
176 + $fs->get_plugin(),
177 + $timestamp,
178 + 'checkout'
179 + );
180 +
181 + /**
182 + * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
183 + */
184 + if ( empty( $context_params['s_ctx_ts'] ) ) {
185 + $context_params['s_ctx_ts'] = $timestamp;
186 + }
187 + }
188 +
189 + $can_user_install = (
190 + ( $fs->is_plugin() && current_user_can( 'install_plugins' ) ) ||
191 + ( $fs->is_theme() && current_user_can( 'install_themes' ) )
192 + );
193 +
194 + $filtered_params = $fs->apply_filters('checkout/parameters', $context_params);
195 +
196 + // Allowlist only allowed query params.
197 + $filtered_params = array_intersect_key($filtered_params, $this->_allowed_custom_params);
198 +
199 + return array_merge( $_GET, $context_params, $filtered_params, array(
200 + // Current plugin version.
201 + 'plugin_version' => $fs->get_plugin_version(),
202 + 'sdk_version' => WP_FS__SDK_VERSION,
203 + 'is_premium' => $is_premium ? 'true' : 'false',
204 + 'can_install' => $can_user_install ? 'true' : 'false',
205 + ) );
206 + }
207 +
208 + /**
209 + * The return URL to pass to the checkout when the checkout is loaded in "redirect" mode.
210 + *
211 + * @param Freemius $fs
212 + *
213 + * @return string
214 + */
215 + public function get_checkout_redirect_return_url( Freemius $fs ) {
216 + $request_url = remove_query_arg( '_wp_http_referer' );
217 +
218 + return fs_nonce_url(
219 + $fs->checkout_url(
220 + fs_request_get( 'billing_cycle' ),
221 + fs_request_get_bool( 'trial' ),
222 + array(
223 + 'process_redirect' => 'true',
224 + '_wp_http_referer' => $request_url,
225 + )
226 + ),
227 + $this->get_checkout_redirect_nonce_action( $fs )
228 + );
229 + }
230 +
231 + /**
232 + * @param array $query_params
233 + * @param string $base_url
234 + *
235 + * @return string
236 + */
237 + public function get_full_checkout_url( array $query_params, $base_url = FS_CHECKOUT__ADDRESS ) {
238 + return $base_url . '/?' . http_build_query( $query_params );
239 + }
240 +
241 + /**
242 + * Verifies the redirect after a checkout with the nonce.
243 + *
244 + * @param Freemius $fs
245 + */
246 + public function verify_checkout_redirect_nonce( Freemius $fs ) {
247 + check_admin_referer( $this->get_checkout_redirect_nonce_action( $fs ) );
248 + }
249 +
250 + /**
251 + * Get the URL to process a new install after the checkout.
252 + *
253 + * @param Freemius $fs
254 + * @param number $plugin_id
255 + *
256 + * @return string
257 + */
258 + public function get_install_url( Freemius $fs, $plugin_id ) {
259 + return fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
260 + 'fs_action' => $fs->get_unique_affix() . '_activate_new',
261 + 'plugin_id' => $plugin_id,
262 + ) ), $fs->get_unique_affix() . '_activate_new' );
263 + }
264 +
265 + /**
266 + * Get the URL to process a pending activation after the checkout.
267 + *
268 + * @param Freemius $fs
269 + * @param number $plugin_id
270 + *
271 + * @return string
272 + */
273 + public function get_pending_activation_url( Freemius $fs, $plugin_id ) {
274 + return fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
275 + 'fs_action' => $fs->get_unique_affix() . '_activate_new',
276 + 'plugin_id' => $plugin_id,
277 + 'pending_activation' => true,
278 + 'has_upgrade_context' => true,
279 + ) ), $fs->get_unique_affix() . '_activate_new' );
280 + }
281 +
282 + private function get_checkout_redirect_nonce_action( Freemius $fs ) {
283 + return $fs->get_unique_affix() . '_checkout_redirect';
284 + }
285 + }