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/ppcard/includes/main.php
<?php

namespace PPCard;

use PPCard\Ajax\Order;
use PPCard\GateWays\Card;
use PPCard\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(PPCARD_PLUGIN_PATH . PPCARD_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=card') . '" aria-label="' . esc_attr__('View PPCard settings', 'woocommerce') . '">' . esc_html__('Settings', 'woocommerce') . '</a>',
        );
        return array_merge($actionLinks, $links);
    }

    public function addPluginStyle()
    {
        wp_enqueue_style('ppcard-styles', PPCARD_PLUGIN_URL . '/assets/css/card.css', [], PPCARD_PLUGIN_VERSION);
        wp_enqueue_script('ppcard-js', PPCARD_PLUGIN_URL . '/assets/js/card.js', [], PPCARD_PLUGIN_VERSION, true);
    }

    public function addGlobalSettings($settings, $currentSection)
    {
        if ($currentSection === 'ppcard_general') {
            $settings = [
                'title' => [
                    'type' => 'title',
                    'desc' => '<h2>API settings</h2>
                                <br>Please enter your ppcard 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', PPCARD_PLUGIN_NAME),
                    'type' => 'text',
                    'desc' => '',
                    'id' => 'ppcard_app_id',
                    'value' => get_option('ppcard_app_id'),
                ],
                'api_key' => [
                    'title' => __('API Key', PPCARD_PLUGIN_NAME),
                    'type' => 'password',
                    'desc' => '',
                    'id' => 'ppcard_api_key',
                    'value' => get_option('ppcard_api_key'),
                ],
                'enable_sandbox' => [
                    'title' => __('Enable sandbox', PPCARD_PLUGIN_NAME),
                    'desc' => __('Yes', PPCARD_PLUGIN_NAME),
                    'type' => 'checkbox',
                    'default' => 'yes',
                    'id' => 'ppcard_enable_sandbox',
                    'value' => get_option('ppcard_enable_sandbox'),
                ],
                'sectionend' => [
                    'type' => 'sectionend',
                ],
            ];
        }
        return $settings;
    }

    public function addPluginJs()
    {
        $async = Card::get_async_intent_url();
        $paymentMessage = Card::PAYMENT_MESSAGE;
        $inlineScript =  <<<PPCARD
            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_card');
                    if (cardPaymentOption.length && cardPaymentOption.is(':checked')) {
                        e.preventDefault();
                        cardClient.getAjax('$async');
                    }
                });
                $(document.body).on('checkout_error', function (e, msg) {
                    if (msg && msg.indexOf('$paymentMessage') !== -1) {
                        cardClient.getAjax('$async');
                    }
                });
            });
PPCARD;
        wp_add_inline_script('ppcard-js', $inlineScript);
    }
}