Plugin Directory

Changeset 2534775


Ignore:
Timestamp:
05/20/2021 11:17:29 AM (5 years ago)
Author:
checkoutx
Message:

Release version 1.2.0

Location:
checkoutx
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • checkoutx/tags/1.2.0/README.txt

    r2514046 r2534775  
    44Requires at least: 5.4
    55Tested up to: 5.7
    6 Stable tag: 1.1.2
     6Stable tag: 1.2.0
    77Requires PHP: 7.0
    88License: GPLv2 or later
  • checkoutx/tags/1.2.0/checkout-x.php

    r2473627 r2534775  
    1818 * Plugin URI:        https://www.checkout-x.com
    1919 * 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.2
     20 * Version:           1.2.0
    2121 * Author:            Checkout X
    2222 * 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  
    9494      "options" => array(
    9595        "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),
    96100      ),
    97101    );
     
    121125    $current_event_secret = get_option('checkout_x_event_secret', '');
    122126
     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
    123139    $shop_id_updated = ($new_shop_id == $current_shop_id) || update_option('checkout_x_shop_id', $new_shop_id);
    124140    $script_url_updated = ($new_js_script_url == $current_js_script_url) || update_option('checkout_x_storefront_url', $new_js_script_url);
    125141    $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);
    126146
    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    ) {
    128155      return $this->wrap_response(array('result' => 'success'), 200);
    129156    } else {
     
    133160        'script_url_updated' => $script_url_updated,
    134161        '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,
    135166      );
    136167      return $this->wrap_response($payload, 403);
  • checkoutx/tags/1.2.0/includes/class-main.php

    r2473627 r2534775  
    6060        $this->define_admin_hooks();
    6161        $this->define_public_hooks();
    62         $this->define_filters();
     62        if (get_option("checkout_x_api_version") != "2") {
     63          $this->define_filters();
     64        }
    6365        $this->define_custom_webhooks();
    6466        $this->define_api();
     
    170172        $plugin_public = new Checkout_X_Public($this->get_plugin_name(), $this->get_version());
    171173
    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        }
    192196    }
    193197
  • checkoutx/tags/1.2.0/public/class-public.php

    r2473627 r2534775  
    125125    }
    126126
    127     /* 
     127    /*
    128128     * Adds parent tag with cart content inside on the page.
    129129     *
     
    138138    }
    139139
    140     /* 
     140    /*
    141141     * Adds cart content to cart fragments.
    142142     *
     
    245245     * Empties WooCommerce cart.
    246246     *
    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
    248248     * indicates that checkout is already completed.
    249249     */
     
    256256            WC()->cart->empty_cart();
    257257        }
    258        
     258
    259259        echo json_encode(WC()->cart->get_cart_contents());
    260260
     
    267267      return WC()->cart->get_cart_contents_count() == 0;
    268268    }
     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    }
    269400}
  • checkoutx/trunk/README.txt

    r2514046 r2534775  
    44Requires at least: 5.4
    55Tested up to: 5.7
    6 Stable tag: 1.1.2
     6Stable tag: 1.2.0
    77Requires PHP: 7.0
    88License: GPLv2 or later
  • checkoutx/trunk/checkout-x.php

    r2473627 r2534775  
    1818 * Plugin URI:        https://www.checkout-x.com
    1919 * 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.2
     20 * Version:           1.2.0
    2121 * Author:            Checkout X
    2222 * Author URI:        https://www.checkout-x.com/?utm_source=partner&utm_medium=woocommerce-marketplace
  • checkoutx/trunk/includes/class-api-controller.php

    r2473627 r2534775  
    9494      "options" => array(
    9595        "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),
    96100      ),
    97101    );
     
    121125    $current_event_secret = get_option('checkout_x_event_secret', '');
    122126
     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
    123139    $shop_id_updated = ($new_shop_id == $current_shop_id) || update_option('checkout_x_shop_id', $new_shop_id);
    124140    $script_url_updated = ($new_js_script_url == $current_js_script_url) || update_option('checkout_x_storefront_url', $new_js_script_url);
    125141    $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);
    126146
    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    ) {
    128155      return $this->wrap_response(array('result' => 'success'), 200);
    129156    } else {
     
    133160        'script_url_updated' => $script_url_updated,
    134161        '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,
    135166      );
    136167      return $this->wrap_response($payload, 403);
  • checkoutx/trunk/includes/class-main.php

    r2473627 r2534775  
    6060        $this->define_admin_hooks();
    6161        $this->define_public_hooks();
    62         $this->define_filters();
     62        if (get_option("checkout_x_api_version") != "2") {
     63          $this->define_filters();
     64        }
    6365        $this->define_custom_webhooks();
    6466        $this->define_api();
     
    170172        $plugin_public = new Checkout_X_Public($this->get_plugin_name(), $this->get_version());
    171173
    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        }
    192196    }
    193197
  • checkoutx/trunk/public/class-public.php

    r2473627 r2534775  
    125125    }
    126126
    127     /* 
     127    /*
    128128     * Adds parent tag with cart content inside on the page.
    129129     *
     
    138138    }
    139139
    140     /* 
     140    /*
    141141     * Adds cart content to cart fragments.
    142142     *
     
    245245     * Empties WooCommerce cart.
    246246     *
    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
    248248     * indicates that checkout is already completed.
    249249     */
     
    256256            WC()->cart->empty_cart();
    257257        }
    258        
     258
    259259        echo json_encode(WC()->cart->get_cart_contents());
    260260
     
    267267      return WC()->cart->get_cart_contents_count() == 0;
    268268    }
     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    }
    269400}
Note: See TracChangeset for help on using the changeset viewer.