Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
17.28% covered (danger)
17.28%
14 / 81
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
CaptiveFlow
17.28% covered (danger)
17.28%
14 / 81
50.00% covered (danger)
50.00%
3 / 6
26.37
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 register_options
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
2
 enqueue_styles
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 register_page
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
2
 render_paypal
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 render_shippo
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace NewfoldLabs\WP\Module\ECommerce\Partials;
3
4use NewfoldLabs\WP\Module\ECommerce\Permissions;
5/**
6 * Class CaptiveFlow
7 *
8 * @package NewfoldLabs\WP\Module\ECommerce\Partials
9 */
10class CaptiveFlow {
11
12    /**
13     * String Identifier for the PayPal captive flow.
14     *
15     * @var string $paypal_captive_flow
16     */
17    public static $paypal_captive_flow = 'nfd-ecommerce-captive-flow-paypal';
18
19    /**
20     * String Identifier for the Shippo captive flow.
21     *
22     * @var string $shippo_captive_flow
23     */
24    public static $shippo_captive_flow = 'nfd-ecommerce-captive-flow-shippo';
25
26    /**
27     * String Identifier for the Razorpay captive flow.
28     *
29     * @var string $razorpay_captive_flow
30     */
31    public static $razorpay_captive_flow = 'nfd-ecommerce-captive-flow-razorpay';
32
33    /**
34     * Initialize the plugin by registering necessary actions.
35     *
36     * @return void
37     */
38    public static function init() {
39        add_action( 'admin_menu', array( __CLASS__, 'register_page' ) );
40        add_action( 'rest_api_init', array( __CLASS__, 'register_options' ) );
41        add_action( 'load-admin_page_' . self::$paypal_captive_flow, array( __CLASS__, 'enqueue_styles' ), 100 );
42        add_action( 'load-admin_page_' . self::$shippo_captive_flow, array( __CLASS__, 'enqueue_styles' ), 100 );
43    }
44
45    /**
46     * Register WooCommerce Razorpay settings options in the WordPress REST API.
47     *
48     * @return void
49     */
50    public static function register_options() {
51        \register_setting(
52            'general',
53            'woocommerce_razorpay_settings',
54            array(
55                'show_in_rest' => array(
56                    'schema' => array(
57                        'type'       => 'object',
58                        'properties' => array(
59                            'enabled'               => array(
60                                'type' => 'string',
61                            ),
62                            'title'                 => array(
63                                'type' => 'string',
64                            ),
65                            'description'           => array(
66                                'type' => 'string',
67                            ),
68                            'key_id'                => array(
69                                'type' => 'string',
70                            ),
71                            'key_secret'            => array(
72                                'type' => 'string',
73                            ),
74                            'payment_action'        => array(
75                                'type' => 'string',
76                            ),
77                            'order_success_message' => array(
78                                'type' => 'string',
79                            ),
80                            'enable_1cc_debug_mode' => array(
81                                'type' => 'string',
82                            ),
83                            'route_enable'          => array(
84                                'type' => 'string',
85                            ),
86                        ),
87                    ),
88                ),
89                'type'         => 'object',
90                'description'  => __( 'NFD eCommerce RazorPay Options', 'wp-module-ecommerce' ),
91            )
92        );
93    }
94
95    /**
96     * Enqueue styles for specific admin pages related to captive flows.
97     *
98     * @return void
99     */
100    public static function enqueue_styles() {
101        \add_filter(
102            'admin_body_class',
103            static function ( $classes ) {
104                return "$classes is-fullscreen-mode";
105            }
106        );
107        \wp_enqueue_style( 'nfd-ecommerce-captive', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/Partials/template.css', null, '1', 'screen' );
108    }
109
110    /**
111     * Register submenu pages for PayPal and Shippo captive flows.
112     *
113     * @return void
114     */
115    public static function register_page() {
116        \add_submenu_page(
117            '',
118            '',
119            '',
120            Permissions::ADMIN,
121            self::$paypal_captive_flow,
122            array( __CLASS__, 'render_paypal' ),
123            100
124        );
125        \add_submenu_page(
126            '',
127            '',
128            '',
129            Permissions::ADMIN,
130            self::$shippo_captive_flow,
131            array( __CLASS__, 'render_shippo' ),
132            100
133        );
134    }
135
136    /**
137     * Render function for the PayPal captive flow admin page.
138     *
139     * @return void
140     */
141    public static function render_paypal() {
142        echo PHP_EOL;
143        echo '<div id="nfd-ecommerce" class="nfd-ecommerce-captive-flow">';
144        do_action( self::$paypal_captive_flow );
145        echo '</div>';
146        echo PHP_EOL;
147    }
148
149    /**
150     * Render function for the Shippo captive flow admin page.
151     *
152     * @return void
153     */
154    public static function render_shippo() {
155        echo PHP_EOL;
156        echo '<div id="nfd-ecommerce" class="nfd-ecommerce-captive-flow">';
157        do_action( self::$shippo_captive_flow );
158        echo '</div>';
159        echo PHP_EOL;
160    }
161}