Passed
Push — master ( e2c1d0...f27242 )
by Brian
04:34
created
templates/payment-forms-admin/edit/time.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
     <label class="d-block">
16
-        <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span>
16
+        <span><?php esc_html_e('Field Label', 'invoicing'); ?></span>
17 17
         <input v-model='active_form_element.label' class='form-control' type="text"/>
18 18
     </label>
19 19
 </div>
20 20
 
21 21
 <div class='form-group'>
22 22
     <label class="d-block">
23
-        <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
24
-        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
23
+        <span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
24
+        <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
25 25
     </label>
26 26
 </div>
27 27
 
28 28
 <div class='form-group form-check'>
29 29
     <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' />
30
-    <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label>
30
+    <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label>
31 31
 </div>
32 32
 
33 33
 <hr class='featurette-divider mt-4'>
34 34
 
35 35
 <div class='form-group'>
36 36
     <label class="d-block">
37
-        <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span>
37
+        <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span>
38 38
         <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" />
39
-        <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span>
39
+        <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span>
40 40
     </label>
41 41
 </div>
42 42
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-payment-form.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 class GetPaid_Meta_Box_Payment_Form {
17 17
 
18 18
     /**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23 23
     public static function output( $post ) {
24 24
         ?>
25 25
         <style>
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-	 * Save meta box data.
106
-	 *
107
-	 * @param int $post_id
108
-	 */
109
-	public static function save( $post_id ) {
105
+     * Save meta box data.
106
+     *
107
+     * @param int $post_id
108
+     */
109
+    public static function save( $post_id ) {
110 110
 
111 111
         // Prepare the form.
112 112
         $form = new GetPaid_Payment_Form( $post_id );
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
     }
138 138
 
139 139
     /**
140
-	 * Converts an array fo form items to objects.
141
-	 *
142
-	 * @param array $items
143
-	 */
144
-	public static function item_to_objects( $items ) {
140
+     * Converts an array fo form items to objects.
141
+     *
142
+     * @param array $items
143
+     */
144
+    public static function item_to_objects( $items ) {
145 145
 
146 146
         $objects = array();
147 147
 
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-    public static function output( $post ) {
23
+    public static function output($post) {
24 24
         ?>
25 25
         <style>
26 26
             .wpinv-form-builder-edit-field-wrapper label.d-block > span:first-child{
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
                 <div class="col-sm-4">
34 34
 
35 35
                     <!-- Builder tabs -->
36
-                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button>
36
+                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button>
37 37
 
38 38
                     <!-- Builder tab content -->
39 39
                     <div class="mt-4">
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
                         <!-- Available builder elements -->
42 42
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
43 43
                             <div class="wpinv-form-builder-add-field-types">
44
-                                <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
44
+                                <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
45 45
                                 <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
46 46
                                     <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
47 47
                                         <button class="button btn text-dark">
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
                         <!-- Edit an element -->
57 57
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;">
58 58
                             <div class="wpinv-form-builder-edit-field-wrapper">
59
-                                <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
60
-                                <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?>
59
+                                <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
60
+                                <?php do_action('getpaid_payment_form_edit_element_template', $post); ?>
61 61
                                 <div class='form-group'>
62
-                                    <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e( 'Width', 'invoicing' ) ?></label>
62
+                                    <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e('Width', 'invoicing') ?></label>
63 63
                                     <select class='form-control custom-select' :id="active_form_element.id + '_grid_width'" v-model='gridWidth'>
64
-                                        <option value='full'><?php esc_html_e( 'Full Width', 'invoicing' ); ?></option>
65
-                                        <option value='half'><?php esc_html_e( 'Half Width', 'invoicing' ); ?></option>
66
-                                        <option value='third'><?php esc_html_e( '1/3 Width', 'invoicing' ); ?></option>
64
+                                        <option value='full'><?php esc_html_e('Full Width', 'invoicing'); ?></option>
65
+                                        <option value='half'><?php esc_html_e('Half Width', 'invoicing'); ?></option>
66
+                                        <option value='third'><?php esc_html_e('1/3 Width', 'invoicing'); ?></option>
67 67
                                     </select>
68 68
                                 </div>
69 69
                                 <div>
70
-                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button>
70
+                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button>
71 71
                                 </div>
72 72
                             </div>
73 73
                         </div>
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 
77 77
                 </div>
78 78
                 <div class="col-sm-8 border-left">
79
-                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
80
-                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
79
+                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
80
+                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
81 81
 
82 82
                     <div class="container-fluid">
83 83
                         <draggable class="section row" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;">
84 84
                             <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element &&  active_tab=='edit_item' }, form_element.type, grid_class( form_element ) ]" @click="active_tab = 'edit_item'; active_form_element = form_element">
85 85
                                 <div class="wpinv-form-builder-element-preview-inner">
86 86
                                     <div class="wpinv-payment-form-field-preview-overlay"></div>
87
-                                    <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
87
+                                    <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
88 88
                                 </div>
89 89
                             </div>
90 90
                         </draggable>
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         </div>
99 99
         <?php
100 100
 
101
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
101
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
102 102
     }
103 103
 
104 104
     /**
@@ -106,33 +106,33 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @param int $post_id
108 108
 	 */
109
-	public static function save( $post_id ) {
109
+	public static function save($post_id) {
110 110
 
111 111
         // Prepare the form.
112
-        $form = new GetPaid_Payment_Form( $post_id );
112
+        $form = new GetPaid_Payment_Form($post_id);
113 113
 
114 114
         // Fetch form items.
115
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
115
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
116 116
 
117 117
         // Ensure that we have an array...
118
-        if ( empty( $form_items ) ) {
118
+        if (empty($form_items)) {
119 119
             $form_items = array();
120 120
         }
121 121
 
122 122
         // Add it to the form.
123
-        $form->set_items( self::item_to_objects( $form_items ) );
123
+        $form->set_items(self::item_to_objects($form_items));
124 124
 
125 125
         // Save form elements.
126
-        $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
127
-        if ( empty( $form_elements ) ) {
126
+        $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
127
+        if (empty($form_elements)) {
128 128
             $form_elements = array();
129 129
         }
130 130
 
131
-        $form->set_elements( $form_elements );
131
+        $form->set_elements($form_elements);
132 132
 
133 133
         // Persist data to the datastore.
134 134
         $form->save();
135
-        do_action( 'getpaid_payment_form_metabox_save', $post_id, $form );
135
+        do_action('getpaid_payment_form_metabox_save', $post_id, $form);
136 136
 
137 137
     }
138 138
 
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 	 *
142 142
 	 * @param array $items
143 143
 	 */
144
-	public static function item_to_objects( $items ) {
144
+	public static function item_to_objects($items) {
145 145
 
146 146
         $objects = array();
147 147
 
148
-        foreach ( $items as $item ) {
149
-            $_item = new GetPaid_Form_Item( $item['id'] );
150
-            $_item->set_allow_quantities( (bool) $item['allow_quantities'] );
151
-            $_item->set_is_required( (bool) $item['required'] );
148
+        foreach ($items as $item) {
149
+            $_item = new GetPaid_Form_Item($item['id']);
150
+            $_item->set_allow_quantities((bool) $item['allow_quantities']);
151
+            $_item->set_is_required((bool) $item['required']);
152 152
             $objects[] = $_item;
153 153
         }
154 154
 
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -12,472 +12,472 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166 166
 wpinv_error_log( $merge_tags );
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
-			return;
185
-		}
186
-
187
-		$mailer     = new GetPaid_Notification_Email_Sender();
188
-		$merge_tags = $email->get_merge_tags();
189
-
190
-		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
194
-			$email->get_attachments()
195
-		);
196
-
197
-		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
199
-			$mailer->send(
200
-				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
203
-				$email->get_attachments()
204
-			);
205
-		}
206
-
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
-		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
-		}
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
+            return;
185
+        }
186
+
187
+        $mailer     = new GetPaid_Notification_Email_Sender();
188
+        $merge_tags = $email->get_merge_tags();
189
+
190
+        $result = $mailer->send(
191
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
+            $email->get_content( $merge_tags, $extra_args ),
194
+            $email->get_attachments()
195
+        );
196
+
197
+        // Maybe send a copy to the admin.
198
+        if ( $email->include_admin_bcc() ) {
199
+            $mailer->send(
200
+                wpinv_get_admin_email(),
201
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
+                $email->get_content( $merge_tags ),
203
+                $email->get_attachments()
204
+            );
205
+        }
206
+
207
+        if ( $result ) {
208
+            $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
+        } else {
210
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
+        }
212 212
 
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
213
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214 214
 
215
-		return $result;
216
-	}
215
+        return $result;
216
+    }
217 217
 
218
-	/**
219
-	 * Also send emails to any cc users.
220
-	 *
221
-	 * @param array $recipients
222
-	 * @param GetPaid_Notification_Email $email
223
-	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
225
-
226
-		if ( ! $email->is_admin_email() ) {
227
-			$cc = $email->object->get_email_cc();
228
-
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
-			}
218
+    /**
219
+     * Also send emails to any cc users.
220
+     *
221
+     * @param array $recipients
222
+     * @param GetPaid_Notification_Email $email
223
+     */
224
+    public function filter_email_recipients( $recipients, $email ) {
225
+
226
+        if ( ! $email->is_admin_email() ) {
227
+            $cc = $email->object->get_email_cc();
228
+
229
+            if ( ! empty( $cc ) ) {
230
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
+            }
233 233
 
234
-		}
234
+        }
235 235
 
236
-		return $recipients;
236
+        return $recipients;
237 237
 
238
-	}
239
-
240
-	/**
241
-	 * Sends a new invoice notification.
242
-	 *
243
-	 * @param WPInv_Invoice $invoice
244
-	 */
245
-	public function new_invoice( $invoice ) {
238
+    }
239
+
240
+    /**
241
+     * Sends a new invoice notification.
242
+     *
243
+     * @param WPInv_Invoice $invoice
244
+     */
245
+    public function new_invoice( $invoice ) {
246 246
 
247
-		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
-			return;
250
-		}
247
+        // Only send this email for invoices created via the admin page.
248
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
+            return;
250
+        }
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
-		$recipient = wpinv_get_admin_email();
254
-
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
252
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
+        $recipient = wpinv_get_admin_email();
254
+
255
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
256 256
 
257
-	}
258
-
259
-	/**
260
-	 * Sends a cancelled invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function cancelled_invoice( $invoice ) {
257
+    }
258
+
259
+    /**
260
+     * Sends a cancelled invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function cancelled_invoice( $invoice ) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
-		$recipient = wpinv_get_admin_email();
266
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
+        $recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
270 270
 
271
-	}
271
+    }
272 272
 
273
-	/**
274
-	 * Sends a failed invoice notification.
275
-	 *
276
-	 * @param WPInv_Invoice $invoice
277
-	 */
278
-	public function failed_invoice( $invoice ) {
273
+    /**
274
+     * Sends a failed invoice notification.
275
+     *
276
+     * @param WPInv_Invoice $invoice
277
+     */
278
+    public function failed_invoice( $invoice ) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
-		$recipient = wpinv_get_admin_email();
280
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
+        $recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
288
-	 * Sends a notification whenever an invoice is put on hold.
289
-	 *
290
-	 * @param WPInv_Invoice $invoice
291
-	 */
292
-	public function onhold_invoice( $invoice ) {
287
+    /**
288
+     * Sends a notification whenever an invoice is put on hold.
289
+     *
290
+     * @param WPInv_Invoice $invoice
291
+     */
292
+    public function onhold_invoice( $invoice ) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
-		$recipient = $invoice->get_email();
294
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
+        $recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Sends a notification whenever an invoice is marked as processing payment.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice
305
-	 */
306
-	public function processing_invoice( $invoice ) {
301
+    /**
302
+     * Sends a notification whenever an invoice is marked as processing payment.
303
+     *
304
+     * @param WPInv_Invoice $invoice
305
+     */
306
+    public function processing_invoice( $invoice ) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
-		$recipient = $invoice->get_email();
308
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
+        $recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Sends a notification whenever an invoice is paid.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 */
320
-	public function completed_invoice( $invoice ) {
315
+    /**
316
+     * Sends a notification whenever an invoice is paid.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     */
320
+    public function completed_invoice( $invoice ) {
321 321
 
322
-		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
-			return;
325
-		}
322
+        // (Maybe) abort if it is a renewal invoice.
323
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
+            return;
325
+        }
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Sends a notification whenever an invoice is refunded.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function refunded_invoice( $invoice ) {
334
+    /**
335
+     * Sends a notification whenever an invoice is refunded.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function refunded_invoice( $invoice ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
349
-	 * Notifies a user about new invoices
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 * @param bool $force
353
-	 */
354
-	public function user_invoice( $invoice, $force = false ) {
348
+    /**
349
+     * Notifies a user about new invoices
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     * @param bool $force
353
+     */
354
+    public function user_invoice( $invoice, $force = false ) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
-			return;
358
-		}
356
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
+            return;
358
+        }
359 359
 
360
-		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
-			return;
363
-		}
360
+        // Only send this email for invoices created via the admin page.
361
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
+            return;
363
+        }
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
-		$recipient = $invoice->get_email();
365
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
+        $recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
369 369
 
370
-	}
370
+    }
371 371
 
372
-	/**
373
-	 * Checks if an invoice is a payment form invoice.
374
-	 *
375
-	 * @param int $invoice
376
-	 * @return bool
377
-	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-	}
372
+    /**
373
+     * Checks if an invoice is a payment form invoice.
374
+     *
375
+     * @param int $invoice
376
+     * @return bool
377
+     */
378
+    public function is_payment_form_invoice( $invoice ) {
379
+        return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
+    }
381 381
 
382
-	/**
383
-	 * Notifies admin about new invoice notes
384
-	 *
385
-	 * @param WPInv_Invoice $invoice
386
-	 * @param string $note
387
-	 */
388
-	public function user_note( $invoice, $note ) {
389
-
390
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
-		$recipient = $invoice->get_email();
382
+    /**
383
+     * Notifies admin about new invoice notes
384
+     *
385
+     * @param WPInv_Invoice $invoice
386
+     * @param string $note
387
+     */
388
+    public function user_note( $invoice, $note ) {
389
+
390
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
+        $recipient = $invoice->get_email();
392 392
 
393
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
-
395
-	}
393
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
+
395
+    }
396 396
 
397
-	/**
398
-	 * (Force) Sends overdue notices.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice
401
-	 */
402
-	public function force_send_overdue_notice( $invoice ) {
403
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
404
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
405
-	}
406
-
407
-	/**
408
-	 * Sends overdue notices.
409
-	 *
410
-	 * @TODO: Create an invoices query class.
411
-	 */
412
-	public function overdue() {
413
-		global $wpdb;
414
-
415
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
416
-
417
-		// Fetch reminder days.
418
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
-
420
-		// Abort if non is set.
421
-		if ( empty( $reminder_days ) ) {
422
-			return;
423
-		}
424
-
425
-		// Retrieve date query.
426
-		$date_query = $this->get_date_query( $reminder_days );
427
-
428
-		// Invoices table.
429
-		$table = $wpdb->prefix . 'getpaid_invoices';
430
-
431
-		// Fetch invoices.
432
-		$invoices  = $wpdb->get_col(
433
-			"SELECT posts.ID FROM $wpdb->posts as posts
397
+    /**
398
+     * (Force) Sends overdue notices.
399
+     *
400
+     * @param WPInv_Invoice $invoice
401
+     */
402
+    public function force_send_overdue_notice( $invoice ) {
403
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
404
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
405
+    }
406
+
407
+    /**
408
+     * Sends overdue notices.
409
+     *
410
+     * @TODO: Create an invoices query class.
411
+     */
412
+    public function overdue() {
413
+        global $wpdb;
414
+
415
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
416
+
417
+        // Fetch reminder days.
418
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
+
420
+        // Abort if non is set.
421
+        if ( empty( $reminder_days ) ) {
422
+            return;
423
+        }
424
+
425
+        // Retrieve date query.
426
+        $date_query = $this->get_date_query( $reminder_days );
427
+
428
+        // Invoices table.
429
+        $table = $wpdb->prefix . 'getpaid_invoices';
430
+
431
+        // Fetch invoices.
432
+        $invoices  = $wpdb->get_col(
433
+            "SELECT posts.ID FROM $wpdb->posts as posts
434 434
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
435 435
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
436 436
 
437
-		foreach ( $invoices as $invoice ) {
437
+        foreach ( $invoices as $invoice ) {
438 438
 
439
-			// Only send this email for invoices created via the admin page.
440
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
441
-				$invoice       = new WPInv_Invoice( $invoice );
442
-				$email->object = $invoice;
439
+            // Only send this email for invoices created via the admin page.
440
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
441
+                $invoice       = new WPInv_Invoice( $invoice );
442
+                $email->object = $invoice;
443 443
 
444
-				if ( $invoice->needs_payment() ) {
445
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
446
-				}
444
+                if ( $invoice->needs_payment() ) {
445
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
446
+                }
447 447
 
448
-			}
448
+            }
449 449
 
450
-		}
450
+        }
451 451
 
452
-	}
452
+    }
453 453
 
454
-	/**
455
-	 * Calculates the date query for an invoices query
456
-	 *
457
-	 * @param array $reminder_days
458
-	 * @return string
459
-	 */
460
-	public function get_date_query( $reminder_days ) {
454
+    /**
455
+     * Calculates the date query for an invoices query
456
+     *
457
+     * @param array $reminder_days
458
+     * @return string
459
+     */
460
+    public function get_date_query( $reminder_days ) {
461 461
 
462
-		$date_query = array(
463
-			'relation'  => 'OR'
464
-		);
462
+        $date_query = array(
463
+            'relation'  => 'OR'
464
+        );
465 465
 
466
-		foreach ( $reminder_days as $days ) {
467
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
466
+        foreach ( $reminder_days as $days ) {
467
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
468 468
 
469
-			$date_query[] = array(
470
-				'year'  => $date['year'],
471
-				'month' => $date['month'],
472
-				'day'   => $date['day'],
473
-			);
469
+            $date_query[] = array(
470
+                'year'  => $date['year'],
471
+                'month' => $date['month'],
472
+                'day'   => $date['day'],
473
+            );
474 474
 
475
-		}
475
+        }
476 476
 
477
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
477
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478 478
 
479
-		return $date_query->get_sql();
479
+        return $date_query->get_sql();
480 480
 
481
-	}
481
+    }
482 482
 
483 483
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,52 +119,52 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 
163 163
 			}
164 164
 
165 165
 		}
166
-wpinv_error_log( $merge_tags );
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+wpinv_error_log($merge_tags);
167
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
168 168
 	}
169 169
 
170 170
 	/**
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 * @param string|array $recipients
177 177
 	 * @param array $extra_args Extra template args.
178 178
 	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
179
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
180 180
 
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
181
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
182 182
 
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
183
+		if (apply_filters('getpaid_skip_invoice_email', false, $type, $invoice)) {
184 184
 			return;
185 185
 		}
186 186
 
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
 		$merge_tags = $email->get_merge_tags();
189 189
 
190 190
 		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
191
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
192
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
193
+			$email->get_content($merge_tags, $extra_args),
194 194
 			$email->get_attachments()
195 195
 		);
196 196
 
197 197
 		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
198
+		if ($email->include_admin_bcc()) {
199 199
 			$mailer->send(
200 200
 				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
201
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
202
+				$email->get_content($merge_tags),
203 203
 				$email->get_attachments()
204 204
 			);
205 205
 		}
206 206
 
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
207
+		if ($result) {
208
+			$invoice->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
209 209
 		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
210
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);	
211 211
 		}
212 212
 
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
213
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
214 214
 
215 215
 		return $result;
216 216
 	}
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 * @param array $recipients
222 222
 	 * @param GetPaid_Notification_Email $email
223 223
 	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
224
+	public function filter_email_recipients($recipients, $email) {
225 225
 
226
-		if ( ! $email->is_admin_email() ) {
226
+		if (!$email->is_admin_email()) {
227 227
 			$cc = $email->object->get_email_cc();
228 228
 
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
229
+			if (!empty($cc)) {
230
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
231
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
232 232
 			}
233 233
 
234 234
 		}
@@ -242,17 +242,17 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @param WPInv_Invoice $invoice
244 244
 	 */
245
-	public function new_invoice( $invoice ) {
245
+	public function new_invoice($invoice) {
246 246
 
247 247
 		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
248
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
249 249
 			return;
250 250
 		}
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
252
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
253 253
 		$recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
256 256
 
257 257
 	}
258 258
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function cancelled_invoice( $invoice ) {
264
+	public function cancelled_invoice($invoice) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
266
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
267 267
 		$recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
270 270
 
271 271
 	}
272 272
 
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @param WPInv_Invoice $invoice
277 277
 	 */
278
-	public function failed_invoice( $invoice ) {
278
+	public function failed_invoice($invoice) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
280
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
281 281
 		$recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
284 284
 
285 285
 	}
286 286
 
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	 *
290 290
 	 * @param WPInv_Invoice $invoice
291 291
 	 */
292
-	public function onhold_invoice( $invoice ) {
292
+	public function onhold_invoice($invoice) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
294
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
295 295
 		$recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
298 298
 
299 299
 	}
300 300
 
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param WPInv_Invoice $invoice
305 305
 	 */
306
-	public function processing_invoice( $invoice ) {
306
+	public function processing_invoice($invoice) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
308
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
309 309
 		$recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
312 312
 
313 313
 	}
314 314
 
@@ -317,17 +317,17 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param WPInv_Invoice $invoice
319 319
 	 */
320
-	public function completed_invoice( $invoice ) {
320
+	public function completed_invoice($invoice) {
321 321
 
322 322
 		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
323
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
324 324
 			return;
325 325
 		}
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
328 328
 		$recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
331 331
 
332 332
 	}
333 333
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @param WPInv_Invoice $invoice
338 338
 	 */
339
-	public function refunded_invoice( $invoice ) {
339
+	public function refunded_invoice($invoice) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
341
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
342 342
 		$recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
345 345
 
346 346
 	}
347 347
 
@@ -351,21 +351,21 @@  discard block
 block discarded – undo
351 351
 	 * @param WPInv_Invoice $invoice
352 352
 	 * @param bool $force
353 353
 	 */
354
-	public function user_invoice( $invoice, $force = false ) {
354
+	public function user_invoice($invoice, $force = false) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
356
+		if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) {
357 357
 			return;
358 358
 		}
359 359
 
360 360
 		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
361
+		if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
365
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
366 366
 		$recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
369 369
 
370 370
 	}
371 371
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param int $invoice
376 376
 	 * @return bool
377 377
 	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
378
+	public function is_payment_form_invoice($invoice) {
379
+		return empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true));
380 380
 	}
381 381
 
382 382
 	/**
@@ -385,12 +385,12 @@  discard block
 block discarded – undo
385 385
 	 * @param WPInv_Invoice $invoice
386 386
 	 * @param string $note
387 387
 	 */
388
-	public function user_note( $invoice, $note ) {
388
+	public function user_note($invoice, $note) {
389 389
 
390
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
390
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
391 391
 		$recipient = $invoice->get_email();
392 392
 
393
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
393
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
394 394
 
395 395
 	}
396 396
 
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
 	 *
400 400
 	 * @param WPInv_Invoice $invoice
401 401
 	 */
402
-	public function force_send_overdue_notice( $invoice ) {
403
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
404
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
402
+	public function force_send_overdue_notice($invoice) {
403
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
404
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,37 +412,37 @@  discard block
 block discarded – undo
412 412
 	public function overdue() {
413 413
 		global $wpdb;
414 414
 
415
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
415
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
416 416
 
417 417
 		// Fetch reminder days.
418
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
418
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
419 419
 
420 420
 		// Abort if non is set.
421
-		if ( empty( $reminder_days ) ) {
421
+		if (empty($reminder_days)) {
422 422
 			return;
423 423
 		}
424 424
 
425 425
 		// Retrieve date query.
426
-		$date_query = $this->get_date_query( $reminder_days );
426
+		$date_query = $this->get_date_query($reminder_days);
427 427
 
428 428
 		// Invoices table.
429 429
 		$table = $wpdb->prefix . 'getpaid_invoices';
430 430
 
431 431
 		// Fetch invoices.
432
-		$invoices  = $wpdb->get_col(
432
+		$invoices = $wpdb->get_col(
433 433
 			"SELECT posts.ID FROM $wpdb->posts as posts
434 434
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
435 435
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
436 436
 
437
-		foreach ( $invoices as $invoice ) {
437
+		foreach ($invoices as $invoice) {
438 438
 
439 439
 			// Only send this email for invoices created via the admin page.
440
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
441
-				$invoice       = new WPInv_Invoice( $invoice );
440
+			if (!$this->is_payment_form_invoice($invoice)) {
441
+				$invoice       = new WPInv_Invoice($invoice);
442 442
 				$email->object = $invoice;
443 443
 
444
-				if ( $invoice->needs_payment() ) {
445
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
444
+				if ($invoice->needs_payment()) {
445
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
446 446
 				}
447 447
 
448 448
 			}
@@ -457,14 +457,14 @@  discard block
 block discarded – undo
457 457
 	 * @param array $reminder_days
458 458
 	 * @return string
459 459
 	 */
460
-	public function get_date_query( $reminder_days ) {
460
+	public function get_date_query($reminder_days) {
461 461
 
462 462
 		$date_query = array(
463 463
 			'relation'  => 'OR'
464 464
 		);
465 465
 
466
-		foreach ( $reminder_days as $days ) {
467
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
466
+		foreach ($reminder_days as $days) {
467
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
468 468
 
469 469
 			$date_query[] = array(
470 470
 				'year'  => $date['year'],
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 
475 475
 		}
476 476
 
477
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
477
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
478 478
 
479 479
 		return $date_query->get_sql();
480 480
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
152
-		$data       = $submission->get_data();
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138
+
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
153 150
 
154
-		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151
+        $submission = $this->payment_form_submission;
152
+        $data       = $submission->get_data();
153
+
154
+        // Set-up the invoice details.
155
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
+        $invoice->set_user_id( $this->get_submission_customer() );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $data['wpi-gateway'] );
163 163
 
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
164
+        $address_confirmed = $submission->get_field( 'confirm-address' );
165
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166 166
 
167
-		if ( $submission->has_discount_code() ) {
167
+        if ( $submission->has_discount_code() ) {
168 168
             $invoice->set_discount_code( $submission->get_discount_code() );
169
-		}
170
-
171
-		getpaid_maybe_add_default_address( $invoice );
172
-		return $invoice;
173
-	}
174
-
175
-	/**
176
-	 * Retrieves the submission's customer.
177
-	 *
178
-	 * @return int The customer id.
179
-	 */
180
-	protected function get_submission_customer() {
181
-		$submission = $this->payment_form_submission;
182
-
183
-		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
185
-			return $submission->get_invoice()->get_user_id();
186
-		}
187
-
188
-		// (Maybe) create the user.
169
+        }
170
+
171
+        getpaid_maybe_add_default_address( $invoice );
172
+        return $invoice;
173
+    }
174
+
175
+    /**
176
+     * Retrieves the submission's customer.
177
+     *
178
+     * @return int The customer id.
179
+     */
180
+    protected function get_submission_customer() {
181
+        $submission = $this->payment_form_submission;
182
+
183
+        // If this is an existing invoice...
184
+        if ( $submission->has_invoice() ) {
185
+            return $submission->get_invoice()->get_user_id();
186
+        }
187
+
188
+        // (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191 191
         if ( empty( $user ) ) {
@@ -202,31 +202,31 @@  discard block
 block discarded – undo
202 202
 
203 203
         if ( is_numeric( $user ) ) {
204 204
             return $user;
205
-		}
205
+        }
206 206
 
207
-		return $user->ID;
207
+        return $user->ID;
208 208
 
209
-	}
209
+    }
210 210
 
211
-	/**
211
+    /**
212 212
      * Prepares submission data for saving to the database.
213 213
      *
214
-	 * @return array
214
+     * @return array
215 215
      */
216 216
     public function prepare_submission_data_for_saving() {
217 217
 
218
-		$submission = $this->payment_form_submission;
218
+        $submission = $this->payment_form_submission;
219 219
 
220
-		// Prepared submission details.
220
+        // Prepared submission details.
221 221
         $prepared = array();
222 222
 
223 223
         // Raw submission details.
224
-		$data     = $submission->get_data();
224
+        $data     = $submission->get_data();
225 225
 
226
-		// Loop through the submitted details.
226
+        // Loop through the submitted details.
227 227
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
228 228
 
229
-			// Skip premade fields.
229
+            // Skip premade fields.
230 230
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
231 231
                 continue;
232 232
             }
@@ -244,176 +244,176 @@  discard block
 block discarded – undo
244 244
                     $label = $field['label'];
245 245
                 }
246 246
 
247
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
247
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
248 248
 
249 249
             }
250 250
 
251
-		}
251
+        }
252 252
 
253
-		return $prepared;
253
+        return $prepared;
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
257
+    /**
258 258
      * Retrieves address details.
259 259
      *
260
-	 * @return array
261
-	 * @param WPInv_Invoice $invoice
262
-	 * @param string $type
260
+     * @return array
261
+     * @param WPInv_Invoice $invoice
262
+     * @param string $type
263 263
      */
264 264
     public function prepare_address_details( $invoice, $type = 'billing' ) {
265 265
 
266
-		$data     = $this->payment_form_submission->get_data();
267
-		$type     = sanitize_key( $type );
268
-		$address  = array();
269
-		$prepared = array();
266
+        $data     = $this->payment_form_submission->get_data();
267
+        $type     = sanitize_key( $type );
268
+        $address  = array();
269
+        $prepared = array();
270 270
 
271
-		if ( ! empty( $data[ $type ] ) ) {
272
-			$address = $data[ $type ];
273
-		}
271
+        if ( ! empty( $data[ $type ] ) ) {
272
+            $address = $data[ $type ];
273
+        }
274 274
 
275
-		// Clean address details.
276
-		foreach ( $address as $key => $value ) {
277
-			$key             = sanitize_key( $key );
278
-			$key             = str_replace( 'wpinv_', '', $key );
279
-			$value           = wpinv_clean( $value );
280
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
-		}
275
+        // Clean address details.
276
+        foreach ( $address as $key => $value ) {
277
+            $key             = sanitize_key( $key );
278
+            $key             = str_replace( 'wpinv_', '', $key );
279
+            $value           = wpinv_clean( $value );
280
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
+        }
282 282
 
283
-		// Filter address details.
284
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
283
+        // Filter address details.
284
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
285 285
 
286
-		// Remove non-whitelisted values.
287
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
286
+        // Remove non-whitelisted values.
287
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
288 288
 
289
-	}
289
+    }
290 290
 
291
-	/**
291
+    /**
292 292
      * Prepares the billing details.
293 293
      *
294
-	 * @return array
295
-	 * @param WPInv_Invoice $invoice
294
+     * @return array
295
+     * @param WPInv_Invoice $invoice
296 296
      */
297 297
     protected function prepare_billing_info( &$invoice ) {
298 298
 
299
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
299
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
300 300
 
301
-		// Update the invoice with the billing details.
302
-		$invoice->set_props( $billing_address );
301
+        // Update the invoice with the billing details.
302
+        $invoice->set_props( $billing_address );
303 303
 
304
-	}
304
+    }
305 305
 
306
-	/**
306
+    /**
307 307
      * Prepares the shipping details.
308 308
      *
309
-	 * @return array
310
-	 * @param WPInv_Invoice $invoice
309
+     * @return array
310
+     * @param WPInv_Invoice $invoice
311 311
      */
312 312
     protected function prepare_shipping_info( $invoice ) {
313 313
 
314
-		$data = $this->payment_form_submission->get_data();
314
+        $data = $this->payment_form_submission->get_data();
315 315
 
316
-		if ( empty( $data['same-shipping-address'] ) ) {
317
-			return $this->prepare_address_details( $invoice, 'shipping' );
318
-		}
316
+        if ( empty( $data['same-shipping-address'] ) ) {
317
+            return $this->prepare_address_details( $invoice, 'shipping' );
318
+        }
319 319
 
320
-		return $this->prepare_address_details( $invoice, 'billing' );
320
+        return $this->prepare_address_details( $invoice, 'billing' );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
325
-	 * Confirms the submission is valid and send users to the gateway.
326
-	 *
327
-	 * @param WPInv_Invoice $invoice
328
-	 * @param array $prepared_payment_form_data
329
-	 * @param array $shipping
330
-	 */
331
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
324
+    /**
325
+     * Confirms the submission is valid and send users to the gateway.
326
+     *
327
+     * @param WPInv_Invoice $invoice
328
+     * @param array $prepared_payment_form_data
329
+     * @param array $shipping
330
+     */
331
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
332 332
 
333
-		// Ensure the invoice exists.
333
+        // Ensure the invoice exists.
334 334
         if ( ! $invoice->exists() ) {
335 335
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
336 336
         }
337 337
 
338
-		// Save payment form data.
339
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
338
+        // Save payment form data.
339
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
340 340
         if ( ! empty( $prepared_payment_form_data ) ) {
341 341
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
342
-		}
342
+        }
343 343
 
344
-		// Save payment form data.
344
+        // Save payment form data.
345 345
         if ( ! empty( $shipping ) ) {
346 346
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
347
-		}
347
+        }
348 348
 
349
-		// Backwards compatibility.
349
+        // Backwards compatibility.
350 350
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
351 351
 
352
-		$this->process_payment( $invoice );
352
+        $this->process_payment( $invoice );
353 353
 
354 354
         // If we are here, there was an error.
355
-		wpinv_send_back_to_checkout( $invoice );
355
+        wpinv_send_back_to_checkout( $invoice );
356 356
 
357
-	}
357
+    }
358 358
 
359
-	/**
360
-	 * Processes the actual payment.
361
-	 *
362
-	 * @param WPInv_Invoice $invoice
363
-	 */
364
-	protected function process_payment( $invoice ) {
359
+    /**
360
+     * Processes the actual payment.
361
+     *
362
+     * @param WPInv_Invoice $invoice
363
+     */
364
+    protected function process_payment( $invoice ) {
365 365
 
366
-		// Clear any checkout errors.
367
-		wpinv_clear_errors();
366
+        // Clear any checkout errors.
367
+        wpinv_clear_errors();
368 368
 
369
-		// No need to send free invoices to the gateway.
370
-		if ( $invoice->is_free() ) {
371
-			$this->process_free_payment( $invoice );
372
-		}
369
+        // No need to send free invoices to the gateway.
370
+        if ( $invoice->is_free() ) {
371
+            $this->process_free_payment( $invoice );
372
+        }
373 373
 
374
-		$submission = $this->payment_form_submission;
374
+        $submission = $this->payment_form_submission;
375 375
 
376
-		// Fires before sending to the gateway.
377
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
376
+        // Fires before sending to the gateway.
377
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
378 378
 
379
-		// Allow the sumission data to be modified before it is sent to the gateway.
380
-		$submission_data    = $submission->get_data();
381
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
379
+        // Allow the sumission data to be modified before it is sent to the gateway.
380
+        $submission_data    = $submission->get_data();
381
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
383 383
 
384
-		// Validate the currency.
385
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
-		}
384
+        // Validate the currency.
385
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
+        }
388 388
 
389
-		// Check to see if we have any errors.
390
-		if ( wpinv_get_errors() ) {
391
-			wpinv_send_back_to_checkout( $invoice );
392
-		}
389
+        // Check to see if we have any errors.
390
+        if ( wpinv_get_errors() ) {
391
+            wpinv_send_back_to_checkout( $invoice );
392
+        }
393 393
 
394
-		// Send info to the gateway for payment processing
395
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
394
+        // Send info to the gateway for payment processing
395
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
396 396
 
397
-		// Backwards compatibility.
398
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
397
+        // Backwards compatibility.
398
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Marks the invoice as paid in case the checkout is free.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 */
407
-	protected function process_free_payment( $invoice ) {
402
+    /**
403
+     * Marks the invoice as paid in case the checkout is free.
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     */
407
+    protected function process_free_payment( $invoice ) {
408 408
 
409
-		$invoice->set_gateway( 'none' );
410
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
-		$invoice->mark_paid();
412
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
409
+        $invoice->set_gateway( 'none' );
410
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
+        $invoice->mark_paid();
412
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
413 413
 
414
-	}
414
+    }
415 415
 
416
-	/**
416
+    /**
417 417
      * Sends a redrect response to payment details.
418 418
      *
419 419
      */
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 		$data       = $submission->get_data();
153 153
 
154 154
 		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158
-        $invoice->set_items( $items );
159
-        $invoice->set_fees( $submission->get_fees() );
160
-        $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
163
-
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166
-
167
-		if ( $submission->has_discount_code() ) {
168
-            $invoice->set_discount_code( $submission->get_discount_code() );
155
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
156
+		$invoice->set_user_id($this->get_submission_customer());
157
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
158
+        $invoice->set_items($items);
159
+        $invoice->set_fees($submission->get_fees());
160
+        $invoice->set_taxes($submission->get_taxes());
161
+		$invoice->set_discounts($submission->get_discounts());
162
+		$invoice->set_gateway($data['wpi-gateway']);
163
+
164
+		$address_confirmed = $submission->get_field('confirm-address');
165
+		$invoice->set_address_confirmed(!empty($address_confirmed));
166
+
167
+		if ($submission->has_discount_code()) {
168
+            $invoice->set_discount_code($submission->get_discount_code());
169 169
 		}
170 170
 
171
-		getpaid_maybe_add_default_address( $invoice );
171
+		getpaid_maybe_add_default_address($invoice);
172 172
 		return $invoice;
173 173
 	}
174 174
 
@@ -181,26 +181,26 @@  discard block
 block discarded – undo
181 181
 		$submission = $this->payment_form_submission;
182 182
 
183 183
 		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
184
+		if ($submission->has_invoice()) {
185 185
 			return $submission->get_invoice()->get_user_id();
186 186
 		}
187 187
 
188 188
 		// (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191
-        if ( empty( $user ) ) {
192
-            $user = get_user_by( 'email', $submission->get_billing_email() );
191
+        if (empty($user)) {
192
+            $user = get_user_by('email', $submission->get_billing_email());
193 193
         }
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = wpinv_create_user( $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = wpinv_create_user($submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( is_wp_error( $user ) ) {
200
-            wp_send_json_error( $user->get_error_message() );
199
+        if (is_wp_error($user)) {
200
+            wp_send_json_error($user->get_error_message());
201 201
         }
202 202
 
203
-        if ( is_numeric( $user ) ) {
203
+        if (is_numeric($user)) {
204 204
             return $user;
205 205
 		}
206 206
 
@@ -221,30 +221,30 @@  discard block
 block discarded – undo
221 221
         $prepared = array();
222 222
 
223 223
         // Raw submission details.
224
-		$data     = $submission->get_data();
224
+		$data = $submission->get_data();
225 225
 
226 226
 		// Loop through the submitted details.
227
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
227
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
228 228
 
229 229
 			// Skip premade fields.
230
-            if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
230
+            if (!empty($field['premade']) || $field['type'] == 'address') {
231 231
                 continue;
232 232
             }
233 233
 
234 234
             // If it is required and not set, abort.
235
-            if ( ! $submission->is_required_field_set( $field ) ) {
236
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
235
+            if (!$submission->is_required_field_set($field)) {
236
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
237 237
             }
238 238
 
239 239
             // Handle misc fields.
240
-            if ( isset( $data[ $field['id'] ] ) ) {
240
+            if (isset($data[$field['id']])) {
241 241
                 $label = $field['id'];
242 242
 
243
-                if ( isset( $field['label'] ) ) {
243
+                if (isset($field['label'])) {
244 244
                     $label = $field['label'];
245 245
                 }
246 246
 
247
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
247
+				$prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]);
248 248
 
249 249
             }
250 250
 
@@ -261,30 +261,30 @@  discard block
 block discarded – undo
261 261
 	 * @param WPInv_Invoice $invoice
262 262
 	 * @param string $type
263 263
      */
264
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
264
+    public function prepare_address_details($invoice, $type = 'billing') {
265 265
 
266 266
 		$data     = $this->payment_form_submission->get_data();
267
-		$type     = sanitize_key( $type );
267
+		$type     = sanitize_key($type);
268 268
 		$address  = array();
269 269
 		$prepared = array();
270 270
 
271
-		if ( ! empty( $data[ $type ] ) ) {
272
-			$address = $data[ $type ];
271
+		if (!empty($data[$type])) {
272
+			$address = $data[$type];
273 273
 		}
274 274
 
275 275
 		// Clean address details.
276
-		foreach ( $address as $key => $value ) {
277
-			$key             = sanitize_key( $key );
278
-			$key             = str_replace( 'wpinv_', '', $key );
279
-			$value           = wpinv_clean( $value );
280
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
276
+		foreach ($address as $key => $value) {
277
+			$key             = sanitize_key($key);
278
+			$key             = str_replace('wpinv_', '', $key);
279
+			$value           = wpinv_clean($value);
280
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
281 281
 		}
282 282
 
283 283
 		// Filter address details.
284
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
284
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
285 285
 
286 286
 		// Remove non-whitelisted values.
287
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
287
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
288 288
 
289 289
 	}
290 290
 
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 	 * @return array
295 295
 	 * @param WPInv_Invoice $invoice
296 296
      */
297
-    protected function prepare_billing_info( &$invoice ) {
297
+    protected function prepare_billing_info(&$invoice) {
298 298
 
299
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
299
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
300 300
 
301 301
 		// Update the invoice with the billing details.
302
-		$invoice->set_props( $billing_address );
302
+		$invoice->set_props($billing_address);
303 303
 
304 304
 	}
305 305
 
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 	 * @return array
310 310
 	 * @param WPInv_Invoice $invoice
311 311
      */
312
-    protected function prepare_shipping_info( $invoice ) {
312
+    protected function prepare_shipping_info($invoice) {
313 313
 
314 314
 		$data = $this->payment_form_submission->get_data();
315 315
 
316
-		if ( empty( $data['same-shipping-address'] ) ) {
317
-			return $this->prepare_address_details( $invoice, 'shipping' );
316
+		if (empty($data['same-shipping-address'])) {
317
+			return $this->prepare_address_details($invoice, 'shipping');
318 318
 		}
319 319
 
320
-		return $this->prepare_address_details( $invoice, 'billing' );
320
+		return $this->prepare_address_details($invoice, 'billing');
321 321
 
322 322
 	}
323 323
 
@@ -328,31 +328,31 @@  discard block
 block discarded – undo
328 328
 	 * @param array $prepared_payment_form_data
329 329
 	 * @param array $shipping
330 330
 	 */
331
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
331
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
332 332
 
333 333
 		// Ensure the invoice exists.
334
-        if ( ! $invoice->exists() ) {
335
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
334
+        if (!$invoice->exists()) {
335
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
336 336
         }
337 337
 
338 338
 		// Save payment form data.
339
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
340
-        if ( ! empty( $prepared_payment_form_data ) ) {
341
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
339
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
340
+        if (!empty($prepared_payment_form_data)) {
341
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
342 342
 		}
343 343
 
344 344
 		// Save payment form data.
345
-        if ( ! empty( $shipping ) ) {
346
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
345
+        if (!empty($shipping)) {
346
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
347 347
 		}
348 348
 
349 349
 		// Backwards compatibility.
350
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
350
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
351 351
 
352
-		$this->process_payment( $invoice );
352
+		$this->process_payment($invoice);
353 353
 
354 354
         // If we are here, there was an error.
355
-		wpinv_send_back_to_checkout( $invoice );
355
+		wpinv_send_back_to_checkout($invoice);
356 356
 
357 357
 	}
358 358
 
@@ -361,41 +361,41 @@  discard block
 block discarded – undo
361 361
 	 *
362 362
 	 * @param WPInv_Invoice $invoice
363 363
 	 */
364
-	protected function process_payment( $invoice ) {
364
+	protected function process_payment($invoice) {
365 365
 
366 366
 		// Clear any checkout errors.
367 367
 		wpinv_clear_errors();
368 368
 
369 369
 		// No need to send free invoices to the gateway.
370
-		if ( $invoice->is_free() ) {
371
-			$this->process_free_payment( $invoice );
370
+		if ($invoice->is_free()) {
371
+			$this->process_free_payment($invoice);
372 372
 		}
373 373
 
374 374
 		$submission = $this->payment_form_submission;
375 375
 
376 376
 		// Fires before sending to the gateway.
377
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
377
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
378 378
 
379 379
 		// Allow the sumission data to be modified before it is sent to the gateway.
380 380
 		$submission_data    = $submission->get_data();
381
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
381
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
382
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
383 383
 
384 384
 		// Validate the currency.
385
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
385
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
386
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
387 387
 		}
388 388
 
389 389
 		// Check to see if we have any errors.
390
-		if ( wpinv_get_errors() ) {
391
-			wpinv_send_back_to_checkout( $invoice );
390
+		if (wpinv_get_errors()) {
391
+			wpinv_send_back_to_checkout($invoice);
392 392
 		}
393 393
 
394 394
 		// Send info to the gateway for payment processing
395
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
395
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
396 396
 
397 397
 		// Backwards compatibility.
398
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
398
+		wpinv_send_to_gateway($submission_gateway, $invoice);
399 399
 
400 400
 	}
401 401
 
@@ -404,12 +404,12 @@  discard block
 block discarded – undo
404 404
 	 *
405 405
 	 * @param WPInv_Invoice $invoice
406 406
 	 */
407
-	protected function process_free_payment( $invoice ) {
407
+	protected function process_free_payment($invoice) {
408 408
 
409
-		$invoice->set_gateway( 'none' );
410
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
409
+		$invoice->set_gateway('none');
410
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
411 411
 		$invoice->mark_paid();
412
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
412
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
413 413
 
414 414
 	}
415 415
 
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
      * Sends a redrect response to payment details.
418 418
      *
419 419
      */
420
-    public function send_redirect_response( $url ) {
421
-        $url = urlencode( $url );
422
-        wp_send_json_success( $url );
420
+    public function send_redirect_response($url) {
421
+        $url = urlencode($url);
422
+        wp_send_json_success($url);
423 423
     }
424 424
 
425 425
 }
Please login to merge, or discard this patch.