HEX
Server: nginx
System: Linux f62c58717270 6.1.0-17-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.69-1 (2023-12-30) x86_64
User: www-data (1000)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /www/sites/timexsaleall.com/index/wp-content/plugins/stripe/includes/main.php
<?php

namespace Stripe;

use Stripe\Ajax\Order;
use Stripe\GateWays\Card;
use Stripe\GateWays\Webhook;

class Main
{
    private static $instance;

    public static function getInstance()
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function init()
    {
        $this->registerEvents();
    }

    private function registerEvents()
    {
        add_filter('woocommerce_payment_gateways', [$this, 'addPaymentGateways']);
        add_action('woocommerce_api_' . Card::ROUTE_SLUG_ASYNC_INTENT, [new Card(), 'checkout']);
        add_action('woocommerce_api_' . Card::ROUTE_SLUG_WEBHOOK, [new Webhook(), 'init']);
        add_action('woocommerce_api_' . Card::ROUTE_SLUG_AJAX, [new Order(), 'init']);
        add_action('woocommerce_plugins_version_' . Card::PLUGIN_VERSION_ID, [new Card(), 'getVersion']);
        add_action('woocommerce_sign_url_' . Card::GATEWAY_ID . '_webhook', [new Card(), 'getWebhookSignUrl']);
        add_action('wp_enqueue_scripts', [$this, 'addPluginStyle']);
        add_filter('plugin_action_links_' . plugin_basename(STRIPE_PLUGIN_PATH . STRIPE_PLUGIN_NAME . '.php'), [$this, 'addPluginSettingsLink']);
    }

    public function addPaymentGateways($gateways)
    {
        $gateways[] = Card::class;
        //$gateways[] = NextPay::class;
        return $gateways;
    }

    public function addPluginSettingsLink($links)
    {
        $actionLinks = array(
            'settings' => '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe') . '" aria-label="' . esc_attr__('View Stripe settings', 'woocommerce') . '">' . esc_html__('Settings', 'woocommerce') . '</a>',
        );
        return array_merge($actionLinks, $links);
    }

    public function addPluginStyle()
    {
        wp_enqueue_script('stripe-js', STRIPE_PLUGIN_URL . '/assets/js/card.js', [], STRIPE_PLUGIN_VERSION, true);
    }

    public function addGlobalSettings($settings, $currentSection)
    {
        if ($currentSection === 'stripe_general') {
            $settings = [
                'title' => [
                    'type' => 'title',
                    'desc' => '<h2>API settings</h2>
                                <br>Please enter your stripe credentials
                                <br><br>
                                <a href="' . admin_url('admin.php?page=wc-settings&tab=checkout') . '">Back to payment overview</a>
                                <br>
                                <br>',
                ],
                'app_id' => [
                    'title' => __('Unique App ID', STRIPE_PLUGIN_NAME),
                    'type' => 'text',
                    'desc' => '',
                    'id' => 'stripe_app_id',
                    'value' => get_option('stripe_app_id'),
                ],
                'api_key' => [
                    'title' => __('API Key', STRIPE_PLUGIN_NAME),
                    'type' => 'password',
                    'desc' => '',
                    'id' => 'stripe_api_key',
                    'value' => get_option('stripe_api_key'),
                ],
                'enable_sandbox' => [
                    'title' => __('Enable sandbox', STRIPE_PLUGIN_NAME),
                    'desc' => __('Yes', STRIPE_PLUGIN_NAME),
                    'type' => 'checkbox',
                    'default' => 'yes',
                    'id' => 'stripe_enable_sandbox',
                    'value' => get_option('stripe_enable_sandbox'),
                ],
                'sectionend' => [
                    'type' => 'sectionend',
                ],
            ];
        }
        return $settings;
    }

    public function addPluginJs()
    {
        $async = Card::get_async_intent_url();
        $paymentMessage = Card::PAYMENT_MESSAGE;
        $inlineScript =  <<<STRIPE
            <script>
                 jQuery(function ($) {
                        $('#billing_phone').on('input', function() {
                            var value = $(this).val();
                            $(this).val(value.replace(/\D/g, ''));
                        });
                        $('#order_review').on('submit', function (e) {
                            let cardPaymentOption = jQuery('#payment_method_stripe');
                            if (cardPaymentOption.length && cardPaymentOption.is(':checked')) {
                                e.preventDefault();
                                stripeClient.getAjax('$async')
                            }
                        })
                        $(document.body).on('checkout_error', function (e, msg) {
                            let cardPaymentOption = jQuery('#payment_method_stripe');
                            if(cardPaymentOption.length && cardPaymentOption.is(':checked')){
                               stripeClient.getAjax('$async')
                            }
                        });
                    })
        </script>
STRIPE;
        wp_add_inline_script('stripe-js', $inlineScript);
    }
}