Changeset 2534775
- Timestamp:
- 05/20/2021 11:17:29 AM (5 years ago)
- Location:
- checkoutx
- Files:
-
- 10 edited
- 1 copied
-
tags/1.2.0 (copied) (copied from checkoutx/trunk)
-
tags/1.2.0/README.txt (modified) (1 diff)
-
tags/1.2.0/checkout-x.php (modified) (1 diff)
-
tags/1.2.0/includes/class-api-controller.php (modified) (3 diffs)
-
tags/1.2.0/includes/class-main.php (modified) (2 diffs)
-
tags/1.2.0/public/class-public.php (modified) (5 diffs)
-
trunk/README.txt (modified) (1 diff)
-
trunk/checkout-x.php (modified) (1 diff)
-
trunk/includes/class-api-controller.php (modified) (3 diffs)
-
trunk/includes/class-main.php (modified) (2 diffs)
-
trunk/public/class-public.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
checkoutx/tags/1.2.0/README.txt
r2514046 r2534775 4 4 Requires at least: 5.4 5 5 Tested up to: 5.7 6 Stable tag: 1. 1.26 Stable tag: 1.2.0 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later -
checkoutx/tags/1.2.0/checkout-x.php
r2473627 r2534775 18 18 * Plugin URI: https://www.checkout-x.com 19 19 * Description: Checkout X boosts your revenue with a high-converting, frictionless, mobile-first checkout experience for your WooCommerce store. Get less abandoned carts and more sales with a fast checkout that completes itself on any device to give you more conversions and average order value. 20 * Version: 1. 1.220 * Version: 1.2.0 21 21 * Author: Checkout X 22 22 * Author URI: https://www.checkout-x.com/?utm_source=partner&utm_medium=woocommerce-marketplace -
checkoutx/tags/1.2.0/includes/class-api-controller.php
r2473627 r2534775 94 94 "options" => array( 95 95 "js_script_url" => get_option("checkout_x_storefront_url", null), 96 "api_version" => get_option("checkout_x_api_version", null), 97 "app_url" => get_option("checkout_x_app_url", null), 98 "api_url" => get_option("checkout_x_api_url", null), 99 "website_url" => get_option("checkout_x_website_url", null), 96 100 ), 97 101 ); … … 121 125 $current_event_secret = get_option('checkout_x_event_secret', ''); 122 126 127 $new_api_version = $request->get_param("api_version"); 128 $current_api_version = get_option("checkout_x_api_version", ""); 129 130 $new_checkout_app_url = $request->get_param("app_url"); 131 $current_checkout_app_url = get_option("checkout_x_app_url", ""); 132 133 $new_checkout_api_url = $request->get_param("api_url"); 134 $current_checkout_api_url = get_option("checkout_x_api_url", ""); 135 136 $new_checkout_website_url = $request->get_param("website_url"); 137 $current_checkout_website_url = get_option("checkout_x_website_url", ""); 138 123 139 $shop_id_updated = ($new_shop_id == $current_shop_id) || update_option('checkout_x_shop_id', $new_shop_id); 124 140 $script_url_updated = ($new_js_script_url == $current_js_script_url) || update_option('checkout_x_storefront_url', $new_js_script_url); 125 141 $event_secret_updated = ($new_event_secret == $current_event_secret) || update_option('checkout_x_event_secret', $new_event_secret); 142 $api_version_updated = ($new_api_version == $current_api_version) || update_option('checkout_x_api_version', $new_api_version); 143 $app_url_updated = ($new_checkout_app_url == $current_checkout_app_url) || update_option('checkout_x_app_url', $new_checkout_app_url); 144 $api_url_updated = ($new_checkout_api_url == $current_checkout_api_url) || update_option('checkout_x_api_url', $new_checkout_api_url); 145 $website_url_updated = ($new_checkout_website_url == $current_checkout_website_url) || update_option('checkout_x_website_url', $new_checkout_website_url); 126 146 127 if ($shop_id_updated && $script_url_updated && $event_secret_updated) { 147 if ($shop_id_updated 148 && $script_url_updated 149 && $event_secret_updated 150 && $api_version_updated 151 && $app_url_updated 152 && $api_url_updated 153 && $website_url_updated 154 ) { 128 155 return $this->wrap_response(array('result' => 'success'), 200); 129 156 } else { … … 133 160 'script_url_updated' => $script_url_updated, 134 161 'event_secret_updated' => $event_secret_updated, 162 'api_version' => $api_version_updated, 163 'app_url' => $app_url_updated, 164 'api_url' => $api_url_updated, 165 'website_url' => $website_url_updated, 135 166 ); 136 167 return $this->wrap_response($payload, 403); -
checkoutx/tags/1.2.0/includes/class-main.php
r2473627 r2534775 60 60 $this->define_admin_hooks(); 61 61 $this->define_public_hooks(); 62 $this->define_filters(); 62 if (get_option("checkout_x_api_version") != "2") { 63 $this->define_filters(); 64 } 63 65 $this->define_custom_webhooks(); 64 66 $this->define_api(); … … 170 172 $plugin_public = new Checkout_X_Public($this->get_plugin_name(), $this->get_version()); 171 173 172 # uncomment this if you want to load some styles from plugin 173 # on shop public pages ( product pages, cart, etc ) 174 # $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); 175 176 # loads plugin JS file on all shop pages 177 # more info in assets/js/public.js documentation 178 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); 179 180 # adds meta tag with shop ID to <head>. Used by CHKX storefront JS. 181 $this->loader->add_action('wp_head', $plugin_public, 'add_resources'); 182 183 // render cart content as json and sync with CHKX on every page load 184 $this->loader->add_action('wp_footer', $plugin_public, 'add_cart_json'); 185 186 # redirect on '/checkout' page in menu 187 $this->loader->add_action('template_redirect', $plugin_public, 'checkout_nav_menu_redirect'); 188 189 # clear cart when checkout is completed 190 $this->loader->add_action('wp_ajax_chkx_clear_cart', $plugin_public, 'clear_cart'); 191 $this->loader->add_action('wp_ajax_nopriv_chkx_clear_cart', $plugin_public, 'clear_cart'); 174 if (get_option("checkout_x_api_version") == "2") { 175 $this->loader->add_action("woocommerce_init", $plugin_public, "page_visit"); 176 $this->loader->add_action("woocommerce_add_to_cart", $plugin_public, "add_to_cart"); 177 $this->loader->add_action("template_redirect", $plugin_public, "redirect_to_checkout"); 178 } else { 179 # loads plugin JS file on all shop pages 180 # more info in assets/js/public.js documentation 181 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); 182 183 # adds meta tag with shop ID to <head>. Used by CHKX storefront JS. 184 $this->loader->add_action('wp_head', $plugin_public, 'add_resources'); 185 186 // render cart content as json and sync with CHKX on every page load 187 $this->loader->add_action('wp_footer', $plugin_public, 'add_cart_json'); 188 189 # redirect on '/checkout' page in menu 190 $this->loader->add_action('template_redirect', $plugin_public, 'checkout_nav_menu_redirect'); 191 192 # clear cart when checkout is completed 193 $this->loader->add_action('wp_ajax_chkx_clear_cart', $plugin_public, 'clear_cart'); 194 $this->loader->add_action('wp_ajax_nopriv_chkx_clear_cart', $plugin_public, 'clear_cart'); 195 } 192 196 } 193 197 -
checkoutx/tags/1.2.0/public/class-public.php
r2473627 r2534775 125 125 } 126 126 127 /* 127 /* 128 128 * Adds parent tag with cart content inside on the page. 129 129 * … … 138 138 } 139 139 140 /* 140 /* 141 141 * Adds cart content to cart fragments. 142 142 * … … 245 245 * Empties WooCommerce cart. 246 246 * 247 * Available for public.js via wp_localize_script. Called when Checkout X API 247 * Available for public.js via wp_localize_script. Called when Checkout X API 248 248 * indicates that checkout is already completed. 249 249 */ … … 256 256 WC()->cart->empty_cart(); 257 257 } 258 258 259 259 echo json_encode(WC()->cart->get_cart_contents()); 260 260 … … 267 267 return WC()->cart->get_cart_contents_count() == 0; 268 268 } 269 270 public function redirect_to_checkout() { 271 if (!is_checkout() || is_null(WC()->cart) || WC()->cart->is_empty() || !$this->is_checkout_x_enabled()) { 272 return null; 273 } 274 275 $cart = WC()->cart; 276 $data = array( 277 "shop_id" => get_option("checkout_x_shop_id"), 278 "items" => $this->build_checkout_items($cart), 279 "discount_code" => $cart->get_applied_coupons()[0], 280 "client_id" => $this->client_id(), 281 ); 282 283 $response = wp_remote_post($this->api_v2_url("checkouts"), array( 284 "timeout" => 5, 285 "headers" => array( 286 "content-type" => "application/json", 287 ), 288 "cookies" => array(), 289 "body" => json_encode($data), 290 )); 291 292 if (is_wp_error($response)) { 293 $error_message = $response->get_error_message(); 294 echo "Something went wrong: $error_message"; 295 } else { 296 if ($response["response"]["code"] == 201) { 297 $json_response = json_decode($response["body"]); 298 $checkout_url = $json_response->url; 299 WC()->session->set("checkout_x_checkout_id", $json_response->id); 300 wp_redirect($checkout_url); 301 exit(); 302 } 303 } 304 } 305 306 public function add_to_cart() { 307 if (!$this->is_checkout_x_enabled()) { 308 return null; 309 } 310 311 $cart = WC()->cart; 312 $data = array( 313 "shop_id" => get_option("checkout_x_shop_id"), 314 "client_id" => $this->client_id(), 315 "items" => $this->build_checkout_items($cart), 316 "event" => "added_to_cart", 317 ); 318 319 $response = wp_remote_post($this->api_v2_url("session_events"), array( 320 "timeout" => 2, 321 "headers" => array( 322 "content-type" => "application/json", 323 ), 324 "cookies" => array(), 325 "body" => json_encode($data), 326 )); 327 } 328 329 public function page_visit() { 330 if (is_null(WC()->cart) || is_null(WC()->session) || is_ajax()) { 331 return null; 332 } 333 334 $data = array( 335 "shop_id" => get_option("checkout_x_shop_id"), 336 "client_id" => $this->client_id(), 337 "event" => "landed_on_shop_page", 338 "checkout_id" => WC()->session->get("checkout_x_checkout_id"), 339 ); 340 341 $response = wp_remote_post($this->api_v2_url("session_events"), array( 342 "timeout" => 2, 343 "headers" => array( 344 "content-type" => "application/json", 345 ), 346 "cookies" => array(), 347 "body" => json_encode($data), 348 )); 349 350 if (!is_wp_error($response)) { 351 if ($response["response"]["code"] == 200) { 352 $json_response = json_decode($response["body"]); 353 354 WC()->session->set("checkout_x_enabled", $json_response->enabled); 355 356 if ($json_response->clear_cart) { 357 WC()->cart->empty_cart(); 358 WC()->session->set("checkout_x_checkout_id", null); 359 } 360 } 361 } 362 } 363 364 private function build_checkout_items($cart) { 365 $items = array(); 366 367 foreach ($cart->get_cart() as $key => $cart_item) { 368 $items[] = array( 369 "product_id" => $cart_item["product_id"], 370 "variant_id" => $cart_item["variation_id"], 371 "quantity" => $cart_item["quantity"], 372 "properties" => $cart_item["variation"], 373 ); 374 } 375 376 return $items; 377 } 378 379 private function client_id() { 380 $client_id = WC()->session->get("checkout_x_client_id"); 381 if (is_null($client_id)) { 382 $client_id = bin2hex(openssl_random_pseudo_bytes(30)); 383 WC()->session->set("checkout_x_client_id", $client_id); 384 } 385 386 return $client_id; 387 } 388 389 private function api_v2_url($path) { 390 $base_url = get_option("checkout_x_api_url"); 391 $v2_url = path_join($base_url, "v2"); 392 $endpoint_url = path_join($v2_url, $path); 393 394 return $endpoint_url; 395 } 396 397 private function is_checkout_x_enabled() { 398 return WC()->session->get('checkout_x_enabled'); 399 } 269 400 } -
checkoutx/trunk/README.txt
r2514046 r2534775 4 4 Requires at least: 5.4 5 5 Tested up to: 5.7 6 Stable tag: 1. 1.26 Stable tag: 1.2.0 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later -
checkoutx/trunk/checkout-x.php
r2473627 r2534775 18 18 * Plugin URI: https://www.checkout-x.com 19 19 * Description: Checkout X boosts your revenue with a high-converting, frictionless, mobile-first checkout experience for your WooCommerce store. Get less abandoned carts and more sales with a fast checkout that completes itself on any device to give you more conversions and average order value. 20 * Version: 1. 1.220 * Version: 1.2.0 21 21 * Author: Checkout X 22 22 * Author URI: https://www.checkout-x.com/?utm_source=partner&utm_medium=woocommerce-marketplace -
checkoutx/trunk/includes/class-api-controller.php
r2473627 r2534775 94 94 "options" => array( 95 95 "js_script_url" => get_option("checkout_x_storefront_url", null), 96 "api_version" => get_option("checkout_x_api_version", null), 97 "app_url" => get_option("checkout_x_app_url", null), 98 "api_url" => get_option("checkout_x_api_url", null), 99 "website_url" => get_option("checkout_x_website_url", null), 96 100 ), 97 101 ); … … 121 125 $current_event_secret = get_option('checkout_x_event_secret', ''); 122 126 127 $new_api_version = $request->get_param("api_version"); 128 $current_api_version = get_option("checkout_x_api_version", ""); 129 130 $new_checkout_app_url = $request->get_param("app_url"); 131 $current_checkout_app_url = get_option("checkout_x_app_url", ""); 132 133 $new_checkout_api_url = $request->get_param("api_url"); 134 $current_checkout_api_url = get_option("checkout_x_api_url", ""); 135 136 $new_checkout_website_url = $request->get_param("website_url"); 137 $current_checkout_website_url = get_option("checkout_x_website_url", ""); 138 123 139 $shop_id_updated = ($new_shop_id == $current_shop_id) || update_option('checkout_x_shop_id', $new_shop_id); 124 140 $script_url_updated = ($new_js_script_url == $current_js_script_url) || update_option('checkout_x_storefront_url', $new_js_script_url); 125 141 $event_secret_updated = ($new_event_secret == $current_event_secret) || update_option('checkout_x_event_secret', $new_event_secret); 142 $api_version_updated = ($new_api_version == $current_api_version) || update_option('checkout_x_api_version', $new_api_version); 143 $app_url_updated = ($new_checkout_app_url == $current_checkout_app_url) || update_option('checkout_x_app_url', $new_checkout_app_url); 144 $api_url_updated = ($new_checkout_api_url == $current_checkout_api_url) || update_option('checkout_x_api_url', $new_checkout_api_url); 145 $website_url_updated = ($new_checkout_website_url == $current_checkout_website_url) || update_option('checkout_x_website_url', $new_checkout_website_url); 126 146 127 if ($shop_id_updated && $script_url_updated && $event_secret_updated) { 147 if ($shop_id_updated 148 && $script_url_updated 149 && $event_secret_updated 150 && $api_version_updated 151 && $app_url_updated 152 && $api_url_updated 153 && $website_url_updated 154 ) { 128 155 return $this->wrap_response(array('result' => 'success'), 200); 129 156 } else { … … 133 160 'script_url_updated' => $script_url_updated, 134 161 'event_secret_updated' => $event_secret_updated, 162 'api_version' => $api_version_updated, 163 'app_url' => $app_url_updated, 164 'api_url' => $api_url_updated, 165 'website_url' => $website_url_updated, 135 166 ); 136 167 return $this->wrap_response($payload, 403); -
checkoutx/trunk/includes/class-main.php
r2473627 r2534775 60 60 $this->define_admin_hooks(); 61 61 $this->define_public_hooks(); 62 $this->define_filters(); 62 if (get_option("checkout_x_api_version") != "2") { 63 $this->define_filters(); 64 } 63 65 $this->define_custom_webhooks(); 64 66 $this->define_api(); … … 170 172 $plugin_public = new Checkout_X_Public($this->get_plugin_name(), $this->get_version()); 171 173 172 # uncomment this if you want to load some styles from plugin 173 # on shop public pages ( product pages, cart, etc ) 174 # $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); 175 176 # loads plugin JS file on all shop pages 177 # more info in assets/js/public.js documentation 178 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); 179 180 # adds meta tag with shop ID to <head>. Used by CHKX storefront JS. 181 $this->loader->add_action('wp_head', $plugin_public, 'add_resources'); 182 183 // render cart content as json and sync with CHKX on every page load 184 $this->loader->add_action('wp_footer', $plugin_public, 'add_cart_json'); 185 186 # redirect on '/checkout' page in menu 187 $this->loader->add_action('template_redirect', $plugin_public, 'checkout_nav_menu_redirect'); 188 189 # clear cart when checkout is completed 190 $this->loader->add_action('wp_ajax_chkx_clear_cart', $plugin_public, 'clear_cart'); 191 $this->loader->add_action('wp_ajax_nopriv_chkx_clear_cart', $plugin_public, 'clear_cart'); 174 if (get_option("checkout_x_api_version") == "2") { 175 $this->loader->add_action("woocommerce_init", $plugin_public, "page_visit"); 176 $this->loader->add_action("woocommerce_add_to_cart", $plugin_public, "add_to_cart"); 177 $this->loader->add_action("template_redirect", $plugin_public, "redirect_to_checkout"); 178 } else { 179 # loads plugin JS file on all shop pages 180 # more info in assets/js/public.js documentation 181 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); 182 183 # adds meta tag with shop ID to <head>. Used by CHKX storefront JS. 184 $this->loader->add_action('wp_head', $plugin_public, 'add_resources'); 185 186 // render cart content as json and sync with CHKX on every page load 187 $this->loader->add_action('wp_footer', $plugin_public, 'add_cart_json'); 188 189 # redirect on '/checkout' page in menu 190 $this->loader->add_action('template_redirect', $plugin_public, 'checkout_nav_menu_redirect'); 191 192 # clear cart when checkout is completed 193 $this->loader->add_action('wp_ajax_chkx_clear_cart', $plugin_public, 'clear_cart'); 194 $this->loader->add_action('wp_ajax_nopriv_chkx_clear_cart', $plugin_public, 'clear_cart'); 195 } 192 196 } 193 197 -
checkoutx/trunk/public/class-public.php
r2473627 r2534775 125 125 } 126 126 127 /* 127 /* 128 128 * Adds parent tag with cart content inside on the page. 129 129 * … … 138 138 } 139 139 140 /* 140 /* 141 141 * Adds cart content to cart fragments. 142 142 * … … 245 245 * Empties WooCommerce cart. 246 246 * 247 * Available for public.js via wp_localize_script. Called when Checkout X API 247 * Available for public.js via wp_localize_script. Called when Checkout X API 248 248 * indicates that checkout is already completed. 249 249 */ … … 256 256 WC()->cart->empty_cart(); 257 257 } 258 258 259 259 echo json_encode(WC()->cart->get_cart_contents()); 260 260 … … 267 267 return WC()->cart->get_cart_contents_count() == 0; 268 268 } 269 270 public function redirect_to_checkout() { 271 if (!is_checkout() || is_null(WC()->cart) || WC()->cart->is_empty() || !$this->is_checkout_x_enabled()) { 272 return null; 273 } 274 275 $cart = WC()->cart; 276 $data = array( 277 "shop_id" => get_option("checkout_x_shop_id"), 278 "items" => $this->build_checkout_items($cart), 279 "discount_code" => $cart->get_applied_coupons()[0], 280 "client_id" => $this->client_id(), 281 ); 282 283 $response = wp_remote_post($this->api_v2_url("checkouts"), array( 284 "timeout" => 5, 285 "headers" => array( 286 "content-type" => "application/json", 287 ), 288 "cookies" => array(), 289 "body" => json_encode($data), 290 )); 291 292 if (is_wp_error($response)) { 293 $error_message = $response->get_error_message(); 294 echo "Something went wrong: $error_message"; 295 } else { 296 if ($response["response"]["code"] == 201) { 297 $json_response = json_decode($response["body"]); 298 $checkout_url = $json_response->url; 299 WC()->session->set("checkout_x_checkout_id", $json_response->id); 300 wp_redirect($checkout_url); 301 exit(); 302 } 303 } 304 } 305 306 public function add_to_cart() { 307 if (!$this->is_checkout_x_enabled()) { 308 return null; 309 } 310 311 $cart = WC()->cart; 312 $data = array( 313 "shop_id" => get_option("checkout_x_shop_id"), 314 "client_id" => $this->client_id(), 315 "items" => $this->build_checkout_items($cart), 316 "event" => "added_to_cart", 317 ); 318 319 $response = wp_remote_post($this->api_v2_url("session_events"), array( 320 "timeout" => 2, 321 "headers" => array( 322 "content-type" => "application/json", 323 ), 324 "cookies" => array(), 325 "body" => json_encode($data), 326 )); 327 } 328 329 public function page_visit() { 330 if (is_null(WC()->cart) || is_null(WC()->session) || is_ajax()) { 331 return null; 332 } 333 334 $data = array( 335 "shop_id" => get_option("checkout_x_shop_id"), 336 "client_id" => $this->client_id(), 337 "event" => "landed_on_shop_page", 338 "checkout_id" => WC()->session->get("checkout_x_checkout_id"), 339 ); 340 341 $response = wp_remote_post($this->api_v2_url("session_events"), array( 342 "timeout" => 2, 343 "headers" => array( 344 "content-type" => "application/json", 345 ), 346 "cookies" => array(), 347 "body" => json_encode($data), 348 )); 349 350 if (!is_wp_error($response)) { 351 if ($response["response"]["code"] == 200) { 352 $json_response = json_decode($response["body"]); 353 354 WC()->session->set("checkout_x_enabled", $json_response->enabled); 355 356 if ($json_response->clear_cart) { 357 WC()->cart->empty_cart(); 358 WC()->session->set("checkout_x_checkout_id", null); 359 } 360 } 361 } 362 } 363 364 private function build_checkout_items($cart) { 365 $items = array(); 366 367 foreach ($cart->get_cart() as $key => $cart_item) { 368 $items[] = array( 369 "product_id" => $cart_item["product_id"], 370 "variant_id" => $cart_item["variation_id"], 371 "quantity" => $cart_item["quantity"], 372 "properties" => $cart_item["variation"], 373 ); 374 } 375 376 return $items; 377 } 378 379 private function client_id() { 380 $client_id = WC()->session->get("checkout_x_client_id"); 381 if (is_null($client_id)) { 382 $client_id = bin2hex(openssl_random_pseudo_bytes(30)); 383 WC()->session->set("checkout_x_client_id", $client_id); 384 } 385 386 return $client_id; 387 } 388 389 private function api_v2_url($path) { 390 $base_url = get_option("checkout_x_api_url"); 391 $v2_url = path_join($base_url, "v2"); 392 $endpoint_url = path_join($v2_url, $path); 393 394 return $endpoint_url; 395 } 396 397 private function is_checkout_x_enabled() { 398 return WC()->session->get('checkout_x_enabled'); 399 } 269 400 }
Note: See TracChangeset
for help on using the changeset viewer.