Plugin Directory

Changeset 3015266


Ignore:
Timestamp:
12/28/2023 10:54:34 PM (2 years ago)
Author:
agechecker
Message:
  • "Element" setting field's default value on fresh installs is now: #place_order,.wc-block-components-checkout-place-order-button
  • Adds support for Before-payment workflow to function on WooCommerce block-based checkout pages
Location:
agecheckernet
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • agecheckernet/trunk/agechecker.php

    r2986427 r3015266  
    44Plugin URI:  https://agechecker.net
    55Description: AgeChecker.Net seamlessly and securely verifies the age of your customers directly on your website during the checkout process. Keep your site up to date on the latest age regulations for your industry while ensuring that purchasing is frustration-free for your site users.
    6 Version:     1.15.3
     6Version:     1.16.0
    77Author:      AgeChecker.Net
    88Author URI:  https://agechecker.net
  • agecheckernet/trunk/class-wc-integration-agechecker-integration.php

    r2986427 r3015266  
    3737            add_action('woocommerce_checkout_process', array(
    3838                $this,
    39                 'validate_order'
     39                'validate_order_shortcode'
    4040            ));
     41            // Add hook for WooCommerce Block Checkout
     42            add_action('woocommerce_store_api_checkout_update_order_from_request', array(
     43                $this,
     44                'validate_order_blocks'
     45            ), 10, 2);
    4146            add_action( 'woocommerce_new_order', array(
    4247                $this,
    43                 'add_verified_notes'
     48                'new_order'
    4449            ));
    4550            add_action( 'rest_api_init', array(
     
    133138                    'type'        => 'text',
    134139                    'description' => 'Element selector to attach the popup event to when using the "Before Payment" workflow. You may need to change this if you use a custom theme/template. Please contact us if the popup is not showing when the element is clicked. The default element is the final checkout button.',
    135                     'default'     => '#place_order',
     140                    'default'     => '#place_order,.wc-block-components-checkout-place-order-button',
    136141                    'desc_tip'    => false,
    137142                ),
     
    10381043        }
    10391044
    1040         public function validate_order() {
    1041             if ($this->workflow_type != "before_payment" || $this->is_excluded(false) || $this->is_total_excluded(false) || $this->is_shipping_excluded() || $this->is_payment_excluded()) {
     1045        public function validate_order_blocks($order, $request) {
     1046            $chosenPayment = "";   
     1047            if(isset($order) && isset($order->payment_method)) {
     1048                $chosenPayment = $order->payment_method;
     1049            }
     1050
     1051            if ($this->is_before_excluded($chosenPayment)) {
    10421052                return true;
    10431053            }
    10441054
     1055            $uuid = "";
     1056            if(isset($request)) {
     1057                $body = $request->get_body();
     1058                if(isset($body)) {
     1059                    $post = json_decode($body);
     1060                    if(isset($post->extensions)) {
     1061                        $extensions = $post->extensions;
     1062                        if(isset($extensions->agecheckernet_checkout) && isset($extensions->agecheckernet_checkout->agechecker_uuid)) {
     1063                            $uuid = $extensions->agecheckernet_checkout->agechecker_uuid;
     1064                        }
     1065                    }
     1066                }
     1067            }
     1068            $this->validate_order($uuid);
     1069            $this->add_verified_notes($order, $uuid);
     1070        }
     1071
     1072        public function validate_order_shortcode() {
     1073            if ($this->is_before_excluded($_POST["payment_method"])) {
     1074                return true;
     1075            }
     1076
     1077            $this->validate_order($_POST["agechecker_uuid"]);
     1078        }
     1079
     1080        public function validate_order($uuid) {
    10451081            // Check custom form trigger
    10461082            if (!empty($this->get_option("form_trigger_name")) && !empty($this->get_option("form_trigger_value"))) {
     
    10531089                }
    10541090            }
    1055 
    1056             $uuid = $_POST["agechecker_uuid"];
    10571091
    10581092            // In order to work around Google Pay or Apple Pay from the WooCommerce Square plugin, we check if
     
    11081142            } else {
    11091143                if (!isset($uuid) || strlen($uuid) != 32) {
    1110                     wc_add_notice('You must complete the age verification process! Need help? Contact help@agechecker.net or try using another device or browser. (Error WP201)', 'error');
     1144                    throw new Exception('You must complete the age verification process! Need help? Contact help@agechecker.net or try using another device or browser. (Error WP201)');
    11111145                } else {
    11121146                    $req  = json_encode(array(
     
    11241158                    ));
    11251159                    if (is_wp_error($post)) {
    1126                         wc_add_notice('The age verification service could not verify you at this time. Need help? Contact help@agechecker.net. (Error WP203)', 'error');
     1160                        throw new Exception('The age verification service could not verify you at this time. Need help? Contact help@agechecker.net. (Error WP203)');
    11271161                    } else {
    11281162                        $res = json_decode($post['body']);
     
    11301164                            return true;
    11311165                        } else {
    1132                             wc_add_notice('You have not been approved by the age verification process! Need help? Contact help@agechecker.net. (Error WP205)' . $res->status, 'error');
     1166                            throw new Exception('You have not been approved by the age verification process! Need help? Contact help@agechecker.net. (Error WP205)');
    11331167                        }
    11341168                    }
     
    11381172        }
    11391173
    1140         public function add_verified_notes( $order_id ) {
     1174        public function is_before_excluded($chosenPayment) {
     1175            if ($this->workflow_type != "before_payment" || $this->is_excluded(false) || $this->is_total_excluded(false) || $this->is_shipping_excluded(null) || $this->is_payment_excluded($chosenPayment)) {
     1176                return true;
     1177            } else {
     1178                return false;
     1179            }
     1180        }
     1181
     1182        public function new_order( $order_id ) {
    11411183            $order = new WC_Order( $order_id );
    11421184
    11431185            if(!isset($_POST['agechecker_uuid'])) return;
     1186
     1187            $uuid = $_POST['agechecker_uuid'];
     1188
     1189            $this->add_verified_notes($order, $uuid);
     1190        }
     1191
     1192        public function add_verified_notes( $order, $uuid ) {
     1193            if(!isset($uuid)) return;
    11441194           
    11451195            // Not order tagging logic, but we set this here for before_payment logic
     
    11521202            if(isset($this->tag_order)) {
    11531203                if($this->tag_order == "tag_notes" || $this->tag_order == "tag_both") {
    1154                     $note = __("Age Verified order. \n\nAgeChecker UUID: ". $_POST['agechecker_uuid']);
     1204                    $note = __("Age Verified order. \n\nAgeChecker UUID: ". $uuid);
    11551205                    $order->add_order_note( $note );
    11561206                }
    11571207                if($this->tag_order == "tag_fields" || $this->tag_order == "tag_both") {
    1158                     $order->update_meta_data( 'Age Verified', 'AgeChecker UUID: '. $_POST['agechecker_uuid'] );
     1208                    $order->update_meta_data( 'Age Verified', 'AgeChecker UUID: '. $uuid );
    11591209                }
    11601210            }
     
    17201770            $order = new WC_Order($order_id);
    17211771
    1722             if ($this->is_excluded($order->get_items()) || $this->is_total_excluded($order->get_total()) || $this->is_shipping_excluded() || $this->is_payment_excluded()) {
     1772            $shipping_methods = array();
     1773            foreach ( $order->get_shipping_methods() as $shipping_method ) {
     1774                $shipping_methods[] = $shipping_method->get_method_id() . ":" . $shipping_method->get_instance_id();
     1775            }
     1776
     1777            if ($this->is_excluded($order->get_items()) || $this->is_total_excluded($order->get_total()) || $this->is_shipping_excluded($shipping_methods) || $this->is_payment_excluded($order->get_payment_method())) {
    17231778                return;
    17241779            }
     
    17391794        }
    17401795
    1741         public function is_shipping_excluded() {
     1796        public function is_shipping_excluded($chosen_methods) {
    17421797            $excluded_shipping_methods = explode(",", $this->excluded_shipping);
    17431798
    17441799            if (!(sizeof($excluded_shipping_methods) == 1 && $excluded_shipping_methods[0] == "")) {
     1800                if($chosen_methods === null) {
     1801                    $chosen_methods = WC()->session->get('chosen_shipping_methods');
     1802                }
     1803
    17451804                $all_shipping_methods = array();
    17461805                foreach(WC_Shipping_Zones::get_zones() as $zone_key => $zone ) {
     
    17561815                }
    17571816
    1758                 $chosen_methods = WC()->session->get('chosen_shipping_methods');
    17591817                if($chosen_methods) {
    17601818                    foreach ($chosen_methods as $shipping_method_key => $shipping_method) {
     
    17731831        }
    17741832
    1775         public function is_payment_excluded() {
     1833        public function is_payment_excluded($chosen_method) {
    17761834            $excluded_payment_methods = explode(",", $this->excluded_payment);
    17771835
    17781836            if (!(sizeof($excluded_payment_methods) == 1 && $excluded_payment_methods[0] == "")) {
    1779                 $chosen_method = WC()->session->get('chosen_payment_method');
     1837                if($chosen_method === null) {
     1838                    $chosen_method = WC()->session->get('chosen_payment_method');
     1839                }
    17801840                if($chosen_method) {
    17811841                    foreach ($excluded_payment_methods as $c) {
  • agecheckernet/trunk/readme.txt

    r2986427 r3015266  
    1 === Age Verification for your checkout page. Verify your customer's identity ===
     1=== Age Verification for your checkout page. Verify your customer's identity ===
    22Contributors: agechecker
    33Tags: age checker, age check, AgeChecker.Net, check age, verify age, age verification, fda, vape, Age Verification and KYC, KYC, Fraud Prevention
    44Requires at least: 4.4
    5 Tested up to: 6.3
    6 Stable tag: 1.15.3
     5Tested up to: 6.4
     6Stable tag: 1.16.0
    77
    88AgeChecker.Net seamlessly and securely verifies the age of your customers directly on your website during the checkout process.
     
    6363== Changelog ==
    6464
     65= 1.16.0 =
     66*Release Date - 28 December 2023*
     67
     68* "Element" setting field's default value on fresh installs is now: **#place_order,.wc-block-components-checkout-place-order-button**
     69* Adds support for Before-payment workflow to function on WooCommerce block-based checkout pages
     70  * Site-owners who installed the plugin before this version, and are looking to set their checkout page to block-based, will need to update set their "Element" setting field to **#place_order,.wc-block-components-checkout-place-order-button**
     71
    6572= 1.15.3 =
    6673*Release Date - 30 October 2023*
Note: See TracChangeset for help on using the changeset viewer.