Passed
Push — master ( e22e0d...0d6515 )
by Brian
05:43
created
includes/wpinv-gateway-functions.php 1 patch
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains gateway functions.
4 4
  *
5 5
  */
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Returns an array of payment gateways.
@@ -11,30 +11,30 @@  discard block
 block discarded – undo
11 11
  * @return array
12 12
  */
13 13
 function wpinv_get_payment_gateways() {
14
-    return apply_filters( 'wpinv_payment_gateways', array() );
14
+    return apply_filters('wpinv_payment_gateways', array());
15 15
 }
16 16
 
17
-function wpinv_payment_gateway_titles( $all_gateways ) {
17
+function wpinv_payment_gateway_titles($all_gateways) {
18 18
     global $wpinv_options;
19 19
 
20 20
     $gateways = array();
21
-    foreach ( $all_gateways as $key => $gateway ) {
22
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
23
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
21
+    foreach ($all_gateways as $key => $gateway) {
22
+        if (!empty($wpinv_options[$key . '_title'])) {
23
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
24 24
         }
25 25
 
26
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
26
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
27 27
     }
28 28
 
29
-    asort( $gateways );
29
+    asort($gateways);
30 30
 
31
-    foreach ( $gateways as $gateway => $key ) {
31
+    foreach ($gateways as $gateway => $key) {
32 32
         $gateways[$gateway] = $all_gateways[$gateway];
33 33
     }
34 34
 
35 35
     return $gateways;
36 36
 }
37
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
37
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
38 38
 
39 39
 /**
40 40
  * Returns an array of enabled gateways.
@@ -42,38 +42,38 @@  discard block
 block discarded – undo
42 42
  * @param bool $sort
43 43
  * @return array
44 44
  */
45
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
45
+function wpinv_get_enabled_payment_gateways($sort = false) {
46 46
 
47 47
     $enabled = array();
48 48
 
49
-    foreach ( wpinv_get_payment_gateways() as $gateway => $data ) {
49
+    foreach (wpinv_get_payment_gateways() as $gateway => $data) {
50 50
 
51
-        if ( (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1 ) {
52
-            $enabled[ $gateway ] = $data;
51
+        if ((int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1) {
52
+            $enabled[$gateway] = $data;
53 53
         }
54 54
 
55 55
     }
56 56
 
57
-    if ( true === $sort ) {
58
-        uasort( $enabled, 'wpinv_sort_gateway_order' );
57
+    if (true === $sort) {
58
+        uasort($enabled, 'wpinv_sort_gateway_order');
59 59
 
60 60
         // Reorder our gateways so the default is first
61 61
         $default_gateway_id = wpinv_get_default_gateway();
62
-        if ( isset( $enabled[ $default_gateway_id ] ) ) {
62
+        if (isset($enabled[$default_gateway_id])) {
63 63
             $default_gateway = array(
64
-                $default_gateway_id => $enabled[ $default_gateway_id ]
64
+                $default_gateway_id => $enabled[$default_gateway_id]
65 65
             );
66 66
 
67
-            unset( $enabled[ $default_gateway_id ] );
68
-            $enabled = array_merge( $default_gateway, $enabled );
67
+            unset($enabled[$default_gateway_id]);
68
+            $enabled = array_merge($default_gateway, $enabled);
69 69
         }
70 70
 
71 71
     }
72 72
 
73
-    return apply_filters( 'wpinv_enabled_payment_gateways', $enabled );
73
+    return apply_filters('wpinv_enabled_payment_gateways', $enabled);
74 74
 }
75 75
 
76
-function wpinv_sort_gateway_order( $a, $b ) {
76
+function wpinv_sort_gateway_order($a, $b) {
77 77
     return $a['ordering'] - $b['ordering'];
78 78
 }
79 79
 
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
  * @param string $gateway
84 84
  * @return bool
85 85
  */
86
-function wpinv_is_gateway_active( $gateway ) {
87
-    $is_active = (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1 ;
88
-    return apply_filters( 'wpinv_is_gateway_active', $is_active, $gateway );
86
+function wpinv_is_gateway_active($gateway) {
87
+    $is_active = (int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1;
88
+    return apply_filters('wpinv_is_gateway_active', $is_active, $gateway);
89 89
 }
90 90
 
91 91
 /**
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
  * @return string|false
95 95
  */
96 96
 function wpinv_get_default_gateway() {
97
-    $default  = wpinv_get_option( 'default_gateway' );
97
+    $default  = wpinv_get_option('default_gateway');
98 98
     $gateways = wpinv_get_enabled_payment_gateways();
99
-    $default  = ! empty( $default ) && isset( $gateways[ $default ] ) ? $default : false;
99
+    $default  = !empty($default) && isset($gateways[$default]) ? $default : false;
100 100
 
101
-    return apply_filters( 'wpinv_default_gateway', $default );
101
+    return apply_filters('wpinv_default_gateway', $default);
102 102
 }
103 103
 
104 104
 /**
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
  * @param string $gateway The gateway to key.
108 108
  * @return string
109 109
  */
110
-function wpinv_get_gateway_admin_label( $gateway ) {
110
+function wpinv_get_gateway_admin_label($gateway) {
111 111
 
112
-    if ( empty( $gateway ) || 'none' == $gateway ) {
113
-        return esc_html__( 'No Gateway', 'invoicing' );
112
+    if (empty($gateway) || 'none' == $gateway) {
113
+        return esc_html__('No Gateway', 'invoicing');
114 114
     }
115 115
 
116 116
     $gateways = wpinv_get_payment_gateways();
117
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
118
-    $gateway  = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
117
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
118
+    $gateway  = apply_filters('wpinv_gateway_admin_label', $label, $gateway);
119 119
 
120
-    return wpinv_clean( $gateway );
120
+    return wpinv_clean($gateway);
121 121
 }
122 122
 
123 123
 /**
@@ -125,48 +125,48 @@  discard block
 block discarded – undo
125 125
  *
126 126
  * @param string $gateway
127 127
  */
128
-function wpinv_get_gateway_description( $gateway ) {
128
+function wpinv_get_gateway_description($gateway) {
129 129
     global $wpinv_options;
130 130
 
131
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
131
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
132 132
 
133
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
133
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_button_label( $gateway ) {
137
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
136
+function wpinv_get_gateway_button_label($gateway) {
137
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
138 138
 }
139 139
 
140
-function wpinv_get_gateway_checkout_label( $gateway ) {
140
+function wpinv_get_gateway_checkout_label($gateway) {
141 141
     $gateways = wpinv_get_payment_gateways();
142
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
142
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
143 143
 
144
-    if ( $gateway == 'none' ) {
145
-        $label = __( 'None', 'invoicing' );
144
+    if ($gateway == 'none') {
145
+        $label = __('None', 'invoicing');
146 146
     }
147 147
 
148
-    return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway );
148
+    return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway);
149 149
 }
150 150
 
151
-function wpinv_settings_sections_gateways( $settings ) {
151
+function wpinv_settings_sections_gateways($settings) {
152 152
     $gateways = wpinv_get_payment_gateways();
153
-    ksort( $gateways );
153
+    ksort($gateways);
154 154
 
155
-    foreach  ( $gateways as $key => $gateway ) {
156
-        $settings[ $key ] = $gateway['admin_label'];
155
+    foreach ($gateways as $key => $gateway) {
156
+        $settings[$key] = $gateway['admin_label'];
157 157
     }
158 158
 
159 159
     return $settings;
160 160
 }
161
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
161
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
162 162
 
163 163
 /**
164 164
  * Adds GateWay settings.
165 165
  */
166
-function wpinv_settings_gateways( $settings ) {
166
+function wpinv_settings_gateways($settings) {
167 167
 
168 168
     // Loop through each gateway.
169
-    foreach  ( wpinv_get_payment_gateways() as $key => $gateway ) {
169
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
170 170
 
171 171
         $gateway_settings = array(
172 172
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             "{$key}_header" => array(
175 175
 
176 176
                 'id'     => "{$key}_gateway_header",
177
-                'name'   => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
177
+                'name'   => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
178 178
                 'custom' => $key,
179 179
                 'type'   => 'gateway_header',
180 180
 
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
             // Activate/Deactivate a gateway.
184 184
             "{$key}_active" => array(
185 185
                 'id'   => $key . '_active',
186
-                'name' => __( 'Activate', 'invoicing' ),
187
-                'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                'name' => __('Activate', 'invoicing'),
187
+                'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                 'type' => 'checkbox',
189 189
                 'std'  => $key === 'manual' ? '1' : '0',
190 190
             ),
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
             // Activate/Deactivate sandbox.
193 193
             "{$key}_sandbox" => array(
194 194
                 'id'   => $key . '_sandbox',
195
-                'name' => __( 'Sandbox', 'invoicing' ),
196
-                'desc' => __( 'Enable sandbox to test payments', 'invoicing' ),
195
+                'name' => __('Sandbox', 'invoicing'),
196
+                'desc' => __('Enable sandbox to test payments', 'invoicing'),
197 197
                 'type' => 'checkbox',
198 198
                 'std'  => '1',
199 199
             ),
@@ -201,40 +201,40 @@  discard block
 block discarded – undo
201 201
             // Checkout title.
202 202
             "{$key}_title" => array(
203 203
                 'id'   => $key . '_title',
204
-                'name' => __( 'Checkout Title', 'invoicing' ),
205
-                'std'  => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '',
204
+                'name' => __('Checkout Title', 'invoicing'),
205
+                'std'  => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '',
206 206
                 'type' => 'text',
207 207
             ),
208 208
 
209 209
             // Checkout description.
210 210
             "{$key}_desc" => array(
211 211
                 'id'   => $key . '_desc',
212
-                'name' => __( 'Checkout Description', 'invoicing' ),
213
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
212
+                'name' => __('Checkout Description', 'invoicing'),
213
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
214 214
                 'type' => 'text',
215 215
             ),
216 216
 
217 217
             // Checkout order.
218 218
             "{$key}_ordering" => array(
219 219
                 'id'   => $key . '_ordering',
220
-                'name' => __( 'Priority', 'invoicing' ),
221
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
220
+                'name' => __('Priority', 'invoicing'),
221
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
222 222
                 'type' => 'number',
223 223
                 'step' => '1',
224 224
                 'min'  => '0',
225 225
                 'max'  => '100000',
226
-                'std'  => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10',
226
+                'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
227 227
             ),
228 228
 
229 229
         );
230 230
 
231 231
         // Maybe remove the sandbox.
232
-        if ( ! getpaid_payment_gateway_supports( $key, 'sandbox' ) ) {
233
-            unset( $gateway_settings["{$key}_sandbox"] );
232
+        if (!getpaid_payment_gateway_supports($key, 'sandbox')) {
233
+            unset($gateway_settings["{$key}_sandbox"]);
234 234
         }
235 235
 
236
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway );
237
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway );
236
+        $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway);
237
+        $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway);
238 238
 
239 239
         $settings[$key] = $gateway_settings;
240 240
     }
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
     return $settings;
243 243
 
244 244
 }
245
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
245
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
246 246
 
247
-function wpinv_gateway_header_callback( $args ) {
248
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
247
+function wpinv_gateway_header_callback($args) {
248
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
249 249
 }
250 250
 
251 251
 /**
@@ -256,64 +256,64 @@  discard block
 block discarded – undo
256 256
  * @return bool
257 257
  * @since 2.3.0
258 258
  */
259
-function getpaid_payment_gateway_supports( $gateway, $feature ) {
259
+function getpaid_payment_gateway_supports($gateway, $feature) {
260 260
 
261 261
     $supports = false;
262 262
 
263
-    if ( wpinv_is_gateway_active( $gateway ) ) {
263
+    if (wpinv_is_gateway_active($gateway)) {
264 264
 
265
-        $supports = apply_filters( "getpaid_{$gateway}_supports_{$feature}", false );
265
+        $supports = apply_filters("getpaid_{$gateway}_supports_{$feature}", false);
266 266
 
267 267
         // Backwards compatibility.
268
-        $supports = apply_filters( "wpinv_{$gateway}_supports_{$feature}", $supports );
269
-        $supports = apply_filters( "wpinv_{$gateway}_support_{$feature}", $supports );
268
+        $supports = apply_filters("wpinv_{$gateway}_supports_{$feature}", $supports);
269
+        $supports = apply_filters("wpinv_{$gateway}_support_{$feature}", $supports);
270 270
 
271
-        $supports = apply_filters( "getpaid_gateway_supports_{$feature}", $supports, $gateway );
272
-        $supports = apply_filters( 'getpaid_payment_gateway_supports', $supports, $feature, $gateway );
271
+        $supports = apply_filters("getpaid_gateway_supports_{$feature}", $supports, $gateway);
272
+        $supports = apply_filters('getpaid_payment_gateway_supports', $supports, $feature, $gateway);
273 273
     }
274 274
 
275 275
     return $supports;
276 276
 }
277 277
 
278
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
279
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
278
+function wpinv_get_chosen_gateway($invoice_id = 0) {
279
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
280 280
 
281 281
     $chosen = false;
282
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
282
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
283 283
         $chosen = $invoice->get_gateway();
284 284
     }
285 285
 
286
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
286
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
287 287
 
288
-	if ( false !== $chosen ) {
289
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
288
+	if (false !== $chosen) {
289
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
290 290
 	}
291 291
 
292
-	if ( ! empty ( $chosen ) ) {
293
-		$enabled_gateway = urldecode( $chosen );
294
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
292
+	if (!empty ($chosen)) {
293
+		$enabled_gateway = urldecode($chosen);
294
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
295 295
 		$enabled_gateway = 'manual';
296 296
 	} else {
297 297
 		$enabled_gateway = wpinv_get_default_gateway();
298 298
 	}
299 299
 
300
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
301
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
300
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
301
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
302 302
             $enabled_gateway = wpinv_get_default_gateway();
303
-        }else{
303
+        } else {
304 304
             $enabled_gateway = $gateways[0];
305 305
         }
306 306
 
307 307
     }
308 308
 
309
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
309
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
310 310
 }
311 311
 
312
-function wpinv_record_gateway_error( $title = '', $message = '' ) {
313
-    return wpinv_error_log( $message, $title );
312
+function wpinv_record_gateway_error($title = '', $message = '') {
313
+    return wpinv_error_log($message, $title);
314 314
 }
315 315
 
316
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
316
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
317 317
 	$ret  = 0;
318 318
 	$args = array(
319 319
 		'meta_key'    => '_wpinv_gateway',
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
 		'fields'      => 'ids'
325 325
 	);
326 326
 
327
-	$payments = new WP_Query( $args );
327
+	$payments = new WP_Query($args);
328 328
 
329
-	if( $payments )
329
+	if ($payments)
330 330
 		$ret = $payments->post_count;
331 331
 	return $ret;
332 332
 }
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
 /**
335 335
  * Displays the ipn url field.
336 336
  */
337
-function wpinv_ipn_url_callback( $args ) {
338
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
337
+function wpinv_ipn_url_callback($args) {
338
+    $sanitize_id = wpinv_sanitize_key($args['id']);
339 339
 
340 340
     $attrs = $args['readonly'] ? ' readonly' : '';
341 341
 
342
-    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
343
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
342
+    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
343
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
344 344
 
345 345
     echo $html;
346 346
 }
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
  *
353 353
  * @return bool
354 354
  */
355
-function wpinv_is_test_mode( $gateway = '' ) {
356
-    $sandbox  = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", true );
357
-    $supports = getpaid_payment_gateway_supports( $gateway, 'sandbox' );
358
-    return apply_filters( 'wpinv_is_test_mode', $sandbox && $supports, $gateway );
355
+function wpinv_is_test_mode($gateway = '') {
356
+    $sandbox  = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", true);
357
+    $supports = getpaid_payment_gateway_supports($gateway, 'sandbox');
358
+    return apply_filters('wpinv_is_test_mode', $sandbox && $supports, $gateway);
359 359
 }
360 360
 
361 361
 /**
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
  *
367 367
  * @return string
368 368
  */
369
-function wpinv_get_ipn_url( $gateway = false, $args = array() ) {
369
+function wpinv_get_ipn_url($gateway = false, $args = array()) {
370 370
     $args = wp_parse_args(
371 371
         array(
372 372
             'wpi-listener' => 'IPN',
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
         $args
376 376
     );
377 377
 
378
-    return apply_filters( 'wpinv_ipn_url', add_query_arg( $args,  home_url( 'index.php' ) ), $gateway, $args );
378
+    return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args);
379 379
 
380 380
 }
381 381
 
@@ -386,34 +386,34 @@  discard block
 block discarded – undo
386 386
  *
387 387
  * @return string
388 388
  */
389
-function getpaid_get_non_query_string_ipn_url( $gateway ) {
390
-    $gateway = wpinv_sanitize_key( $gateway );
391
-    return home_url( "getpaid-ipn/$gateway" );
389
+function getpaid_get_non_query_string_ipn_url($gateway) {
390
+    $gateway = wpinv_sanitize_key($gateway);
391
+    return home_url("getpaid-ipn/$gateway");
392 392
 }
393 393
 
394 394
 
395 395
 /**
396 396
  * Retrieves request data with slashes removed slashes.
397 397
  */
398
-function wpinv_get_post_data( $method = 'request' ) {
398
+function wpinv_get_post_data($method = 'request') {
399 399
 
400
-    if ( $method == 'post' ) {
401
-        return wp_unslash( $_POST );
400
+    if ($method == 'post') {
401
+        return wp_unslash($_POST);
402 402
     }
403 403
 
404
-    if ( $method == 'get' ) {
405
-        return wp_unslash( $_GET );
404
+    if ($method == 'get') {
405
+        return wp_unslash($_GET);
406 406
     }
407 407
 
408
-    return wp_unslash( $_REQUEST );
408
+    return wp_unslash($_REQUEST);
409 409
 
410 410
 }
411 411
 
412 412
 /**
413 413
  * Checks if a given gateway supports subscription payments.
414 414
  */
415
-function wpinv_gateway_support_subscription( $gateway ) {
416
-    return getpaid_payment_gateway_supports( $gateway, 'subscription' );
415
+function wpinv_gateway_support_subscription($gateway) {
416
+    return getpaid_payment_gateway_supports($gateway, 'subscription');
417 417
 }
418 418
 
419 419
 /**
@@ -422,14 +422,14 @@  discard block
 block discarded – undo
422 422
  * @param array $gateways an array of gateways.
423 423
  * @param GetPaid_Payment_Form $form payment form.
424 424
  */
425
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
425
+function wpinv_payment_gateways_on_cart($gateways, $form) {
426 426
 
427
-    if ( $form->is_recurring() ) {
427
+    if ($form->is_recurring()) {
428 428
 
429
-        foreach ( array_keys( $gateways ) as $gateway ) {
429
+        foreach (array_keys($gateways) as $gateway) {
430 430
 
431
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
432
-                unset( $gateways[$gateway] );
431
+            if (!wpinv_gateway_support_subscription($gateway)) {
432
+                unset($gateways[$gateway]);
433 433
             }
434 434
 
435 435
         }
@@ -438,4 +438,4 @@  discard block
 block discarded – undo
438 438
 
439 439
     return $gateways;
440 440
 }
441
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
441
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +97 added lines, -97 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
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
62
+	public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR');
63 63
 
64 64
     /**
65 65
 	 * URL to view a transaction.
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
88
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
89
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
90 90
 
91 91
         parent::__construct();
92 92
     }
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101 101
 	 * @return array
102 102
 	 */
103
-	public function process_payment( $invoice, $submission_data, $submission ) {
103
+	public function process_payment($invoice, $submission_data, $submission) {
104 104
 
105 105
         // Get redirect url.
106
-        $paypal_redirect = $this->get_request_url( $invoice );
106
+        $paypal_redirect = $this->get_request_url($invoice);
107 107
 
108 108
         // Add a note about the request url.
109 109
         $invoice->add_note(
110 110
             sprintf(
111
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
112
-                esc_url( $paypal_redirect )
111
+                __('Redirecting to PayPal: %s', 'invoicing'),
112
+                esc_url($paypal_redirect)
113 113
             ),
114 114
             false,
115 115
             false,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         );
118 118
 
119 119
         // Redirect to PayPal
120
-        wp_redirect( $paypal_redirect );
120
+        wp_redirect($paypal_redirect);
121 121
         exit;
122 122
 
123 123
     }
@@ -128,21 +128,21 @@  discard block
 block discarded – undo
128 128
 	 * @param  WPInv_Invoice $invoice Invoice object.
129 129
 	 * @return string
130 130
 	 */
131
-	public function get_request_url( $invoice ) {
131
+	public function get_request_url($invoice) {
132 132
 
133 133
         // Endpoint for this request
134
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
134
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
135 135
 
136 136
         // Retrieve paypal args.
137
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
137
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
138 138
 
139
-        if ( $invoice->is_recurring() ) {
139
+        if ($invoice->is_recurring()) {
140 140
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
141 141
         } else {
142 142
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
143 143
         }
144 144
 
145
-        return add_query_arg( $paypal_args, $this->endpoint );
145
+        return add_query_arg($paypal_args, $this->endpoint);
146 146
 
147 147
 	}
148 148
 
@@ -152,25 +152,25 @@  discard block
 block discarded – undo
152 152
 	 * @param  WPInv_Invoice $invoice Invoice object.
153 153
 	 * @return array
154 154
 	 */
155
-	protected function get_paypal_args( $invoice ) {
155
+	protected function get_paypal_args($invoice) {
156 156
 
157 157
         // Whether or not to send the line items as one item.
158
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
158
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
159 159
 
160
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
160
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
161 161
 			$force_one_line_item = true;
162 162
 		}
163 163
 
164 164
 		$paypal_args = apply_filters(
165 165
 			'getpaid_paypal_args',
166 166
 			array_merge(
167
-				$this->get_transaction_args( $invoice ),
168
-				$this->get_line_item_args( $invoice, $force_one_line_item )
167
+				$this->get_transaction_args($invoice),
168
+				$this->get_line_item_args($invoice, $force_one_line_item)
169 169
 			),
170 170
 			$invoice
171 171
 		);
172 172
 
173
-		return $this->fix_request_length( $invoice, $paypal_args );
173
+		return $this->fix_request_length($invoice, $paypal_args);
174 174
     }
175 175
 
176 176
     /**
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 	 * @param WPInv_Invoice $invoice Invoice object.
180 180
 	 * @return array
181 181
 	 */
182
-	protected function get_transaction_args( $invoice ) {
182
+	protected function get_transaction_args($invoice) {
183 183
 
184 184
 		return array(
185 185
             'cmd'           => '_cart',
186
-            'business'      => wpinv_get_option( 'paypal_email', false ),
186
+            'business'      => wpinv_get_option('paypal_email', false),
187 187
             'no_shipping'   => '1',
188 188
             'shipping'      => '0',
189 189
             'no_note'       => '1',
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
             'rm'            => is_ssl() ? 2 : 1,
192 192
             'upload'        => 1,
193 193
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
194
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
195
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
196
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
197
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
194
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
195
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
196
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
197
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
198 198
             'custom'        => $invoice->get_id(),
199
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
200
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
201
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
202
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
203
-            'cbt'           => get_bloginfo( 'name' )
199
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
200
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
201
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
202
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
203
+            'cbt'           => get_bloginfo('name')
204 204
         );
205 205
 
206 206
     }
@@ -212,30 +212,30 @@  discard block
 block discarded – undo
212 212
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
213 213
 	 * @return array
214 214
 	 */
215
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
215
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
216 216
 
217 217
         // Maybe send invoice as a single item.
218
-		if ( $force_one_line_item ) {
219
-            return $this->get_line_item_args_single_item( $invoice );
218
+		if ($force_one_line_item) {
219
+            return $this->get_line_item_args_single_item($invoice);
220 220
         }
221 221
 
222 222
         // Send each line item individually.
223 223
         $line_item_args = array();
224 224
 
225 225
         // Prepare line items.
226
-        $this->prepare_line_items( $invoice );
226
+        $this->prepare_line_items($invoice);
227 227
 
228 228
         // Add taxes to the cart
229
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
230
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
229
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
230
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
231 231
         }
232 232
 
233 233
         // Add discount.
234
-        if ( $invoice->get_total_discount() > 0 ) {
235
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
234
+        if ($invoice->get_total_discount() > 0) {
235
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
236 236
         }
237 237
 
238
-		return array_merge( $line_item_args, $this->get_line_items() );
238
+		return array_merge($line_item_args, $this->get_line_items());
239 239
 
240 240
     }
241 241
 
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 	 * @param  WPInv_Invoice $invoice Invoice object.
246 246
 	 * @return array
247 247
 	 */
248
-	protected function get_line_item_args_single_item( $invoice ) {
248
+	protected function get_line_item_args_single_item($invoice) {
249 249
 		$this->delete_line_items();
250 250
 
251
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
252
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
251
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
252
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
253 253
 
254 254
 		return $this->get_line_items();
255 255
     }
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @param  WPInv_Invoice $invoice Invoice object.
275 275
 	 */
276
-	protected function prepare_line_items( $invoice ) {
276
+	protected function prepare_line_items($invoice) {
277 277
 		$this->delete_line_items();
278 278
 
279 279
 		// Items.
280
-		foreach ( $invoice->get_items() as $item ) {
280
+		foreach ($invoice->get_items() as $item) {
281 281
 			$amount   = $item->get_price();
282 282
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
283
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
284 284
         }
285 285
 
286 286
         // Fees.
287
-		foreach ( $invoice->get_fees() as $fee => $data ) {
288
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
287
+		foreach ($invoice->get_fees() as $fee => $data) {
288
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
289 289
         }
290 290
 
291 291
     }
@@ -298,15 +298,15 @@  discard block
 block discarded – undo
298 298
 	 * @param  float  $amount Amount.
299 299
 	 * @param  string $item_number Item number.
300 300
 	 */
301
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
-		$index = ( count( $this->line_items ) / 4 ) + 1;
301
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
302
+		$index = (count($this->line_items) / 4) + 1;
303 303
 
304 304
 		$item = apply_filters(
305 305
 			'getpaid_paypal_line_item',
306 306
 			array(
307
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
307
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
308 308
 				'quantity'    => (float) $quantity,
309
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
309
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
310 310
 				'item_number' => $item_number,
311 311
 			),
312 312
 			$item_name,
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 			$item_number
316 316
 		);
317 317
 
318
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
319
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
318
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
319
+        $this->line_items['quantity_' . $index] = $item['quantity'];
320 320
 
321 321
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
322
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
323
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
324 324
     }
325 325
 
326 326
     /**
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
333 333
 	 * @return array
334 334
 	 */
335
-	protected function fix_request_length( $invoice, $paypal_args ) {
335
+	protected function fix_request_length($invoice, $paypal_args) {
336 336
 		$max_paypal_length = 2083;
337
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
337
+		$query_candidate   = http_build_query($paypal_args, '', '&');
338 338
 
339
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
339
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
340 340
 			return $paypal_args;
341 341
 		}
342 342
 
343 343
 		return apply_filters(
344 344
 			'getpaid_paypal_args',
345 345
 			array_merge(
346
-				$this->get_transaction_args( $invoice ),
347
-				$this->get_line_item_args( $invoice, true )
346
+				$this->get_transaction_args($invoice),
347
+				$this->get_line_item_args($invoice, true)
348 348
 			),
349 349
 			$invoice
350 350
 		);
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	 * @param  array $paypal_args PayPal args.
358 358
 	 * @param  WPInv_Invoice    $invoice Invoice object.
359 359
 	 */
360
-	public function process_subscription( $paypal_args, $invoice ) {
360
+	public function process_subscription($paypal_args, $invoice) {
361 361
 
362 362
         // Make sure this is a subscription.
363
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
363
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
364 364
             return $paypal_args;
365 365
         }
366 366
 
@@ -368,17 +368,17 @@  discard block
 block discarded – undo
368 368
         $paypal_args['cmd'] = '_xclick-subscriptions';
369 369
 
370 370
         // Subscription name.
371
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
371
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
372 372
 
373 373
         // Get subscription args.
374
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1) );
374
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
375 375
         $interval               = (int) $subscription->get_frequency();
376 376
         $bill_times             = (int) $subscription->get_bill_times();
377
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
378
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
379
-        $subscription_item      = $invoice->get_recurring( true );
377
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
378
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
379
+        $subscription_item      = $invoice->get_recurring(true);
380 380
 
381
-        if ( $subscription_item->has_free_trial() ) {
381
+        if ($subscription_item->has_free_trial()) {
382 382
 
383 383
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
384 384
 
@@ -388,28 +388,28 @@  discard block
 block discarded – undo
388 388
 			// Trial period.
389 389
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
390 390
 
391
-        } else if ( $initial_amount != $recurring_amount ) {
391
+        } else if ($initial_amount != $recurring_amount) {
392 392
 
393 393
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
394 394
 
395
-            if ( 1 == $bill_times ) {
395
+            if (1 == $bill_times) {
396 396
                 $param_number = 3;
397 397
             } else {
398 398
                 $param_number = 1;
399 399
             }
400 400
 
401
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
401
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
402 402
 
403 403
             // Sign Up interval
404
-            $paypal_args[ 'p' . $param_number ] = $interval;
404
+            $paypal_args['p' . $param_number] = $interval;
405 405
 
406 406
             // Sign Up unit of duration
407
-            $paypal_args[ 't' . $param_number ] = $period;
407
+            $paypal_args['t' . $param_number] = $period;
408 408
 
409 409
         }
410 410
 
411 411
         // We have a recurring payment
412
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
412
+		if (!isset($param_number) || 1 == $param_number) {
413 413
 
414 414
 			// Subscription price
415 415
 			$paypal_args['a3'] = $recurring_amount;
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         }
424 424
 
425 425
         // Recurring payments
426
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
426
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
427 427
 
428 428
 			// Non-recurring payments
429 429
 			$paypal_args['src'] = 0;
@@ -432,15 +432,15 @@  discard block
 block discarded – undo
432 432
 
433 433
 			$paypal_args['src'] = 1;
434 434
 
435
-			if ( $bill_times > 0 ) {
435
+			if ($bill_times > 0) {
436 436
 
437 437
 				// An initial period is being used to charge a sign-up fee
438
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
438
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
439 439
 					$bill_times--;
440 440
 				}
441 441
 
442 442
                 // Make sure it's not over the max of 52
443
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
443
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
444 444
 
445 445
 			}
446 446
         }
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
         $paypal_args['rm'] = 2;
450 450
 
451 451
         // Get rid of redudant items.
452
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
452
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
453 453
 
454
-            if ( isset( $paypal_args[ $arg ] ) ) {
455
-                unset( $paypal_args[ $arg ] );
454
+            if (isset($paypal_args[$arg])) {
455
+                unset($paypal_args[$arg]);
456 456
             }
457 457
 
458 458
         }
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 	 * @return void
472 472
 	 */
473 473
 	public function verify_ipn() {
474
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
474
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
475 475
     }
476 476
 
477 477
     /**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
     public function sandbox_notice() {
481 481
 
482 482
         return sprintf(
483
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
483
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
484 484
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
485 485
 			'</a>'
486 486
 		);
@@ -492,29 +492,29 @@  discard block
 block discarded – undo
492 492
 	 *
493 493
 	 * @param array $admin_settings
494 494
 	 */
495
-	public function admin_settings( $admin_settings ) {
495
+	public function admin_settings($admin_settings) {
496 496
 
497 497
         $currencies = sprintf(
498
-            __( 'Supported Currencies: %s', 'invoicing' ),
499
-            implode( ', ', $this->currencies )
498
+            __('Supported Currencies: %s', 'invoicing'),
499
+            implode(', ', $this->currencies)
500 500
         );
501 501
 
502 502
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
503
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
503
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
504 504
 
505 505
         $admin_settings['paypal_email'] = array(
506 506
             'type' => 'text',
507 507
             'id'   => 'paypal_email',
508
-            'name' => __( 'PayPal Email', 'invoicing' ),
509
-            'desc' => __( "Please enter your PayPal account's email address. Use your sandbox email address in case you've enabled sandbox above.", 'invoicing' ),
508
+            'name' => __('PayPal Email', 'invoicing'),
509
+            'desc' => __("Please enter your PayPal account's email address. Use your sandbox email address in case you've enabled sandbox above.", 'invoicing'),
510 510
         );
511 511
 
512 512
         $admin_settings['paypal_ipn_url'] = array(
513 513
             'type'     => 'ipn_url',
514 514
             'id'       => 'paypal_ipn_url',
515
-            'name'     => __( 'IPN Url', 'invoicing' ),
515
+            'name'     => __('IPN Url', 'invoicing'),
516 516
             'std'      => $this->notify_url,
517
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
517
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
518 518
             'readonly' => true,
519 519
         );
520 520
 
Please login to merge, or discard this patch.