PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.2
Tiered Pricing Table for WooCommerce v2.2.2
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / freemius / templates / checkout.php

checkout.php in Tiered Pricing Table for WooCommerce 2.2.2, at freemius/templates/checkout.php

329 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 1.0.3
7 */
8
9 /**
10 * Note for WordPress.org Theme/Plugin reviewer:
11 * Freemius is an SDK for plugin and theme developers. Since the core
12 * of the SDK is relevant both for plugins and themes, for obvious reasons,
13 * we only develop and maintain one code base.
14 *
15 * This code (and page) will not run for wp.org themes (only plugins).
16 *
17 * In addition, this page loads an i-frame. We intentionally named it 'frame'
18 * so it will pass the "Theme Check" that is looking for the string "i" . "frame".
19 *
20 * UPDATE:
21 * After ongoing conversations with the WordPress.org TRT we received
22 * an official approval for including i-frames in the theme's WP Admin setting's
23 * page tab (the SDK will never add any i-frames on the sitefront). i-frames
24 * were never against the guidelines, but we wanted to get the team's blessings
25 * before we move forward. For the record, I got the final approval from
26 * Ulrich Pogson (@grapplerulrich), a team lead at the TRT during WordCamp
27 * Europe 2017 (June 16th, 2017).
28 *
29 * If you have any questions or need clarifications, please don't hesitate
30 * pinging me on slack, my username is @svovaf.
31 *
32 * @author Vova Feldman (@svovaf)
33 * @since 1.2.2
34 */
35
36 if ( ! defined( 'ABSPATH' ) ) {
37 exit;
38 }
39
40 wp_enqueue_script( 'jquery' );
41 wp_enqueue_script( 'json2' );
42 fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
43 fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
44 fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
45
46 fs_enqueue_local_style( 'fs_checkout', '/admin/checkout.css' );
47
48 /**
49 * @var array $VARS
50 * @var Freemius $fs
51 */
52 $fs = freemius( $VARS['id'] );
53 $slug = $fs->get_slug();
54
55 $timestamp = time();
56
57 $context_params = array(
58 'plugin_id' => $fs->get_id(),
59 'public_key' => $fs->get_public_key(),
60 'plugin_version' => $fs->get_plugin_version(),
61 'mode' => 'dashboard',
62 'trial' => fs_request_get_bool( 'trial' ),
63 );
64
65 $plan_id = fs_request_get( 'plan_id' );
66 if ( FS_Plugin_Plan::is_valid_id( $plan_id ) ) {
67 $context_params['plan_id'] = $plan_id;
68 }
69
70 $licenses = fs_request_get( 'licenses' );
71 if ( $licenses === strval( intval( $licenses ) ) && $licenses > 0 ) {
72 $context_params['licenses'] = $licenses;
73 }
74
75 $plugin_id = fs_request_get( 'plugin_id' );
76 if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
77 $plugin_id = $fs->get_id();
78 }
79
80 if ( $plugin_id == $fs->get_id() ) {
81 $is_premium = $fs->is_premium();
82 } else {
83 // Identify the module code version of the checkout context module.
84 if ( $fs->is_addon_activated( $plugin_id ) ) {
85 $fs_addon = Freemius::get_instance_by_id( $plugin_id );
86 $is_premium = $fs_addon->is_premium();
87 } else {
88 // If add-on isn't activated assume the premium version isn't installed.
89 $is_premium = false;
90 }
91 }
92
93 // Get site context secure params.
94 if ( $fs->is_registered() ) {
95 $site = $fs->get_site();
96
97 if ( $plugin_id != $fs->get_id() ) {
98 if ( $fs->is_addon_activated( $plugin_id ) ) {
99 $fs_addon = Freemius::get_instance_by_id( $plugin_id );
100 $site = $fs_addon->get_site();
101 }
102 }
103
104 $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
105 $site,
106 $timestamp,
107 'checkout'
108 ) );
109 } else {
110 $current_user = Freemius::_get_current_wp_user();
111
112 // Add site and user info to the request, this information
113 // is NOT being stored unless the user complete the purchase
114 // and agrees to the TOS.
115 $context_params = array_merge( $context_params, array(
116 'user_firstname' => $current_user->user_firstname,
117 'user_lastname' => $current_user->user_lastname,
118 'user_email' => $current_user->user_email,
119 'home_url' => home_url(),
120 ) );
121
122 $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
123
124 if ( is_object( $fs_user ) && $fs_user->is_verified() ) {
125 $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
126 $fs_user,
127 $timestamp,
128 'checkout'
129 ) );
130 }
131 }
132
133 if ( $fs->is_payments_sandbox() ) {
134 // Append plugin secure token for sandbox mode authentication.
135 $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
136 $fs->get_plugin(),
137 $timestamp,
138 'checkout'
139 );
140
141 /**
142 * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
143 */
144 if ( empty( $context_params['s_ctx_ts'] ) ) {
145 $context_params['s_ctx_ts'] = $timestamp;
146 }
147 }
148
149 $return_url = $fs->_get_sync_license_url( $plugin_id );
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 $query_params = 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 'return_url' => $return_url,
163 ) );
164
165 $xdebug_session = fs_request_get( 'XDEBUG_SESSION' );
166 if ( false !== $xdebug_session ) {
167 $query_params['XDEBUG_SESSION'] = $xdebug_session;
168 }
169
170 $view_params = array(
171 'id' => $VARS['id'],
172 'page' => strtolower( $fs->get_text_inline( 'Checkout', 'checkout' ) ) . ' ' . $fs->get_text_inline( 'PCI compliant', 'pci-compliant' ),
173 );
174 fs_require_once_template('secure-https-header.php', $view_params);
175 ?>
176 <div id="fs_checkout" class="wrap fs-section fs-full-size-wrapper">
177 <div id="fs_frame"></div>
178 <script type="text/javascript">
179 // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
180 jQuery(function ($) {
181 $.extend({
182 form: function (url, data, method) {
183 if (method == null) method = 'POST';
184 if (data == null) data = {};
185
186 var form = $('<form>').attr({
187 method: method,
188 action: url
189 }).css({
190 display: 'none'
191 });
192
193 var addData = function (name, data) {
194 if ($.isArray(data)) {
195 for (var i = 0; i < data.length; i++) {
196 var value = data[i];
197 addData(name + '[]', value);
198 }
199 } else if (typeof data === 'object') {
200 for (var key in data) {
201 if (data.hasOwnProperty(key)) {
202 addData(name + '[' + key + ']', data[key]);
203 }
204 }
205 } else if (data != null) {
206 form.append($('<input>').attr({
207 type : 'hidden',
208 name : String(name),
209 value: String(data)
210 }));
211 }
212 };
213
214 for (var key in data) {
215 if (data.hasOwnProperty(key)) {
216 addData(key, data[key]);
217 }
218 }
219
220 return form.appendTo('body');
221 }
222 });
223 });
224
225 (function ($) {
226 $(function () {
227
228 var
229 // Keep track of the i-frame height.
230 frame_height = 800,
231 base_url = '<?php echo FS_CHECKOUT__ADDRESS ?>',
232 // Pass the parent page URL into the i-frame in a meaningful way (this URL could be
233 // passed via query string or hard coded into the child page, it depends on your needs).
234 src = base_url + '/?<?php echo http_build_query( $query_params ) ?>#' + encodeURIComponent(document.location.href),
235 // Append the i-frame into the DOM.
236 frame = $('<i' + 'frame " src="' + src + '" width="100%" height="' + frame_height + 'px" scrolling="no" frameborder="0" style="background: transparent; width: 1px; min-width: 100%;"><\/i' + 'frame>')
237 .appendTo('#fs_frame');
238
239 FS.PostMessage.init(base_url, [frame[0]]);
240 FS.PostMessage.receiveOnce('height', function (data) {
241 var h = data.height;
242 if (!isNaN(h) && h > 0 && h != frame_height) {
243 frame_height = h;
244 frame.height(frame_height + 'px');
245
246 FS.PostMessage.postScroll(frame[0]);
247 }
248 });
249
250 FS.PostMessage.receiveOnce('install', function (data) {
251 var requestData = {
252 user_id : data.user.id,
253 user_secret_key : data.user.secret_key,
254 user_public_key : data.user.public_key,
255 install_id : data.install.id,
256 install_secret_key: data.install.secret_key,
257 install_public_key: data.install.public_key
258 };
259
260 if (true === data.auto_install)
261 requestData.auto_install = true;
262
263 // Post data to activation URL.
264 $.form('<?php echo fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
265 'fs_action' => $fs->get_unique_affix() . '_activate_new',
266 'plugin_id' => $plugin_id
267 ) ), $fs->get_unique_affix() . '_activate_new' ) ?>', requestData).submit();
268 });
269
270 FS.PostMessage.receiveOnce('pending_activation', function (data) {
271 var requestData = {
272 user_email: data.user_email
273 };
274
275 if (true === data.auto_install)
276 requestData.auto_install = true;
277
278 $.form('<?php echo fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
279 'fs_action' => $fs->get_unique_affix() . '_activate_new',
280 'plugin_id' => $plugin_id,
281 'pending_activation' => true,
282 ) ), $fs->get_unique_affix() . '_activate_new' ) ?>', requestData).submit();
283 });
284
285 FS.PostMessage.receiveOnce('get_context', function () {
286 console.debug('receiveOnce', 'get_context');
287
288 // If the user didn't connect his account with Freemius,
289 // once he accepts the Terms of Service and Privacy Policy,
290 // and then click the purchase button, the context information
291 // of the user will be shared with Freemius in order to complete the
292 // purchase workflow and activate the license for the right user.
293 <?php $install_data = array_merge( $fs->get_opt_in_params(),
294 array(
295 'activation_url' => fs_nonce_url( $fs->_get_admin_page_url( '',
296 array(
297 'fs_action' => $fs->get_unique_affix() . '_activate_new',
298 'plugin_id' => $plugin_id,
299
300 ) ),
301 $fs->get_unique_affix() . '_activate_new' )
302 ) ) ?>
303 FS.PostMessage.post('context', <?php echo json_encode( $install_data ) ?>, frame[0]);
304 });
305
306 FS.PostMessage.receiveOnce('purchaseCompleted', <?php echo $fs->apply_filters('checkout/purchaseCompleted', 'function (data) {
307 console.log("checkout", "purchaseCompleted");
308 }') ?>);
309
310 FS.PostMessage.receiveOnce('get_dimensions', function (data) {
311 console.debug('receiveOnce', 'get_dimensions');
312
313 FS.PostMessage.post('dimensions', {
314 height : $(document.body).height(),
315 scrollTop: $(document).scrollTop()
316 }, frame[0]);
317 });
318
319 var updateHeight = function () {
320 frame.css('min-height', $(document.body).height() + 'px');
321 };
322
323 $(document).ready(updateHeight);
324
325 $(window).resize(updateHeight);
326 });
327 })(jQuery);
328 </script>
329 </div>