Passed
Push — master ( 9d2707...de43a2 )
by Brian
04:26
created
includes/gateways/class-getpaid-payment-gateway.php 2 patches
Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -13,449 +13,449 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-		$this->enabled = wpinv_is_gateway_active( $this->id );
141
-
142
-		// Register gateway.
143
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
-
145
-		// Enable Subscriptions.
146
-		if ( $this->supports( 'subscription' ) ) {
147
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
-		}
149
-
150
-		// Enable sandbox.
151
-		if ( $this->supports( 'sandbox' ) ) {
152
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
-		}
154
-
155
-		// Gateway settings.
156
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+        $this->enabled = wpinv_is_gateway_active( $this->id );
141
+
142
+        // Register gateway.
143
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
+
145
+        // Enable Subscriptions.
146
+        if ( $this->supports( 'subscription' ) ) {
147
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
+        }
149
+
150
+        // Enable sandbox.
151
+        if ( $this->supports( 'sandbox' ) ) {
152
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
+        }
154
+
155
+        // Gateway settings.
156
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
157 157
 		
158 158
 
159
-		// Gateway checkout fiellds.
160
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
-
162
-		// Process payment.
163
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
159
+        // Gateway checkout fiellds.
160
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
+
162
+        // Process payment.
163
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
164
+
165
+        // Change the checkout button text.
166
+        if ( ! empty( $this->checkout_button_text ) ) {
167
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
+        }
169
+
170
+        // Check if a gateway is valid for a given currency.
171
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
+
173
+        // Generate the transaction url.
174
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
+
176
+        // Generate the subscription url.
177
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
+
179
+        // Confirm payments.
180
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
+
182
+        // Verify IPNs.
183
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
+
185
+    }
186
+
187
+    /**
188
+     * Checks if this gateway is a given gateway.
189
+     *
190
+     * @since 1.0.19
191
+     * @return bool
192
+     */
193
+    public function is( $gateway ) {
194
+        return $gateway == $this->id;
195
+    }
196
+
197
+    /**
198
+     * Returns a users saved tokens for this gateway.
199
+     *
200
+     * @since 1.0.19
201
+     * @return array
202
+     */
203
+    public function get_tokens( $sandbox = null ) {
204
+
205
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
206
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
207
+
208
+            if ( is_array( $tokens ) ) {
209
+                $this->tokens = $tokens;
210
+            }
211
+
212
+        }
213
+
214
+        if ( ! is_bool( $sandbox ) ) {
215
+            return $this->tokens;
216
+        }
217
+
218
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
219
+        return wp_list_filter( $this->tokens, $args );
220
+
221
+    }
222
+
223
+    /**
224
+     * Saves a token for this gateway.
225
+     *
226
+     * @since 1.0.19
227
+     */
228
+    public function save_token( $token ) {
229
+
230
+        $tokens   = $this->get_tokens();
231
+        $tokens[] = $token;
232
+
233
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
234
+
235
+        $this->tokens = $tokens;
236
+
237
+    }
238
+
239
+    /**
240
+     * Return the title for admin screens.
241
+     *
242
+     * @return string
243
+     */
244
+    public function get_method_title() {
245
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
246
+    }
247
+
248
+    /**
249
+     * Return the description for admin screens.
250
+     *
251
+     * @return string
252
+     */
253
+    public function get_method_description() {
254
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
255
+    }
256
+
257
+    /**
258
+     * Get the success url.
259
+     *
260
+     * @param WPInv_Invoice $invoice Invoice object.
261
+     * @return string
262
+     */
263
+    public function get_return_url( $invoice ) {
264
+
265
+        // Payment success url
266
+        $return_url = add_query_arg(
267
+            array(
268
+                'payment-confirm' => $this->id,
269
+                'invoice_key'     => $invoice->get_key(),
270
+                'utm_nooverride'  => 1
271
+            ),
272
+            wpinv_get_success_page_uri()
273
+        );
274
+
275
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
276
+    }
277
+
278
+    /**
279
+     * Confirms payments when rendering the success page.
280
+     *
281
+     * @param string $content Success page content.
282
+     * @return string
283
+     */
284
+    public function confirm_payment( $content ) {
285
+
286
+        // Retrieve the invoice.
287
+        $invoice_id = getpaid_get_current_invoice_id();
288
+        $invoice    = wpinv_get_invoice( $invoice_id );
289
+
290
+        // Ensure that it exists and that it is pending payment.
291
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
292
+            return $content;
293
+        }
294
+
295
+        // Can the user view this invoice??
296
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
297
+            return $content;
298
+        }
299
+
300
+        // Show payment processing indicator.
301
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
302
+    }
303
+
304
+    /**
305
+     * Processes ipns and marks payments as complete.
306
+     *
307
+     * @return void
308
+     */
309
+    public function verify_ipn() {}
310
+
311
+    /**
312
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
313
+     *
314
+     * @param string $transaction_url transaction url.
315
+     * @param WPInv_Invoice $invoice Invoice object.
316
+     * @return string transaction URL, or empty string.
317
+     */
318
+    public function filter_transaction_url( $transaction_url, $invoice ) {
319
+
320
+        $transaction_id  = $invoice->get_transaction_id();
321
+
322
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
323
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
324
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
325
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
326
+        }
327
+
328
+        return $transaction_url;
329
+    }
330
+
331
+    /**
332
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
333
+     *
334
+     * @param string $subscription_url transaction url.
335
+     * @param WPInv_Invoice $invoice Invoice object.
336
+     * @return string subscription URL, or empty string.
337
+     */
338
+    public function filter_subscription_url( $subscription_url, $invoice ) {
339
+
340
+        $profile_id      = $invoice->get_subscription_id();
341
+
342
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
343
+
344
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
345
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
346
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
347
+
348
+        }
349
+
350
+        return $subscription_url;
351
+    }
352
+
353
+    /**
354
+     * Check if the gateway is available for use.
355
+     *
356
+     * @return bool
357
+     */
358
+    public function is_available() {
359
+        return ! empty( $this->enabled );
360
+    }
361
+
362
+    /**
363
+     * Return the gateway's title.
364
+     *
365
+     * @return string
366
+     */
367
+    public function get_title() {
368
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
369
+    }
370
+
371
+    /**
372
+     * Return the gateway's description.
373
+     *
374
+     * @return string
375
+     */
376
+    public function get_description() {
377
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
378
+    }
379
+
380
+    /**
381
+     * Process Payment.
382
+     *
383
+     *
384
+     * @param WPInv_Invoice $invoice Invoice.
385
+     * @param array $submission_data Posted checkout fields.
386
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
387
+     * @return void
388
+     */
389
+    public function process_payment( $invoice, $submission_data, $submission ) {
390
+        // Process the payment then either redirect to the success page or the gateway.
391
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
392
+    }
393
+
394
+    /**
395
+     * Process refund.
396
+     *
397
+     * If the gateway declares 'refunds' support, this will allow it to refund.
398
+     * a passed in amount.
399
+     *
400
+     * @param WPInv_Invoice $invoice Invoice.
401
+     * @param  float  $amount Refund amount.
402
+     * @param  string $reason Refund reason.
403
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
404
+     */
405
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
406
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
407
+    }
408
+
409
+    /**
410
+     * Displays the payment fields, credit cards etc.
411
+     * 
412
+     * @param int $invoice_id 0 or invoice id.
413
+     * @param GetPaid_Payment_Form $form Current payment form.
414
+     */
415
+    public function payment_fields( $invoice_id, $form ) {
416
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
417
+    }
418
+
419
+    /**
420
+     * Filters the gateway settings.
421
+     * 
422
+     * @param array $admin_settings
423
+     */
424
+    public function admin_settings( $admin_settings ) {
425
+        return $admin_settings;
426
+    }
427
+
428
+    /**
429
+     * Retrieves the value of a gateway setting.
430
+     * 
431
+     * @param string $option
432
+     */
433
+    public function get_option( $option, $default = false ) {
434
+        return wpinv_get_option( $this->id . '_' . $option, $default );
435
+    }
436
+
437
+    /**
438
+     * Check if a gateway supports a given feature.
439
+     *
440
+     * Gateways should override this to declare support (or lack of support) for a feature.
441
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
442
+     *
443
+     * @param string $feature string The name of a feature to test support for.
444
+     * @return bool True if the gateway supports the feature, false otherwise.
445
+     * @since 1.0.19
446
+     */
447
+    public function supports( $feature ) {
448
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
449
+    }
164 450
 
165
-		// Change the checkout button text.
166
-		if ( ! empty( $this->checkout_button_text ) ) {
167
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
-		}
169
-
170
-		// Check if a gateway is valid for a given currency.
171
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
-
173
-		// Generate the transaction url.
174
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
-
176
-		// Generate the subscription url.
177
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
-
179
-		// Confirm payments.
180
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
-
182
-		// Verify IPNs.
183
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
-
185
-	}
186
-
187
-	/**
188
-	 * Checks if this gateway is a given gateway.
189
-	 *
190
-	 * @since 1.0.19
191
-	 * @return bool
192
-	 */
193
-	public function is( $gateway ) {
194
-		return $gateway == $this->id;
195
-	}
196
-
197
-	/**
198
-	 * Returns a users saved tokens for this gateway.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @return array
202
-	 */
203
-	public function get_tokens( $sandbox = null ) {
204
-
205
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
206
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
207
-
208
-			if ( is_array( $tokens ) ) {
209
-				$this->tokens = $tokens;
210
-			}
211
-
212
-		}
213
-
214
-		if ( ! is_bool( $sandbox ) ) {
215
-			return $this->tokens;
216
-		}
217
-
218
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
219
-		return wp_list_filter( $this->tokens, $args );
220
-
221
-	}
222
-
223
-	/**
224
-	 * Saves a token for this gateway.
225
-	 *
226
-	 * @since 1.0.19
227
-	 */
228
-	public function save_token( $token ) {
229
-
230
-		$tokens   = $this->get_tokens();
231
-		$tokens[] = $token;
232
-
233
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
234
-
235
-		$this->tokens = $tokens;
236
-
237
-	}
238
-
239
-	/**
240
-	 * Return the title for admin screens.
241
-	 *
242
-	 * @return string
243
-	 */
244
-	public function get_method_title() {
245
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
246
-	}
247
-
248
-	/**
249
-	 * Return the description for admin screens.
250
-	 *
251
-	 * @return string
252
-	 */
253
-	public function get_method_description() {
254
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
255
-	}
256
-
257
-	/**
258
-	 * Get the success url.
259
-	 *
260
-	 * @param WPInv_Invoice $invoice Invoice object.
261
-	 * @return string
262
-	 */
263
-	public function get_return_url( $invoice ) {
264
-
265
-		// Payment success url
266
-		$return_url = add_query_arg(
267
-			array(
268
-				'payment-confirm' => $this->id,
269
-				'invoice_key'     => $invoice->get_key(),
270
-				'utm_nooverride'  => 1
271
-			),
272
-			wpinv_get_success_page_uri()
273
-		);
274
-
275
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
276
-	}
277
-
278
-	/**
279
-	 * Confirms payments when rendering the success page.
280
-	 *
281
-	 * @param string $content Success page content.
282
-	 * @return string
283
-	 */
284
-	public function confirm_payment( $content ) {
285
-
286
-		// Retrieve the invoice.
287
-		$invoice_id = getpaid_get_current_invoice_id();
288
-		$invoice    = wpinv_get_invoice( $invoice_id );
289
-
290
-		// Ensure that it exists and that it is pending payment.
291
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
292
-			return $content;
293
-		}
294
-
295
-		// Can the user view this invoice??
296
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
297
-			return $content;
298
-		}
299
-
300
-		// Show payment processing indicator.
301
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
302
-	}
303
-
304
-	/**
305
-	 * Processes ipns and marks payments as complete.
306
-	 *
307
-	 * @return void
308
-	 */
309
-	public function verify_ipn() {}
310
-
311
-	/**
312
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
313
-	 *
314
-	 * @param string $transaction_url transaction url.
315
-	 * @param WPInv_Invoice $invoice Invoice object.
316
-	 * @return string transaction URL, or empty string.
317
-	 */
318
-	public function filter_transaction_url( $transaction_url, $invoice ) {
319
-
320
-		$transaction_id  = $invoice->get_transaction_id();
321
-
322
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
323
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
324
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
325
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
326
-		}
327
-
328
-		return $transaction_url;
329
-	}
330
-
331
-	/**
332
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
333
-	 *
334
-	 * @param string $subscription_url transaction url.
335
-	 * @param WPInv_Invoice $invoice Invoice object.
336
-	 * @return string subscription URL, or empty string.
337
-	 */
338
-	public function filter_subscription_url( $subscription_url, $invoice ) {
339
-
340
-		$profile_id      = $invoice->get_subscription_id();
341
-
342
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
343
-
344
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
345
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
346
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
347
-
348
-		}
349
-
350
-		return $subscription_url;
351
-	}
352
-
353
-	/**
354
-	 * Check if the gateway is available for use.
355
-	 *
356
-	 * @return bool
357
-	 */
358
-	public function is_available() {
359
-		return ! empty( $this->enabled );
360
-	}
361
-
362
-	/**
363
-	 * Return the gateway's title.
364
-	 *
365
-	 * @return string
366
-	 */
367
-	public function get_title() {
368
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
369
-	}
370
-
371
-	/**
372
-	 * Return the gateway's description.
373
-	 *
374
-	 * @return string
375
-	 */
376
-	public function get_description() {
377
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
378
-	}
379
-
380
-	/**
381
-	 * Process Payment.
382
-	 *
383
-	 *
384
-	 * @param WPInv_Invoice $invoice Invoice.
385
-	 * @param array $submission_data Posted checkout fields.
386
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
387
-	 * @return void
388
-	 */
389
-	public function process_payment( $invoice, $submission_data, $submission ) {
390
-		// Process the payment then either redirect to the success page or the gateway.
391
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
392
-	}
393
-
394
-	/**
395
-	 * Process refund.
396
-	 *
397
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
398
-	 * a passed in amount.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice Invoice.
401
-	 * @param  float  $amount Refund amount.
402
-	 * @param  string $reason Refund reason.
403
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
404
-	 */
405
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
406
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
407
-	}
408
-
409
-	/**
410
-	 * Displays the payment fields, credit cards etc.
411
-	 * 
412
-	 * @param int $invoice_id 0 or invoice id.
413
-	 * @param GetPaid_Payment_Form $form Current payment form.
414
-	 */
415
-	public function payment_fields( $invoice_id, $form ) {
416
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
417
-	}
418
-
419
-	/**
420
-	 * Filters the gateway settings.
421
-	 * 
422
-	 * @param array $admin_settings
423
-	 */
424
-	public function admin_settings( $admin_settings ) {
425
-		return $admin_settings;
426
-	}
427
-
428
-	/**
429
-	 * Retrieves the value of a gateway setting.
430
-	 * 
431
-	 * @param string $option
432
-	 */
433
-	public function get_option( $option, $default = false ) {
434
-		return wpinv_get_option( $this->id . '_' . $option, $default );
435
-	}
436
-
437
-	/**
438
-	 * Check if a gateway supports a given feature.
439
-	 *
440
-	 * Gateways should override this to declare support (or lack of support) for a feature.
441
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
442
-	 *
443
-	 * @param string $feature string The name of a feature to test support for.
444
-	 * @return bool True if the gateway supports the feature, false otherwise.
445
-	 * @since 1.0.19
446
-	 */
447
-	public function supports( $feature ) {
448
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
449
-	}
450
-
451
-	/**
452
-	 * Returns the credit card form html.
453
-	 * 
454
-	 * @param bool $save whether or not to display the save button.
455
-	 */
451
+    /**
452
+     * Returns the credit card form html.
453
+     * 
454
+     * @param bool $save whether or not to display the save button.
455
+     */
456 456
     public function get_cc_form( $save = false ) {
457 457
 
458
-		ob_start();
458
+        ob_start();
459 459
 
460 460
         $id_prefix = esc_attr( uniqid( $this->id ) );
461 461
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
                                         'name'              => $this->id . '[cc_cvv2]',
551 551
                                         'id'                => "$id_prefix-cc-cvv2",
552 552
                                         'label'             => __( 'CCV', 'invoicing' ),
553
-										'label_type'        => 'vertical',
554
-										'class'             => 'form-control-sm',
553
+                                        'label_type'        => 'vertical',
554
+                                        'class'             => 'form-control-sm',
555 555
                                     )
556 556
                                 );
557 557
                             ?>
@@ -561,175 +561,175 @@  discard block
 block discarded – undo
561 561
 					
562 562
 					<?php
563 563
 
564
-						if ( $save ) {
565
-							echo $this->save_payment_method_checkbox();
566
-						}
564
+                        if ( $save ) {
565
+                            echo $this->save_payment_method_checkbox();
566
+                        }
567 567
 
568
-					?>
568
+                    ?>
569 569
                 </div>
570 570
 
571 571
             </div>
572 572
 		<?php
573 573
 		
574
-		return ob_get_clean();
574
+        return ob_get_clean();
575 575
 
576 576
     }
577 577
 
578
-	/**
579
-	 * Displays a new payment method entry form.
580
-	 *
581
-	 * @since 1.0.19
582
-	 */
583
-	public function new_payment_method_entry( $form ) {
584
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
585
-	}
586
-
587
-	/**
588
-	 * Grab and display our saved payment methods.
589
-	 *
590
-	 * @since 1.0.19
591
-	 */
592
-	public function saved_payment_methods() {
593
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
594
-
595
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
596
-			$html .= $this->get_saved_payment_method_option_html( $token );
597
-		}
598
-
599
-		$html .= $this->get_new_payment_method_option_html();
600
-		$html .= '</ul>';
601
-
602
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
603
-	}
604
-
605
-	/**
606
-	 * Gets saved payment method HTML from a token.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  array $token Payment Token.
610
-	 * @return string Generated payment method HTML
611
-	 */
612
-	public function get_saved_payment_method_option_html( $token ) {
613
-
614
-		return sprintf(
615
-			'<li class="getpaid-payment-method form-group">
578
+    /**
579
+     * Displays a new payment method entry form.
580
+     *
581
+     * @since 1.0.19
582
+     */
583
+    public function new_payment_method_entry( $form ) {
584
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
585
+    }
586
+
587
+    /**
588
+     * Grab and display our saved payment methods.
589
+     *
590
+     * @since 1.0.19
591
+     */
592
+    public function saved_payment_methods() {
593
+        $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
594
+
595
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
596
+            $html .= $this->get_saved_payment_method_option_html( $token );
597
+        }
598
+
599
+        $html .= $this->get_new_payment_method_option_html();
600
+        $html .= '</ul>';
601
+
602
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
603
+    }
604
+
605
+    /**
606
+     * Gets saved payment method HTML from a token.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  array $token Payment Token.
610
+     * @return string Generated payment method HTML
611
+     */
612
+    public function get_saved_payment_method_option_html( $token ) {
613
+
614
+        return sprintf(
615
+            '<li class="getpaid-payment-method form-group">
616 616
 				<label>
617 617
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
618 618
 					<span>%3$s</span>
619 619
 				</label>
620 620
 			</li>',
621
-			esc_attr( $this->id ),
622
-			esc_attr( $token['id'] ),
623
-			esc_html( $token['name'] ),
624
-			checked( empty( $token['default'] ), false, false )
625
-		);
621
+            esc_attr( $this->id ),
622
+            esc_attr( $token['id'] ),
623
+            esc_html( $token['name'] ),
624
+            checked( empty( $token['default'] ), false, false )
625
+        );
626 626
 
627
-	}
627
+    }
628 628
 
629
-	/**
630
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
631
-	 *
632
-	 * @since 1.0.19
633
-	 */
634
-	public function get_new_payment_method_option_html() {
629
+    /**
630
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
631
+     *
632
+     * @since 1.0.19
633
+     */
634
+    public function get_new_payment_method_option_html() {
635 635
 
636
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
636
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
637 637
 
638
-		return sprintf(
639
-			'<li class="getpaid-new-payment-method">
638
+        return sprintf(
639
+            '<li class="getpaid-new-payment-method">
640 640
 				<label>
641 641
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
642 642
 					<span>%2$s</span>
643 643
 				</label>
644 644
 			</li>',
645
-			esc_attr( $this->id ),
646
-			esc_html( $label )
647
-		);
645
+            esc_attr( $this->id ),
646
+            esc_html( $label )
647
+        );
648 648
 
649
-	}
649
+    }
650 650
 
651
-	/**
652
-	 * Outputs a checkbox for saving a new payment method to the database.
653
-	 *
654
-	 * @since 1.0.19
655
-	 */
656
-	public function save_payment_method_checkbox() {
651
+    /**
652
+     * Outputs a checkbox for saving a new payment method to the database.
653
+     *
654
+     * @since 1.0.19
655
+     */
656
+    public function save_payment_method_checkbox() {
657 657
 
658
-		return sprintf(
659
-			'<p class="form-group getpaid-save-payment-method">
658
+        return sprintf(
659
+            '<p class="form-group getpaid-save-payment-method">
660 660
 				<label>
661 661
 					<input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
662 662
 					<span>%2$s</span>
663 663
 				</label>
664 664
 			</p>',
665
-			esc_attr( $this->id ),
666
-			esc_html__( 'Save payment method', 'invoicing' )
667
-		);
665
+            esc_attr( $this->id ),
666
+            esc_html__( 'Save payment method', 'invoicing' )
667
+        );
668 668
 
669
-	}
669
+    }
670 670
 
671
-	/**
672
-	 * Registers the gateway.
673
-	 *
674
-	 * @return array
675
-	 */
676
-	public function register_gateway( $gateways ) {
671
+    /**
672
+     * Registers the gateway.
673
+     *
674
+     * @return array
675
+     */
676
+    public function register_gateway( $gateways ) {
677 677
 
678
-		$gateways[ $this->id ] = array(
678
+        $gateways[ $this->id ] = array(
679 679
 
680
-			'admin_label'    => $this->method_title,
680
+            'admin_label'    => $this->method_title,
681 681
             'checkout_label' => $this->title,
682
-			'ordering'       => $this->order,
683
-
684
-		);
685
-
686
-		return $gateways;
687
-
688
-	}
689
-
690
-	/**
691
-	 * Checks whether or not this is a sandbox request.
692
-	 *
693
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
694
-	 * @return bool
695
-	 */
696
-	public function is_sandbox( $invoice = null ) {
697
-
698
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
699
-			return $invoice->get_mode() == 'test';
700
-		}
701
-
702
-		return wpinv_is_test_mode( $this->id );
703
-
704
-	}
705
-
706
-	/**
707
-	 * Renames the checkout button
708
-	 *
709
-	 * @return string
710
-	 */
711
-	public function rename_checkout_button() {
712
-		return $this->checkout_button_text;
713
-	}
714
-
715
-	/**
716
-	 * Validate gateway currency
717
-	 *
718
-	 * @return bool
719
-	 */
720
-	public function validate_currency( $validation, $currency ) {
721
-
722
-		// Required currencies.
723
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
724
-			return false;
725
-		}
726
-
727
-		// Excluded currencies.
728
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
729
-			return false;
730
-		}
731
-
732
-		return $validation;
733
-	}
682
+            'ordering'       => $this->order,
683
+
684
+        );
685
+
686
+        return $gateways;
687
+
688
+    }
689
+
690
+    /**
691
+     * Checks whether or not this is a sandbox request.
692
+     *
693
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
694
+     * @return bool
695
+     */
696
+    public function is_sandbox( $invoice = null ) {
697
+
698
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
699
+            return $invoice->get_mode() == 'test';
700
+        }
701
+
702
+        return wpinv_is_test_mode( $this->id );
703
+
704
+    }
705
+
706
+    /**
707
+     * Renames the checkout button
708
+     *
709
+     * @return string
710
+     */
711
+    public function rename_checkout_button() {
712
+        return $this->checkout_button_text;
713
+    }
714
+
715
+    /**
716
+     * Validate gateway currency
717
+     *
718
+     * @return bool
719
+     */
720
+    public function validate_currency( $validation, $currency ) {
721
+
722
+        // Required currencies.
723
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
724
+            return false;
725
+        }
726
+
727
+        // Excluded currencies.
728
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
729
+            return false;
730
+        }
731
+
732
+        return $validation;
733
+    }
734 734
 
735 735
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 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
  * Abstaract Payment Gateway class.
@@ -137,50 +137,50 @@  discard block
 block discarded – undo
137 137
 	 * Class constructor.
138 138
 	 */
139 139
 	public function __construct() {
140
-		$this->enabled = wpinv_is_gateway_active( $this->id );
140
+		$this->enabled = wpinv_is_gateway_active($this->id);
141 141
 
142 142
 		// Register gateway.
143
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
+		add_filter('wpinv_payment_gateways', array($this, 'register_gateway'));
144 144
 
145 145
 		// Enable Subscriptions.
146
-		if ( $this->supports( 'subscription' ) ) {
147
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
146
+		if ($this->supports('subscription')) {
147
+			add_filter("wpinv_{$this->id}_support_subscription", '__return_true');
148 148
 		}
149 149
 
150 150
 		// Enable sandbox.
151
-		if ( $this->supports( 'sandbox' ) ) {
152
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
151
+		if ($this->supports('sandbox')) {
152
+			add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true');
153 153
 		}
154 154
 
155 155
 		// Gateway settings.
156
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
156
+		add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings'));
157 157
 		
158 158
 
159 159
 		// Gateway checkout fiellds.
160
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
160
+		add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2);
161 161
 
162 162
 		// Process payment.
163
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
163
+		add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3);
164 164
 
165 165
 		// Change the checkout button text.
166
-		if ( ! empty( $this->checkout_button_text ) ) {
167
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
166
+		if (!empty($this->checkout_button_text)) {
167
+			add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button'));
168 168
 		}
169 169
 
170 170
 		// Check if a gateway is valid for a given currency.
171
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
171
+		add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2);
172 172
 
173 173
 		// Generate the transaction url.
174
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
174
+		add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2);
175 175
 
176 176
 		// Generate the subscription url.
177
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
177
+		add_filter("getpaid_gateway_{$this->id}_subscription_url", array($this, 'filter_subscription_url'), 10, 2);
178 178
 
179 179
 		// Confirm payments.
180
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
180
+		add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2);
181 181
 
182 182
 		// Verify IPNs.
183
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
183
+		add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn'));
184 184
 
185 185
 	}
186 186
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @since 1.0.19
191 191
 	 * @return bool
192 192
 	 */
193
-	public function is( $gateway ) {
193
+	public function is($gateway) {
194 194
 		return $gateway == $this->id;
195 195
 	}
196 196
 
@@ -200,23 +200,23 @@  discard block
 block discarded – undo
200 200
 	 * @since 1.0.19
201 201
 	 * @return array
202 202
 	 */
203
-	public function get_tokens( $sandbox = null ) {
203
+	public function get_tokens($sandbox = null) {
204 204
 
205
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
206
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
205
+		if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) {
206
+			$tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true);
207 207
 
208
-			if ( is_array( $tokens ) ) {
208
+			if (is_array($tokens)) {
209 209
 				$this->tokens = $tokens;
210 210
 			}
211 211
 
212 212
 		}
213 213
 
214
-		if ( ! is_bool( $sandbox ) ) {
214
+		if (!is_bool($sandbox)) {
215 215
 			return $this->tokens;
216 216
 		}
217 217
 
218
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
219
-		return wp_list_filter( $this->tokens, $args );
218
+		$args = array('type' => $sandbox ? 'sandbox' : 'live');
219
+		return wp_list_filter($this->tokens, $args);
220 220
 
221 221
 	}
222 222
 
@@ -225,12 +225,12 @@  discard block
 block discarded – undo
225 225
 	 *
226 226
 	 * @since 1.0.19
227 227
 	 */
228
-	public function save_token( $token ) {
228
+	public function save_token($token) {
229 229
 
230 230
 		$tokens   = $this->get_tokens();
231 231
 		$tokens[] = $token;
232 232
 
233
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
233
+		update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens);
234 234
 
235 235
 		$this->tokens = $tokens;
236 236
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 * @return string
243 243
 	 */
244 244
 	public function get_method_title() {
245
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
245
+		return apply_filters('getpaid_gateway_method_title', $this->method_title, $this);
246 246
 	}
247 247
 
248 248
 	/**
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @return string
252 252
 	 */
253 253
 	public function get_method_description() {
254
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
254
+		return apply_filters('getpaid_gateway_method_description', $this->method_description, $this);
255 255
 	}
256 256
 
257 257
 	/**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @param WPInv_Invoice $invoice Invoice object.
261 261
 	 * @return string
262 262
 	 */
263
-	public function get_return_url( $invoice ) {
263
+	public function get_return_url($invoice) {
264 264
 
265 265
 		// Payment success url
266 266
 		$return_url = add_query_arg(
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 			wpinv_get_success_page_uri()
273 273
 		);
274 274
 
275
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
275
+		return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this);
276 276
 	}
277 277
 
278 278
 	/**
@@ -281,24 +281,24 @@  discard block
 block discarded – undo
281 281
 	 * @param string $content Success page content.
282 282
 	 * @return string
283 283
 	 */
284
-	public function confirm_payment( $content ) {
284
+	public function confirm_payment($content) {
285 285
 
286 286
 		// Retrieve the invoice.
287 287
 		$invoice_id = getpaid_get_current_invoice_id();
288
-		$invoice    = wpinv_get_invoice( $invoice_id );
288
+		$invoice    = wpinv_get_invoice($invoice_id);
289 289
 
290 290
 		// Ensure that it exists and that it is pending payment.
291
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
291
+		if (empty($invoice_id) || !$invoice->needs_payment()) {
292 292
 			return $content;
293 293
 		}
294 294
 
295 295
 		// Can the user view this invoice??
296
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
296
+		if (!wpinv_user_can_view_invoice($invoice)) {
297 297
 			return $content;
298 298
 		}
299 299
 
300 300
 		// Show payment processing indicator.
301
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
301
+		return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice'));
302 302
 	}
303 303
 
304 304
 	/**
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 	 * @param WPInv_Invoice $invoice Invoice object.
316 316
 	 * @return string transaction URL, or empty string.
317 317
 	 */
318
-	public function filter_transaction_url( $transaction_url, $invoice ) {
318
+	public function filter_transaction_url($transaction_url, $invoice) {
319 319
 
320
-		$transaction_id  = $invoice->get_transaction_id();
320
+		$transaction_id = $invoice->get_transaction_id();
321 321
 
322
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
323
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
324
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
325
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
322
+		if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
323
+			$transaction_url = sprintf($this->view_transaction_url, $transaction_id);
324
+			$replace         = $this->is_sandbox($invoice) ? 'sandbox' : '';
325
+			$transaction_url = str_replace('{sandbox}', $replace, $transaction_url);
326 326
 		}
327 327
 
328 328
 		return $transaction_url;
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
 	 * @param WPInv_Invoice $invoice Invoice object.
336 336
 	 * @return string subscription URL, or empty string.
337 337
 	 */
338
-	public function filter_subscription_url( $subscription_url, $invoice ) {
338
+	public function filter_subscription_url($subscription_url, $invoice) {
339 339
 
340
-		$profile_id      = $invoice->get_subscription_id();
340
+		$profile_id = $invoice->get_subscription_id();
341 341
 
342
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
342
+		if (!empty($this->view_subscription_url) && !empty($profile_id)) {
343 343
 
344
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
345
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
346
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
344
+			$subscription_url = sprintf($this->view_subscription_url, $profile_id);
345
+			$replace          = $this->is_sandbox($invoice) ? 'sandbox' : '';
346
+			$subscription_url = str_replace('{sandbox}', $replace, $subscription_url);
347 347
 
348 348
 		}
349 349
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 * @return bool
357 357
 	 */
358 358
 	public function is_available() {
359
-		return ! empty( $this->enabled );
359
+		return !empty($this->enabled);
360 360
 	}
361 361
 
362 362
 	/**
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @return string
366 366
 	 */
367 367
 	public function get_title() {
368
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
368
+		return apply_filters('getpaid_gateway_title', $this->title, $this);
369 369
 	}
370 370
 
371 371
 	/**
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 	 * @return string
375 375
 	 */
376 376
 	public function get_description() {
377
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
377
+		return apply_filters('getpaid_gateway_description', $this->description, $this);
378 378
 	}
379 379
 
380 380
 	/**
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
387 387
 	 * @return void
388 388
 	 */
389
-	public function process_payment( $invoice, $submission_data, $submission ) {
389
+	public function process_payment($invoice, $submission_data, $submission) {
390 390
 		// Process the payment then either redirect to the success page or the gateway.
391
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
391
+		do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission);
392 392
 	}
393 393
 
394 394
 	/**
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 	 * @param  string $reason Refund reason.
403 403
 	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
404 404
 	 */
405
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
406
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
405
+	public function process_refund($invoice, $amount = null, $reason = '') {
406
+		return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason);
407 407
 	}
408 408
 
409 409
 	/**
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 	 * @param int $invoice_id 0 or invoice id.
413 413
 	 * @param GetPaid_Payment_Form $form Current payment form.
414 414
 	 */
415
-	public function payment_fields( $invoice_id, $form ) {
416
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
415
+	public function payment_fields($invoice_id, $form) {
416
+		do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form);
417 417
 	}
418 418
 
419 419
 	/**
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 	 * 
422 422
 	 * @param array $admin_settings
423 423
 	 */
424
-	public function admin_settings( $admin_settings ) {
424
+	public function admin_settings($admin_settings) {
425 425
 		return $admin_settings;
426 426
 	}
427 427
 
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	 * 
431 431
 	 * @param string $option
432 432
 	 */
433
-	public function get_option( $option, $default = false ) {
434
-		return wpinv_get_option( $this->id . '_' . $option, $default );
433
+	public function get_option($option, $default = false) {
434
+		return wpinv_get_option($this->id . '_' . $option, $default);
435 435
 	}
436 436
 
437 437
 	/**
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 * @return bool True if the gateway supports the feature, false otherwise.
445 445
 	 * @since 1.0.19
446 446
 	 */
447
-	public function supports( $feature ) {
448
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
447
+	public function supports($feature) {
448
+		return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this);
449 449
 	}
450 450
 
451 451
 	/**
@@ -453,36 +453,36 @@  discard block
 block discarded – undo
453 453
 	 * 
454 454
 	 * @param bool $save whether or not to display the save button.
455 455
 	 */
456
-    public function get_cc_form( $save = false ) {
456
+    public function get_cc_form($save = false) {
457 457
 
458 458
 		ob_start();
459 459
 
460
-        $id_prefix = esc_attr( uniqid( $this->id ) );
460
+        $id_prefix = esc_attr(uniqid($this->id));
461 461
 
462 462
         $months = array(
463
-            '01' => __( 'January', 'invoicing' ),
464
-            '02' => __( 'February', 'invoicing' ),
465
-            '03' => __( 'March', 'invoicing' ),
466
-            '04' => __( 'April', 'invoicing' ),
467
-            '05' => __( 'May', 'invoicing' ),
468
-            '06' => __( 'June', 'invoicing' ),
469
-            '07' => __( 'July', 'invoicing' ),
470
-            '08' => __( 'August', 'invoicing' ),
471
-            '09' => __( 'September', 'invoicing' ),
472
-            '10' => __( 'October', 'invoicing' ),
473
-            '11' => __( 'November', 'invoicing' ),
474
-            '12' => __( 'December', 'invoicing' ),
463
+            '01' => __('January', 'invoicing'),
464
+            '02' => __('February', 'invoicing'),
465
+            '03' => __('March', 'invoicing'),
466
+            '04' => __('April', 'invoicing'),
467
+            '05' => __('May', 'invoicing'),
468
+            '06' => __('June', 'invoicing'),
469
+            '07' => __('July', 'invoicing'),
470
+            '08' => __('August', 'invoicing'),
471
+            '09' => __('September', 'invoicing'),
472
+            '10' => __('October', 'invoicing'),
473
+            '11' => __('November', 'invoicing'),
474
+            '12' => __('December', 'invoicing'),
475 475
         );
476 476
 
477
-        $year  = (int) date( 'Y', current_time( 'timestamp' ) );
477
+        $year  = (int) date('Y', current_time('timestamp'));
478 478
         $years = array();
479 479
 
480
-        for ( $i = 0; $i <= 10; $i++ ) {
481
-            $years[ $year + $i ] = $year + $i;
480
+        for ($i = 0; $i <= 10; $i++) {
481
+            $years[$year + $i] = $year + $i;
482 482
         }
483 483
 
484 484
         ?>
485
-            <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1">
485
+            <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1">
486 486
 
487 487
 
488 488
                 <div class="getpaid-cc-card-inner">
@@ -491,14 +491,14 @@  discard block
 block discarded – undo
491 491
                         <div class="col-12">
492 492
 
493 493
 							<div class="form-group">
494
-								<label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label>
494
+								<label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label>
495 495
 								<div class="input-group input-group-sm">
496 496
 									<div class="input-group-prepend ">
497 497
 										<span class="input-group-text">
498 498
 											<i class="fa fa-credit-card"></i>
499 499
 										</span>
500 500
 									</div>
501
-									<input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ) ?>authorizenet[cc_number]" id="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>" class="form-control form-control-sm">
501
+									<input type="text" name="<?php echo esc_attr($this->id . '[cc_number]') ?>authorizenet[cc_number]" id="<?php echo esc_attr("$id_prefix-cc-number") ?>" class="form-control form-control-sm">
502 502
 								</div>
503 503
 							</div>
504 504
 
@@ -506,17 +506,17 @@  discard block
 block discarded – undo
506 506
 
507 507
                         <div class="col-12">
508 508
                             <div class="form-group">
509
-                                <label><?php _e( 'Expiration', 'invoicing' ); ?></label>
509
+                                <label><?php _e('Expiration', 'invoicing'); ?></label>
510 510
                                 <div class="form-row">
511 511
 
512 512
                                     <div class="col">
513
-                                        <select class="form-control form-control-sm" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]">
514
-                                            <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option>
513
+                                        <select class="form-control form-control-sm" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]">
514
+                                            <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option>
515 515
 
516 516
                                             <?php
517
-                                                foreach ( $months as $key => $month ) {
518
-                                                    $key   = esc_attr( $key );
519
-                                                    $month = wpinv_clean( $month );
517
+                                                foreach ($months as $key => $month) {
518
+                                                    $key   = esc_attr($key);
519
+                                                    $month = wpinv_clean($month);
520 520
                                                     echo "<option value='$key'>$month</option>" . PHP_EOL;
521 521
                                                 }
522 522
                                             ?>
@@ -525,13 +525,13 @@  discard block
 block discarded – undo
525 525
                                     </div>
526 526
 
527 527
                                     <div class="col">
528
-                                        <select class="form-control form-control-sm" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]">
529
-                                            <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option>
528
+                                        <select class="form-control form-control-sm" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]">
529
+                                            <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option>
530 530
 
531 531
                                             <?php
532
-                                                foreach ( $years as $key => $year ) {
533
-                                                    $key   = esc_attr( $key );
534
-                                                    $year  = wpinv_clean( $year );
532
+                                                foreach ($years as $key => $year) {
533
+                                                    $key   = esc_attr($key);
534
+                                                    $year  = wpinv_clean($year);
535 535
                                                     echo "<option value='$key'>$year</option>" . PHP_EOL;
536 536
                                                 }
537 537
                                             ?>
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
                                     array(
550 550
                                         'name'              => $this->id . '[cc_cvv2]',
551 551
                                         'id'                => "$id_prefix-cc-cvv2",
552
-                                        'label'             => __( 'CCV', 'invoicing' ),
552
+                                        'label'             => __('CCV', 'invoicing'),
553 553
 										'label_type'        => 'vertical',
554 554
 										'class'             => 'form-control-sm',
555 555
                                     )
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 					
562 562
 					<?php
563 563
 
564
-						if ( $save ) {
564
+						if ($save) {
565 565
 							echo $this->save_payment_method_checkbox();
566 566
 						}
567 567
 
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	 *
581 581
 	 * @since 1.0.19
582 582
 	 */
583
-	public function new_payment_method_entry( $form ) {
583
+	public function new_payment_method_entry($form) {
584 584
 		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
585 585
 	}
586 586
 
@@ -590,16 +590,16 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 */
592 592
 	public function saved_payment_methods() {
593
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
593
+		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">';
594 594
 
595
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
596
-			$html .= $this->get_saved_payment_method_option_html( $token );
595
+		foreach ($this->get_tokens($this->is_sandbox()) as $token) {
596
+			$html .= $this->get_saved_payment_method_option_html($token);
597 597
 		}
598 598
 
599 599
 		$html .= $this->get_new_payment_method_option_html();
600 600
 		$html .= '</ul>';
601 601
 
602
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
602
+		echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this);
603 603
 	}
604 604
 
605 605
 	/**
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 	 * @param  array $token Payment Token.
610 610
 	 * @return string Generated payment method HTML
611 611
 	 */
612
-	public function get_saved_payment_method_option_html( $token ) {
612
+	public function get_saved_payment_method_option_html($token) {
613 613
 
614 614
 		return sprintf(
615 615
 			'<li class="getpaid-payment-method form-group">
@@ -618,10 +618,10 @@  discard block
 block discarded – undo
618 618
 					<span>%3$s</span>
619 619
 				</label>
620 620
 			</li>',
621
-			esc_attr( $this->id ),
622
-			esc_attr( $token['id'] ),
623
-			esc_html( $token['name'] ),
624
-			checked( empty( $token['default'] ), false, false )
621
+			esc_attr($this->id),
622
+			esc_attr($token['id']),
623
+			esc_html($token['name']),
624
+			checked(empty($token['default']), false, false)
625 625
 		);
626 626
 
627 627
 	}
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 	 */
634 634
 	public function get_new_payment_method_option_html() {
635 635
 
636
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
636
+		$label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this);
637 637
 
638 638
 		return sprintf(
639 639
 			'<li class="getpaid-new-payment-method">
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
 					<span>%2$s</span>
643 643
 				</label>
644 644
 			</li>',
645
-			esc_attr( $this->id ),
646
-			esc_html( $label )
645
+			esc_attr($this->id),
646
+			esc_html($label)
647 647
 		);
648 648
 
649 649
 	}
@@ -662,8 +662,8 @@  discard block
 block discarded – undo
662 662
 					<span>%2$s</span>
663 663
 				</label>
664 664
 			</p>',
665
-			esc_attr( $this->id ),
666
-			esc_html__( 'Save payment method', 'invoicing' )
665
+			esc_attr($this->id),
666
+			esc_html__('Save payment method', 'invoicing')
667 667
 		);
668 668
 
669 669
 	}
@@ -673,9 +673,9 @@  discard block
 block discarded – undo
673 673
 	 *
674 674
 	 * @return array
675 675
 	 */
676
-	public function register_gateway( $gateways ) {
676
+	public function register_gateway($gateways) {
677 677
 
678
-		$gateways[ $this->id ] = array(
678
+		$gateways[$this->id] = array(
679 679
 
680 680
 			'admin_label'    => $this->method_title,
681 681
             'checkout_label' => $this->title,
@@ -693,13 +693,13 @@  discard block
 block discarded – undo
693 693
 	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
694 694
 	 * @return bool
695 695
 	 */
696
-	public function is_sandbox( $invoice = null ) {
696
+	public function is_sandbox($invoice = null) {
697 697
 
698
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
698
+		if (!empty($invoice) && !$invoice->needs_payment()) {
699 699
 			return $invoice->get_mode() == 'test';
700 700
 		}
701 701
 
702
-		return wpinv_is_test_mode( $this->id );
702
+		return wpinv_is_test_mode($this->id);
703 703
 
704 704
 	}
705 705
 
@@ -717,15 +717,15 @@  discard block
 block discarded – undo
717 717
 	 *
718 718
 	 * @return bool
719 719
 	 */
720
-	public function validate_currency( $validation, $currency ) {
720
+	public function validate_currency($validation, $currency) {
721 721
 
722 722
 		// Required currencies.
723
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
723
+		if (!empty($this->currencies) && !in_array($currency, $this->currencies)) {
724 724
 			return false;
725 725
 		}
726 726
 
727 727
 		// Excluded currencies.
728
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
728
+		if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) {
729 729
 			return false;
730 730
 		}
731 731
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +153 added lines, -153 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
  * Authorize.net 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', 'tokens' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,28 +311,28 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319 319
                         'name'                 => getpaid_tax()->get_vat_name(),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330 330
 
331
-        if ( 0 == $invoice->get_total_tax() ) {
332
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
331
+        if (0 == $invoice->get_total_tax()) {
332
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
333 333
         }
334 334
 
335
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
335
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
336 336
 
337 337
     }
338 338
 
@@ -342,29 +342,29 @@  discard block
 block discarded – undo
342 342
      * @param stdClass $result Api response.
343 343
 	 * @param WPInv_Invoice $invoice Invoice.
344 344
 	 */
345
-	public function process_charge_response( $result, $invoice ) {
345
+	public function process_charge_response($result, $invoice) {
346 346
 
347 347
         wpinv_clear_errors();
348 348
 		$response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350 350
 		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
351
+		if (1 == $response_code || 4 == $response_code) {
352 352
 
353 353
 			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
354
+			if (!empty($result->transactionResponse->transId)) {
355
+				$invoice->set_transaction_id($result->transactionResponse->transId);
356 356
 			}
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
359 359
 
360
-			if ( 1 == $response_code ) {
360
+			if (1 == $response_code) {
361 361
 				return $invoice->mark_paid();
362 362
 			}
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
364
+			$invoice->set_status('wpi-onhold');
365 365
         	$invoice->add_note(
366 366
                 sprintf(
367
-                    __( 'Held for review: %s', 'invoicing' ),
367
+                    __('Held for review: %s', 'invoicing'),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370 370
 			);
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
 
374 374
 		}
375 375
 
376
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
376
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
377 377
 
378
-        if ( ! empty( $result->transactionResponse->errors ) ) {
378
+        if (!empty($result->transactionResponse->errors)) {
379 379
             $errors = (object) $result->transactionResponse->errors;
380
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
380
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
381 381
         }
382 382
 
383 383
     }
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @param array $card Card details.
390 390
 	 * @return array
391 391
 	 */
392
-	public function get_payment_information( $card ) {
392
+	public function get_payment_information($card) {
393 393
         return array(
394 394
 
395
-            'creditCard'         => array (
395
+            'creditCard'         => array(
396 396
                 'cardNumber'     => $card['cc_number'],
397 397
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
398 398
                 'cardCode'       => $card['cc_cvv2'],
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param WPInv_Invoice $invoice Invoice.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
412
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
411
+	public function get_customer_profile_meta_name($invoice) {
412
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
@@ -420,34 +420,34 @@  discard block
 block discarded – undo
420 420
      * @param WPInv_Invoice $invoice
421 421
 	 * @return WP_Error|string The payment profile id
422 422
 	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
423
+	public function validate_submission_data($submission_data, $invoice) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
427 427
 
428
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
429
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
428
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
429
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
430 430
         }
431 431
 
432 432
         // Validate the payment method.
433
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
434
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
433
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
434
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
435 435
         }
436 436
 
437 437
         // Are we adding a new payment method?
438
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
438
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
439 439
             return $submission_data['getpaid-authorizenet-payment-method'];
440 440
         }
441 441
 
442 442
         // Retrieve the customer profile id.
443
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
443
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
444 444
 
445 445
         // Create payment method.
446
-        if ( empty( $profile_id ) ) {
447
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        if (empty($profile_id)) {
447
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
448 448
         }
449 449
 
450
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
450
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
451 451
 
452 452
     }
453 453
 
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 	 * @param WPInv_Invoice $invoice Invoice.
459 459
 	 * @return array
460 460
 	 */
461
-	public function get_line_items( $invoice ) {
461
+	public function get_line_items($invoice) {
462 462
         $items = array();
463 463
 
464
-        foreach ( $invoice->get_items() as $item ) {
464
+        foreach ($invoice->get_items() as $item) {
465 465
 
466 466
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
467 467
             $items[] = array(
468
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
469
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
470
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
468
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
469
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
470
+                'description' => getpaid_limit_length($item->get_description(), 255),
471 471
                 'quantity'    => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
472 472
                 'unitPrice'   => (float) $amount,
473 473
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
 
476 476
         }
477 477
 
478
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
478
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
479 479
 
480
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
480
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
481 481
 
482
-            if ( $amount > 0 ) {
482
+            if ($amount > 0) {
483 483
                 $items[] = array(
484
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
485
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
486
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
484
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
485
+                    'name'        => getpaid_limit_length($fee_name, 31),
486
+                    'description' => getpaid_limit_length($fee_name, 255),
487 487
                     'quantity'    => '1',
488 488
                     'unitPrice'   => (float) $amount,
489 489
                     'taxable'     => false,
@@ -504,36 +504,36 @@  discard block
 block discarded – undo
504 504
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505 505
 	 * @return array
506 506
 	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
507
+	public function process_payment($invoice, $submission_data, $submission) {
508 508
 
509 509
         // Validate the submitted data.
510
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
510
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
511 511
 
512 512
         // Do we have an error?
513
-        if ( is_wp_error( $payment_profile_id ) ) {
514
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
513
+        if (is_wp_error($payment_profile_id)) {
514
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
515 515
             wpinv_send_back_to_checkout();
516 516
         }
517 517
 
518 518
         // Save the payment method to the order.
519
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
519
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
520 520
 
521 521
         // Check if this is a subscription or not.
522
-        $subscription = getpaid_get_invoice_subscription( $invoice );
523
-        if ( ! empty( $subscription ) ) {
524
-            $this->process_subscription( $invoice, $subscription );
522
+        $subscription = getpaid_get_invoice_subscription($invoice);
523
+        if (!empty($subscription)) {
524
+            $this->process_subscription($invoice, $subscription);
525 525
         }
526 526
 
527 527
         // If it is free, send to the success page.
528
-        if ( ! $invoice->needs_payment() ) {
528
+        if (!$invoice->needs_payment()) {
529 529
             $invoice->mark_paid();
530
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
530
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
531 531
         }
532 532
 
533 533
         // Charge the payment profile.
534
-        $this->process_initial_payment( $invoice );
534
+        $this->process_initial_payment($invoice);
535 535
 
536
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
536
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
537 537
 
538 538
         exit;
539 539
 
@@ -544,22 +544,22 @@  discard block
 block discarded – undo
544 544
 	 *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546 546
 	 */
547
-	protected function process_initial_payment( $invoice ) {
547
+	protected function process_initial_payment($invoice) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
549
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
550
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
551
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
552 552
 
553 553
 		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
554
+		if (is_wp_error($result)) {
555
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
556 556
 			wpinv_send_back_to_checkout();
557 557
 		}
558 558
 
559 559
 		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
560
+		$this->process_charge_response($result, $invoice);
561 561
 
562
-		if ( wpinv_get_errors() ) {
562
+		if (wpinv_get_errors()) {
563 563
 			wpinv_send_back_to_checkout();
564 564
 		}
565 565
 
@@ -571,24 +571,24 @@  discard block
 block discarded – undo
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573 573
 	 */
574
-	public function process_subscription( $invoice, $subscription ) {
574
+	public function process_subscription($invoice, $subscription) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577
-        if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
577
+        if ((float) $invoice->get_total() > 0) {
578
+			$this->process_initial_payment($invoice);
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
582
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
583
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
585
+		$subscription->set_next_renewal_date($expiry);
586
+		$subscription->set_date_created(current_time('mysql'));
587
+		$subscription->set_profile_id($invoice->generate_key());
588 588
 		$subscription->activate();
589 589
 
590 590
 		// Redirect to the success page.
591
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
591
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
592 592
 
593 593
     }
594 594
 
@@ -599,20 +599,20 @@  discard block
 block discarded – undo
599 599
 	 * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601 601
 	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
602
+	public function maybe_renew_subscription($should_expire, $subscription) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
605
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
606 606
             return $should_expire;
607 607
         }
608 608
 
609 609
         // If this is the last renewal, complete the subscription.
610
-        if ( $subscription->is_last_renewal() ) {
610
+        if ($subscription->is_last_renewal()) {
611 611
             $subscription->complete();
612 612
             return false;
613 613
         }
614 614
 
615
-        $this->renew_subscription( $subscription );
615
+        $this->renew_subscription($subscription);
616 616
 
617 617
         return false;
618 618
 
@@ -623,28 +623,28 @@  discard block
 block discarded – undo
623 623
 	 *
624 624
      * @param WPInv_Subscription $subscription
625 625
 	 */
626
-	public function renew_subscription( $subscription ) {
626
+	public function renew_subscription($subscription) {
627 627
 
628 628
 		// Generate the renewal invoice.
629 629
 		$new_invoice = $subscription->create_payment();
630 630
 		$old_invoice = $subscription->get_parent_payment();
631 631
 
632
-        if ( empty( $new_invoice ) ) {
633
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
632
+        if (empty($new_invoice)) {
633
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
634 634
             $subscription->failing();
635 635
             return;
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
639
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
640
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
641
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
642 642
 
643 643
 		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
644
+		if (is_wp_error($result)) {
645 645
 
646 646
 			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
647
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
648 648
 				true,
649 649
 				false,
650 650
 				true
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
658
+		$this->process_charge_response($result, $new_invoice);
659 659
 
660
-		if ( wpinv_get_errors() ) {
660
+		if (wpinv_get_errors()) {
661 661
 
662 662
 			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
663
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
664 664
 				true,
665 665
 				false,
666 666
 				true
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
         }
672 672
 
673
-        $subscription->add_payment( array(), $new_invoice );
673
+        $subscription->add_payment(array(), $new_invoice);
674 674
         $subscription->renew();
675 675
     }
676 676
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     public function sandbox_notice() {
681 681
 
682 682
         return sprintf(
683
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
683
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
684 684
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
685 685
             '</a>'
686 686
         );
@@ -692,42 +692,42 @@  discard block
 block discarded – undo
692 692
 	 *
693 693
 	 * @param array $admin_settings
694 694
 	 */
695
-	public function admin_settings( $admin_settings ) {
695
+	public function admin_settings($admin_settings) {
696 696
 
697 697
         $currencies = sprintf(
698
-            __( 'Supported Currencies: %s', 'invoicing' ),
699
-            implode( ', ', $this->currencies )
698
+            __('Supported Currencies: %s', 'invoicing'),
699
+            implode(', ', $this->currencies)
700 700
         );
701 701
 
702 702
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
703
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
703
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
704 704
 
705 705
         $admin_settings['authorizenet_login_id'] = array(
706 706
             'type' => 'text',
707 707
             'id'   => 'authorizenet_login_id',
708
-            'name' => __( 'API Login ID', 'invoicing' ),
709
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
708
+            'name' => __('API Login ID', 'invoicing'),
709
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
710 710
         );
711 711
 
712 712
         $admin_settings['authorizenet_transaction_key'] = array(
713 713
             'type' => 'text',
714 714
             'id'   => 'authorizenet_transaction_key',
715
-            'name' => __( 'Transaction Key', 'invoicing' ),
715
+            'name' => __('Transaction Key', 'invoicing'),
716 716
         );
717 717
 
718 718
         $admin_settings['authorizenet_signature_key'] = array(
719 719
             'type' => 'text',
720 720
             'id'   => 'authorizenet_signature_key',
721
-            'name' => __( 'Signature Key', 'invoicing' ),
722
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
721
+            'name' => __('Signature Key', 'invoicing'),
722
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
723 723
         );
724 724
 
725 725
         $admin_settings['authorizenet_ipn_url'] = array(
726 726
             'type'     => 'ipn_url',
727 727
             'id'       => 'authorizenet_ipn_url',
728
-            'name'     => __( 'Webhook URL', 'invoicing' ),
728
+            'name'     => __('Webhook URL', 'invoicing'),
729 729
             'std'      => $this->notify_url,
730
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
730
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
731 731
             'custom'   => 'authorizenet',
732 732
             'readonly' => true,
733 733
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -13,94 +13,94 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
     
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
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' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
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' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90 90
 
91 91
         parent::__construct();
92 92
     }
93 93
 
94 94
     /**
95
-	 * Process Payment.
96
-	 *
97
-	 *
98
-	 * @param WPInv_Invoice $invoice Invoice.
99
-	 * @param array $submission_data Posted checkout fields.
100
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
-	 * @return array
102
-	 */
103
-	public function process_payment( $invoice, $submission_data, $submission ) {
95
+     * Process Payment.
96
+     *
97
+     *
98
+     * @param WPInv_Invoice $invoice Invoice.
99
+     * @param array $submission_data Posted checkout fields.
100
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
+     * @return array
102
+     */
103
+    public function process_payment( $invoice, $submission_data, $submission ) {
104 104
 
105 105
         // Get redirect url.
106 106
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
     }
124 124
 
125 125
     /**
126
-	 * Get the PayPal request URL for an invoice.
127
-	 *
128
-	 * @param  WPInv_Invoice $invoice Invoice object.
129
-	 * @return string
130
-	 */
131
-	public function get_request_url( $invoice ) {
126
+     * Get the PayPal request URL for an invoice.
127
+     *
128
+     * @param  WPInv_Invoice $invoice Invoice object.
129
+     * @return string
130
+     */
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 137
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -144,44 +144,44 @@  discard block
 block discarded – undo
144 144
 
145 145
         return add_query_arg( $paypal_args, $this->endpoint );
146 146
 
147
-	}
147
+    }
148 148
 
149 149
     /**
150
-	 * Get PayPal Args for passing to PP.
151
-	 *
152
-	 * @param  WPInv_Invoice $invoice Invoice object.
153
-	 * @return array
154
-	 */
155
-	protected function get_paypal_args( $invoice ) {
150
+     * Get PayPal Args for passing to PP.
151
+     *
152
+     * @param  WPInv_Invoice $invoice Invoice object.
153
+     * @return array
154
+     */
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', false, $invoice );
159
-
160
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
-			$force_one_line_item = true;
162
-		}
163
-
164
-		$paypal_args = apply_filters(
165
-			'getpaid_paypal_args',
166
-			array_merge(
167
-				$this->get_transaction_args( $invoice ),
168
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
-			),
170
-			$invoice
171
-		);
172
-
173
-		return $this->fix_request_length( $invoice, $paypal_args );
158
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
159
+
160
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
+            $force_one_line_item = true;
162
+        }
163
+
164
+        $paypal_args = apply_filters(
165
+            'getpaid_paypal_args',
166
+            array_merge(
167
+                $this->get_transaction_args( $invoice ),
168
+                $this->get_line_item_args( $invoice, $force_one_line_item )
169
+            ),
170
+            $invoice
171
+        );
172
+
173
+        return $this->fix_request_length( $invoice, $paypal_args );
174 174
     }
175 175
 
176 176
     /**
177
-	 * Get transaction args for paypal request.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 * @return array
181
-	 */
182
-	protected function get_transaction_args( $invoice ) {
183
-
184
-		return array(
177
+     * Get transaction args for paypal request.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     * @return array
181
+     */
182
+    protected function get_transaction_args( $invoice ) {
183
+
184
+        return array(
185 185
             'cmd'           => '_cart',
186 186
             'business'      => wpinv_get_option( 'paypal_email', false ),
187 187
             'no_shipping'   => '1',
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
     }
207 207
 
208 208
     /**
209
-	 * Get line item args for paypal request.
210
-	 *
211
-	 * @param  WPInv_Invoice $invoice Invoice object.
212
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
213
-	 * @return array
214
-	 */
215
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
209
+     * Get line item args for paypal request.
210
+     *
211
+     * @param  WPInv_Invoice $invoice Invoice object.
212
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
213
+     * @return array
214
+     */
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 ) {
218
+        if ( $force_one_line_item ) {
219 219
             return $this->get_line_item_args_single_item( $invoice );
220 220
         }
221 221
 
@@ -235,129 +235,129 @@  discard block
 block discarded – undo
235 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
 
242 242
     /**
243
-	 * Get line item args for paypal request as a single line item.
244
-	 *
245
-	 * @param  WPInv_Invoice $invoice Invoice object.
246
-	 * @return array
247
-	 */
248
-	protected function get_line_item_args_single_item( $invoice ) {
249
-		$this->delete_line_items();
243
+     * Get line item args for paypal request as a single line item.
244
+     *
245
+     * @param  WPInv_Invoice $invoice Invoice object.
246
+     * @return array
247
+     */
248
+    protected function get_line_item_args_single_item( $invoice ) {
249
+        $this->delete_line_items();
250 250
 
251 251
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
252
-		$this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
252
+        $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
253 253
 
254
-		return $this->get_line_items();
254
+        return $this->get_line_items();
255 255
     }
256 256
 
257 257
     /**
258
-	 * Return all line items.
259
-	 */
260
-	protected function get_line_items() {
261
-		return $this->line_items;
262
-	}
258
+     * Return all line items.
259
+     */
260
+    protected function get_line_items() {
261
+        return $this->line_items;
262
+    }
263 263
 
264 264
     /**
265
-	 * Remove all line items.
266
-	 */
267
-	protected function delete_line_items() {
268
-		$this->line_items = array();
265
+     * Remove all line items.
266
+     */
267
+    protected function delete_line_items() {
268
+        $this->line_items = array();
269 269
     }
270 270
 
271 271
     /**
272
-	 * Prepare line items to send to paypal.
273
-	 *
274
-	 * @param  WPInv_Invoice $invoice Invoice object.
275
-	 */
276
-	protected function prepare_line_items( $invoice ) {
277
-		$this->delete_line_items();
278
-
279
-		// Items.
280
-		foreach ( $invoice->get_items() as $item ) {
281
-			$amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
272
+     * Prepare line items to send to paypal.
273
+     *
274
+     * @param  WPInv_Invoice $invoice Invoice object.
275
+     */
276
+    protected function prepare_line_items( $invoice ) {
277
+        $this->delete_line_items();
278
+
279
+        // Items.
280
+        foreach ( $invoice->get_items() as $item ) {
281
+            $amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
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 ) {
287
+        foreach ( $invoice->get_fees() as $fee => $data ) {
288 288
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
289 289
         }
290 290
 
291 291
     }
292 292
 
293 293
     /**
294
-	 * Add PayPal Line Item.
295
-	 *
296
-	 * @param  string $item_name Item name.
297
-	 * @param  int    $quantity Item quantity.
298
-	 * @param  float  $amount Amount.
299
-	 * @param  string $item_number Item number.
300
-	 */
301
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
-		$index = ( count( $this->line_items ) / 4 ) + 1;
303
-
304
-		$item = apply_filters(
305
-			'getpaid_paypal_line_item',
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' ),
308
-				'quantity'    => (int) $quantity,
309
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
-				'item_number' => $item_number,
311
-			),
312
-			$item_name,
313
-			$quantity,
314
-			$amount,
315
-			$item_number
316
-		);
317
-
318
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
294
+     * Add PayPal Line Item.
295
+     *
296
+     * @param  string $item_name Item name.
297
+     * @param  int    $quantity Item quantity.
298
+     * @param  float  $amount Amount.
299
+     * @param  string $item_number Item number.
300
+     */
301
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
+        $index = ( count( $this->line_items ) / 4 ) + 1;
303
+
304
+        $item = apply_filters(
305
+            'getpaid_paypal_line_item',
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' ),
308
+                'quantity'    => (int) $quantity,
309
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
+                'item_number' => $item_number,
311
+            ),
312
+            $item_name,
313
+            $quantity,
314
+            $amount,
315
+            $item_number
316
+        );
317
+
318
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
319 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'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
324 324
     }
325 325
 
326 326
     /**
327
-	 * If the default request with line items is too long, generate a new one with only one line item.
328
-	 *
329
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
-	 *
331
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
333
-	 * @return array
334
-	 */
335
-	protected function fix_request_length( $invoice, $paypal_args ) {
336
-		$max_paypal_length = 2083;
337
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
338
-
339
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
-			return $paypal_args;
341
-		}
342
-
343
-		return apply_filters(
344
-			'getpaid_paypal_args',
345
-			array_merge(
346
-				$this->get_transaction_args( $invoice ),
347
-				$this->get_line_item_args( $invoice, true )
348
-			),
349
-			$invoice
350
-		);
327
+     * If the default request with line items is too long, generate a new one with only one line item.
328
+     *
329
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
+     *
331
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
333
+     * @return array
334
+     */
335
+    protected function fix_request_length( $invoice, $paypal_args ) {
336
+        $max_paypal_length = 2083;
337
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
338
+
339
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
+            return $paypal_args;
341
+        }
342
+
343
+        return apply_filters(
344
+            'getpaid_paypal_args',
345
+            array_merge(
346
+                $this->get_transaction_args( $invoice ),
347
+                $this->get_line_item_args( $invoice, true )
348
+            ),
349
+            $invoice
350
+        );
351 351
 
352 352
     }
353 353
     
354 354
     /**
355
-	 * Processes recurring invoices.
356
-	 *
357
-	 * @param  array $paypal_args PayPal args.
358
-	 * @param  WPInv_Invoice    $invoice Invoice object.
359
-	 */
360
-	public function process_subscription( $paypal_args, $invoice ) {
355
+     * Processes recurring invoices.
356
+     *
357
+     * @param  array $paypal_args PayPal args.
358
+     * @param  WPInv_Invoice    $invoice Invoice object.
359
+     */
360
+    public function process_subscription( $paypal_args, $invoice ) {
361 361
 
362 362
         // Make sure this is a subscription.
363 363
         if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) {
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 
383 383
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
384 384
 
385
-			// Trial period length.
386
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
385
+            // Trial period length.
386
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
387 387
 
388
-			// Trial period.
389
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
388
+            // Trial period.
389
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
390 390
 
391 391
         } else if ( $initial_amount != $recurring_amount ) {
392 392
 
@@ -409,40 +409,40 @@  discard block
 block discarded – undo
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
-			// Subscription price
415
-			$paypal_args['a3'] = $recurring_amount;
414
+            // Subscription price
415
+            $paypal_args['a3'] = $recurring_amount;
416 416
 
417
-			// Subscription duration
418
-			$paypal_args['p3'] = $interval;
417
+            // Subscription duration
418
+            $paypal_args['p3'] = $interval;
419 419
 
420
-			// Subscription period
421
-			$paypal_args['t3'] = $period;
420
+            // Subscription period
421
+            $paypal_args['t3'] = $period;
422 422
 
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
-			// Non-recurring payments
429
-			$paypal_args['src'] = 0;
428
+            // Non-recurring payments
429
+            $paypal_args['src'] = 0;
430 430
 
431
-		} else {
431
+        } else {
432 432
 
433
-			$paypal_args['src'] = 1;
433
+            $paypal_args['src'] = 1;
434 434
 
435
-			if ( $bill_times > 0 ) {
435
+            if ( $bill_times > 0 ) {
436 436
 
437
-				// An initial period is being used to charge a sign-up fee
438
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
-					$bill_times--;
440
-				}
437
+                // An initial period is being used to charge a sign-up fee
438
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
+                    $bill_times--;
440
+                }
441 441
 
442 442
                 // Make sure it's not over the max of 52
443 443
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
444 444
 
445
-			}
445
+            }
446 446
         }
447 447
         
448 448
         // Force return URL so that order description & instructions display
@@ -458,19 +458,19 @@  discard block
 block discarded – undo
458 458
         }
459 459
 
460 460
         return apply_filters(
461
-			'getpaid_paypal_subscription_args',
462
-			$paypal_args,
463
-			$invoice
461
+            'getpaid_paypal_subscription_args',
462
+            $paypal_args,
463
+            $invoice
464 464
         );
465 465
 
466 466
     }
467 467
 
468 468
     /**
469
-	 * Processes ipns and marks payments as complete.
470
-	 *
471
-	 * @return void
472
-	 */
473
-	public function verify_ipn() {
469
+     * Processes ipns and marks payments as complete.
470
+     *
471
+     * @return void
472
+     */
473
+    public function verify_ipn() {
474 474
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
475 475
     }
476 476
 
@@ -480,10 +480,10 @@  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' ),
484
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
485
-			'</a>'
486
-		);
483
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
484
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
485
+            '</a>'
486
+        );
487 487
 
488 488
     }
489 489
 
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 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' );
27
+    protected $supports = array('subscription', 'sandbox');
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', false, $invoice );
158
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $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_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
251
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
252
+		$this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $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   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
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'    => (int) $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'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+		$this->line_items['amount_' . $index]      = $item['amount'];
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 = wpinv_get_subscription( $invoice ) ) {
363
+        if (!$invoice->is_recurring() || !$subscription = wpinv_get_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
 		);
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -12,216 +12,216 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-
42
-	}
43
-
44
-	/**
45
-	 * Adds totals to a response for submission refresh prices.
46
-	 *
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function add_totals( $submission ) {
50
-
51
-		$this->response = array_merge(
52
-			$this->response,
53
-			array(
54
-
55
-				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
61
-				),
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+
42
+    }
43
+
44
+    /**
45
+     * Adds totals to a response for submission refresh prices.
46
+     *
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function add_totals( $submission ) {
50
+
51
+        $this->response = array_merge(
52
+            $this->response,
53
+            array(
54
+
55
+                'totals'        => array(
56
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
58
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
59
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
60
+                    'total'     => $submission->format_amount( $submission->get_total() ),
61
+                ),
62 62
 	
63
-				'recurring'     => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
69
-				),
63
+                'recurring'     => array(
64
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
65
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
66
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
67
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
68
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
69
+                ),
70 70
 
71
-			)
72
-		);
71
+            )
72
+        );
73 73
 
74
-	}
74
+    }
75 75
 
76
-	/**
77
-	 * Adds texts to a response for submission refresh prices.
78
-	 *
79
-	 * @param GetPaid_Payment_Form_Submission $submission
80
-	 */
81
-	public function add_texts( $submission ) {
76
+    /**
77
+     * Adds texts to a response for submission refresh prices.
78
+     *
79
+     * @param GetPaid_Payment_Form_Submission $submission
80
+     */
81
+    public function add_texts( $submission ) {
82 82
 
83
-		$payable = $submission->format_amount( $submission->get_total() );
83
+        $payable = $submission->format_amount( $submission->get_total() );
84 84
 
85
-		if ( $submission->has_recurring != 0 ) {
85
+        if ( $submission->has_recurring != 0 ) {
86 86
 
87
-			$recurring = new WPInv_Item( $submission->has_recurring );
88
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
87
+            $recurring = new WPInv_Item( $submission->has_recurring );
88
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
89 89
 
90
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
91
-				$payable = "$payable / $period";
92
-			} else {
93
-				$payable = sprintf(
94
-					__( '%1$s (renews at %2$s / %3$s)'),
95
-					$submission->format_amount( $submission->get_total() ),
96
-					$submission->format_amount( $submission->get_recurring_total() ),
97
-					$period
98
-				);
99
-			}
90
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
91
+                $payable = "$payable / $period";
92
+            } else {
93
+                $payable = sprintf(
94
+                    __( '%1$s (renews at %2$s / %3$s)'),
95
+                    $submission->format_amount( $submission->get_total() ),
96
+                    $submission->format_amount( $submission->get_recurring_total() ),
97
+                    $period
98
+                );
99
+            }
100 100
 
101
-		}
101
+        }
102 102
 
103
-		$texts = array(
104
-			'.getpaid-checkout-total-payable' => $payable,
105
-		);
103
+        $texts = array(
104
+            '.getpaid-checkout-total-payable' => $payable,
105
+        );
106 106
 
107
-		foreach ( $submission->get_items() as $item_id => $item ) {
108
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
109
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
110
-		}
107
+        foreach ( $submission->get_items() as $item_id => $item ) {
108
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
109
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
110
+        }
111 111
 
112
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
113 113
 
114
-	}
114
+    }
115 115
 
116
-	/**
117
-	 * Adds items to a response for submission refresh prices.
118
-	 *
119
-	 * @param GetPaid_Payment_Form_Submission $submission
120
-	 */
121
-	public function add_items( $submission ) {
116
+    /**
117
+     * Adds items to a response for submission refresh prices.
118
+     *
119
+     * @param GetPaid_Payment_Form_Submission $submission
120
+     */
121
+    public function add_items( $submission ) {
122 122
 
123
-		// Add items.
124
-		$items = array();
123
+        // Add items.
124
+        $items = array();
125 125
 
126 126
         foreach ( $submission->get_items() as $item_id => $item ) {
127
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
128
-		}
127
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
128
+        }
129 129
 
130
-		$this->response = array_merge(
131
-			$this->response,
132
-			array( 'items' => $items )
133
-		);
130
+        $this->response = array_merge(
131
+            $this->response,
132
+            array( 'items' => $items )
133
+        );
134 134
 
135
-	}
135
+    }
136 136
 
137
-	/**
138
-	 * Adds fees to a response for submission refresh prices.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 */
142
-	public function add_fees( $submission ) {
137
+    /**
138
+     * Adds fees to a response for submission refresh prices.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     */
142
+    public function add_fees( $submission ) {
143 143
 
144
-		$fees = array();
144
+        $fees = array();
145 145
 
146 146
         foreach ( $submission->get_fees() as $name => $data ) {
147
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
148
-		}
147
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
148
+        }
149 149
 
150
-		$this->response = array_merge(
151
-			$this->response,
152
-			array( 'fees' => $fees )
153
-		);
150
+        $this->response = array_merge(
151
+            $this->response,
152
+            array( 'fees' => $fees )
153
+        );
154 154
 
155
-	}
155
+    }
156 156
 
157
-	/**
158
-	 * Adds discounts to a response for submission refresh prices.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 */
162
-	public function add_discounts( $submission ) {
157
+    /**
158
+     * Adds discounts to a response for submission refresh prices.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     */
162
+    public function add_discounts( $submission ) {
163 163
 
164
-		$discounts = array();
164
+        $discounts = array();
165 165
 
166 166
         foreach ( $submission->get_discounts() as $name => $data ) {
167
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
168
-		}
167
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
168
+        }
169 169
 
170
-		$this->response = array_merge(
171
-			$this->response,
172
-			array( 'discounts' => $discounts )
173
-		);
170
+        $this->response = array_merge(
171
+            $this->response,
172
+            array( 'discounts' => $discounts )
173
+        );
174 174
 
175
-	}
175
+    }
176 176
 
177
-	/**
178
-	 * Adds taxes to a response for submission refresh prices.
179
-	 *
180
-	 * @param GetPaid_Payment_Form_Submission $submission
181
-	 */
182
-	public function add_taxes( $submission ) {
177
+    /**
178
+     * Adds taxes to a response for submission refresh prices.
179
+     *
180
+     * @param GetPaid_Payment_Form_Submission $submission
181
+     */
182
+    public function add_taxes( $submission ) {
183 183
 
184
-		$taxes = array();
184
+        $taxes = array();
185 185
 
186 186
         foreach ( $submission->get_taxes() as $name => $data ) {
187
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
188
-		}
187
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
188
+        }
189 189
 
190
-		$this->response = array_merge(
191
-			$this->response,
192
-			array( 'taxes' => $taxes )
193
-		);
190
+        $this->response = array_merge(
191
+            $this->response,
192
+            array( 'taxes' => $taxes )
193
+        );
194 194
 
195
-	}
195
+    }
196 196
 
197
-	/**
198
-	 * Adds gateways to a response for submission refresh prices.
199
-	 *
200
-	 * @param GetPaid_Payment_Form_Submission $submission
201
-	 */
202
-	public function add_gateways( $submission ) {
197
+    /**
198
+     * Adds gateways to a response for submission refresh prices.
199
+     *
200
+     * @param GetPaid_Payment_Form_Submission $submission
201
+     */
202
+    public function add_gateways( $submission ) {
203 203
 
204
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
204
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205 205
 
206
-		if ( $this->response['has_recurring'] ) {
206
+        if ( $this->response['has_recurring'] ) {
207 207
 
208
-			foreach ( $gateways as $i => $gateway ) {
208
+            foreach ( $gateways as $i => $gateway ) {
209 209
 
210
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
211
-					unset( $gateways[ $i ] );
212
-				}
210
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
211
+                    unset( $gateways[ $i ] );
212
+                }
213 213
 
214
-			}
214
+            }
215 215
 
216
-		}
216
+        }
217 217
 
218 218
 
219
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
220
-		$this->response = array_merge(
221
-			$this->response,
222
-			array( 'gateways' => $gateways )
223
-		);
219
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
220
+        $this->response = array_merge(
221
+            $this->response,
222
+            array( 'gateways' => $gateways )
223
+        );
224 224
 
225
-	}
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 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
  * Payment form submission refresh prices class
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31
-            'is_free'       => ! $submission->should_collect_payment_details(),
31
+            'is_free'       => !$submission->should_collect_payment_details(),
32 32
 		);
33 33
 
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
34
+		$this->add_totals($submission);
35
+		$this->add_texts($submission);
36
+		$this->add_items($submission);
37
+		$this->add_fees($submission);
38
+		$this->add_discounts($submission);
39
+		$this->add_taxes($submission);
40
+		$this->add_gateways($submission);
41 41
 
42 42
 	}
43 43
 
@@ -46,26 +46,26 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @param GetPaid_Payment_Form_Submission $submission
48 48
 	 */
49
-	public function add_totals( $submission ) {
49
+	public function add_totals($submission) {
50 50
 
51 51
 		$this->response = array_merge(
52 52
 			$this->response,
53 53
 			array(
54 54
 
55 55
 				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
56
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
57
+					'discount'  => $submission->format_amount($submission->get_discount()),
58
+					'fees'      => $submission->format_amount($submission->get_fee()),
59
+					'tax'       => $submission->format_amount($submission->get_tax()),
60
+					'total'     => $submission->format_amount($submission->get_total()),
61 61
 				),
62 62
 	
63 63
 				'recurring'     => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
64
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
65
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
66
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
67
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
68
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
69 69
 				),
70 70
 
71 71
 			)
@@ -78,22 +78,22 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param GetPaid_Payment_Form_Submission $submission
80 80
 	 */
81
-	public function add_texts( $submission ) {
81
+	public function add_texts($submission) {
82 82
 
83
-		$payable = $submission->format_amount( $submission->get_total() );
83
+		$payable = $submission->format_amount($submission->get_total());
84 84
 
85
-		if ( $submission->has_recurring != 0 ) {
85
+		if ($submission->has_recurring != 0) {
86 86
 
87
-			$recurring = new WPInv_Item( $submission->has_recurring );
88
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
87
+			$recurring = new WPInv_Item($submission->has_recurring);
88
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
89 89
 
90
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
+			if ($submission->get_total() == $submission->get_recurring_total()) {
91 91
 				$payable = "$payable / $period";
92 92
 			} else {
93 93
 				$payable = sprintf(
94
-					__( '%1$s (renews at %2$s / %3$s)'),
95
-					$submission->format_amount( $submission->get_total() ),
96
-					$submission->format_amount( $submission->get_recurring_total() ),
94
+					__('%1$s (renews at %2$s / %3$s)'),
95
+					$submission->format_amount($submission->get_total()),
96
+					$submission->format_amount($submission->get_recurring_total()),
97 97
 					$period
98 98
 				);
99 99
 			}
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 			'.getpaid-checkout-total-payable' => $payable,
105 105
 		);
106 106
 
107
-		foreach ( $submission->get_items() as $item_id => $item ) {
108
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
109
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
107
+		foreach ($submission->get_items() as $item_id => $item) {
108
+			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount($item->get_sub_total());
109
+			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount($item->get_recurring_sub_total());
110 110
 		}
111 111
 
112
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112
+		$this->response = array_merge($this->response, array('texts' => $texts));
113 113
 
114 114
 	}
115 115
 
@@ -118,18 +118,18 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param GetPaid_Payment_Form_Submission $submission
120 120
 	 */
121
-	public function add_items( $submission ) {
121
+	public function add_items($submission) {
122 122
 
123 123
 		// Add items.
124 124
 		$items = array();
125 125
 
126
-        foreach ( $submission->get_items() as $item_id => $item ) {
127
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
126
+        foreach ($submission->get_items() as $item_id => $item) {
127
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
128 128
 		}
129 129
 
130 130
 		$this->response = array_merge(
131 131
 			$this->response,
132
-			array( 'items' => $items )
132
+			array('items' => $items)
133 133
 		);
134 134
 
135 135
 	}
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @param GetPaid_Payment_Form_Submission $submission
141 141
 	 */
142
-	public function add_fees( $submission ) {
142
+	public function add_fees($submission) {
143 143
 
144 144
 		$fees = array();
145 145
 
146
-        foreach ( $submission->get_fees() as $name => $data ) {
147
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
146
+        foreach ($submission->get_fees() as $name => $data) {
147
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
148 148
 		}
149 149
 
150 150
 		$this->response = array_merge(
151 151
 			$this->response,
152
-			array( 'fees' => $fees )
152
+			array('fees' => $fees)
153 153
 		);
154 154
 
155 155
 	}
@@ -159,17 +159,17 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @param GetPaid_Payment_Form_Submission $submission
161 161
 	 */
162
-	public function add_discounts( $submission ) {
162
+	public function add_discounts($submission) {
163 163
 
164 164
 		$discounts = array();
165 165
 
166
-        foreach ( $submission->get_discounts() as $name => $data ) {
167
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
166
+        foreach ($submission->get_discounts() as $name => $data) {
167
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
168 168
 		}
169 169
 
170 170
 		$this->response = array_merge(
171 171
 			$this->response,
172
-			array( 'discounts' => $discounts )
172
+			array('discounts' => $discounts)
173 173
 		);
174 174
 
175 175
 	}
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @param GetPaid_Payment_Form_Submission $submission
181 181
 	 */
182
-	public function add_taxes( $submission ) {
182
+	public function add_taxes($submission) {
183 183
 
184 184
 		$taxes = array();
185 185
 
186
-        foreach ( $submission->get_taxes() as $name => $data ) {
187
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
186
+        foreach ($submission->get_taxes() as $name => $data) {
187
+			$taxes[$name] = $submission->format_amount($data['initial_tax']);
188 188
 		}
189 189
 
190 190
 		$this->response = array_merge(
191 191
 			$this->response,
192
-			array( 'taxes' => $taxes )
192
+			array('taxes' => $taxes)
193 193
 		);
194 194
 
195 195
 	}
@@ -199,16 +199,16 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @param GetPaid_Payment_Form_Submission $submission
201 201
 	 */
202
-	public function add_gateways( $submission ) {
202
+	public function add_gateways($submission) {
203 203
 
204
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
204
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
205 205
 
206
-		if ( $this->response['has_recurring'] ) {
206
+		if ($this->response['has_recurring']) {
207 207
 
208
-			foreach ( $gateways as $i => $gateway ) {
208
+			foreach ($gateways as $i => $gateway) {
209 209
 
210
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
211
-					unset( $gateways[ $i ] );
210
+				if (!wpinv_gateway_support_subscription($gateway)) {
211
+					unset($gateways[$i]);
212 212
 				}
213 213
 
214 214
 			}
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
 		}
217 217
 
218 218
 
219
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
219
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
220 220
 		$this->response = array_merge(
221 221
 			$this->response,
222
-			array( 'gateways' => $gateways )
222
+			array('gateways' => $gateways)
223 223
 		);
224 224
 
225 225
 	}
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +140 added lines, -140 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,96 +11,96 @@  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
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
39
+function wpinv_get_enabled_payment_gateways($sort = false) {
40 40
     $gateways = wpinv_get_payment_gateways();
41
-    $enabled  = wpinv_get_option( 'gateways', false );
41
+    $enabled  = wpinv_get_option('gateways', false);
42 42
 
43 43
     $gateway_list = array();
44 44
 
45
-    foreach ( $gateways as $key => $gateway ) {
46
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
47
-            $gateway_list[ $key ] = $gateway;
45
+    foreach ($gateways as $key => $gateway) {
46
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
47
+            $gateway_list[$key] = $gateway;
48 48
         }
49 49
     }
50 50
 
51
-    if ( true === $sort ) {
52
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
51
+    if (true === $sort) {
52
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
53 53
         
54 54
         // Reorder our gateways so the default is first
55 55
         $default_gateway_id = wpinv_get_default_gateway();
56 56
 
57
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
58
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
59
-            unset( $gateway_list[ $default_gateway_id ] );
57
+        if (wpinv_is_gateway_active($default_gateway_id)) {
58
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
59
+            unset($gateway_list[$default_gateway_id]);
60 60
 
61
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
61
+            $gateway_list = array_merge($default_gateway, $gateway_list);
62 62
         }
63 63
     }
64 64
 
65
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
65
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
66 66
 }
67 67
 
68
-function wpinv_sort_gateway_order( $a, $b ) {
68
+function wpinv_sort_gateway_order($a, $b) {
69 69
     return $a['ordering'] - $b['ordering'];
70 70
 }
71 71
 
72
-function wpinv_is_gateway_active( $gateway ) {
72
+function wpinv_is_gateway_active($gateway) {
73 73
     $gateways = wpinv_get_enabled_payment_gateways();
74 74
 
75
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
75
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
76 76
 
77
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
77
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
78 78
 }
79 79
 
80 80
 function wpinv_get_default_gateway() {
81
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
81
+    $default = wpinv_get_option('default_gateway', 'paypal');
82 82
 
83
-    if ( !wpinv_is_gateway_active( $default ) ) {
83
+    if (!wpinv_is_gateway_active($default)) {
84 84
         $gateways = wpinv_get_enabled_payment_gateways();
85
-        $gateways = array_keys( $gateways );
86
-        $default  = reset( $gateways );
85
+        $gateways = array_keys($gateways);
86
+        $default  = reset($gateways);
87 87
     }
88 88
 
89
-    return apply_filters( 'wpinv_default_gateway', $default );
89
+    return apply_filters('wpinv_default_gateway', $default);
90 90
 }
91 91
 
92
-function wpinv_get_gateway_admin_label( $gateway ) {
92
+function wpinv_get_gateway_admin_label($gateway) {
93 93
     $gateways = wpinv_get_payment_gateways();
94
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
95
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
94
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
95
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
96 96
 
97
-    if( $gateway == 'manual' && $payment ) {
98
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
99
-            $label = __( 'Free Purchase', 'invoicing' );
97
+    if ($gateway == 'manual' && $payment) {
98
+        if (!((float) wpinv_payment_total($payment) > 0)) {
99
+            $label = __('Free Purchase', 'invoicing');
100 100
         }
101 101
     }
102 102
 
103
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
103
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
104 104
 }
105 105
 
106 106
 /**
@@ -108,49 +108,49 @@  discard block
 block discarded – undo
108 108
  * 
109 109
  * @param string $gateway
110 110
  */
111
-function wpinv_get_gateway_description( $gateway ) {
111
+function wpinv_get_gateway_description($gateway) {
112 112
     global $wpinv_options;
113 113
 
114
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
114
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
115 115
 
116
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
116
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
117 117
 }
118 118
 
119
-function wpinv_get_gateway_button_label( $gateway ) {
120
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
119
+function wpinv_get_gateway_button_label($gateway) {
120
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
121 121
 }
122 122
 
123
-function wpinv_get_gateway_checkout_label( $gateway ) {
123
+function wpinv_get_gateway_checkout_label($gateway) {
124 124
     $gateways = wpinv_get_payment_gateways();
125
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
125
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
126 126
 
127
-    if ( $gateway == 'none' ) {
128
-        $label = __( 'None', 'invoicing' );
127
+    if ($gateway == 'none') {
128
+        $label = __('None', 'invoicing');
129 129
     }
130 130
 
131
-    return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway );
131
+    return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway);
132 132
 }
133 133
 
134
-function wpinv_settings_sections_gateways( $settings ) {
134
+function wpinv_settings_sections_gateways($settings) {
135 135
     $gateways = wpinv_get_payment_gateways();
136 136
     
137 137
     if (!empty($gateways)) {
138
-        foreach  ($gateways as $key => $gateway) {
138
+        foreach ($gateways as $key => $gateway) {
139 139
             $settings[$key] = $gateway['admin_label'];
140 140
         }
141 141
     }
142 142
     
143 143
     return $settings;    
144 144
 }
145
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
145
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
146 146
 
147 147
 /**
148 148
  * Adds GateWay settings.
149 149
  */
150
-function wpinv_settings_gateways( $settings ) {
150
+function wpinv_settings_gateways($settings) {
151 151
 
152 152
     // Loop through each gateway.
153
-    foreach  ( wpinv_get_payment_gateways() as $key => $gateway ) {
153
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
154 154
 
155 155
         $gateway_settings = array(
156 156
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             "{$key}_header" => array(
159 159
 
160 160
                 'id'     => "{$key}_gateway_header",
161
-                'name'   => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
161
+                'name'   => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
162 162
                 'custom' => $key,
163 163
                 'type'   => 'gateway_header',
164 164
 
@@ -167,56 +167,56 @@  discard block
 block discarded – undo
167 167
             // Activate/Deactivate a gateway.
168 168
             "{$key}_active" => array(
169 169
                 'id'   => $key . '_active',
170
-                'name' => __( 'Activate', 'invoicing' ),
171
-                'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
170
+                'name' => __('Activate', 'invoicing'),
171
+                'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
172 172
                 'type' => 'checkbox',
173 173
             ),
174 174
 
175 175
             // Activate/Deactivate sandbox.
176 176
             "{$key}_sandbox" => array(
177 177
                 'id'   => $key . '_sandbox',
178
-                'name' => __( 'Sandbox', 'invoicing' ),
179
-                'desc' => __( 'Enable sandbox to test payments', 'invoicing' ),
178
+                'name' => __('Sandbox', 'invoicing'),
179
+                'desc' => __('Enable sandbox to test payments', 'invoicing'),
180 180
                 'type' => 'checkbox',
181 181
             ),
182 182
 
183 183
             // Checkout title.
184 184
             "{$key}_title" => array(
185 185
                 'id'   => $key . '_title',
186
-                'name' => __( 'Checkout Title', 'invoicing' ),
187
-                'std'  => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '',
186
+                'name' => __('Checkout Title', 'invoicing'),
187
+                'std'  => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '',
188 188
                 'type' => 'text',
189 189
             ),
190 190
 
191 191
             // Checkout description.
192 192
             "{$key}_desc" => array(
193 193
                 'id'   => $key . '_desc',
194
-                'name' => __( 'Checkout Description', 'invoicing' ),
195
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
194
+                'name' => __('Checkout Description', 'invoicing'),
195
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
196 196
                 'type' => 'text',
197 197
             ),
198 198
 
199 199
             // Checkout order.
200 200
             "{$key}_ordering" => array(
201 201
                 'id'   => $key . '_ordering',
202
-                'name' => __( 'Priority', 'invoicing' ),
203
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
202
+                'name' => __('Priority', 'invoicing'),
203
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
204 204
                 'type' => 'number',
205 205
                 'step' => '1',
206 206
                 'min'  => '-100000',
207 207
                 'max'  => '100000',
208
-                'std'  => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10',
208
+                'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
209 209
             ),
210 210
 
211 211
         );
212 212
 
213 213
         // Maybe remove the sandbox.
214
-        if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) {
215
-            unset( $gateway_settings["{$key}_sandbox"] );
214
+        if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) {
215
+            unset($gateway_settings["{$key}_sandbox"]);
216 216
         }
217 217
   
218
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway );
219
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway );
218
+        $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway);
219
+        $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway);
220 220
         
221 221
         $settings[$key] = $gateway_settings;
222 222
     }
@@ -224,57 +224,57 @@  discard block
 block discarded – undo
224 224
     return $settings;
225 225
 
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_get_chosen_gateway( $invoice_id = 0 ) {
240
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
239
+function wpinv_get_chosen_gateway($invoice_id = 0) {
240
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
241 241
 
242 242
     $chosen = false;
243
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
243
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
244 244
         $chosen = $invoice->get_gateway();
245 245
     }
246 246
 
247
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
247
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
248 248
 
249
-	if ( false !== $chosen ) {
250
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
249
+	if (false !== $chosen) {
250
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
251 251
 	}
252 252
 
253
-	if ( ! empty ( $chosen ) ) {
254
-		$enabled_gateway = urldecode( $chosen );
255
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
253
+	if (!empty ($chosen)) {
254
+		$enabled_gateway = urldecode($chosen);
255
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
256 256
 		$enabled_gateway = 'manual';
257 257
 	} else {
258 258
 		$enabled_gateway = wpinv_get_default_gateway();
259 259
 	}
260 260
     
261
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
262
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
261
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
262
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
263 263
             $enabled_gateway = wpinv_get_default_gateway();
264
-        }else{
264
+        } else {
265 265
             $enabled_gateway = $gateways[0];
266 266
         }
267 267
 
268 268
     }
269 269
 
270
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
270
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
271 271
 }
272 272
 
273
-function wpinv_record_gateway_error( $title = '', $message = '' ) {
274
-    return wpinv_error_log( $message, $title );
273
+function wpinv_record_gateway_error($title = '', $message = '') {
274
+    return wpinv_error_log($message, $title);
275 275
 }
276 276
 
277
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
277
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
278 278
 	$ret  = 0;
279 279
 	$args = array(
280 280
 		'meta_key'    => '_wpinv_gateway',
@@ -285,48 +285,48 @@  discard block
 block discarded – undo
285 285
 		'fields'      => 'ids'
286 286
 	);
287 287
 
288
-	$payments = new WP_Query( $args );
288
+	$payments = new WP_Query($args);
289 289
 
290
-	if( $payments )
290
+	if ($payments)
291 291
 		$ret = $payments->post_count;
292 292
 	return $ret;
293 293
 }
294 294
 
295
-function wpinv_settings_update_gateways( $input ) {
295
+function wpinv_settings_update_gateways($input) {
296 296
     global $wpinv_options;
297 297
     
298
-    if ( !empty( $input['save_gateway'] ) ) {
299
-        $gateways = wpinv_get_option( 'gateways', false );
298
+    if (!empty($input['save_gateway'])) {
299
+        $gateways = wpinv_get_option('gateways', false);
300 300
         $gateways = !empty($gateways) ? $gateways : array();
301 301
         $gateway = $input['save_gateway'];
302 302
         
303
-        if ( !empty( $input[$gateway . '_active'] ) ) {
303
+        if (!empty($input[$gateway . '_active'])) {
304 304
             $gateways[$gateway] = 1;
305 305
         } else {
306
-            if ( isset( $gateways[$gateway] ) ) {
307
-                unset( $gateways[$gateway] );
306
+            if (isset($gateways[$gateway])) {
307
+                unset($gateways[$gateway]);
308 308
             }
309 309
         }
310 310
         
311 311
         $input['gateways'] = $gateways;
312 312
     }
313 313
     
314
-    if ( !empty( $input['default_gateway'] ) ) {
314
+    if (!empty($input['default_gateway'])) {
315 315
         $gateways = wpinv_get_payment_gateways();
316 316
         
317
-        foreach ( $gateways as $key => $gateway ) {
318
-            $active   = 0;
319
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
317
+        foreach ($gateways as $key => $gateway) {
318
+            $active = 0;
319
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
320 320
                 $active = 1;
321 321
             }
322 322
             
323 323
             $input[$key . '_active'] = $active;
324 324
             
325
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
325
+            if (empty($wpinv_options[$key . '_title'])) {
326 326
                 $input[$key . '_title'] = $gateway['checkout_label'];
327 327
             }
328 328
             
329
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
329
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
330 330
                 $input[$key . '_ordering'] = $gateway['ordering'];
331 331
             }
332 332
         }
@@ -334,27 +334,27 @@  discard block
 block discarded – undo
334 334
     
335 335
     return $input;
336 336
 }
337
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
337
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
338 338
 
339 339
 // PayPal Standard settings
340
-function wpinv_gateway_settings_paypal( $setting ) {    
341
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
342
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
340
+function wpinv_gateway_settings_paypal($setting) {    
341
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
342
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
343 343
     
344 344
     $setting['paypal_sandbox'] = array(
345 345
             'type' => 'checkbox',
346 346
             'id'   => 'paypal_sandbox',
347
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
348
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
347
+            'name' => __('PayPal Sandbox', 'invoicing'),
348
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
349 349
             'std'  => 1
350 350
         );
351 351
         
352 352
     $setting['paypal_email'] = array(
353 353
             'type' => 'text',
354 354
             'id'   => 'paypal_email',
355
-            'name' => __( 'PayPal Email', 'invoicing' ),
356
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
357
-            'std' => __( '[email protected]', 'invoicing' ),
355
+            'name' => __('PayPal Email', 'invoicing'),
356
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
357
+            'std' => __('[email protected]', 'invoicing'),
358 358
         );
359 359
     /*
360 360
     $setting['paypal_ipn_url'] = array(
@@ -368,18 +368,18 @@  discard block
 block discarded – undo
368 368
         
369 369
     return $setting;
370 370
 }
371
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
371
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
372 372
 
373 373
 /**
374 374
  * Displays the ipn url field.
375 375
  */
376
-function wpinv_ipn_url_callback( $args ) {
377
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
376
+function wpinv_ipn_url_callback($args) {
377
+    $sanitize_id = wpinv_sanitize_key($args['id']);
378 378
     
379 379
     $attrs = $args['readonly'] ? ' readonly' : '';
380 380
 
381
-    $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()">';
382
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
381
+    $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()">';
382
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
383 383
 
384 384
     echo $html;
385 385
 }
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
  * 
392 392
  * @return bool
393 393
  */
394
-function wpinv_is_test_mode( $gateway = '' ) {
395
-    $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", false );
396
-    return apply_filters( 'wpinv_is_test_mode', $sandbox, $gateway );
394
+function wpinv_is_test_mode($gateway = '') {
395
+    $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", false);
396
+    return apply_filters('wpinv_is_test_mode', $sandbox, $gateway);
397 397
 }
398 398
 
399 399
 /**
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
  * 
405 405
  * @return string
406 406
  */
407
-function wpinv_get_ipn_url( $gateway = false, $args = array() ) {
407
+function wpinv_get_ipn_url($gateway = false, $args = array()) {
408 408
     $args = wp_parse_args(
409 409
         array(
410 410
             'wpi-listener' => 'IPN',
@@ -413,37 +413,37 @@  discard block
 block discarded – undo
413 413
         $args
414 414
     );
415 415
 
416
-    return apply_filters( 'wpinv_ipn_url', add_query_arg( $args,  home_url( 'index.php' ) ), $gateway, $args );
416
+    return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args);
417 417
 
418 418
 }
419 419
 
420 420
 /**
421 421
  * Retrieves request data with slashes removed slashes.
422 422
  */
423
-function wpinv_get_post_data( $method = 'request' ) {
423
+function wpinv_get_post_data($method = 'request') {
424 424
 
425
-    if ( $method == 'post' ) {
426
-        return wp_unslash( $_POST );
425
+    if ($method == 'post') {
426
+        return wp_unslash($_POST);
427 427
     }
428 428
 
429
-    if ( $method == 'get' ) {
430
-        return wp_unslash( $_GET );
429
+    if ($method == 'get') {
430
+        return wp_unslash($_GET);
431 431
     }
432 432
 
433
-    return wp_unslash( $_REQUEST );
433
+    return wp_unslash($_REQUEST);
434 434
   
435 435
 }
436 436
 
437 437
 /**
438 438
  * Checks if a given gateway supports subscription payments.
439 439
  */
440
-function wpinv_gateway_support_subscription( $gateway ) {
440
+function wpinv_gateway_support_subscription($gateway) {
441 441
     $supports = false;
442 442
 
443
-    if ( wpinv_is_gateway_active( $gateway ) ) {
444
-        $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports );
443
+    if (wpinv_is_gateway_active($gateway)) {
444
+        $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports);
445 445
 
446
-        $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway );
446
+        $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway);
447 447
     }
448 448
 
449 449
     return $supports;
@@ -455,14 +455,14 @@  discard block
 block discarded – undo
455 455
  * @param array $gateways an array of gateways.
456 456
  * @param GetPaid_Payment_Form $form payment form.
457 457
  */
458
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
458
+function wpinv_payment_gateways_on_cart($gateways, $form) {
459 459
 
460
-    if ( $form->is_recurring() ) {
460
+    if ($form->is_recurring()) {
461 461
 
462
-        foreach ( array_keys( $gateways ) as $gateway ) {
462
+        foreach (array_keys($gateways) as $gateway) {
463 463
 
464
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
465
-                unset( $gateways[$gateway] );
464
+            if (!wpinv_gateway_support_subscription($gateway)) {
465
+                unset($gateways[$gateway]);
466 466
             }
467 467
 
468 468
         }
@@ -471,4 +471,4 @@  discard block
 block discarded – undo
471 471
 
472 472
     return $gateways;
473 473
 }
474
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
474
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
Please login to merge, or discard this patch.
templates/payment-forms/elements/gateway_select.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // The payment methods select title.
13
-if ( empty( $text ) ) {
14
-    $text = __( 'Select Payment Method', 'invoicing' );
13
+if (empty($text)) {
14
+    $text = __('Select Payment Method', 'invoicing');
15 15
 }
16 16
 
17 17
 // An array of active payment methods.
18
-$gateways = wpinv_get_enabled_payment_gateways( true );
18
+$gateways = wpinv_get_enabled_payment_gateways(true);
19 19
 
20 20
 // The current invoice id.
21 21
 $invoice_id     = 0;
22 22
 $chosen_gateway = wpinv_get_default_gateway();
23 23
 
24
-if ( ! empty( $form->invoice ) ) {
24
+if (!empty($form->invoice)) {
25 25
     $invoice_id = $form->invoice->get_id();
26 26
     $chosen_gateway = $form->invoice->get_gateway();
27 27
 }
@@ -30,21 +30,21 @@  discard block
 block discarded – undo
30 30
 
31 31
     <div class="mt-4 mb-4 getpaid-gateways">
32 32
 
33
-        <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
33
+        <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?>
34 34
 
35 35
         <div class="getpaid-select-gateway-title-div">
36
-            <h6><?php echo sanitize_text_field( $text ); ?></h6>
36
+            <h6><?php echo sanitize_text_field($text); ?></h6>
37 37
         </div>
38 38
 
39 39
         <div class="getpaid-available-gateways-div">
40 40
 
41
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
41
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
42 42
 
43
-                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'>
43
+                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'>
44 44
 
45 45
                     <label class="d-block w-100 getpaid-gateway-radio">
46
-                        <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway">
47
-                        <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span>
46
+                        <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway">
47
+                        <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span>
48 48
                     </label>
49 49
 
50 50
                 </div>
@@ -55,22 +55,22 @@  discard block
 block discarded – undo
55 55
 
56 56
         <div class="getpaid-gateway-descriptions-div">
57 57
 
58
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
58
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
59 59
 
60
-                <div class="mb-2 mt-2 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;">
60
+                <div class="mb-2 mt-2 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;">
61 61
                     <?php
62 62
 
63
-                        $description = wpinv_get_gateway_description( $gateway );
63
+                        $description = wpinv_get_gateway_description($gateway);
64 64
 
65
-                        if ( wpinv_is_test_mode( $gateway ) ) {
66
-                            $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) );
65
+                        if (wpinv_is_test_mode($gateway)) {
66
+                            $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing'));
67 67
                             $description = "$description $sandbox_notice";
68 68
                         }
69 69
 
70
-                        echo wpautop( wp_kses_post( $description ) );
70
+                        echo wpautop(wp_kses_post($description));
71 71
 
72
-                        do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ;
73
-                        do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ;
72
+                        do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id);
73
+                        do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form);
74 74
 
75 75
                     ?>
76 76
                 </div>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             <?php
84 84
                 echo aui()->alert(
85 85
                     array(
86
-                        'content'     => __( 'None of the available payment gateways support subscriptions.', 'invoicing' ),
86
+                        'content'     => __('None of the available payment gateways support subscriptions.', 'invoicing'),
87 87
                         'type'        => 'danger',
88 88
                     )
89 89
                 );
@@ -94,14 +94,14 @@  discard block
 block discarded – undo
94 94
             <?php
95 95
                 echo aui()->alert(
96 96
                     array(
97
-                        'content'     => __( 'There is no active payment gateway available to process your request.', 'invoicing' ),
97
+                        'content'     => __('There is no active payment gateway available to process your request.', 'invoicing'),
98 98
                         'type'        => 'danger',
99 99
                     )
100 100
                 );
101 101
             ?>
102 102
         </div>
103 103
 
104
-        <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
104
+        <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?>
105 105
 
106 106
     </div>
107 107
 
Please login to merge, or discard this patch.
templates/payment-forms/elements/pay_button.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$class = empty( $class ) ? 'btn-primary' : sanitize_html_class( $class );
13
-$label = empty( $label ) ? esc_attr__( 'Proceed to Pay »', 'invoicing' ) : esc_attr( $label );
14
-$free  = empty( $free ) ? esc_attr__( 'Continue »', 'invoicing' ) : esc_attr( $free );
12
+$class = empty($class) ? 'btn-primary' : sanitize_html_class($class);
13
+$label = empty($label) ? esc_attr__('Proceed to Pay »', 'invoicing') : esc_attr($label);
14
+$free  = empty($free) ? esc_attr__('Continue »', 'invoicing') : esc_attr($free);
15 15
 
16 16
 echo aui()->input(
17 17
     array(
18
-        'name'             => esc_attr( $id ),
19
-        'id'               => esc_attr( $id ) . uniqid( '_' ),
20
-        'value'            => empty( $label ) ? __( 'Proceed to Pay »', 'invoicing' ) : esc_attr( $label ),
21
-        'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
18
+        'name'             => esc_attr($id),
19
+        'id'               => esc_attr($id) . uniqid('_'),
20
+        'value'            => empty($label) ? __('Proceed to Pay »', 'invoicing') : esc_attr($label),
21
+        'help_text'        => empty($description) ? '' : wp_kses_post($description),
22 22
         'type'             => 'submit',
23 23
         'class'            => 'getpaid-payment-form-submit btn btn-block submit-button ' . $class,
24 24
         'extra_attributes' => array(
Please login to merge, or discard this patch.