Passed
Push — master ( 9b92ba...883a6e )
by Stiofan
04:13
created
includes/wpinv-gateway-functions.php 1 patch
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float)wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
391 391
     
392 392
     $setting['paypal_sandbox'] = array(
393 393
             'type' => 'checkbox',
394 394
             'id'   => 'paypal_sandbox',
395
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
396
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
395
+            'name' => __('PayPal Sandbox', 'invoicing'),
396
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
397 397
             'std'  => 1
398 398
         );
399 399
         
400 400
     $setting['paypal_email'] = array(
401 401
             'type' => 'text',
402 402
             'id'   => 'paypal_email',
403
-            'name' => __( 'PayPal Email', 'invoicing' ),
404
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
405
-            'std' => __( '[email protected]', 'invoicing' ),
403
+            'name' => __('PayPal Email', 'invoicing'),
404
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
405
+            'std' => __('[email protected]', 'invoicing'),
406 406
         );
407 407
     /*
408 408
     $setting['paypal_ipn_url'] = array(
@@ -416,123 +416,123 @@  discard block
 block discarded – undo
416 416
         
417 417
     return $setting;
418 418
 }
419
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
419
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
420 420
 
421 421
 // Pre Bank Transfer settings
422
-function wpinv_gateway_settings_bank_transfer( $setting ) {
423
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
422
+function wpinv_gateway_settings_bank_transfer($setting) {
423
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
424 424
     
425 425
     $setting['bank_transfer_ac_name'] = array(
426 426
             'type' => 'text',
427 427
             'id' => 'bank_transfer_ac_name',
428
-            'name' => __( 'Account Name', 'invoicing' ),
429
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
430
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
428
+            'name' => __('Account Name', 'invoicing'),
429
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
430
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
431 431
         );
432 432
     
433 433
     $setting['bank_transfer_ac_no'] = array(
434 434
             'type' => 'text',
435 435
             'id' => 'bank_transfer_ac_no',
436
-            'name' => __( 'Account Number', 'invoicing' ),
437
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
438
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
436
+            'name' => __('Account Number', 'invoicing'),
437
+            'desc' => __('Enter your bank account number.', 'invoicing'),
438
+            'std'  =>  __('TEST1234567890', 'invoicing'),
439 439
         );
440 440
     
441 441
     $setting['bank_transfer_bank_name'] = array(
442 442
             'type' => 'text',
443 443
             'id'   => 'bank_transfer_bank_name',
444
-            'name' => __( 'Bank Name', 'invoicing' ),
445
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
446
-            'std' => __( 'ICICI Bank', 'invoicing' ),
444
+            'name' => __('Bank Name', 'invoicing'),
445
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
446
+            'std' => __('ICICI Bank', 'invoicing'),
447 447
         );
448 448
     
449 449
     $setting['bank_transfer_ifsc'] = array(
450 450
             'type' => 'text',
451 451
             'id'   => 'bank_transfer_ifsc',
452
-            'name' => __( 'IFSC Code', 'invoicing' ),
453
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
454
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
452
+            'name' => __('IFSC Code', 'invoicing'),
453
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
454
+            'std'  =>  __('ICIC0001234', 'invoicing'),
455 455
         );
456 456
         
457 457
     $setting['bank_transfer_iban'] = array(
458 458
             'type' => 'text',
459 459
             'id'   => 'bank_transfer_iban',
460
-            'name' => __( 'IBAN', 'invoicing' ),
461
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
462
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
460
+            'name' => __('IBAN', 'invoicing'),
461
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
462
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
463 463
         );
464 464
         
465 465
     $setting['bank_transfer_bic'] = array(
466 466
             'type' => 'text',
467 467
             'id'   => 'bank_transfer_bic',
468
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
469
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
468
+            'name' => __('BIC/Swift Code', 'invoicing'),
469
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
470 470
         );
471 471
 
472 472
     $setting['bank_transfer_sort_code'] = array(
473 473
         'type' => 'text',
474 474
         'id'   => 'bank_transfer_sort_code',
475
-        'name' => __( 'Sort Code', 'invoicing' ),
476
-        'std'  =>  __( '12-34-56', 'invoicing' ),
475
+        'name' => __('Sort Code', 'invoicing'),
476
+        'std'  =>  __('12-34-56', 'invoicing'),
477 477
     );
478 478
         
479 479
     $setting['bank_transfer_info'] = array(
480 480
             'id'   => 'bank_transfer_info',
481
-            'name' => __( 'Instructions', 'invoicing' ),
482
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
481
+            'name' => __('Instructions', 'invoicing'),
482
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
483 483
             'type' => 'textarea',
484
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
484
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
485 485
             'cols' => 37,
486 486
             'rows' => 5
487 487
         );
488 488
         
489 489
     return $setting;
490 490
 }
491
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
491
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
492 492
 
493 493
 // Authorize.Net settings
494
-function wpinv_gateway_settings_authorizenet( $setting ) {
495
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
496
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' );
494
+function wpinv_gateway_settings_authorizenet($setting) {
495
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
496
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing');
497 497
     
498 498
     $setting['authorizenet_sandbox'] = array(
499 499
             'type' => 'checkbox',
500 500
             'id'   => 'authorizenet_sandbox',
501
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
502
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
501
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
502
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
503 503
             'std'  => 1
504 504
         );
505 505
         
506 506
     $setting['authorizenet_login_id'] = array(
507 507
             'type' => 'text',
508 508
             'id'   => 'authorizenet_login_id',
509
-            'name' => __( 'API Login ID', 'invoicing' ),
510
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
509
+            'name' => __('API Login ID', 'invoicing'),
510
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
511 511
             'std' => '2j4rBekUnD',
512 512
         );
513 513
     
514 514
     $setting['authorizenet_transaction_key'] = array(
515 515
             'type' => 'text',
516 516
             'id'   => 'authorizenet_transaction_key',
517
-            'name' => __( 'Transaction Key', 'invoicing' ),
518
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
517
+            'name' => __('Transaction Key', 'invoicing'),
518
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
519 519
             'std' => '4vyBUOJgR74679xa',
520 520
         );
521 521
         
522 522
     $setting['authorizenet_md5_hash'] = array(
523 523
             'type' => 'text',
524 524
             'id'   => 'authorizenet_md5_hash',
525
-            'name' => __( 'MD5-Hash', 'invoicing' ),
526
-            'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
525
+            'name' => __('MD5-Hash', 'invoicing'),
526
+            'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
527 527
             'std' => '',
528 528
         );
529 529
         
530 530
     $setting['authorizenet_ipn_url'] = array(
531 531
             'type' => 'ipn_url',
532 532
             'id'   => 'authorizenet_ipn_url',
533
-            'name' => __( 'Silent Post URL', 'invoicing' ),
534
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
535
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
533
+            'name' => __('Silent Post URL', 'invoicing'),
534
+            'std' => wpinv_get_ipn_url('authorizenet'),
535
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
536 536
             'size' => 'large',
537 537
             'custom' => 'authorizenet',
538 538
             'readonly' => true
@@ -540,25 +540,25 @@  discard block
 block discarded – undo
540 540
         
541 541
     return $setting;
542 542
 }
543
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
543
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
544 544
 
545 545
 // Worldpay settings
546
-function wpinv_gateway_settings_worldpay( $setting ) {
547
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' );
546
+function wpinv_gateway_settings_worldpay($setting) {
547
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing');
548 548
     
549 549
     $setting['worldpay_sandbox'] = array(
550 550
             'type' => 'checkbox',
551 551
             'id'   => 'worldpay_sandbox',
552
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
553
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
552
+            'name' => __('Worldpay Test Mode', 'invoicing'),
553
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
554 554
             'std'  => 1
555 555
         );
556 556
         
557 557
     $setting['worldpay_instId'] = array(
558 558
             'type' => 'text',
559 559
             'id'   => 'worldpay_instId',
560
-            'name' => __( 'Installation Id', 'invoicing' ),
561
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
560
+            'name' => __('Installation Id', 'invoicing'),
561
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
562 562
             'std' => '211616',
563 563
         );
564 564
     /*
@@ -574,9 +574,9 @@  discard block
 block discarded – undo
574 574
     $setting['worldpay_ipn_url'] = array(
575 575
             'type' => 'ipn_url',
576 576
             'id'   => 'worldpay_ipn_url',
577
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
578
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
579
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
577
+            'name' => __('Worldpay Callback Url', 'invoicing'),
578
+            'std' => wpinv_get_ipn_url('worldpay'),
579
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
580 580
             'size' => 'large',
581 581
             'custom' => 'worldpay',
582 582
             'readonly' => true
@@ -584,95 +584,95 @@  discard block
 block discarded – undo
584 584
         
585 585
     return $setting;
586 586
 }
587
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
587
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
588 588
 
589
-function wpinv_ipn_url_callback( $args ) {    
590
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
589
+function wpinv_ipn_url_callback($args) {    
590
+    $sanitize_id = wpinv_sanitize_key($args['id']);
591 591
     
592 592
     $attrs = $args['readonly'] ? ' readonly' : '';
593 593
 
594
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
595
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
594
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
595
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
596 596
 
597 597
     echo $html;
598 598
 }
599 599
 
600
-function wpinv_is_test_mode( $gateway = '' ) {
601
-    if ( empty( $gateway ) ) {
600
+function wpinv_is_test_mode($gateway = '') {
601
+    if (empty($gateway)) {
602 602
         return false;
603 603
     }
604 604
     
605
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
605
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
606 606
     
607
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
607
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
608 608
 }
609 609
 
610
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
611
-    $data = array( 'wpi-listener' => 'IPN' );
610
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
611
+    $data = array('wpi-listener' => 'IPN');
612 612
     
613
-    if ( !empty( $gateway ) ) {
614
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
613
+    if (!empty($gateway)) {
614
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
615 615
     }
616 616
     
617
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
617
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
618 618
     
619
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
619
+    $ipn_url = add_query_arg($args, home_url('index.php'));
620 620
     
621
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
621
+    return apply_filters('wpinv_ipn_url', $ipn_url);
622 622
 }
623 623
 
624 624
 function wpinv_listen_for_payment_ipn() {
625 625
     // Regular PayPal IPN
626
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
627
-        do_action( 'wpinv_verify_payment_ipn' );
626
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
627
+        do_action('wpinv_verify_payment_ipn');
628 628
         
629
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
630
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ );
631
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
629
+        if (!empty($_GET['wpi-gateway'])) {
630
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__);
631
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
632 632
         }
633 633
     }
634 634
 }
635
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
635
+add_action('init', 'wpinv_listen_for_payment_ipn');
636 636
 
637 637
 function wpinv_get_bank_instructions() {
638
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
638
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
639 639
     
640
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
640
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
641 641
 }
642 642
 
643
-function wpinv_get_bank_info( $filtered = false ) {
643
+function wpinv_get_bank_info($filtered = false) {
644 644
     $bank_fields = array(
645
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
646
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
647
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
648
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
649
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
650
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
651
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
645
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
646
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
647
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
648
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
649
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
650
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
651
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
652 652
     );
653 653
     
654 654
     $bank_info = array();
655
-    foreach ( $bank_fields as $field => $label ) {
656
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
655
+    foreach ($bank_fields as $field => $label) {
656
+        if ($filtered && !($value = wpinv_get_option($field))) {
657 657
             continue;
658 658
         }
659 659
         
660
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
660
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
661 661
     }
662 662
     
663
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
663
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
664 664
 }
665 665
 
666
-function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) {
667
-    if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) {        
666
+function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) {
667
+    if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) {        
668 668
         $args                          = array();
669 669
         $args['item_id']               = $subscription_item->ID;
670
-        $args['initial_amount']        = wpinv_round_amount( $invoice->get_total() );
671
-        $args['recurring_amount']      = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
670
+        $args['initial_amount']        = wpinv_round_amount($invoice->get_total());
671
+        $args['recurring_amount']      = wpinv_round_amount($invoice->get_recurring_details('total'));
672 672
         $args['currency']              = $invoice->get_currency();
673 673
         $args['period']                = $subscription_item->get_recurring_period();
674 674
         $args['interval']              = $subscription_item->get_recurring_interval();
675
-        if ( $subscription_item->has_free_trial() ) {
675
+        if ($subscription_item->has_free_trial()) {
676 676
             $args['trial_period']      = $subscription_item->get_trial_period();
677 677
             $args['trial_interval']    = $subscription_item->get_trial_interval();
678 678
         } else {
@@ -681,25 +681,25 @@  discard block
 block discarded – undo
681 681
         }
682 682
         $args['bill_times']            = (int)$subscription_item->get_recurring_limit();
683 683
         
684
-        $invoice->update_subscription( $args );
684
+        $invoice->update_subscription($args);
685 685
     }
686 686
 }
687
-add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 );
687
+add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2);
688 688
 
689
-function wpinv_get_post_data( $method = 'request' ) {
689
+function wpinv_get_post_data($method = 'request') {
690 690
     $data       = array();
691 691
     $request    = $_REQUEST;
692 692
     
693
-    if ( $method == 'post' ) {
694
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
693
+    if ($method == 'post') {
694
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
695 695
             return $data;
696 696
         }
697 697
         
698 698
         $request = $_POST;
699 699
     }
700 700
     
701
-    if ( $method == 'get' ) {
702
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
701
+    if ($method == 'get') {
702
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
703 703
             return $data;
704 704
         }
705 705
         
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
     $post_data = '';
711 711
     
712 712
     // Fallback just in case post_max_size is lower than needed
713
-    if ( ini_get( 'allow_url_fopen' ) ) {
714
-        $post_data = file_get_contents( 'php://input' );
713
+    if (ini_get('allow_url_fopen')) {
714
+        $post_data = file_get_contents('php://input');
715 715
     } else {
716 716
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
717
-        ini_set( 'post_max_size', '12M' );
717
+        ini_set('post_max_size', '12M');
718 718
     }
719 719
     // Start the encoded data collection with notification command
720 720
     $encoded_data = 'cmd=_notify-validate';
@@ -723,58 +723,58 @@  discard block
 block discarded – undo
723 723
     $arg_separator = wpinv_get_php_arg_separator_output();
724 724
 
725 725
     // Verify there is a post_data
726
-    if ( $post_data || strlen( $post_data ) > 0 ) {
726
+    if ($post_data || strlen($post_data) > 0) {
727 727
         // Append the data
728 728
         $encoded_data .= $arg_separator . $post_data;
729 729
     } else {
730 730
         // Check if POST is empty
731
-        if ( empty( $request ) ) {
731
+        if (empty($request)) {
732 732
             // Nothing to do
733 733
             return;
734 734
         } else {
735 735
             // Loop through each POST
736
-            foreach ( $request as $key => $value ) {
736
+            foreach ($request as $key => $value) {
737 737
                 // Encode the value and append the data
738
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
738
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
739 739
             }
740 740
         }
741 741
     }
742 742
 
743 743
     // Convert collected post data to an array
744
-    parse_str( $encoded_data, $data );
744
+    parse_str($encoded_data, $data);
745 745
 
746
-    foreach ( $data as $key => $value ) {
747
-        if ( false !== strpos( $key, 'amp;' ) ) {
748
-            $new_key = str_replace( '&amp;', '&', $key );
749
-            $new_key = str_replace( 'amp;', '&' , $new_key );
746
+    foreach ($data as $key => $value) {
747
+        if (false !== strpos($key, 'amp;')) {
748
+            $new_key = str_replace('&amp;', '&', $key);
749
+            $new_key = str_replace('amp;', '&', $new_key);
750 750
 
751
-            unset( $data[ $key ] );
752
-            $data[ $new_key ] = sanitize_text_field( $value );
751
+            unset($data[$key]);
752
+            $data[$new_key] = sanitize_text_field($value);
753 753
         }
754 754
     }
755 755
     
756 756
     return $data;
757 757
 }
758 758
 
759
-function wpinv_gateway_support_subscription( $gateway ) {
759
+function wpinv_gateway_support_subscription($gateway) {
760 760
     $return = false;
761 761
     
762
-    if ( wpinv_is_gateway_active( $gateway ) ) {
763
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
762
+    if (wpinv_is_gateway_active($gateway)) {
763
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
764 764
     }
765 765
     
766 766
     return $return;
767 767
 }
768 768
 
769
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
770
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
771
-        foreach ( $gateways as $gateway => $info ) {
772
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
773
-                unset( $gateways[$gateway] );
769
+function wpinv_payment_gateways_on_cart($gateways = array()) {
770
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
771
+        foreach ($gateways as $gateway => $info) {
772
+            if (!wpinv_gateway_support_subscription($gateway)) {
773
+                unset($gateways[$gateway]);
774 774
             }
775 775
         }
776 776
     }
777 777
     
778 778
     return $gateways;
779 779
 }
780
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
781 780
\ No newline at end of file
781
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
782 782
\ No newline at end of file
Please login to merge, or discard this patch.