Plugin Directory

Changeset 3084475


Ignore:
Timestamp:
05/10/2024 10:22:32 AM (21 months ago)
Author:
geideapg123
Message:

Enable support for block based checkout

Location:
geidea-online-payments/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • geidea-online-payments/trunk/class.geidea.php

    r3066643 r3084475  
    88 * @class       WC_Geidea
    99 * @extends     WC_Payment_Gateway
    10  * @version     3.1.1
     10 * @version     3.2.0
    1111 * @author      Geidea
    1212 */
     
    110110        add_action('wp_ajax_ajax_order', array('WC_Gateway_Geidea', 'init_payment'));
    111111        add_action('wp_ajax_nopriv_ajax_order', array('WC_Gateway_Geidea', 'init_payment'));
     112        add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
    112113    }
    113114
     
    171172        return $settings;
    172173    }
     174
     175    public function payment_scripts()
     176    {
     177        if (!isset($_GET['geidea-session'])) {
     178            return;
     179        }
     180        if ($this->enabled === 'no') {
     181            return;
     182        }
     183        if (!isset($_GET['geidea_session_nonce']) || !wp_verify_nonce(sanitize_key(wp_unslash($_GET['geidea_session_nonce'])), 'geidea_session_action')) {
     184            echo '<script>alert("Nonce Verification Failed")</script>';
     185            echo '<script>setTimeout(document.location.href = "' . wc_get_checkout_url() . '", 1000)</script>';
     186            return;
     187        }
     188
     189        $data_string = urldecode(wp_unslash($_GET['geidea-session'])); // phpcs:ignore
     190        $data_array = json_decode($data_string, true);
     191
     192?>
     193        <div style="display: none;">
     194            <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
     195            <script src='<?php echo $this->config['jsSdkUrl']; ?>'></script>
     196            <script>
     197                let y_offsetWhenScrollDisabled = 0;
     198
     199                function disableScrollOnBody() {
     200                    y_offsetWhenScrollDisabled = jQuery(window).scrollTop();
     201                    jQuery('body').addClass('scrollDisabled').css('margin-top', -y_offsetWhenScrollDisabled);
     202                }
     203
     204                function enableScrollOnBody() {
     205                    jQuery('body').removeClass('scrollDisabled').css('margin-top', 0);
     206                    jQuery(window).scrollTop(y_offsetWhenScrollDisabled);
     207                }
     208
     209                let onError = function(error) {
     210                    enableScrollOnBody();
     211                    jQuery("#place_order").removeAttr("disabled");
     212                    alert("Geidea Payment Gateway error: " + error.responseMessage);
     213                    setTimeout(document.location.href = '<?php echo wc_get_checkout_url(); ?>', 1000);
     214                }
     215
     216                let onCancel = function() {
     217                    enableScrollOnBody();
     218                    jQuery("#place_order").removeAttr("disabled");
     219                    setTimeout(document.location.href = '<?php echo wc_get_checkout_url(); ?>', 1000);
     220                }
     221
     222                const startV2HPP = (data) => {
     223                    console.log("Session create API response", data);
     224                    disableScrollOnBody();
     225                    let onSuccess = function(_message, _statusCode) {
     226                        setTimeout(document.location.href = data.successUrl, 1000);
     227                    }
     228                    try {
     229                        if (data.responseCode !== '000') {
     230                            throw data
     231                        }
     232                        const api = new GeideaCheckout(onSuccess, onError, onCancel);
     233                        api.startPayment(data.session.id);
     234                    } catch (error) {
     235                        let receivedError;
     236                        const errorFields = [];
     237
     238                        if (error.status && error.errors) {
     239                            const errorsObject = error.errors;
     240
     241                            for (const key of Object.keys(errorsObject)) {
     242                                errorFields.push(key.replace('$.', ''))
     243                            }
     244                            receivedError = {
     245                                responseCode: '100',
     246                                responseMessage: 'Field formatting errors',
     247                                detailResponseMessage: `Fields with errors: ${errorFields.toString()}`,
     248                                reference: error.reference,
     249                                detailResponseCode: null,
     250                                orderId: null
     251                            }
     252                        } else {
     253                            receivedError = {
     254                                responseCode: error.responseCode,
     255                                responseMessage: error.responseMessage,
     256                                detailResponseMessage: error.detailedResponseMessage,
     257                                detailResponseCode: error.detailedResponseCode,
     258                                orderId: null,
     259                                reference: error.reference,
     260                            }
     261                        }
     262                        onError(receivedError);
     263                    }
     264                }
     265
     266                startV2HPP(JSON.parse('<?php echo $data_array; ?>'));
     267            </script>
     268        </div>
     269<?php
     270    }
    173271}
  • geidea-online-payments/trunk/functions/ProcessPayment.php

    r3040351 r3084475  
    4040        $token_id = null;
    4141        try {
    42             if (isset($_POST['wc-geidea-payment-token']) && isset($_POST['woocommerce-process-checkout-nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['woocommerce-process-checkout-nonce'])), 'woocommerce-process_checkout')) {
    43                 $selected_token_id = sanitize_text_field(wp_unslash($_POST['wc-geidea-payment-token']));
     42            if (isset($_POST['wc-geidea-payment-token'])) { // phpcs:ignore
     43                $selected_token_id = sanitize_text_field(wp_unslash($_POST['wc-geidea-payment-token'])); // phpcs:ignore
    4444                $token = WC_Payment_Tokens::get($selected_token_id);
    4545                if ($token) {
     
    4747                }
    4848            }
    49             if (isset($_POST['wc-geidea-new-payment-method']) && isset($_POST['woocommerce-process-checkout-nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['woocommerce-process-checkout-nonce'])), 'woocommerce-process_checkout')) {
     49            if (isset($_POST['wc-geidea-new-payment-method']) && sanitize_text_field(wp_unslash($_POST['wc-geidea-new-payment-method']))) { // phpcs:ignore
    5050                $save_card = true;
    5151            }
     
    158158        </script>
    159159        ';
     160        $geidea_session_nonce = wp_create_nonce('geidea_session_action');
    160161        return array(
    161162            'result' => 'success',
    162             'messages' => $script,
    163             'refresh' => true,
    164             'reload' => false,
     163            'redirect' => wc_get_checkout_url() . '?geidea-session=' . urlencode(json_encode($response['body'])) . "&geidea_session_nonce=$geidea_session_nonce"
    165164        );
    166165    }
  • geidea-online-payments/trunk/readme.txt

    r3066643 r3084475  
    22
    33Contributors: geideapg123
    4 Version: 3.1.1
     4Version: 3.2.0
    55Tags: credit card, geidea, Apple Pay, payment, payment for WordPress, payment for woocommerce, payment request, woocommerce
    66Requires at least: 6.0.2
    77Tested up to: 6.5
    88Requires PHP: 7.4
    9 Stable tag: 3.1.1
     9Stable tag: 3.2.0
    1010License: GPLv3
    1111License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    209209= 3.1.1 - 2024-04-08 =
    210210* Plugin tested on wordpress v6.5
     211
     212= 3.2.0 - 2024-05-12 =
     213* Enable support for block based checkout
  • geidea-online-payments/trunk/wc-geidea.php

    r3066643 r3084475  
    44Plugin Name: Geidea Online Payments
    55Description: Geidea Online Payments.
    6 Version: 3.1.1
     6Version: 3.2.0
    77Author: Geidea
    88Author URI: https://geidea.net
     
    5353}
    5454
     55/**
     56 * Function for declare compatibility with cart_checkout_blocks feature
     57 */
     58function declare_cart_checkout_blocks_compatibility()
     59{
     60    if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
     61        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
     62            'cart_checkout_blocks',
     63            __FILE__,
     64            true
     65        );
     66    }
     67}
     68
     69/**
     70 * Function for register a payment method type
     71 */
     72function register_order_approval_payment_method_type()
     73{
     74    if (!class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) {
     75        return;
     76    }
     77    require_once('class.blocks-checkout.php');
     78    add_action(
     79        'woocommerce_blocks_payment_method_type_registration',
     80        function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     81            $payment_method_registry->register(new WC_geidea_Blocks);
     82        }
     83    );
     84}
     85
    5586/*
    5687 * Function for load plugin
     
    75106    add_filter('woocommerce_payment_gateways', 'geidea_add_gateway');
    76107    add_action('admin_menu', 'geidea_add_card_tokens_menu', 99);
     108    add_action('before_woocommerce_init', 'declare_cart_checkout_blocks_compatibility');
     109    add_action('woocommerce_blocks_loaded', 'register_order_approval_payment_method_type');
    77110}
Note: See TracChangeset for help on using the changeset viewer.