Passed
Push — master ( a08dcb...182caa )
by Brian
10:26
created

render_checkbox_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
    exit; // Exit if accessed directly
5
}
6
7
class WPInv_Payment_Form_Elements {
8
9
    /**
10
     * @param array payment form elements
11
     */
12
    protected $elements;
13
14
    public function __construct() {
15
16
        foreach( $this->get_elements() as $element ) {
17
            $element = $element['type'];
18
19
            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
21
            }
22
23
            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
25
            }
26
27
            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
29
            }
30
31
        }
32
        
33
    }
34
35
    /**
36
     * Returns all the elements that can be added to a form.
37
     */
38
    public function get_elements() {
39
40
        if ( ! empty( $this->elements ) ) {
41
            return $this->elements;
42
        }
43
44
        $this->elements = array(
45
46
            array(
47
                'type'     => 'heading',
48
                'name'     => __( 'Heading', 'invoicing' ),
49
                'defaults' => array(
50
                    'level' => 'h2',
51
                    'text'  => __( 'Heading', 'invoicing' ),
52
                )
53
            ),
54
55
            array(
56
                'type' => 'paragraph',
57
                'name' => __( 'Paragraph', 'invoicing' ),
58
                'defaults'  => array(
59
                    'text'  => __( 'Paragraph text', 'invoicing' ),
60
                )
61
            ),
62
63
            array( 
64
                'type' => 'alert',
65
                'name' => __( 'Alert', 'invoicing' ),
66
                'defaults'  => array(
67
                    'value'        => '',
68
                    'class'        => 'alert-warning',
69
                    'text'         => __( 'Alert', 'invoicing' ),
70
                    'dismissible'  => false,
71
                )
72
            ),
73
74
            /*array( 
75
                'type' => 'separator',
76
                'name' => __( 'Separator', 'invoicing' ),
77
                'defaults'  => array(
78
                    'value'        => '',
79
                    'dismissible'  => false,
80
                )
81
            ),*/
82
83
            array(
84
                'type' => 'text',
85
                'name' => __( 'Text Input', 'invoicing' ),
86
                'defaults'  => array(
87
                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
88
                    'value'        => '',
89
                    'label'        => __( 'Field Label', 'invoicing' ),
90
                    'description'  => '',
91
                    'required'     => false,
92
                )
93
            ),
94
95
            array(
96
                'type' => 'textarea',
97
                'name' => __( 'Textarea', 'invoicing' ),
98
                'defaults'         => array(
99
                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
100
                    'value'        => '',
101
                    'label'        => __( 'Textarea Label', 'invoicing' ),
102
                    'description'  => '',
103
                    'required'     => false,
104
                )
105
            ),
106
107
            array(
108
                'type' => 'select',
109
                'name' => __( 'Dropdown', 'invoicing' ),
110
                'defaults'         => array(
111
                    'placeholder'  => __( 'Select a value', 'invoicing' ),
112
                    'value'        => '',
113
                    'label'        => __( 'Dropdown Label', 'invoicing' ),
114
                    'description'  => '',
115
                    'required'     => false,
116
                    'options'      => array(
117
                        esc_attr__( 'Option One', 'invoicing' ),
118
                        esc_attr__( 'Option Two', 'invoicing' ),
119
                        esc_attr__( 'Option Three', 'invoicing' )
120
                    ),
121
                )
122
            ),
123
124
            array(
125
                'type' => 'checkbox',
126
                'name' => __( 'Checkbox', 'invoicing' ),
127
                'defaults'         => array(
128
                    'value'        => '',
129
                    'label'        => __( 'Checkbox Label', 'invoicing' ),
130
                    'description'  => '',
131
                    'required'     => false,
132
                )
133
            ),
134
135
            array( 
136
                'type' => 'radio',
137
                'name' => __( 'Multiple Choice', 'invoicing' ),
138
                'defaults'     => array(
139
                    'label'    => __( 'Select one choice', 'invoicing' ),
140
                    'options'  => array(
141
                        esc_attr__( 'Choice One', 'invoicing' ),
142
                        esc_attr__( 'Choice Two', 'invoicing' ),
143
                        esc_attr__( 'Choice Three', 'invoicing' )
144
                    ),
145
                )
146
            ),
147
148
            array( 
149
                'type' => 'date',
150
                'name' => __( 'Date', 'invoicing' ),
151
                'defaults' => array(
152
                    'value'        => '',
153
                    'label'        => __( 'Date', 'invoicing' ),
154
                    'description'  => '',
155
                    'required'     => false,
156
                )
157
            ),
158
159
            array( 
160
                'type' => 'time',
161
                'name' => __( 'Time', 'invoicing' ),
162
                'defaults' => array(
163
                    'value'        => '',
164
                    'label'        => __( 'Time', 'invoicing' ),
165
                    'description'  => '',
166
                    'required'     => false,
167
                )
168
            ),
169
170
            array( 
171
                'type' => 'number',
172
                'name' => __( 'Number', 'invoicing' ),
173
                'defaults' => array(
174
                    'placeholder'  => '',
175
                    'value'        => '',
176
                    'label'        => __( 'Number', 'invoicing' ),
177
                    'description'  => '',
178
                    'required'     => false,
179
                )
180
            ),
181
182
            array( 
183
                'type' => 'website',
184
                'name' => __( 'Website', 'invoicing' ),
185
                'defaults' => array(
186
                    'placeholder'  => 'http://example.com',
187
                    'value'        => '',
188
                    'label'        => __( 'Website', 'invoicing' ),
189
                    'description'  => '',
190
                    'required'     => false,
191
                )
192
            ),
193
194
            array( 
195
                'type' => 'email',
196
                'name' => __( 'Email', 'invoicing' ),
197
                'defaults'  => array(
198
                    'placeholder'  => '[email protected]',
199
                    'value'        => '',
200
                    'label'        => __( 'Email Address', 'invoicing' ),
201
                    'description'  => '',
202
                    'required'     => false,
203
                )
204
            ),
205
206
            array( 
207
                'type' => 'address',
208
                'name' => __( 'Address', 'invoicing' ),
209
                'defaults'  => array(
210
211
                    'fields' => array(
212
                        array(
213
                            'placeholder'  => 'Jon',
214
                            'value'        => '',
215
                            'label'        => __( 'First Name', 'invoicing' ),
216
                            'description'  => '',
217
                            'required'     => false,
218
                            'visible'      => true,
219
                            'name'         => 'wpinv_first_name',
220
                        ),
221
222
                        array(
223
                            'placeholder'  => 'Snow',
224
                            'value'        => '',
225
                            'label'        => __( 'Last Name', 'invoicing' ),
226
                            'description'  => '',
227
                            'required'     => false,
228
                            'visible'      => true,
229
                            'name'         => 'wpinv_last_name',
230
                        ),
231
                    
232
                        array(
233
                            'placeholder'  => '',
234
                            'value'        => '',
235
                            'label'        => __( 'Address', 'invoicing' ),
236
                            'description'  => '',
237
                            'required'     => false,
238
                            'visible'      => true,
239
                            'name'         => 'wpinv_address',
240
                        ),
241
242
                        array(
243
                            'placeholder'  => '',
244
                            'value'        => '',
245
                            'label'        => __( 'City', 'invoicing' ),
246
                            'description'  => '',
247
                            'required'     => false,
248
                            'visible'      => true,
249
                            'name'         => 'wpinv_city',
250
                        ),
251
252
                        array(
253
                            'placeholder'  => __( 'Select your country' ),
254
                            'value'        => '',
255
                            'label'        => __( 'Country', 'invoicing' ),
256
                            'description'  => '',
257
                            'required'     => false,
258
                            'visible'      => true,
259
                            'name'         => 'wpinv_country',
260
                        ),
261
262
                        array(
263
                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
264
                            'value'        => '',
265
                            'label'        => __( 'State / Province', 'invoicing' ),
266
                            'description'  => '',
267
                            'required'     => false,
268
                            'visible'      => true,
269
                            'name'         => 'wpinv_state',
270
                        ),
271
272
                        array(
273
                            'placeholder'  => '',
274
                            'value'        => '',
275
                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
276
                            'description'  => '',
277
                            'required'     => false,
278
                            'visible'      => true,
279
                            'name'         => 'wpinv_zip',
280
                        ),
281
282
                        array(
283
                            'placeholder'  => '',
284
                            'value'        => '',
285
                            'label'        => __( 'Phone', 'invoicing' ),
286
                            'description'  => '',
287
                            'required'     => false,
288
                            'visible'      => true,
289
                            'name'         => 'wpinv_phone',
290
                        )
291
                    )
292
                )
293
            ),
294
295
            array( 
296
                'type' => 'billing_email',
297
                'name' => __( 'Billing Email', 'invoicing' ),
298
                'defaults'  => array(
299
                    'placeholder'  => '[email protected]',
300
                    'value'        => '',
301
                    'label'        => __( 'Billing Email', 'invoicing' ),
302
                    'description'  => '',
303
                    'premade'      => true,
304
                )
305
            ),
306
/*
307
            array( 
308
                'type' => 'discount',
309
                'name' => __( 'Discount Input', 'invoicing' ),
310
                'defaults'  => array(
311
                    'value'        => '',
312
                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
313
                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
314
                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
315
                )
316
            ),*/
317
318
            array( 
319
                'type' => 'items',
320
                'name' => __( 'Items', 'invoicing' ),
321
                'defaults'  => array(
322
                    'value'        => '',
323
                    'items_type'   => 'total',
324
                    'description'  => '',
325
                    'premade'      => true,
326
                )
327
            ),
328
329
            array( 
330
                'type'       => 'pay_button',
331
                'name'       => __( 'Payment Button', 'invoicing' ),
332
                'defaults'   => array(
333
                    'value'        => '',
334
                    'class'        => 'btn-primary',
335
                    'label'        => __( 'Pay Now »', 'invoicing' ),
336
                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
337
                    'premade'      => true,
338
                )
339
            )
340
        );
341
342
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
343
        return $this->elements;
344
    }
345
346
    /**
347
     * Returns the restrict markup.
348
     */
349
    public function get_restrict_markup( $field, $field_type ) {
350
        $restrict = "$field.type=='$field_type'";
351
        return "v-if=\"$restrict\"";
352
    }
353
354
    /**
355
     * Renders the title element template.
356
     */
357
    public function render_heading_template( $field ) {
358
        $restrict = $this->get_restrict_markup( $field, 'heading' );
359
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
360
    }
361
362
    /**
363
     * Renders the title element on the frontend.
364
     */
365
    public function frontend_render_heading_template( $field ) {
366
        $tag = $field['level'];
367
        echo "<$tag>{$field['text']}</$tag>";
368
    }
369
370
    /**
371
     * Renders the edit title element template.
372
     */
373
    public function edit_heading_template( $field ) {
374
        $restrict = $this->get_restrict_markup( $field, 'heading' );
375
        $label    = __( 'Heading', 'invoicing' );
376
        $label2   = __( 'Select Heading Level', 'invoicing' );
377
        $id       = $field . '.id + "_edit"';
378
        $id2      = $field . '.id + "_edit2"';
379
380
        echo "
381
            <div $restrict>
382
                <div class='form-group'>
383
                    <label :for='$id'>$label</label>
384
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
385
                </div>
386
387
                <div class='form-group'>
388
                    <label :for='$id2'>$label2</label>
389
390
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
391
                        <option value='h1'>H1</option>
392
                        <option value='h2'>H2</option>
393
                        <option value='h3'>H3</option>
394
                        <option value='h4'>H4</option>
395
                        <option value='h5'>H5</option>
396
                        <option value='h6'>H6</option>
397
                        <option value='h7'>H7</option>
398
                    </select>
399
                </div>
400
            </div>
401
        ";
402
403
    }
404
405
    /**
406
     * Renders a paragraph element template.
407
     */
408
    public function render_paragraph_template( $field ) {
409
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
410
        $label    = "$field.text";
411
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
412
    }
413
414
    /**
415
     * Renders the paragraph element on the frontend.
416
     */
417
    public function frontend_render_paragraph_template( $field ) {
418
        echo "<p>{$field['text']}</p>";
419
    }
420
421
    /**
422
     * Renders the edit paragraph element template.
423
     */
424
    public function edit_paragraph_template( $field ) {
425
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
426
        $label    = __( 'Enter your text', 'invoicing' );
427
        $id       = $field . '.id + "_edit"';
428
        echo "
429
            <div $restrict>
430
                <div class='form-group'>
431
                    <label :for='$id'>$label</label>
432
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
433
                </div>
434
            </div>
435
        ";
436
437
    }
438
439
    /**
440
     * Renders the text element template.
441
     */
442
    public function render_text_template( $field ) {
443
        $restrict = $this->get_restrict_markup( $field, 'text' );
444
        $label    = "$field.label";
445
        echo "
446
            <div $restrict class='wpinv-payment-form-field-preview'>
447
                <div class='wpinv-payment-form-field-preview-overlay'></div>
448
                <label :for='$field.id'>{{" . $label . "}}</label>
449
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
450
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
451
            </div>    
452
        ";
453
    }
454
455
    /**
456
     * Renders the text element on the frontend.
457
     */
458
    public function frontend_render_text_template( $field ) {
459
        
460
        echo "<div class='form-group'>";
461
462
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

462
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
463
            array(
464
                'name'       => esc_attr( $field['id'] ),
465
                'id'         => esc_attr( $field['id'] ),
466
                'placeholder'=> esc_attr( $field['placeholder'] ),
467
                'required'   => (bool) $field['required'],
468
                'label'      => wp_kses_post( $field['label'] ),
469
                'no_wrap'    => true,
470
            )
471
        );
472
473
        if ( ! empty( $field['description'] ) ) {
474
            $description = wp_kses_post( $field['description'] );
475
            echo "<small class='form-text text-muted'>$description</small>";
476
        }
477
478
        echo '</div>';
479
480
    }
481
482
    /**
483
     * Renders the edit text element template.
484
     */
485
    public function edit_text_template( $field ) {
486
        $restrict = $this->get_restrict_markup( $field, 'text' );
487
        $label    = __( 'Field Label', 'invoicing' );
488
        $id       = $field . '.id + "_edit"';
489
        $label2   = __( 'Placeholder text', 'invoicing' );
490
        $id2      = $field . '.id + "_edit2"';
491
        $label3   = __( 'Help text', 'invoicing' );
492
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
493
        $id3      = $field . '.id + "_edit3"';
494
        $label5   = __( 'Is this field required?', 'invoicing' );
495
        $id4      = $field . '.id + "_edit4"';
496
        echo "
497
            <div $restrict>
498
                <div class='form-group'>
499
                    <label :for='$id'>$label</label>
500
                    <input :id='$id' v-model='$field.label' class='form-control' />
501
                </div>
502
                <div class='form-group'>
503
                    <label :for='$id2'>$label2</label>
504
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
505
                </div>
506
                <div class='form-group'>
507
                    <label :for='$id3'>$label3</label>
508
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
509
                </div>
510
                <div class='form-group form-check'>
511
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
512
                    <label class='form-check-label' :for='$id4'>$label5</label>
513
                </div>
514
            </div>
515
        ";
516
517
    }
518
519
    /**
520
     * Renders the textarea element template.
521
     */
522
    public function render_textarea_template( $field ) {
523
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
524
        $label    = "$field.label";
525
        echo "
526
            <div $restrict class='wpinv-payment-form-field-preview'>
527
                <div class='wpinv-payment-form-field-preview-overlay'></div>
528
                <label :for='$field.id'>{{" . $label . "}}</label>
529
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
530
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
531
            </div>    
532
        ";
533
    }
534
535
    /**
536
     * Renders the textarea element on the frontend.
537
     */
538
    public function frontend_render_textarea_template( $field ) {
539
        
540
        echo "<div class='form-group'>";
541
542
        echo aui()->textarea(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

542
        echo /** @scrutinizer ignore-call */ aui()->textarea(
Loading history...
543
            array(
544
                'name'       => esc_attr( $field['id'] ),
545
                'id'         => esc_attr( $field['id'] ),
546
                'placeholder'=> esc_attr( $field['placeholder'] ),
547
                'required'   => (bool) $field['required'],
548
                'label'      => wp_kses_post( $field['label'] ),
549
                'no_wrap'    => true,
550
                'rows'       => 3,
551
            )
552
        );
553
554
        if ( ! empty( $field['description'] ) ) {
555
            $description = wp_kses_post( $field['description'] );
556
            echo "<small class='form-text text-muted'>$description</small>";
557
        }
558
559
        echo '</div>';
560
561
    }
562
563
    /**
564
     * Renders the edit textarea element template.
565
     */
566
    public function edit_textarea_template( $field ) {
567
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
568
        $label    = __( 'Field Label', 'invoicing' );
569
        $id       = $field . '.id + "_edit"';
570
        $label2   = __( 'Placeholder text', 'invoicing' );
571
        $id2      = $field . '.id + "_edit2"';
572
        $label3   = __( 'Help text', 'invoicing' );
573
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
574
        $id3      = $field . '.id + "_edit3"';
575
        $label5   = __( 'Is this field required?', 'invoicing' );
576
        $id4      = $field . '.id + "_edit4"';
577
        echo "
578
            <div $restrict>
579
                <div class='form-group'>
580
                    <label :for='$id'>$label</label>
581
                    <input :id='$id' v-model='$field.label' class='form-control' />
582
                </div>
583
                <div class='form-group'>
584
                    <label :for='$id2'>$label2</label>
585
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
586
                </div>
587
                <div class='form-group'>
588
                    <label :for='$id3'>$label3</label>
589
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
590
                </div>
591
                <div class='form-group form-check'>
592
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
593
                    <label class='form-check-label' :for='$id4'>$label5</label>
594
                </div>
595
            </div>
596
        ";
597
598
    }
599
600
    /**
601
     * Renders the select element template.
602
     */
603
    public function render_select_template( $field ) {
604
        $restrict    = $this->get_restrict_markup( $field, 'select' );
605
        $label       = "$field.label";
606
        $placeholder = "$field.placeholder";
607
        $id          = $field . '.id';
608
        echo "
609
            <div $restrict class='wpinv-payment-form-field-preview'>
610
                <div class='wpinv-payment-form-field-preview-overlay'></div>
611
                <label :for='$id'>{{" . $label . "}}</label>
612
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
613
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
614
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
615
                </select>
616
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
617
            </div>
618
        ";
619
    }
620
621
    /**
622
     * Renders the select element on the frontend.
623
     */
624
    public function frontend_render_select_template( $field ) {
625
        
626
        echo "<div class='form-group'>";
627
628
        echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

628
        echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
629
            array(
630
                'name'       => esc_attr( $field['id'] ),
631
                'id'         => esc_attr( $field['id'] ),
632
                'placeholder'=> esc_attr( $field['placeholder'] ),
633
                'required'   => (bool) $field['required'],
634
                'label'      => wp_kses_post( $field['label'] ),
635
                'no_wrap'    => true,
636
                'options'    => array_combine( $field['options'], $field['options'] ),
637
            )
638
        );
639
640
        if ( ! empty( $field['description'] ) ) {
641
            $description = wp_kses_post( $field['description'] );
642
            echo "<small class='form-text text-muted'>$description</small>";
643
        }
644
645
        echo '</div>';
646
647
    }
648
649
    /**
650
     * Renders the edit select element template.
651
     */
652
    public function edit_select_template( $field ) {
653
        $restrict = $this->get_restrict_markup( $field, 'select' );
654
        $label    = __( 'Field Label', 'invoicing' );
655
        $id       = $field . '.id + "_edit"';
656
        $label2   = __( 'Placeholder text', 'invoicing' );
657
        $id2      = $field . '.id + "_edit2"';
658
        $label3   = __( 'Help text', 'invoicing' );
659
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
660
        $id3      = $field . '.id + "_edit3"';
661
        $label5   = __( 'Is this field required?', 'invoicing' );
662
        $id4      = $field . '.id + "_edit4"';
663
        $label6   = __( 'Available Options', 'invoicing' );
664
        echo "
665
            <div $restrict>
666
                <div class='form-group'>
667
                    <label :for='$id'>$label</label>
668
                    <input :id='$id' v-model='$field.label' class='form-control' />
669
                </div>
670
                <div class='form-group'>
671
                    <label :for='$id2'>$label2</label>
672
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
673
                </div>
674
                <div class='form-group'>
675
                    <label :for='$id3'>$label3</label>
676
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
677
                </div>
678
                <div class='form-group form-check'>
679
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
680
                    <label class='form-check-label' :for='$id4'>$label5</label>
681
                </div>
682
                <hr class='featurette-divider mt-4'>
683
                <h5>$label6</h5>
684
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
685
                    <input type='text' class='form-control' v-model='$field.options[index]'>
686
                    <div class='input-group-append'>
687
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
688
                    </div>
689
                </div>
690
                <div class='form-group'>
691
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
692
                </div>
693
            </div>
694
        ";
695
696
    }
697
698
    /**
699
     * Renders the checkbox element template.
700
     */
701
    public function render_checkbox_template( $field ) {
702
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
703
        $label    = "$field.label";
704
        echo "
705
            <div class='form-check' $restrict>
706
                <div class='wpinv-payment-form-field-preview-overlay'></div>
707
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
708
                <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label>
709
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
710
            </div>    
711
        ";
712
    }
713
714
    /**
715
     * Renders the checkbox element on the frontend.
716
     */
717
    public function frontend_render_checkbox_template( $field ) {
718
        
719
        echo "<div class='form-group'>";
720
721
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

721
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
722
            array(
723
                'name'       => esc_attr( $field['id'] ),
724
                'id'         => esc_attr( $field['id'] ),
725
                'required'   => (bool) $field['required'],
726
                'label'      => wp_kses_post( $field['label'] ),
727
                'no_wrap'    => true,
728
                'value'      => esc_attr__( 'Yes', 'invoicing' ),
729
                'type'       => 'checkbox',
730
            )
731
        );
732
733
        if ( ! empty( $field['description'] ) ) {
734
            $description = wp_kses_post( $field['description'] );
735
            echo "<small class='form-text text-muted'>$description</small>";
736
        }
737
738
        echo '</div>';
739
740
    }
741
742
    /**
743
     * Renders the edit checkbox element template.
744
     */
745
    public function edit_checkbox_template( $field ) {
746
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
747
        $label    = __( 'Field Label', 'invoicing' );
748
        $id       = $field . '.id + "_edit"';
749
        $label2   = __( 'Help text', 'invoicing' );
750
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
751
        $id2      = $field . '.id + "_edit2"';
752
        $label4   = __( 'Is this field required?', 'invoicing' );
753
        $id3      = $field . '.id + "_edit3"';
754
        echo "
755
            <div $restrict>
756
                <div class='form-group'>
757
                    <label :for='$id'>$label</label>
758
                    <input :id='$id' v-model='$field.label' class='form-control' />
759
                </div>
760
                <div class='form-group'>
761
                    <label :for='$id2'>$label2</label>
762
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
763
                </div>
764
                <div class='form-group form-check'>
765
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
766
                    <label class='form-check-label' :for='$id3'>$label4</label>
767
                </div>
768
            </div>
769
        ";
770
771
    }
772
773
    /**
774
     * Renders the radio element template.
775
     */
776
    public function render_radio_template( $field ) {
777
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
778
        $label       = "$field.label";
779
        $id          = $field . '.id';
780
        echo "
781
            <div $restrict class='wpinv-payment-form-field-preview'>
782
                <div class='wpinv-payment-form-field-preview-overlay'></div>
783
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
784
                <div class='form-check' v-for='(option, index) in $field.options'>
785
                    <input class='form-check-input' type='radio' :id='$id + index'>
786
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
787
                </div>
788
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
789
            </div>
790
        ";
791
    }
792
793
    /**
794
     * Renders the radio element on the frontend.
795
     */
796
    public function frontend_render_radio_template( $field ) {
797
        
798
        echo "<div class='form-group'>";
799
800
        if ( ! empty( $field['label'] ) ) {
801
            $label = wp_kses_post( $field['label'] );
802
            echo "<legend class='col-form-label'>$label</legend>";
803
        }
804
805
        foreach( $field['options'] as $index => $option ) {
806
            $id    = $field['id'] . $index;
807
            $name  = $field['id'];
808
            $value = esc_attr( $option );
809
            $label = wp_kses_post( $option );
810
811
            echo "
812
                <div class='form-check'>
813
                    <input class='form-check-input' type='radio' name='$name' id='$id' value='$value'>
814
                    <label class='form-check-label' for='$id'>$label</label>
815
                </div>
816
            ";
817
        }
818
819
        if ( ! empty( $field['description'] ) ) {
820
            $description = wp_kses_post( $field['description'] );
821
            echo "<small class='form-text text-muted'>$description</small>";
822
        }
823
824
        echo '</div>';
825
826
    }
827
828
    /**
829
     * Renders the edit radio element template.
830
     */
831
    public function edit_radio_template( $field ) {
832
        $restrict = $this->get_restrict_markup( $field, 'radio' );
833
        $label    = __( 'Field Label', 'invoicing' );
834
        $id       = $field . '.id + "_edit"';
835
        $label2   = __( 'Help text', 'invoicing' );
836
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
837
        $id2      = $field . '.id + "_edit3"';
838
        $label4   = __( 'Is this field required?', 'invoicing' );
839
        $id3      = $field . '.id + "_edit4"';
840
        $label5   = __( 'Available Options', 'invoicing' );
841
        echo "
842
            <div $restrict>
843
                <div class='form-group'>
844
                    <label :for='$id'>$label</label>
845
                    <input :id='$id' v-model='$field.label' class='form-control' />
846
                </div>
847
                <div class='form-group'>
848
                    <label :for='$id2'>$label2</label>
849
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
850
                </div>
851
                <div class='form-group form-check'>
852
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
853
                    <label class='form-check-label' :for='$id3'>$label4</label>
854
                </div>
855
                <hr class='featurette-divider mt-4'>
856
                <h5>$label5</h5>
857
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
858
                    <input type='text' class='form-control' v-model='$field.options[index]'>
859
                    <div class='input-group-append'>
860
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
861
                    </div>
862
                </div>
863
                <div class='form-group'>
864
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
865
                </div>
866
            </div>
867
        ";
868
869
    }
870
871
    /**
872
     * Renders the address element template.
873
     */
874
    public function render_address_template( $field ) {
875
        $restrict    = $this->get_restrict_markup( $field, 'address' );
876
877
        echo "
878
            <div class='wpinv-address-wrapper' $restrict>
879
                <draggable v-model='$field.fields' group='address_fields_preview'>
880
                    <div class='form-group address-field-preview wpinv-payment-form-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'>
881
                        <div class='wpinv-payment-form-field-preview-overlay'></div>
882
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
883
                        <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
884
                        <select v-else class='form-control' :id='field.name'>
885
                            <option v-if='field.placeholder'>{{field.placeholder}}</option>
886
                        </select>
887
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
888
                    </div>
889
                </draggable>
890
            </div>
891
        ";
892
    }
893
894
    /**
895
     * Renders the address element on the frontend.
896
     */
897
    public function frontend_render_address_template( $field ) {
898
        
899
        echo "<div class='wpinv-address-fields'>";
900
901
        foreach( $field['fields'] as $address_field ) {
902
903
            if ( empty( $address_field['visible'] ) ) {
904
                continue;
905
            }
906
907
            $class = esc_attr( $address_field['name'] );
908
            echo "<div class='form-group $class'>";
909
910
            $label = $address_field['label'];
911
912
            if ( ! empty( $address_field['required'] ) ) {
913
                $label .= "<span class='text-danger'> *</span>";
914
            }
915
916
            if ( 'wpinv_country' == $address_field['name'] ) {
917
918
                echo aui()->select( array(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

918
                echo /** @scrutinizer ignore-call */ aui()->select( array(
Loading history...
919
                    'options'          => wpinv_get_country_list(),
920
                    'name'             => esc_attr( $address_field['name'] ),
921
                    'id'               => esc_attr( $address_field['name'] ),
922
                    'value'            => wpinv_get_default_country(),
923
                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
924
                    'required'         => (bool) $address_field['required'],
925
                    'no_wrap'          => true,
926
                    'label'            => wp_kses_post( $label ),
927
                    'select2'          => false,
928
                ));
929
    
930
            } else if ( 'wpinv_state' == $address_field['name'] ) {
931
932
                $states = wpinv_get_country_states( wpinv_get_default_country() );
933
                $state  = wpinv_get_default_state();
934
935
                if ( ! empty( $states ) ) {
936
937
                    echo aui()->select( array(
938
                        'options'          => $states,
939
                        'name'             => esc_attr( $address_field['name'] ),
940
                        'id'               => esc_attr( $address_field['name'] ),
941
                        'value'            => $state,
942
                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
943
                        'required'         => (bool) $address_field['required'],
944
                        'no_wrap'          => true,
945
                        'label'            => wp_kses_post( $label ),
946
                        'select2'          => false,
947
                    ));
948
949
                } else {
950
951
                    echo aui()->input(
952
                        array(
953
                            'name'       => esc_attr( $address_field['name'] ),
954
                            'id'         => esc_attr( $address_field['name'] ),
955
                            'required'   => (bool) $address_field['required'],
956
                            'label'      => wp_kses_post( $label ),
957
                            'no_wrap'    => true,
958
                            'type'       => 'text',
959
                        )
960
                    );
961
962
                }
963
964
            } else {
965
966
                echo aui()->input(
967
                    array(
968
                        'name'       => esc_attr( $address_field['name'] ),
969
                        'id'         => esc_attr( $address_field['name'] ),
970
                        'required'   => (bool) $address_field['required'],
971
                        'label'      => wp_kses_post( $label ),
972
                        'no_wrap'    => true,
973
                        'placeholder' => esc_attr( $address_field['placeholder'] ),
974
                        'type'       => 'text',
975
                    )
976
                );
977
978
            }
979
            
980
981
            if ( ! empty( $address_field['description'] ) ) {
982
                $description = wp_kses_post( $address_field['description'] );
983
                echo "<small class='form-text text-muted'>$description</small>";
984
            }
985
    
986
            echo '</div>';
987
988
        }
989
990
        echo '</div>';
991
992
    }
993
994
    /**
995
     * Renders the edit address element template.
996
     */
997
    public function edit_address_template( $field ) {
998
        $restrict  = $this->get_restrict_markup( $field, 'address' );
999
        $label     = __( 'Field Label', 'invoicing' );
1000
        $label2    = __( 'Placeholder', 'invoicing' );
1001
        $label3    = __( 'Description', 'invoicing' );
1002
        $label4    = __( 'Is required', 'invoicing' );
1003
        $label5    = __( 'Is visible', 'invoicing' );
1004
        $id        = $field . '.id + "_edit_label"';
1005
        $id2       = $field . '.id + "_edit_placeholder"';
1006
        $id3       = $field . '.id + "_edit_description"';
1007
        $id4       = $field . '.id + "_edit_required"';
1008
        $id5       = $field . '.id + "_edit_visible"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id5 is dead and can be removed.
Loading history...
1009
        $id5       = $field . '.id + "_edit_visible"';
1010
        $id_main   = $field . '.id';
1011
1012
        echo "
1013
            <div $restrict :id='$id_main'>
1014
                <draggable v-model='$field.fields' group='address_fields'>
1015
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
1016
1017
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
1018
                            <span class='label'>{{field.label}}</span>
1019
                            <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'>
1020
                                <span class='dashicons dashicons-hidden'></span>
1021
                                <span class='dashicons dashicons-visibility'></span>
1022
                            </span>
1023
                            <span class='toggle-icon'>
1024
                                <span class='dashicons dashicons-arrow-down'></span>
1025
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1026
                            </span>
1027
                        </div>
1028
1029
                        <div class='wpinv-form-address-field-editor-editor-body'>
1030
                            <div class='p-2'>
1031
1032
                                <div class='form-group'>
1033
                                    <label :for='$id + index'>$label</label>
1034
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
1035
                                </div>
1036
1037
                                <div class='form-group'>
1038
                                    <label :for='$id2 + index'>$label2</label>
1039
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
1040
                                </div>
1041
1042
                                <div class='form-group'>
1043
                                    <label :for='$id3 + index'>$label3</label>
1044
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
1045
                                </div>
1046
1047
                                <div class='form-group form-check'>
1048
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
1049
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
1050
                                </div>
1051
1052
                                <div class='form-group form-check'>
1053
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
1054
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
1055
                                </div>
1056
1057
                            </div>
1058
                        </div>
1059
1060
                    </div>
1061
                </draggable>
1062
1063
            </div>
1064
        ";
1065
1066
    }
1067
1068
    /**
1069
     * Renders the email element template.
1070
     */
1071
    public function render_email_template( $field ) {
1072
        $restrict = $this->get_restrict_markup( $field, 'email' );
1073
        $label    = "$field.label";
1074
        echo "
1075
            <div $restrict class='wpinv-payment-form-field-preview'>
1076
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1077
                <label :for='$field.id'>{{" . $label . "}}</label>
1078
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1079
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1080
            </div>    
1081
        ";
1082
    }
1083
1084
    /**
1085
     * Renders the billing_email element template.
1086
     */
1087
    public function render_billing_email_template( $field ) {
1088
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1089
        $label    = "$field.label";
1090
        echo "
1091
            <div $restrict>
1092
                <label :for='$field.id'>{{" . $label . "}}</label>
1093
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1094
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1095
            </div>    
1096
        ";
1097
    }
1098
1099
    /**
1100
     * Renders the email element on the frontend.
1101
     */
1102
    public function frontend_render_email_template( $field ) {
1103
        
1104
        echo "<div class='form-group'>";
1105
1106
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1106
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1107
            array(
1108
                'name'       => esc_attr( $field['id'] ),
1109
                'id'         => esc_attr( $field['id'] ),
1110
                'required'   => (bool) $field['required'],
1111
                'label'      => wp_kses_post( $field['label'] ),
1112
                'no_wrap'    => true,
1113
                'placeholder' => esc_attr( $field['placeholder'] ),
1114
                'type'       => 'email',
1115
            )
1116
        );
1117
1118
        if ( ! empty( $field['description'] ) ) {
1119
            $description = wp_kses_post( $field['description'] );
1120
            echo "<small class='form-text text-muted'>$description</small>";
1121
        }
1122
1123
        echo '</div>';
1124
1125
    }
1126
1127
    /**
1128
     * Renders the billing email element on the frontend.
1129
     */
1130
    public function frontend_render_billing_email_template( $field ) {
1131
        
1132
        echo "<div class='form-group'>";
1133
        $value = '';
1134
1135
        if ( is_user_logged_in() ) {
1136
            $user  = wp_get_current_user();
1137
            $value = sanitize_email( $user->user_email );
1138
        }
1139
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1139
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1140
            array(
1141
                'name'       => 'billing_email',
1142
                'value'      => $value,
1143
                'id'         => esc_attr( $field['id'] ),
1144
                'required'   => true,
1145
                'label'      => wp_kses_post( $field['label'] ),
1146
                'no_wrap'    => true,
1147
                'placeholder' => esc_attr( $field['placeholder'] ),
1148
                'type'       => 'email',
1149
            )
1150
        );
1151
1152
        if ( ! empty( $field['description'] ) ) {
1153
            $description = wp_kses_post( $field['description'] );
1154
            echo "<small class='form-text text-muted'>$description</small>";
1155
        }
1156
1157
        echo '</div>';
1158
1159
    }
1160
1161
    /**
1162
     * Renders the edit email element template.
1163
     */
1164
    public function edit_email_template( $field ) {
1165
        $restrict = $this->get_restrict_markup( $field, 'email' );
1166
        $label    = __( 'Field Label', 'invoicing' );
1167
        $id       = $field . '.id + "_edit"';
1168
        $label2   = __( 'Placeholder text', 'invoicing' );
1169
        $id2      = $field . '.id + "_edit2"';
1170
        $label3   = __( 'Help text', 'invoicing' );
1171
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1172
        $id3      = $field . '.id + "_edit3"';
1173
        $label5   = __( 'Is this field required?', 'invoicing' );
1174
        $id4      = $field . '.id + "_edit4"';
1175
        echo "
1176
            <div $restrict>
1177
                <div class='form-group'>
1178
                    <label :for='$id'>$label</label>
1179
                    <input :id='$id' v-model='$field.label' class='form-control' />
1180
                </div>
1181
                <div class='form-group'>
1182
                    <label :for='$id2'>$label2</label>
1183
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1184
                </div>
1185
                <div class='form-group'>
1186
                    <label :for='$id3'>$label3</label>
1187
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1188
                </div>
1189
                <div class='form-group form-check'>
1190
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1191
                    <label class='form-check-label' :for='$id4'>$label5</label>
1192
                </div>
1193
            </div>
1194
        ";
1195
1196
    }
1197
1198
    /**
1199
     * Renders the edit billing_email element template.
1200
     */
1201
    public function edit_billing_email_template( $field ) {
1202
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1203
        $label    = __( 'Field Label', 'invoicing' );
1204
        $id       = $field . '.id + "_edit"';
1205
        $label2   = __( 'Placeholder text', 'invoicing' );
1206
        $id2      = $field . '.id + "_edit2"';
1207
        $label3   = __( 'Help text', 'invoicing' );
1208
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1209
        $id3      = $field . '.id + "_edit3"';
1210
        $label5   = __( 'Is this field required?', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label5 is dead and can be removed.
Loading history...
1211
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
1212
        echo "
1213
            <div $restrict>
1214
                <div class='form-group'>
1215
                    <label :for='$id'>$label</label>
1216
                    <input :id='$id' v-model='$field.label' class='form-control' />
1217
                </div>
1218
                <div class='form-group'>
1219
                    <label :for='$id2'>$label2</label>
1220
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1221
                </div>
1222
                <div class='form-group'>
1223
                    <label :for='$id3'>$label3</label>
1224
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1225
                </div>
1226
            </div>
1227
        ";
1228
1229
    }
1230
1231
    /**
1232
     * Renders the website element template.
1233
     */
1234
    public function render_website_template( $field ) {
1235
        $restrict = $this->get_restrict_markup( $field, 'website' );
1236
        $label    = "$field.label";
1237
        echo "
1238
            <div $restrict class='wpinv-payment-form-field-preview'>
1239
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1240
                <label :for='$field.id'>{{" . $label . "}}</label>
1241
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
1242
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1243
            </div>    
1244
        ";
1245
    }
1246
1247
    /**
1248
     * Renders the website element on the frontend.
1249
     */
1250
    public function frontend_render_website_template( $field ) {
1251
        
1252
        echo "<div class='form-group'>";
1253
1254
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1254
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1255
            array(
1256
                'name'       => esc_attr( $field['id'] ),
1257
                'id'         => esc_attr( $field['id'] ),
1258
                'required'   => (bool) $field['required'],
1259
                'label'      => wp_kses_post( $field['label'] ),
1260
                'no_wrap'    => true,
1261
                'placeholder' => esc_attr( $field['placeholder'] ),
1262
                'type'       => 'url',
1263
            )
1264
        );
1265
1266
        if ( ! empty( $field['description'] ) ) {
1267
            $description = wp_kses_post( $field['description'] );
1268
            echo "<small class='form-text text-muted'>$description</small>";
1269
        }
1270
1271
        echo '</div>';
1272
1273
    }
1274
1275
    /**
1276
     * Renders the edit website element template.
1277
     */
1278
    public function edit_website_template( $field ) {
1279
        $restrict = $this->get_restrict_markup( $field, 'website' );
1280
        $label    = __( 'Field Label', 'invoicing' );
1281
        $id       = $field . '.id + "_edit"';
1282
        $label2   = __( 'Placeholder text', 'invoicing' );
1283
        $id2      = $field . '.id + "_edit2"';
1284
        $label3   = __( 'Help text', 'invoicing' );
1285
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1286
        $id3      = $field . '.id + "_edit3"';
1287
        $label5   = __( 'Is this field required?', 'invoicing' );
1288
        $id4      = $field . '.id + "_edit4"';
1289
        echo "
1290
            <div $restrict>
1291
                <div class='form-group'>
1292
                    <label :for='$id'>$label</label>
1293
                    <input :id='$id' v-model='$field.label' class='form-control' />
1294
                </div>
1295
                <div class='form-group'>
1296
                    <label :for='$id2'>$label2</label>
1297
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1298
                </div>
1299
                <div class='form-group'>
1300
                    <label :for='$id3'>$label3</label>
1301
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1302
                </div>
1303
                <div class='form-group form-check'>
1304
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1305
                    <label class='form-check-label' :for='$id4'>$label5</label>
1306
                </div>
1307
            </div>
1308
        ";
1309
1310
    }
1311
1312
    /**
1313
     * Renders the date element template.
1314
     */
1315
    public function render_date_template( $field ) {
1316
        $restrict = $this->get_restrict_markup( $field, 'date' );
1317
        $label    = "$field.label";
1318
        echo "
1319
            <div $restrict class='wpinv-payment-form-field-preview'>
1320
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1321
                <label :for='$field.id'>{{" . $label . "}}</label>
1322
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
1323
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1324
            </div>    
1325
        ";
1326
    }
1327
1328
    /**
1329
     * Renders the date element on the frontend.
1330
     */
1331
    public function frontend_render_date_template( $field ) {
1332
        
1333
        echo "<div class='form-group'>";
1334
1335
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1335
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1336
            array(
1337
                'name'       => esc_attr( $field['id'] ),
1338
                'id'         => esc_attr( $field['id'] ),
1339
                'required'   => (bool) $field['required'],
1340
                'label'      => wp_kses_post( $field['label'] ),
1341
                'no_wrap'    => true,
1342
                'type'       => 'date',
1343
            )
1344
        );
1345
1346
        if ( ! empty( $field['description'] ) ) {
1347
            $description = wp_kses_post( $field['description'] );
1348
            echo "<small class='form-text text-muted'>$description</small>";
1349
        }
1350
1351
        echo '</div>';
1352
1353
    }
1354
1355
    /**
1356
     * Renders the edit date element template.
1357
     */
1358
    public function edit_date_template( $field ) {
1359
        $restrict = $this->get_restrict_markup( $field, 'date' );
1360
        $label    = __( 'Field Label', 'invoicing' );
1361
        $id       = $field . '.id + "_edit"';
1362
        $label3   = __( 'Help text', 'invoicing' );
1363
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1364
        $id3      = $field . '.id + "_edit3"';
1365
        $label5   = __( 'Is this field required?', 'invoicing' );
1366
        $id4      = $field . '.id + "_edit4"';
1367
        echo "
1368
            <div $restrict>
1369
                <div class='form-group'>
1370
                    <label :for='$id'>$label</label>
1371
                    <input :id='$id' v-model='$field.label' class='form-control' />
1372
                </div>
1373
                <div class='form-group'>
1374
                    <label :for='$id3'>$label3</label>
1375
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1376
                </div>
1377
                <div class='form-group form-check'>
1378
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1379
                    <label class='form-check-label' :for='$id4'>$label5</label>
1380
                </div>
1381
            </div>
1382
        ";
1383
1384
    }
1385
1386
    /**
1387
     * Renders the time element template.
1388
     */
1389
    public function render_time_template( $field ) {
1390
        $restrict = $this->get_restrict_markup( $field, 'time' );
1391
        $label    = "$field.label";
1392
        echo "
1393
            <div $restrict class='wpinv-payment-form-field-preview'>
1394
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1395
                <label :for='$field.id'>{{" . $label . "}}</label>
1396
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
1397
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1398
            </div>    
1399
        ";
1400
    }
1401
1402
    /**
1403
     * Renders the time element on the frontend.
1404
     */
1405
    public function frontend_render_time_template( $field ) {
1406
        
1407
        echo "<div class='form-group'>";
1408
1409
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1409
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1410
            array(
1411
                'name'       => esc_attr( $field['id'] ),
1412
                'id'         => esc_attr( $field['id'] ),
1413
                'required'   => (bool) $field['required'],
1414
                'label'      => wp_kses_post( $field['label'] ),
1415
                'no_wrap'    => true,
1416
                'type'       => 'time',
1417
            )
1418
        );
1419
1420
        if ( ! empty( $field['description'] ) ) {
1421
            $description = wp_kses_post( $field['description'] );
1422
            echo "<small class='form-text text-muted'>$description</small>";
1423
        }
1424
1425
        echo '</div>';
1426
1427
    }
1428
1429
    /**
1430
     * Renders the edit time element template.
1431
     */
1432
    public function edit_time_template( $field ) {
1433
        $restrict = $this->get_restrict_markup( $field, 'time' );
1434
        $label    = __( 'Field Label', 'invoicing' );
1435
        $id       = $field . '.id + "_edit"';
1436
        $label3   = __( 'Help text', 'invoicing' );
1437
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1438
        $id3      = $field . '.id + "_edit3"';
1439
        $label5   = __( 'Is this field required?', 'invoicing' );
1440
        $id4      = $field . '.id + "_edit4"';
1441
        echo "
1442
            <div $restrict>
1443
                <div class='form-group'>
1444
                    <label :for='$id'>$label</label>
1445
                    <input :id='$id' v-model='$field.label' class='form-control' />
1446
                </div>
1447
                <div class='form-group'>
1448
                    <label :for='$id3'>$label3</label>
1449
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1450
                </div>
1451
                <div class='form-group form-check'>
1452
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1453
                    <label class='form-check-label' :for='$id4'>$label5</label>
1454
                </div>
1455
            </div>
1456
        ";
1457
1458
    }
1459
1460
    /**
1461
     * Renders the number element template.
1462
     */
1463
    public function render_number_template( $field ) {
1464
        $restrict = $this->get_restrict_markup( $field, 'number' );
1465
        $label    = "$field.label";
1466
        echo "
1467
            <div $restrict class='wpinv-payment-form-field-preview'>
1468
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1469
                <label :for='$field.id'>{{" . $label . "}}</label>
1470
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1471
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1472
            </div>    
1473
        ";
1474
    }
1475
1476
    /**
1477
     * Renders the number element on the frontend.
1478
     */
1479
    public function frontend_render_number_template( $field ) {
1480
        
1481
        echo "<div class='form-group'>";
1482
1483
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1483
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1484
            array(
1485
                'name'       => esc_attr( $field['id'] ),
1486
                'id'         => esc_attr( $field['id'] ),
1487
                'required'   => (bool) $field['required'],
1488
                'label'      => wp_kses_post( $field['label'] ),
1489
                'placeholder' => esc_attr( $field['placeholder'] ),
1490
                'no_wrap'    => true,
1491
                'type'       => 'number',
1492
            )
1493
        );
1494
1495
        if ( ! empty( $field['description'] ) ) {
1496
            $description = wp_kses_post( $field['description'] );
1497
            echo "<small class='form-text text-muted'>$description</small>";
1498
        }
1499
1500
        echo '</div>';
1501
1502
    }
1503
1504
    /**
1505
     * Renders the edit number element template.
1506
     */
1507
    public function edit_number_template( $field ) {
1508
        $restrict = $this->get_restrict_markup( $field, 'number' );
1509
        $label    = __( 'Field Label', 'invoicing' );
1510
        $id       = $field . '.id + "_edit"';
1511
        $label2   = __( 'Placeholder text', 'invoicing' );
1512
        $id2      = $field . '.id + "_edit2"';
1513
        $label3   = __( 'Help text', 'invoicing' );
1514
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1515
        $id3      = $field . '.id + "_edit3"';
1516
        $label5   = __( 'Is this field required?', 'invoicing' );
1517
        $id4      = $field . '.id + "_edit4"';
1518
        echo "
1519
            <div $restrict>
1520
                <div class='form-group'>
1521
                    <label :for='$id'>$label</label>
1522
                    <input :id='$id' v-model='$field.label' class='form-control' />
1523
                </div>
1524
                <div class='form-group'>
1525
                    <label :for='$id2'>$label2</label>
1526
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1527
                </div>
1528
                <div class='form-group'>
1529
                    <label :for='$id3'>$label3</label>
1530
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1531
                </div>
1532
                <div class='form-group form-check'>
1533
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1534
                    <label class='form-check-label' :for='$id4'>$label5</label>
1535
                </div>
1536
            </div>
1537
        ";
1538
1539
    }
1540
1541
    /**
1542
     * Renders the separator element template.
1543
     */
1544
    public function render_separator_template( $field ) {
1545
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1546
        echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1547
    }
1548
1549
    /**
1550
     * Renders the separator element on the frontend.
1551
     */
1552
    public function frontend_render_separator_template( $field ) {
1553
        echo '<hr class="featurette-divider mt-0 mb-2" />';
1554
    }
1555
1556
    /**
1557
     * Renders the pay button element template.
1558
     */
1559
    public function render_pay_button_template( $field ) {
1560
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1561
        $label    = "$field.label";
1562
        echo "
1563
            <div $restrict>
1564
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1565
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1566
            </div>    
1567
        ";
1568
    }
1569
1570
    /**
1571
     * Renders the pay_button element on the frontend.
1572
     */
1573
    public function frontend_render_pay_button_template( $field ) {
1574
1575
        echo "<div class='mt-4 mb-4'>";
1576
            do_action( 'wpinv_payment_mode_select' );
1577
        echo "</div>";
1578
1579
        echo "<div class='form-group'>";
1580
1581
        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1582
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1582
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1583
            array(
1584
                'name'       => esc_attr( $field['id'] ),
1585
                'id'         => esc_attr( $field['id'] ),
1586
                'value'      => esc_attr( $field['label'] ),
1587
                'no_wrap'    => true,
1588
                'type'       => 'submit',
1589
                'class'      => $class,
1590
            )
1591
        );
1592
1593
        if ( ! empty( $field['description'] ) ) {
1594
            $description = wp_kses_post( $field['description'] );
1595
            echo "<small class='form-text text-muted'>$description</small>";
1596
        }
1597
1598
        echo '</div>';
1599
1600
    }
1601
1602
    /**
1603
     * Renders the pay button element template.
1604
     */
1605
    public function edit_pay_button_template( $field ) {
1606
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1607
        $label    = __( 'Button Text', 'invoicing' );
1608
        $id       = $field . '.id + "_edit"';
1609
        $label2   = __( 'Help text', 'invoicing' );
1610
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1611
        $id2      = $field . '.id + "_edit2"';
1612
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1613
        $id3      = $field . '.id + "_edit3"';
1614
        echo "
1615
            <div $restrict>
1616
                <div class='form-group'>
1617
                    <label :for='$id'>$label</label>
1618
                    <input :id='$id' v-model='$field.label' class='form-control' />
1619
                </div>
1620
                <div class='form-group'>
1621
                    <label :for='$id2'>$label2</label>
1622
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1623
                </div>
1624
                <div class='form-group'>
1625
                    <label :for='$id3'>$label4</label>
1626
1627
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1628
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1629
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1630
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1631
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1632
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1633
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1634
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1635
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1636
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1637
                    </select>
1638
                </div>
1639
            </div>
1640
        ";
1641
1642
    }
1643
1644
    /**
1645
     * Renders the alert element template.
1646
     */
1647
    public function render_alert_template( $field ) {
1648
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1649
        $text     = "$field.text";
1650
        echo "
1651
            <div $restrict class='alert' :class='$field.class' role='alert'>
1652
                <span v-html='$text'></span>
1653
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1654
                    <span aria-hidden='true'>&times;</span>
1655
                </button>
1656
            </div>    
1657
        ";
1658
    }
1659
1660
    /**
1661
     * Renders the alert element on the frontend.
1662
     */
1663
    public function frontend_render_alert_template( $field ) {
1664
        
1665
        echo "<div class='form-group'>";
1666
1667
        echo aui()->alert(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1667
        echo /** @scrutinizer ignore-call */ aui()->alert(
Loading history...
1668
            array(
1669
                'content'     => wp_kses_post( $field['text'] ),
1670
                'dismissible' => $field['dismissible'],
1671
                'type'        => str_replace( 'alert-', '', $field['class'] ),
1672
            )
1673
        );
1674
1675
        echo '</div>';
1676
1677
    }
1678
1679
    /**
1680
     * Renders the alert element template.
1681
     */
1682
    public function edit_alert_template( $field ) {
1683
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1684
        $label    = __( 'Alert Text', 'invoicing' );
1685
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1686
        $id       = $field . '.id + "_edit"';
1687
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1688
        $id2      = $field . '.id + "_edit2"';
1689
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1690
        $id3      = $field . '.id + "_edit3"';
1691
        echo "
1692
            <div $restrict>
1693
                <div class='form-group'>
1694
                    <label :for='$id'>$label</label>
1695
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1696
                </div>
1697
                <div class='form-group form-check'>
1698
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1699
                    <label class='form-check-label' :for='$id2'>$label3</label>
1700
                </div>
1701
                <div class='form-group'>
1702
                    <label :for='$id3'>$label4</label>
1703
1704
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1705
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1706
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1707
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1708
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1709
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1710
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1711
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1712
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1713
                    </select>
1714
                </div>
1715
            </div>
1716
        ";
1717
1718
    }
1719
1720
    /**
1721
     * Renders the discount element template.
1722
     */
1723
    public function render_discount_template( $field ) {
1724
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1725
        ?>
1726
1727
            <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
1728
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1729
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1730
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1731
                </div>
1732
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1733
            </div>
1734
1735
        <?php
1736
    }
1737
1738
    /**
1739
     * Renders the discount element on the frontend.
1740
     */
1741
    public function frontend_render_discount_template( $field ) {
1742
        
1743
        $placeholder = esc_attr( $field['input_label'] );
1744
        $label       = sanitize_text_field( $field['button_label'] );
1745
        $description = '';
1746
1747
        if ( ! empty( $field['description'] ) ) {
1748
            $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1749
        }
1750
?>
1751
1752
    <div class="form-group">
1753
        <div class="discount_field  border rounded p-3">
1754
            <div class="discount_field_inner d-flex flex-column flex-md-row">
1755
                <input  placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1756
                <a href="#" class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button"><?php echo $label; ?></a>
1757
            </div>
1758
            <?php echo $description ?>
1759
        </div>
1760
    </div>
1761
1762
<?php
1763
    }
1764
1765
    /**
1766
     * Renders the discount element template.
1767
     */
1768
    public function edit_discount_template( $field ) {
1769
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1770
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1771
        $label2   = __( 'Help Text', 'invoicing' );
1772
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1773
        $label4   = __( 'Button Text', 'invoicing' );
1774
        $id       = $field . '.id + "_edit"';
1775
        $id2      = $field . '.id + "_edit2"';
1776
        $id3      = $field . '.id + "_edit3"';
1777
        echo "
1778
            <div $restrict>
1779
                <div class='form-group'>
1780
                    <label :for='$id'>$label</label>
1781
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1782
                </div>
1783
1784
                <div class='form-group'>
1785
                    <label :for='$id2'>$label4</label>
1786
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1787
                </div>
1788
1789
                <div class='form-group'>
1790
                    <label :for='$id3'>$label2</label>
1791
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1792
                </div>
1793
1794
            </div>
1795
        ";
1796
1797
    }
1798
1799
    /**
1800
     * Renders the items element template.
1801
     */
1802
    public function render_items_template( $field ) {
1803
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1804
        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1805
        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1806
        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1807
        $label3    = __( 'Item totals will appear here.', 'invoicing' );
1808
        echo "
1809
            <div $restrict class='item_totals text-center'>
1810
                <div v-if='!is_default'>
1811
                    <div v-if='canCheckoutSeveralSubscriptions($field)' class='p-4 bg-danger text-light'>$label2</div>
1812
                    <div v-if='! canCheckoutSeveralSubscriptions($field)' class='p-4 bg-warning'>$label</div>
1813
                </div>
1814
                <div v-if='is_default'>
1815
                    <div class='p-4 bg-warning'>$label3</div>
1816
                </div>
1817
            </div>
1818
        ";
1819
    }
1820
1821
    /**
1822
     * Renders the items element on the frontend.
1823
     */
1824
    public function frontend_render_items_template( $field, $items ) {
1825
1826
        echo "<div class='form-group item_totals'>";
1827
        
1828
        $id = esc_attr( $field['id'] );
1829
        if ( 'total' == $field[ 'items_type' ] ) {
1830
            $total     = 0;
1831
            $tax       = 0;
1832
            $sub_total = 0;
1833
1834
            ?>
1835
            <div class="border item_totals_type_total">
1836
1837
                <?php
1838
                    foreach( $items as $item ) {
1839
1840
                        $amount = floatval( $item['price'] );
1841
1842
                        if ( wpinv_use_taxes() ) {
1843
1844
                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1845
1846
                            if ( wpinv_prices_include_tax() ) {
1847
                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1848
                                $item_tax = $amount - $pre_tax;
1849
                            } else {
1850
                                $pre_tax  = $amount;
1851
                                $item_tax = $amount * $rate * 0.01;
1852
                            }
1853
1854
                            $tax       = $tax + $item_tax;
1855
                            $sub_total = $sub_total + $pre_tax;
1856
                            $total     = $sub_total + $tax;
1857
1858
                        } else {
1859
                            $total  = $total + $amount;
1860
                        }
1861
1862
                        $class  = 'col-8';
1863
                        $class2 = '';
1864
1865
                        if ( ! empty( $item['allow_quantities'] ) ) {
1866
                            $class = 'col-6 pt-2';
1867
                            $class2 = 'pt-2';
1868
                        }
1869
1870
                        if ( ! empty( $item['custom_price'] ) ) {
1871
                            $class .= ' pt-2';
1872
                        }
1873
            
1874
                ?>
1875
                    <div  class="item_totals_item">
1876
                        <div class='row pl-2 pr-2 pt-2'>
1877
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
1878
1879
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1880
1881
                                <div class='col-2'>
1882
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1883
                                </div>
1884
1885
                            <?php } else { ?>
1886
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1887
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1888
1889
                                <div class='col-4 <?php echo $class2; ?>'>
1890
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1891
                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1892
                                </div>
1893
1894
                            <?php } else {?>
1895
1896
                                <div class='col-4'>
1897
                                    <div class='input-group'>
1898
1899
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1900
                                            <div class='input-group-prepend'>
1901
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1902
                                            </div>
1903
                                        <?php } ?>
1904
1905
                                        <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1906
                                    
1907
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1908
                                            <div class='input-group-append'>
1909
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1910
                                            </div>
1911
                                        <?php } ?>
1912
1913
                                    </div>
1914
                                </div>
1915
                            <?php } ?>
1916
1917
                        </div>
1918
                        <?php if ( ! empty( $item['description'] )) { ?>
1919
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1920
                        <?php } ?>
1921
                    </div>
1922
                <?php } ?>
1923
1924
                <div class='mt-4 border-top item_totals_total p-2'>
1925
1926
                    <?php if ( wpinv_use_taxes() ) { ?>
1927
                        <div class='row'>
1928
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1929
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1930
                        </div>
1931
                        <div class='row'>
1932
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1933
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1934
                        </div>
1935
                    <?php } ?>
1936
1937
                    <div class='row'>
1938
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1939
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1940
                    </div>
1941
1942
                </div>
1943
1944
            </div>
1945
        <?php } ?>
1946
1947
        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
1948
            <div class="item_totals_type_radio">
1949
1950
                <?php
1951
                    foreach( $items as $index => $item ) {
1952
1953
                        if ( ! empty( $item['required'] ) ) {
1954
                            continue;
1955
                        }
1956
                ?>
1957
                    <div  class="form-check">
1958
                        <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
1959
                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
1960
                    </div>
1961
                    <?php if ( ! empty( $item['description'] )) { ?>
1962
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1963
                    <?php } ?>
1964
                <?php } ?>
1965
1966
                <div class="mt-3 border item_totals_type_radio_totals">
1967
1968
                    <?php
1969
1970
                        $total     = 0;
1971
                        $tax       = 0;
1972
                        $sub_total = 0;
1973
1974
                        foreach ( $items as $item ) {
1975
1976
                            $class  = 'col-8';
1977
                            $class2 = '';
1978
1979
                            if ( ! empty( $item['allow_quantities'] ) ) {
1980
                                $class = 'col-6 pt-2';
1981
                                $class2 = 'pt-2';
1982
                            }
1983
1984
                            if ( ! empty( $item['custom_price'] ) ) {
1985
                                $class .= ' pt-2';
1986
                            }
1987
1988
                            $class3 = 'd-none';
1989
                            $name   = '';
1990
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
1991
1992
                                $amount = floatval( $item['price'] );
1993
1994
                                if ( wpinv_use_taxes() ) {
1995
1996
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1997
1998
                                    if ( wpinv_prices_include_tax() ) {
1999
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2000
                                        $item_tax = $amount - $pre_tax;
2001
                                    } else {
2002
                                        $pre_tax  = $amount;
2003
                                        $item_tax = $amount * $rate * 0.01;
2004
                                    }
2005
2006
                                    $tax       = $tax + $item_tax;
2007
                                    $sub_total = $sub_total + $pre_tax;
2008
                                    $total     = $sub_total + $tax;
2009
2010
                                } else {
2011
                                    $total  = $total + $amount;
2012
                                }
2013
2014
                                $class3 = '';
2015
                                $name   = "wpinv-items[{$item['id']}]";
2016
2017
                                if ( empty( $item['required'] ) ) {
2018
                                    $totals_selected_radio_item = 1;
2019
                                }
2020
2021
                            }
2022
2023
                            $class3 .= " wpinv_item_{$item['id']}";
2024
2025
                    ?>
2026
2027
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2028
                        <div class='row pl-2 pr-2 pt-2'>
2029
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2030
2031
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2032
2033
                                <div class='col-2'>
2034
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2035
                                </div>
2036
2037
                            <?php } else { ?>
2038
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2039
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2040
2041
                                <div class='col-4 <?php echo $class2; ?>'>
2042
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2043
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2044
                                </div>
2045
2046
                            <?php } else {?>
2047
2048
                                <div class='col-4'>
2049
                                    <div class='input-group'>
2050
2051
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2052
                                            <div class='input-group-prepend'>
2053
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2054
                                            </div>
2055
                                        <?php } ?>
2056
2057
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2058
                                    
2059
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2060
                                            <div class='input-group-append'>
2061
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2062
                                            </div>
2063
                                        <?php } ?>
2064
2065
                                    </div>
2066
                                </div>
2067
                            <?php } ?>
2068
2069
                        </div>
2070
                        <?php if ( ! empty( $item['description'] )) { ?>
2071
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2072
                        <?php } ?>
2073
                    </div>
2074
                <?php } ?>
2075
2076
                <div class='mt-4 border-top item_totals_total p-2'>
2077
                    <?php if ( wpinv_use_taxes() ) { ?>
2078
                        <div class='row'>
2079
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2080
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2081
                        </div>
2082
                        <div class='row'>
2083
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2084
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2085
                        </div>
2086
                    <?php } ?>
2087
2088
                    <div class='row'>
2089
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2090
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2091
                    </div>
2092
                </div>
2093
2094
            </div>
2095
            </div>
2096
        <?php } ?>
2097
2098
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2099
2100
            <div class="item_totals_type_checkbox">
2101
2102
                <?php
2103
                    foreach ( $items as $index => $item ) {
2104
2105
                        if ( ! empty( $item['required'] ) ) {
2106
                            continue;
2107
                        }
2108
2109
                        $title = sanitize_text_field(  $item['title'] );
2110
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2111
                        $item_id    = esc_attr( $id . "_$index" );
2112
                        $value = esc_attr( $item['id'] );
2113
                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2114
                        $selected_checkbox_item = 1;
2115
2116
                        echo "
2117
                            <div class='custom-control custom-checkbox'>
2118
                                <input type='checkbox' name='payment-form-items[]' id='$item_id' value='$value' class='wpi-payment-form-items-select-checkbox form-control custom-control-input' $checked>
2119
                                <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2120
                            </div>";
2121
2122
                        if ( ! empty( $item['description'] ) ) {
2123
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
2124
                        }
2125
                    }
2126
                ?>
2127
2128
                <div class="mt-3 border item_totals_type_checkbox_totals">
2129
2130
                    <?php
2131
2132
                        $total     = 0;
2133
                        $tax       = 0;
2134
                        $sub_total = 0;
2135
2136
                        foreach ( $items as $item ) {
2137
2138
                            $class  = 'col-8';
2139
                            $class2 = '';
2140
2141
                            if ( ! empty( $item['allow_quantities'] ) ) {
2142
                                $class = 'col-6 pt-2';
2143
                                $class2 = 'pt-2';
2144
                            }
2145
2146
                            if ( ! empty( $item['custom_price'] ) ) {
2147
                                $class .= ' pt-2';
2148
                            }
2149
2150
                            $class3 = 'd-none';
2151
                            $name  = '';
2152
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2153
2154
                                $amount = floatval( $item['price'] );
2155
                                if ( wpinv_use_taxes() ) {
2156
2157
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2158
2159
                                    if ( wpinv_prices_include_tax() ) {
2160
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2161
                                        $item_tax = $amount - $pre_tax;
2162
                                    } else {
2163
                                        $pre_tax  = $amount;
2164
                                        $item_tax = $amount * $rate * 0.01;
2165
                                    }
2166
2167
                                    $tax       = $tax + $item_tax;
2168
                                    $sub_total = $sub_total + $pre_tax;
2169
                                    $total     = $sub_total + $tax;
2170
2171
                                } else {
2172
                                    $total  = $total + $amount;
2173
                                }
2174
2175
                                $class3 = '';
2176
                                $name  = "wpinv-items[{$item['id']}]";
2177
2178
                                if ( empty( $item['required'] ) ) {
2179
                                    $totals_selected_checkbox_item = 1;
2180
                                }
2181
2182
                            }
2183
2184
                            $class3 .= " wpinv_item_{$item['id']}";
2185
2186
                    ?>
2187
2188
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2189
                        <div class='row pl-2 pr-2 pt-2'>
2190
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2191
2192
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2193
2194
                                <div class='col-2'>
2195
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2196
                                </div>
2197
2198
                            <?php } else { ?>
2199
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2200
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2201
2202
                                <div class='col-4 <?php echo $class2; ?>'>
2203
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2204
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2205
                                </div>
2206
2207
                            <?php } else {?>
2208
2209
                                <div class='col-4'>
2210
                                    <div class='input-group'>
2211
2212
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2213
                                            <div class='input-group-prepend'>
2214
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2215
                                            </div>
2216
                                        <?php } ?>
2217
2218
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2219
                                    
2220
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2221
                                            <div class='input-group-append'>
2222
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2223
                                            </div>
2224
                                        <?php } ?>
2225
2226
                                    </div>
2227
                                </div>
2228
                            <?php } ?>
2229
2230
                        </div>
2231
                        <?php if ( ! empty( $item['description'] )) { ?>
2232
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2233
                        <?php } ?>
2234
                    </div>
2235
                <?php } ?>
2236
2237
                <div class='mt-4 border-top item_totals_total p-2'>
2238
2239
                    <?php if ( wpinv_use_taxes() ) { ?>
2240
                        <div class='row'>
2241
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2242
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2243
                        </div>
2244
                        <div class='row'>
2245
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2246
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2247
                        </div>
2248
                    <?php } ?>
2249
2250
                    <div class='row'>
2251
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2252
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2253
                    </div>
2254
                </div>
2255
            </div>
2256
            </div>
2257
        <?php } ?>
2258
2259
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2260
2261
            <div class="item_totals_type_select">
2262
2263
                <?php
2264
2265
                    $options  = array();
2266
                    $selected = '';
2267
                    foreach ( $items as $index => $item ) {
2268
2269
                        if ( ! empty( $item['required'] ) ) {
2270
                            continue;
2271
                        }
2272
2273
                        $title = sanitize_text_field(  $item['title'] );
2274
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2275
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2276
2277
                        if ( ! isset( $selected_item ) ) {
2278
                            $selected = $item['id'];
2279
                            $selected_item = 1;
2280
                        }
2281
                        
2282
                    }
2283
2284
                    echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2284
                    echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
2285
                        array(
2286
                                'name'        => 'payment-form-items',
2287
                                'id'          => $id,
2288
                                'placeholder' => __( 'Select an item', 'invoicing' ),
2289
                                'no_wrap'     => true,
2290
                                'options'     => $options,
2291
                                'class'       => 'wpi_select2 wpinv-items-select-selector',
2292
                                'value'       => $selected,
2293
                        )
2294
                    );
2295
                ?>
2296
2297
                <div class="mt-3 border item_totals_type_select_totals">
2298
2299
                    <?php
2300
2301
                        $total     = 0;
2302
                        $tax       = 0;
2303
                        $sub_total = 0;
2304
2305
                        foreach ( $items as $item ) {
2306
2307
                            $class  = 'col-8';
2308
                            $class2 = '';
2309
2310
                            if ( ! empty( $item['allow_quantities'] ) ) {
2311
                                $class = 'col-6 pt-2';
2312
                                $class2 = 'pt-2';
2313
                            }
2314
2315
                            if ( ! empty( $item['custom_price'] ) ) {
2316
                                $class .= ' pt-2';
2317
                            }
2318
2319
                            $class3 = 'd-none';
2320
                            $name  = '';
2321
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2322
2323
                                $amount = floatval( $item['price'] );
2324
                                if ( wpinv_use_taxes() ) {
2325
2326
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2327
2328
                                    if ( wpinv_prices_include_tax() ) {
2329
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2330
                                        $item_tax = $amount - $pre_tax;
2331
                                    } else {
2332
                                        $pre_tax  = $amount;
2333
                                        $item_tax = $amount * $rate * 0.01;
2334
                                    }
2335
2336
                                    $tax       = $tax + $item_tax;
2337
                                    $sub_total = $sub_total + $pre_tax;
2338
                                    $total     = $sub_total + $tax;
2339
2340
                                } else {
2341
                                    $total  = $total + $amount;
2342
                                }
2343
2344
                                $class3 = '';
2345
                                $name  = "wpinv-items[{$item['id']}]";
2346
2347
                                if ( empty( $item['required'] ) ) {
2348
                                    $totals_selected_select_item = 1;
2349
                                }
2350
2351
                            }
2352
2353
                            $class3 .= " wpinv_item_{$item['id']}";
2354
2355
                    ?>
2356
2357
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2358
                        <div class='row pl-2 pr-2 pt-2'>
2359
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2360
2361
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2362
2363
                                <div class='col-2'>
2364
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2365
                                </div>
2366
2367
                            <?php } else { ?>
2368
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2369
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2370
2371
                                <div class='col-4 <?php echo $class2; ?>'>
2372
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2373
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2374
                                </div>
2375
2376
                            <?php } else {?>
2377
2378
                                <div class='col-4'>
2379
                                    <div class='input-group'>
2380
2381
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2382
                                            <div class='input-group-prepend'>
2383
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2384
                                            </div>
2385
                                        <?php } ?>
2386
2387
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2388
                                    
2389
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2390
                                            <div class='input-group-append'>
2391
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2392
                                            </div>
2393
                                        <?php } ?>
2394
2395
                                    </div>
2396
                                </div>
2397
                            <?php } ?>
2398
2399
                        </div>
2400
                        <?php if ( ! empty( $item['description'] )) { ?>
2401
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2402
                        <?php } ?>
2403
                    </div>
2404
                <?php } ?>
2405
2406
                <div class='mt-4 border-top item_totals_total p-2'>
2407
2408
                    <?php if ( wpinv_use_taxes() ) { ?>
2409
                        <div class='row'>
2410
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2411
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2412
                        </div>
2413
                        <div class='row'>
2414
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2415
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2416
                        </div>
2417
                    <?php } ?>
2418
                    <div class='row'>
2419
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2420
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2421
                    </div>
2422
                </div>
2423
2424
            </div>
2425
        <?php } ?>
2426
2427
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2428
2429
            <div class="item_totals_type_multi_select">
2430
2431
                <?php
2432
2433
                    $options  = array();
2434
                    $selected = array();
2435
2436
                    foreach ( $items as $index => $item ) {
2437
2438
                        if ( ! empty( $item['required'] ) ) {
2439
                            continue;
2440
                        }
2441
2442
                        $title = sanitize_text_field(  $item['title'] );
2443
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2444
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2445
2446
                        if ( ! isset( $selected_item ) ) {
2447
                            $selected = array( $item['id'] );
2448
                            $selected_item = 1;
2449
                        }
2450
2451
                    }
2452
2453
                    echo aui()->select(
2454
                        array(
2455
                                'name'        => 'payment-form-items',
2456
                                'id'          => $id,
2457
                                'no_wrap'     => true,
2458
                                'options'     => $options,
2459
                                'multiple'    => true,
2460
                                'class'       => 'wpi_select2 wpinv-items-multiselect-selector',
2461
                                'value'       => $selected,
2462
                        )
2463
                    );
2464
                ?>
2465
2466
                <div class="mt-3 border item_totals_type_select_totals">
2467
2468
                    <?php
2469
2470
                        $total     = 0;
2471
                        $tax       = 0;
2472
                        $sub_total = 0;
2473
2474
                        foreach ( $items as $item ) {
2475
2476
                            $class  = 'col-8';
2477
                            $class2 = '';
2478
2479
                            if ( ! empty( $item['allow_quantities'] ) ) {
2480
                                $class = 'col-6 pt-2';
2481
                                $class2 = 'pt-2';
2482
                            }
2483
2484
                            if ( ! empty( $item['custom_price'] ) ) {
2485
                                $class .= ' pt-2';
2486
                            }
2487
2488
                            $class3 = 'd-none';
2489
                            $name  = '';
2490
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2491
2492
                                $amount = floatval( $item['price'] );
2493
                                if ( wpinv_use_taxes() ) {
2494
2495
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2496
2497
                                    if ( wpinv_prices_include_tax() ) {
2498
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2499
                                        $item_tax = $amount - $pre_tax;
2500
                                    } else {
2501
                                        $pre_tax  = $amount;
2502
                                        $item_tax = $amount * $rate * 0.01;
2503
                                    }
2504
2505
                                    $tax       = $tax + $item_tax;
2506
                                    $sub_total = $sub_total + $pre_tax;
2507
                                    $total     = $sub_total + $tax;
2508
2509
                                } else {
2510
                                    $total  = $total + $amount;
2511
                                }
2512
2513
                                $class3 = '';
2514
                                $name  = "wpinv-items[{$item['id']}]";
2515
2516
                                if ( empty( $item['required'] ) ) {
2517
                                    $totals_selected_select_item = 1;
2518
                                }
2519
2520
                            }
2521
2522
                            $class3 .= " wpinv_item_{$item['id']}";
2523
2524
                    ?>
2525
2526
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2527
                        <div class='row pl-2 pr-2 pt-2'>
2528
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2529
2530
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2531
2532
                                <div class='col-2'>
2533
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2534
                                </div>
2535
2536
                            <?php } else { ?>
2537
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2538
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2539
2540
                                <div class='col-4 <?php echo $class2; ?>'>
2541
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2542
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2543
                                </div>
2544
2545
                            <?php } else {?>
2546
2547
                                <div class='col-4'>
2548
                                    <div class='input-group'>
2549
2550
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2551
                                            <div class='input-group-prepend'>
2552
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2553
                                            </div>
2554
                                        <?php } ?>
2555
2556
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2557
                                    
2558
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2559
                                            <div class='input-group-append'>
2560
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2561
                                            </div>
2562
                                        <?php } ?>
2563
2564
                                    </div>
2565
                                </div>
2566
                            <?php } ?>
2567
2568
                        </div>
2569
                        <?php if ( ! empty( $item['description'] )) { ?>
2570
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2571
                        <?php } ?>
2572
                    </div>
2573
                <?php } ?>
2574
2575
                <div class='mt-4 border-top item_totals_total p-2'>
2576
2577
                    <?php if ( wpinv_use_taxes() ) { ?>
2578
                        <div class='row'>
2579
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2580
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2581
                        </div>
2582
                        <div class='row'>
2583
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2584
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2585
                        </div>
2586
                    <?php } ?>
2587
2588
                    <div class='row'>
2589
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2590
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2591
                    </div>
2592
                </div>
2593
2594
            </div>
2595
        <?php } ?>
2596
        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2597
            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2598
        <?php } ?>
2599
        </div>
2600
        <?php
2601
    }
2602
2603
    /**
2604
     * Renders the items element template.
2605
     */
2606
    public function edit_items_template( $field ) {
2607
        global $wpinv_euvat, $post;
2608
2609
        $restrict = $this->get_restrict_markup( $field, 'items' );
2610
        $label    = __( 'Let customers...', 'invoicing' );
2611
        $label2   = __( 'Available Items', 'invoicing' );
2612
        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2613
        $id       = $field . '.id + "_edit"';
2614
        $id2      = $field . '.id + "_edit2"';
2615
        $id3      = $field . '.id + "_edit3"';
2616
        $id4      = $field . '.id + "_edit4"';
2617
        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2618
        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2619
        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2620
        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2621
        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2622
2623
        // Item types.
2624
        $item_types      = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
2625
        $item_types_html = '';
2626
2627
        foreach ( $item_types as $type => $_label ) {
2628
            $type  = esc_attr( $type );
2629
            $_label = esc_html( $_label );
2630
            $item_types_html .= "<option value='$type'>$_label</type>";
2631
        }
2632
2633
        // Taxes.
2634
        $taxes = '';
2635
        if ( $wpinv_euvat->allow_vat_rules() ) {
2636
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>";
2637
            $taxes .= __( 'VAT rule type', 'invoicing' );
2638
            $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>";
2639
2640
            foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
2641
                $type    = esc_attr( $type );
2642
                $_label  = esc_html( $_label );
2643
                $taxes  .= "<option value='$type'>$_label</type>";
2644
            }
2645
2646
            $taxes .= '</select></div>';
2647
        }
2648
2649
        if ( $wpinv_euvat->allow_vat_classes() ) {
2650
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>";
2651
            $taxes .= __( 'VAT class', 'invoicing' );
2652
            $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>";
2653
2654
            foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
2655
                $type    = esc_attr( $type );
2656
                $_label  = esc_html( $_label );
2657
                $taxes  .= "<option value='$type'>$_label</type>";
2658
            }
2659
2660
            $taxes .= '</select></div>';
2661
        }
2662
2663
        echo "<div $restrict>
2664
2665
                <label v-if='!is_default'>$label2</label>
2666
2667
                <draggable v-model='form_items' group='selectable_form_items'>
2668
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'>
2669
2670
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
2671
                            <span class='label'>{{item.title}}</span>
2672
                            <span class='price'>({{formatPrice(item.price)}})</span>
2673
                            <span class='toggle-icon'>
2674
                                <span class='dashicons dashicons-arrow-down'></span>
2675
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
2676
                            </span>
2677
                        </div>
2678
2679
                        <div class='wpinv-available-items-editor-body'>
2680
                            <div class='p-2'>
2681
2682
                                <div class='form-group'>
2683
                                    <label :for='$id + item.id'>Item Name</label>
2684
                                    <input :id='$id + item.id' v-model='item.title' class='form-control' />
2685
                                </div>
2686
2687
                                <div class='form-group'>
2688
                                    <label :for='$id + item.id + \"price\"'>Item Price</label>
2689
                                    <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' />
2690
                                    <small class='form-text text-muted' v-if='item.custom_price'>$label4</small>
2691
                                </div>
2692
2693
                                <div class='form-group' v-if='item.new'>
2694
                                    <label :for='$id + item.id + \"type\"'>Item Type</label>
2695
                                    <select class='form-control custom-select' v-model='item.type'>
2696
                                        $item_types_html
2697
                                    </select>
2698
                                </div>
2699
2700
                                <div v-if='item.new'>$taxes</div>
2701
2702
                                <div class='form-group form-check'>
2703
                                    <input :id='$id4 + item.id + \"custom_price\"' v-model='item.custom_price' type='checkbox' class='form-check-input' />
2704
                                    <label class='form-check-label' :for='$id4 + item.id + \"custom_price\"'>$label5</label>
2705
                                </div>
2706
2707
                                <div class='form-group' v-if='item.custom_price'>
2708
                                    <label :for='$id + item.id + \"minimum_price\"'>Minimum Price</label>
2709
                                    <input :id='$id + item.id + \"minimum_price\"' placeholder='0.00' v-model='item.minimum_price' class='form-control' />
2710
                                    <small class='form-text text-muted'>$label6</small>
2711
                                </div>
2712
2713
                                <div class='form-group form-check'>
2714
                                    <input :id='$id + item.id + \"quantities\"' v-model='item.allow_quantities' type='checkbox' class='form-check-input' />
2715
                                    <label class='form-check-label' :for='$id + item.id + \"quantities\"'>$label7</label>
2716
                                </div>
2717
2718
                                <div class='form-group form-check'>
2719
                                    <input :id='$id + item.id + \"required\"' v-model='item.required' type='checkbox' class='form-check-input' />
2720
                                    <label class='form-check-label' :for='$id + item.id + \"required\"'>$label8</label>
2721
                                </div>
2722
2723
                                <div class='form-group'>
2724
                                    <label :for='$id + item.id + \"description\"'>Item Description</label>
2725
                                    <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea>
2726
                                </div>
2727
2728
                                <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'>Delete Item</button>
2729
2730
                            </div>
2731
                        </div>
2732
2733
                    </div>
2734
                </draggable>
2735
2736
                <small v-if='! form_items.length && !is_default' class='form-text text-danger'> You have not set up any items. Please select an item below or create a new item.</small>
2737
2738
                <div class='form-group mt-2' v-if='!is_default'>
2739
2740
                    <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2741
                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2742
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2743
                    </select>
2744
2745
                </div>
2746
2747
                <div class='form-group' v-if='!is_default'>
2748
                    <input type='button' value='Add item' class='button button-primary'  @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'>
2749
                    <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small>
2750
                </div>
2751
2752
                <div class='form-group mt-5' v-if='!is_default'>
2753
                    <label :for='$id2'>$label</label>
2754
2755
                    <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2756
                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2757
                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2758
                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2759
                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2760
                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2761
                    </select>
2762
2763
                </div>
2764
2765
                <div class='form-group'>
2766
                    <label :for='$id3'>Help Text</label>
2767
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
2768
                </div>
2769
2770
            </div>
2771
        ";
2772
2773
    }
2774
2775
    /**
2776
     * Returns an array of all published items.
2777
     */
2778
    public function get_published_items() {
2779
    
2780
        $item_args = array(
2781
            'post_type'      => 'wpi_item',
2782
            'orderby'        => 'title',
2783
            'order'          => 'ASC',
2784
            'posts_per_page' => -1,
2785
            'post_status'    => array( 'publish' ),
2786
            'meta_query'     => array(
2787
                array(
2788
                    'key'       => '_wpinv_type',
2789
                    'compare'   => '!=',
2790
                    'value'     => 'package'
2791
                )
2792
            )
2793
        );
2794
    
2795
        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
2796
2797
        if ( empty( $items ) ) {
2798
            return array();
2799
        }
2800
2801
        $options    = array();
2802
        foreach ( $items as $item ) {
2803
            $title            = esc_html( $item->post_title );
2804
            $title           .= wpinv_get_item_suffix( $item->ID, false );
2805
            $id               = absint( $item->ID );
2806
            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2807
            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2808
            $description      = $item->post_excerpt;
2809
            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2810
            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2811
            $allow_quantities = false;
2812
            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2813
2814
        }
2815
        return $options;
2816
2817
    }
2818
2819
    /**
2820
     * Returns an array of items for the currently being edited form.
2821
     */
2822
    public function get_form_items( $id = false ) {
2823
        
2824
        if ( empty( $id ) ) {
2825
            return wpinv_get_data( 'sample-payment-form-items' );
2826
        }
2827
        
2828
        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2829
2830
        if ( is_array( $form_elements ) ) {
2831
            return $form_elements;
2832
        }
2833
2834
        return wpinv_get_data( 'sample-payment-form-items' );
2835
2836
    }
2837
2838
    /**
2839
     * Converts form items for use.
2840
     */
2841
    public function convert_checkout_items( $items, $invoice ) {
2842
2843
        $converted = array();
2844
        foreach ( $items as $item ) {
2845
2846
            $item_id = $item['id'];
2847
            $_item   = new WPInv_Item( $item_id );
2848
    
2849
            if( ! $_item ) {
2850
                continue;
2851
            }
2852
2853
            $converted[] = array(
2854
                'title'        => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
2855
                'id'           => $item['id'],
2856
                'price'        => $item['subtotal'],
2857
                'custom_price' => $_item->get_is_dynamic_pricing(),
2858
                'recurring'    => $_item->is_recurring(),
2859
                'description'  => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
2860
            );
2861
        }
2862
        return $converted;
2863
2864
    }
2865
2866
    /**
2867
     * Returns an array of elements for the currently being edited form.
2868
     */
2869
    public function get_form_elements( $id = false ) {
2870
2871
        if ( empty( $id ) ) {
2872
            return wpinv_get_data( 'sample-payment-form' );
2873
        }
2874
        
2875
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
2876
2877
        if ( is_array( $form_elements ) ) {
2878
            return $form_elements;
2879
        }
2880
2881
        return wpinv_get_data( 'sample-payment-form' );
2882
    }
2883
2884
    /**
2885
     * Sends a redrect response to payment details.
2886
     *
2887
     */
2888
    public function send_redirect_response( $url ) {
2889
        $url = urlencode( $url );
2890
        wp_send_json_success( $url );
2891
    }
2892
2893
    /**
2894
     * Fired when a checkout error occurs
2895
     *
2896
     */
2897
    public function checkout_error() {
2898
2899
        $errors = wpinv_get_errors();
2900
2901
        if ( ! empty( $errors ) ) {
2902
            wpinv_print_errors();
2903
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2904
        }
2905
2906
        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
2907
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2908
2909
    }
2910
2911
}
2912