Plugin Directory

Changeset 2655823


Ignore:
Timestamp:
01/11/2022 12:45:22 PM (4 years ago)
Author:
handcraftbyte
Message:

Testing code removal, versions testing and debug endpoint

Location:
gtm-ecommerce-woo/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gtm-ecommerce-woo/trunk/gtm-ecommerce-woo.php

    r2624990 r2655823  
    44 * Plugin URI:  https://wordpress.org/plugins/gtm-ecommerce-woo
    55 * Description: Push WooCommerce eCommerce (GA4 and UA compatible) information to GTM DataLayer. Use any GTM integration to measure your customers' activites.
    6  * Version:     1.9.3
     6 * Version:     1.9.4
    77 * Author:      Handcraft Byte
    88 * Author URI:  https://handcraftbyte.com/
     
    1313 *
    1414 * WC requires at least: 4.0
    15  * WC tested up to: 5.8.0
     15 * WC tested up to: 6.0.0
    1616 */
    1717
  • gtm-ecommerce-woo/trunk/lib/Service/EventInspectorService.php

    r2615627 r2655823  
    5656
    5757    public function footerHtml() {
    58         var_dump($this->wpSettingsUtil->getOption('event_inspector_demo_mode'));
    5958        if ($this->isDisabled()) {
    6059            return;
  • gtm-ecommerce-woo/trunk/lib/Service/ThemeValidatorService.php

    r2618200 r2655823  
    3535            return;
    3636        }
     37
     38        add_action(
     39            'rest_api_init',
     40            function () {
     41                register_rest_route(
     42                    'gtm-ecommerce-woo/v1',
     43                    '/theme-validator/',
     44                    array(
     45                        'methods'             => 'GET',
     46                        'callback'            => array( $this, 'getThemeValidator' ),
     47                        'permission_callback' => array( $this, 'verifyRequest'),
     48                    )
     49                );
     50            }
     51        );
     52
    3753        if (!isset($_GET['gtm-ecommerce-woo-validator'])
    3854            || md5($this->wpSettingsUtil->getOption('uuid')) !== $_GET['gtm-ecommerce-woo-validator']) {
     
    4965    }
    5066
     67    public function verifyRequest($data) {
     68        if (!is_string($data->get_header('X-TC-Signature'))
     69            || !is_string($data->get_header('X-TC-Timestamp'))) {
     70            return new \WP_Error("missing-signature", "Missing Signature");
     71        }
     72
     73        if ($data->get_header('X-TC-Timestamp') >= time()) {
     74            return new \WP_Error("wrong-signature", "Wrong Signature");
     75        }
     76
     77        $response  = wp_remote_get( $this->tagConciergeApiUrl . '/v2/public-key');
     78        $publicKey = wp_remote_retrieve_body( $response );
     79
     80        try {
     81            $verified = openssl_verify(
     82                $data->get_header('X-TC-Timestamp'),
     83                base64_decode($data->get_header('X-TC-Signature')),
     84                $publicKey,
     85                "sha512"
     86            );
     87        } catch (\Exception $err) {
     88            return new \WP_Error("wrong-signature", "Wrong Signature");
     89        }
     90
     91        if ($verified !== 1) {
     92            return new \WP_Error("wrong-signature", "Wrong Signature");
     93        }
     94
     95        return true;
     96    }
     97
     98    public function getThemeValidator( $data ) {
     99        $query = new \WC_Order_Query( array(
     100            'orderby' => 'date',
     101            'order' => 'DESC',
     102            'limit' => 1,
     103            'type' => 'shop_order',
     104            'status' => ['on-hold', 'completed']
     105        ) );
     106        $orders = $query->get_orders();
     107        if (count($orders) === 0) {
     108            $thankYou = null;
     109        } else {
     110            $thankYou = $orders[0]->get_checkout_order_received_url();
     111        }
     112
     113        $query = new \WC_Product_Query( array(
     114            'orderby' => 'date',
     115            'order' => 'DESC',
     116            'limit' => 1,
     117            'status' => ['publish']
     118        ) );
     119        $products = $query->get_products();
     120        if (count($products) === 0) {
     121            $productUrl = null;
     122        } else {
     123            $productUrl = $products[0]->get_permalink();
     124        }
     125
     126        $categories = get_terms( ['taxonomy' => 'product_cat'] );
     127        if (count($categories) === 0) {
     128            $productCatUrl = null;
     129        } else {
     130            $productCatUrl = get_term_link($categories[0]);
     131        }
     132
     133        $payload = [
     134            'platform' => 'woocommerce',
     135            'uuid_hash' => md5($this->wpSettingsUtil->getOption('uuid')),
     136            'uuid' => $this->wpSettingsUtil->getOption('uuid'),
     137            'events' => $this->events,
     138            'urls' => [
     139                'product_category' => $productCatUrl,
     140                'product' => $productUrl,
     141                'cart' => wc_get_cart_url(),
     142                'checkout' => wc_get_checkout_url(),
     143                'home' => get_home_url(),
     144                'thank_you' => $thankYou,
     145                'shop' => get_permalink(wc_get_page_id('shop'))
     146                // 'thank_you' =>    $return_url = $order->get_checkout_order_received_url();
     147                //     } else {
     148                //         $return_url = wc_get_endpoint_url( 'order-received', '', wc_get_checkout_url() );
     149            ]
     150        ];
     151        return $payload;
     152    }
     153
    51154    public function ajaxPostValidateTheme() {
    52155        $query = new \WC_Order_Query( array(
     
    54157            'order' => 'DESC',
    55158            'limit' => 1,
     159            'type' => 'shop_order',
    56160            'status' => ['on-hold', 'completed']
    57161        ) );
  • gtm-ecommerce-woo/trunk/readme.txt

    r2624990 r2655823  
    33Tags: google tag manager, GA4, ecommerce events, Google Analytics, Facebook Pixel, shopping behavior
    44Requires at least: 5.1.0
    5 Tested up to: 5.8.1
     5Tested up to: 5.8.3
    66Requires PHP: 7.2
    77Stable tag: trunk
     
    118118== Changelog ==
    119119
     120= 1.9.4 =
     121
     122* remove testing code
     123* test against latest WooCommerce and WordPress versions
     124* introduce secured endpoint for obtaining debugging info
     125
    120126= 1.9.3 =
    121127
Note: See TracChangeset for help on using the changeset viewer.