Passed
Push — master ( 8cc3cf...2975b0 )
by Brian
04:06
created
includes/gateways/class-getpaid-manual-gateway.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_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 = 'manual';
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', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 11;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 11;
35 35
     
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title        = __( 'Manual Payment', 'invoicing' );
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Process Payment.
50
-	 *
51
-	 *
52
-	 * @param WPInv_Invoice $invoice Invoice.
53
-	 * @param array $submission_data Posted checkout fields.
54
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
-	 * @return array
56
-	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
49
+     * Process Payment.
50
+     *
51
+     *
52
+     * @param WPInv_Invoice $invoice Invoice.
53
+     * @param array $submission_data Posted checkout fields.
54
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
+     * @return array
56
+     */
57
+    public function process_payment( $invoice, $submission_data, $submission ) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
     }
69 69
 
70 70
     /**
71
-	 * (Maybe) renews a manual subscription profile.
72
-	 *
73
-	 *
74
-	 * @param bool $should_expire
71
+     * (Maybe) renews a manual subscription profile.
72
+     *
73
+     *
74
+     * @param bool $should_expire
75 75
      * @param WPInv_Subscription $subscription
76
-	 */
77
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
76
+     */
77
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
78 78
 
79 79
         // Ensure its our subscription && it's active.
80 80
         if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-	 * Processes invoice addons.
106
-	 *
107
-	 * @param WPInv_Invoice $invoice
108
-	 * @param GetPaid_Form_Item[] $items
109
-	 * @return WPInv_Invoice
110
-	 */
111
-	public function process_addons( $invoice, $items ) {
105
+     * Processes invoice addons.
106
+     *
107
+     * @param WPInv_Invoice $invoice
108
+     * @param GetPaid_Form_Item[] $items
109
+     * @return WPInv_Invoice
110
+     */
111
+    public function process_addons( $invoice, $items ) {
112 112
 
113 113
         foreach ( $items as $item ) {
114 114
             $invoice->add_item( $item );
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 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
  * Manual 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', 'addons' );
27
+    protected $supports = array('subscription', 'addons');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title        = __( 'Manual Payment', 'invoicing' );
43
-        $this->method_title = __( 'Manual Payment', 'invoicing' );
42
+        $this->title        = __('Manual Payment', 'invoicing');
43
+        $this->method_title = __('Manual Payment', 'invoicing');
44 44
 
45
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
45
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
46 46
     }
47 47
 
48 48
     /**
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55 55
 	 * @return array
56 56
 	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+	public function process_payment($invoice, $submission_data, $submission) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
61 61
 
62 62
         // (Maybe) activate subscription.
63
-        getpaid_activate_invoice_subscription( $invoice );
63
+        getpaid_activate_invoice_subscription($invoice);
64 64
 
65 65
         // Send to the success page.
66
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
66
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
67 67
 
68 68
     }
69 69
 
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 	 * @param bool $should_expire
75 75
      * @param WPInv_Subscription $subscription
76 76
 	 */
77
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
77
+	public function maybe_renew_subscription($should_expire, $subscription) {
78 78
 
79 79
         // Ensure its our subscription && it's active.
80
-        if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
80
+        if ('manual' != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
81 81
             return $should_expire;
82 82
         }
83 83
 
84 84
         // If this is the last renewal, complete the subscription.
85
-        if ( $subscription->is_last_renewal() ) {
85
+        if ($subscription->is_last_renewal()) {
86 86
             $subscription->complete();
87 87
             return false;
88 88
         }
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 	 * @param GetPaid_Form_Item[] $items
109 109
 	 * @return WPInv_Invoice
110 110
 	 */
111
-	public function process_addons( $invoice, $items ) {
111
+	public function process_addons($invoice, $items) {
112 112
 
113
-        foreach ( $items as $item ) {
114
-            $invoice->add_item( $item );
113
+        foreach ($items as $item) {
114
+            $invoice->add_item($item);
115 115
         }
116 116
 
117 117
         $invoice->recalculate_total();
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 2 patches
Indentation   +592 added lines, -592 removed lines patch added patch discarded remove patch
@@ -13,467 +13,467 @@  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
-
141
-		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
-
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
145
-
146
-		// Enable Subscriptions.
147
-		if ( $this->supports( 'subscription' ) ) {
148
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
-		}
150
-
151
-		// Enable sandbox.
152
-		if ( $this->supports( 'sandbox' ) ) {
153
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
-		}
155
-
156
-		// Invoice addons.
157
-		if ( $this->supports( 'addons' ) ) {
158
-			add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
-		}
161
-
162
-		// Gateway settings.
163
-		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
+
141
+        // Register gateway.
142
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
+
144
+        $this->enabled = wpinv_is_gateway_active( $this->id );
145
+
146
+        // Enable Subscriptions.
147
+        if ( $this->supports( 'subscription' ) ) {
148
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
+        }
150
+
151
+        // Enable sandbox.
152
+        if ( $this->supports( 'sandbox' ) ) {
153
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
+        }
155
+
156
+        // Invoice addons.
157
+        if ( $this->supports( 'addons' ) ) {
158
+            add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
+        }
161
+
162
+        // Gateway settings.
163
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
164 164
 		
165 165
 
166
-		// Gateway checkout fiellds.
167
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
-
169
-		// Process payment.
170
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
166
+        // Gateway checkout fiellds.
167
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
+
169
+        // Process payment.
170
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
171
+
172
+        // Change the checkout button text.
173
+        if ( ! empty( $this->checkout_button_text ) ) {
174
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
+        }
176
+
177
+        // Check if a gateway is valid for a given currency.
178
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
+
180
+        // Generate the transaction url.
181
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
+
183
+        // Generate the subscription url.
184
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
185
+
186
+        // Confirm payments.
187
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
+
189
+        // Verify IPNs.
190
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
+
192
+    }
193
+
194
+    /**
195
+     * Checks if this gateway is a given gateway.
196
+     *
197
+     * @since 1.0.19
198
+     * @return bool
199
+     */
200
+    public function is( $gateway ) {
201
+        return $gateway == $this->id;
202
+    }
203
+
204
+    /**
205
+     * Returns a users saved tokens for this gateway.
206
+     *
207
+     * @since 1.0.19
208
+     * @return array
209
+     */
210
+    public function get_tokens( $sandbox = null ) {
211
+
212
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
+
215
+            if ( is_array( $tokens ) ) {
216
+                $this->tokens = $tokens;
217
+            }
218
+
219
+        }
220
+
221
+        if ( ! is_bool( $sandbox ) ) {
222
+            return $this->tokens;
223
+        }
224
+
225
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
+        return wp_list_filter( $this->tokens, $args );
227
+
228
+    }
229
+
230
+    /**
231
+     * Saves a token for this gateway.
232
+     *
233
+     * @since 1.0.19
234
+     */
235
+    public function save_token( $token ) {
236
+
237
+        $tokens   = $this->get_tokens();
238
+        $tokens[] = $token;
239
+
240
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
+
242
+        $this->tokens = $tokens;
243
+
244
+    }
245
+
246
+    /**
247
+     * Return the title for admin screens.
248
+     *
249
+     * @return string
250
+     */
251
+    public function get_method_title() {
252
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
+    }
254
+
255
+    /**
256
+     * Return the description for admin screens.
257
+     *
258
+     * @return string
259
+     */
260
+    public function get_method_description() {
261
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
+    }
263
+
264
+    /**
265
+     * Get the success url.
266
+     *
267
+     * @param WPInv_Invoice $invoice Invoice object.
268
+     * @return string
269
+     */
270
+    public function get_return_url( $invoice ) {
271
+
272
+        // Payment success url
273
+        $return_url = add_query_arg(
274
+            array(
275
+                'payment-confirm' => $this->id,
276
+                'invoice_key'     => $invoice->get_key(),
277
+                'utm_nooverride'  => 1
278
+            ),
279
+            wpinv_get_success_page_uri()
280
+        );
281
+
282
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
+    }
284
+
285
+    /**
286
+     * Confirms payments when rendering the success page.
287
+     *
288
+     * @param string $content Success page content.
289
+     * @return string
290
+     */
291
+    public function confirm_payment( $content ) {
292
+
293
+        // Retrieve the invoice.
294
+        $invoice_id = getpaid_get_current_invoice_id();
295
+        $invoice    = wpinv_get_invoice( $invoice_id );
296
+
297
+        // Ensure that it exists and that it is pending payment.
298
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
+            return $content;
300
+        }
301
+
302
+        // Can the user view this invoice??
303
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
+            return $content;
305
+        }
306
+
307
+        // Show payment processing indicator.
308
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
+    }
310
+
311
+    /**
312
+     * Processes ipns and marks payments as complete.
313
+     *
314
+     * @return void
315
+     */
316
+    public function verify_ipn() {}
317
+
318
+    /**
319
+     * Processes invoice addons.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     * @param GetPaid_Form_Item[] $items
323
+     * @return WPInv_Invoice
324
+     */
325
+    public function process_addons( $invoice, $items ) {
326
+
327
+    }
328
+
329
+    /**
330
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
+     *
332
+     * @param string $transaction_url transaction url.
333
+     * @param WPInv_Invoice $invoice Invoice object.
334
+     * @return string transaction URL, or empty string.
335
+     */
336
+    public function filter_transaction_url( $transaction_url, $invoice ) {
337
+
338
+        $transaction_id  = $invoice->get_transaction_id();
339
+
340
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
+        }
345
+
346
+        return $transaction_url;
347
+    }
348
+
349
+    /**
350
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
+     *
352
+     * @param string $subscription_url transaction url.
353
+     * @param WPInv_Invoice $invoice Invoice object.
354
+     * @return string subscription URL, or empty string.
355
+     */
356
+    public function filter_subscription_url( $subscription_url, $invoice ) {
357
+
358
+        $profile_id      = $invoice->get_subscription_id();
359
+
360
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
171 361
 
172
-		// Change the checkout button text.
173
-		if ( ! empty( $this->checkout_button_text ) ) {
174
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
-		}
176
-
177
-		// Check if a gateway is valid for a given currency.
178
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
-
180
-		// Generate the transaction url.
181
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
-
183
-		// Generate the subscription url.
184
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
185
-
186
-		// Confirm payments.
187
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
-
189
-		// Verify IPNs.
190
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
-
192
-	}
193
-
194
-	/**
195
-	 * Checks if this gateway is a given gateway.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @return bool
199
-	 */
200
-	public function is( $gateway ) {
201
-		return $gateway == $this->id;
202
-	}
203
-
204
-	/**
205
-	 * Returns a users saved tokens for this gateway.
206
-	 *
207
-	 * @since 1.0.19
208
-	 * @return array
209
-	 */
210
-	public function get_tokens( $sandbox = null ) {
211
-
212
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
-
215
-			if ( is_array( $tokens ) ) {
216
-				$this->tokens = $tokens;
217
-			}
218
-
219
-		}
220
-
221
-		if ( ! is_bool( $sandbox ) ) {
222
-			return $this->tokens;
223
-		}
224
-
225
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
-		return wp_list_filter( $this->tokens, $args );
227
-
228
-	}
229
-
230
-	/**
231
-	 * Saves a token for this gateway.
232
-	 *
233
-	 * @since 1.0.19
234
-	 */
235
-	public function save_token( $token ) {
236
-
237
-		$tokens   = $this->get_tokens();
238
-		$tokens[] = $token;
239
-
240
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
-
242
-		$this->tokens = $tokens;
243
-
244
-	}
245
-
246
-	/**
247
-	 * Return the title for admin screens.
248
-	 *
249
-	 * @return string
250
-	 */
251
-	public function get_method_title() {
252
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
-	}
254
-
255
-	/**
256
-	 * Return the description for admin screens.
257
-	 *
258
-	 * @return string
259
-	 */
260
-	public function get_method_description() {
261
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
-	}
263
-
264
-	/**
265
-	 * Get the success url.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice Invoice object.
268
-	 * @return string
269
-	 */
270
-	public function get_return_url( $invoice ) {
271
-
272
-		// Payment success url
273
-		$return_url = add_query_arg(
274
-			array(
275
-				'payment-confirm' => $this->id,
276
-				'invoice_key'     => $invoice->get_key(),
277
-				'utm_nooverride'  => 1
278
-			),
279
-			wpinv_get_success_page_uri()
280
-		);
281
-
282
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
-	}
284
-
285
-	/**
286
-	 * Confirms payments when rendering the success page.
287
-	 *
288
-	 * @param string $content Success page content.
289
-	 * @return string
290
-	 */
291
-	public function confirm_payment( $content ) {
292
-
293
-		// Retrieve the invoice.
294
-		$invoice_id = getpaid_get_current_invoice_id();
295
-		$invoice    = wpinv_get_invoice( $invoice_id );
296
-
297
-		// Ensure that it exists and that it is pending payment.
298
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
-			return $content;
300
-		}
301
-
302
-		// Can the user view this invoice??
303
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
-			return $content;
305
-		}
306
-
307
-		// Show payment processing indicator.
308
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
-	}
310
-
311
-	/**
312
-	 * Processes ipns and marks payments as complete.
313
-	 *
314
-	 * @return void
315
-	 */
316
-	public function verify_ipn() {}
317
-
318
-	/**
319
-	 * Processes invoice addons.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 * @param GetPaid_Form_Item[] $items
323
-	 * @return WPInv_Invoice
324
-	 */
325
-	public function process_addons( $invoice, $items ) {
326
-
327
-	}
328
-
329
-	/**
330
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
-	 *
332
-	 * @param string $transaction_url transaction url.
333
-	 * @param WPInv_Invoice $invoice Invoice object.
334
-	 * @return string transaction URL, or empty string.
335
-	 */
336
-	public function filter_transaction_url( $transaction_url, $invoice ) {
337
-
338
-		$transaction_id  = $invoice->get_transaction_id();
339
-
340
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
-		}
345
-
346
-		return $transaction_url;
347
-	}
348
-
349
-	/**
350
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
-	 *
352
-	 * @param string $subscription_url transaction url.
353
-	 * @param WPInv_Invoice $invoice Invoice object.
354
-	 * @return string subscription URL, or empty string.
355
-	 */
356
-	public function filter_subscription_url( $subscription_url, $invoice ) {
357
-
358
-		$profile_id      = $invoice->get_subscription_id();
359
-
360
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
361
-
362
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
364
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
-
366
-		}
367
-
368
-		return $subscription_url;
369
-	}
370
-
371
-	/**
372
-	 * Check if the gateway is available for use.
373
-	 *
374
-	 * @return bool
375
-	 */
376
-	public function is_available() {
377
-		return ! empty( $this->enabled );
378
-	}
379
-
380
-	/**
381
-	 * Return the gateway's title.
382
-	 *
383
-	 * @return string
384
-	 */
385
-	public function get_title() {
386
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
-	}
388
-
389
-	/**
390
-	 * Return the gateway's description.
391
-	 *
392
-	 * @return string
393
-	 */
394
-	public function get_description() {
395
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
-	}
397
-
398
-	/**
399
-	 * Process Payment.
400
-	 *
401
-	 *
402
-	 * @param WPInv_Invoice $invoice Invoice.
403
-	 * @param array $submission_data Posted checkout fields.
404
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
-	 * @return void
406
-	 */
407
-	public function process_payment( $invoice, $submission_data, $submission ) {
408
-		// Process the payment then either redirect to the success page or the gateway.
409
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
-	}
411
-
412
-	/**
413
-	 * Process refund.
414
-	 *
415
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
416
-	 * a passed in amount.
417
-	 *
418
-	 * @param WPInv_Invoice $invoice Invoice.
419
-	 * @param  float  $amount Refund amount.
420
-	 * @param  string $reason Refund reason.
421
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
-	 */
423
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
-	}
426
-
427
-	/**
428
-	 * Displays the payment fields, credit cards etc.
429
-	 * 
430
-	 * @param int $invoice_id 0 or invoice id.
431
-	 * @param GetPaid_Payment_Form $form Current payment form.
432
-	 */
433
-	public function payment_fields( $invoice_id, $form ) {
434
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
-	}
436
-
437
-	/**
438
-	 * Filters the gateway settings.
439
-	 * 
440
-	 * @param array $admin_settings
441
-	 */
442
-	public function admin_settings( $admin_settings ) {
443
-		return $admin_settings;
444
-	}
445
-
446
-	/**
447
-	 * Retrieves the value of a gateway setting.
448
-	 * 
449
-	 * @param string $option
450
-	 */
451
-	public function get_option( $option, $default = false ) {
452
-		return wpinv_get_option( $this->id . '_' . $option, $default );
453
-	}
454
-
455
-	/**
456
-	 * Check if a gateway supports a given feature.
457
-	 *
458
-	 * Gateways should override this to declare support (or lack of support) for a feature.
459
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
460
-	 *
461
-	 * @param string $feature string The name of a feature to test support for.
462
-	 * @return bool True if the gateway supports the feature, false otherwise.
463
-	 * @since 1.0.19
464
-	 */
465
-	public function supports( $feature ) {
466
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
-	}
468
-
469
-	/**
470
-	 * Returns the credit card form html.
471
-	 * 
472
-	 * @param bool $save whether or not to display the save button.
473
-	 */
362
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
364
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
+
366
+        }
367
+
368
+        return $subscription_url;
369
+    }
370
+
371
+    /**
372
+     * Check if the gateway is available for use.
373
+     *
374
+     * @return bool
375
+     */
376
+    public function is_available() {
377
+        return ! empty( $this->enabled );
378
+    }
379
+
380
+    /**
381
+     * Return the gateway's title.
382
+     *
383
+     * @return string
384
+     */
385
+    public function get_title() {
386
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
+    }
388
+
389
+    /**
390
+     * Return the gateway's description.
391
+     *
392
+     * @return string
393
+     */
394
+    public function get_description() {
395
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
+    }
397
+
398
+    /**
399
+     * Process Payment.
400
+     *
401
+     *
402
+     * @param WPInv_Invoice $invoice Invoice.
403
+     * @param array $submission_data Posted checkout fields.
404
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
+     * @return void
406
+     */
407
+    public function process_payment( $invoice, $submission_data, $submission ) {
408
+        // Process the payment then either redirect to the success page or the gateway.
409
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
+    }
411
+
412
+    /**
413
+     * Process refund.
414
+     *
415
+     * If the gateway declares 'refunds' support, this will allow it to refund.
416
+     * a passed in amount.
417
+     *
418
+     * @param WPInv_Invoice $invoice Invoice.
419
+     * @param  float  $amount Refund amount.
420
+     * @param  string $reason Refund reason.
421
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
+     */
423
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
+    }
426
+
427
+    /**
428
+     * Displays the payment fields, credit cards etc.
429
+     * 
430
+     * @param int $invoice_id 0 or invoice id.
431
+     * @param GetPaid_Payment_Form $form Current payment form.
432
+     */
433
+    public function payment_fields( $invoice_id, $form ) {
434
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
+    }
436
+
437
+    /**
438
+     * Filters the gateway settings.
439
+     * 
440
+     * @param array $admin_settings
441
+     */
442
+    public function admin_settings( $admin_settings ) {
443
+        return $admin_settings;
444
+    }
445
+
446
+    /**
447
+     * Retrieves the value of a gateway setting.
448
+     * 
449
+     * @param string $option
450
+     */
451
+    public function get_option( $option, $default = false ) {
452
+        return wpinv_get_option( $this->id . '_' . $option, $default );
453
+    }
454
+
455
+    /**
456
+     * Check if a gateway supports a given feature.
457
+     *
458
+     * Gateways should override this to declare support (or lack of support) for a feature.
459
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
460
+     *
461
+     * @param string $feature string The name of a feature to test support for.
462
+     * @return bool True if the gateway supports the feature, false otherwise.
463
+     * @since 1.0.19
464
+     */
465
+    public function supports( $feature ) {
466
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
+    }
468
+
469
+    /**
470
+     * Returns the credit card form html.
471
+     * 
472
+     * @param bool $save whether or not to display the save button.
473
+     */
474 474
     public function get_cc_form( $save = false ) {
475 475
 
476
-		ob_start();
476
+        ob_start();
477 477
 
478 478
         $id_prefix = esc_attr( uniqid( $this->id ) );
479 479
 
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
                                         'name'              => $this->id . '[cc_cvv2]',
569 569
                                         'id'                => "$id_prefix-cc-cvv2",
570 570
                                         'label'             => __( 'CCV', 'invoicing' ),
571
-										'label_type'        => 'vertical',
572
-										'class'             => 'form-control-sm',
571
+                                        'label_type'        => 'vertical',
572
+                                        'class'             => 'form-control-sm',
573 573
                                     )
574 574
                                 );
575 575
                             ?>
@@ -579,175 +579,175 @@  discard block
 block discarded – undo
579 579
 					
580 580
 					<?php
581 581
 
582
-						if ( $save ) {
583
-							echo $this->save_payment_method_checkbox();
584
-						}
582
+                        if ( $save ) {
583
+                            echo $this->save_payment_method_checkbox();
584
+                        }
585 585
 
586
-					?>
586
+                    ?>
587 587
                 </div>
588 588
 
589 589
             </div>
590 590
 		<?php
591 591
 		
592
-		return ob_get_clean();
592
+        return ob_get_clean();
593
+
594
+    }
593 595
 
596
+    /**
597
+     * Displays a new payment method entry form.
598
+     *
599
+     * @since 1.0.19
600
+     */
601
+    public function new_payment_method_entry( $form ) {
602
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
594 603
     }
595 604
 
596
-	/**
597
-	 * Displays a new payment method entry form.
598
-	 *
599
-	 * @since 1.0.19
600
-	 */
601
-	public function new_payment_method_entry( $form ) {
602
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
603
-	}
604
-
605
-	/**
606
-	 * Grab and display our saved payment methods.
607
-	 *
608
-	 * @since 1.0.19
609
-	 */
610
-	public function saved_payment_methods() {
611
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
612
-
613
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
614
-			$html .= $this->get_saved_payment_method_option_html( $token );
615
-		}
616
-
617
-		$html .= $this->get_new_payment_method_option_html();
618
-		$html .= '</ul>';
619
-
620
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
621
-	}
622
-
623
-	/**
624
-	 * Gets saved payment method HTML from a token.
625
-	 *
626
-	 * @since 1.0.19
627
-	 * @param  array $token Payment Token.
628
-	 * @return string Generated payment method HTML
629
-	 */
630
-	public function get_saved_payment_method_option_html( $token ) {
631
-
632
-		return sprintf(
633
-			'<li class="getpaid-payment-method form-group">
605
+    /**
606
+     * Grab and display our saved payment methods.
607
+     *
608
+     * @since 1.0.19
609
+     */
610
+    public function saved_payment_methods() {
611
+        $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
612
+
613
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
614
+            $html .= $this->get_saved_payment_method_option_html( $token );
615
+        }
616
+
617
+        $html .= $this->get_new_payment_method_option_html();
618
+        $html .= '</ul>';
619
+
620
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
621
+    }
622
+
623
+    /**
624
+     * Gets saved payment method HTML from a token.
625
+     *
626
+     * @since 1.0.19
627
+     * @param  array $token Payment Token.
628
+     * @return string Generated payment method HTML
629
+     */
630
+    public function get_saved_payment_method_option_html( $token ) {
631
+
632
+        return sprintf(
633
+            '<li class="getpaid-payment-method form-group">
634 634
 				<label>
635 635
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
636 636
 					<span>%3$s</span>
637 637
 				</label>
638 638
 			</li>',
639
-			esc_attr( $this->id ),
640
-			esc_attr( $token['id'] ),
641
-			esc_html( $token['name'] ),
642
-			checked( empty( $token['default'] ), false, false )
643
-		);
639
+            esc_attr( $this->id ),
640
+            esc_attr( $token['id'] ),
641
+            esc_html( $token['name'] ),
642
+            checked( empty( $token['default'] ), false, false )
643
+        );
644 644
 
645
-	}
645
+    }
646 646
 
647
-	/**
648
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
649
-	 *
650
-	 * @since 1.0.19
651
-	 */
652
-	public function get_new_payment_method_option_html() {
647
+    /**
648
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
649
+     *
650
+     * @since 1.0.19
651
+     */
652
+    public function get_new_payment_method_option_html() {
653 653
 
654
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
654
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
655 655
 
656
-		return sprintf(
657
-			'<li class="getpaid-new-payment-method">
656
+        return sprintf(
657
+            '<li class="getpaid-new-payment-method">
658 658
 				<label>
659 659
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
660 660
 					<span>%2$s</span>
661 661
 				</label>
662 662
 			</li>',
663
-			esc_attr( $this->id ),
664
-			esc_html( $label )
665
-		);
663
+            esc_attr( $this->id ),
664
+            esc_html( $label )
665
+        );
666 666
 
667
-	}
667
+    }
668 668
 
669
-	/**
670
-	 * Outputs a checkbox for saving a new payment method to the database.
671
-	 *
672
-	 * @since 1.0.19
673
-	 */
674
-	public function save_payment_method_checkbox() {
669
+    /**
670
+     * Outputs a checkbox for saving a new payment method to the database.
671
+     *
672
+     * @since 1.0.19
673
+     */
674
+    public function save_payment_method_checkbox() {
675 675
 
676
-		return sprintf(
677
-			'<p class="form-group getpaid-save-payment-method">
676
+        return sprintf(
677
+            '<p class="form-group getpaid-save-payment-method">
678 678
 				<label>
679 679
 					<input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
680 680
 					<span>%2$s</span>
681 681
 				</label>
682 682
 			</p>',
683
-			esc_attr( $this->id ),
684
-			esc_html__( 'Save payment method', 'invoicing' )
685
-		);
683
+            esc_attr( $this->id ),
684
+            esc_html__( 'Save payment method', 'invoicing' )
685
+        );
686 686
 
687
-	}
687
+    }
688 688
 
689
-	/**
690
-	 * Registers the gateway.
691
-	 *
692
-	 * @return array
693
-	 */
694
-	public function register_gateway( $gateways ) {
689
+    /**
690
+     * Registers the gateway.
691
+     *
692
+     * @return array
693
+     */
694
+    public function register_gateway( $gateways ) {
695 695
 
696
-		$gateways[ $this->id ] = array(
696
+        $gateways[ $this->id ] = array(
697 697
 
698
-			'admin_label'    => $this->method_title,
698
+            'admin_label'    => $this->method_title,
699 699
             'checkout_label' => $this->title,
700
-			'ordering'       => $this->order,
701
-
702
-		);
703
-
704
-		return $gateways;
705
-
706
-	}
707
-
708
-	/**
709
-	 * Checks whether or not this is a sandbox request.
710
-	 *
711
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
712
-	 * @return bool
713
-	 */
714
-	public function is_sandbox( $invoice = null ) {
715
-
716
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
717
-			return $invoice->get_mode() == 'test';
718
-		}
719
-
720
-		return wpinv_is_test_mode( $this->id );
721
-
722
-	}
723
-
724
-	/**
725
-	 * Renames the checkout button
726
-	 *
727
-	 * @return string
728
-	 */
729
-	public function rename_checkout_button() {
730
-		return $this->checkout_button_text;
731
-	}
732
-
733
-	/**
734
-	 * Validate gateway currency
735
-	 *
736
-	 * @return bool
737
-	 */
738
-	public function validate_currency( $validation, $currency ) {
739
-
740
-		// Required currencies.
741
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
742
-			return false;
743
-		}
744
-
745
-		// Excluded currencies.
746
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
747
-			return false;
748
-		}
749
-
750
-		return $validation;
751
-	}
700
+            'ordering'       => $this->order,
701
+
702
+        );
703
+
704
+        return $gateways;
705
+
706
+    }
707
+
708
+    /**
709
+     * Checks whether or not this is a sandbox request.
710
+     *
711
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
712
+     * @return bool
713
+     */
714
+    public function is_sandbox( $invoice = null ) {
715
+
716
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
717
+            return $invoice->get_mode() == 'test';
718
+        }
719
+
720
+        return wpinv_is_test_mode( $this->id );
721
+
722
+    }
723
+
724
+    /**
725
+     * Renames the checkout button
726
+     *
727
+     * @return string
728
+     */
729
+    public function rename_checkout_button() {
730
+        return $this->checkout_button_text;
731
+    }
732
+
733
+    /**
734
+     * Validate gateway currency
735
+     *
736
+     * @return bool
737
+     */
738
+    public function validate_currency( $validation, $currency ) {
739
+
740
+        // Required currencies.
741
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
742
+            return false;
743
+        }
744
+
745
+        // Excluded currencies.
746
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
747
+            return false;
748
+        }
749
+
750
+        return $validation;
751
+    }
752 752
 
753 753
 }
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 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.
@@ -139,55 +139,55 @@  discard block
 block discarded – undo
139 139
 	public function __construct() {
140 140
 
141 141
 		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
142
+		add_filter('wpinv_payment_gateways', array($this, 'register_gateway'));
143 143
 
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
144
+		$this->enabled = wpinv_is_gateway_active($this->id);
145 145
 
146 146
 		// Enable Subscriptions.
147
-		if ( $this->supports( 'subscription' ) ) {
148
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
147
+		if ($this->supports('subscription')) {
148
+			add_filter("wpinv_{$this->id}_support_subscription", '__return_true');
149 149
 		}
150 150
 
151 151
 		// Enable sandbox.
152
-		if ( $this->supports( 'sandbox' ) ) {
153
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
152
+		if ($this->supports('sandbox')) {
153
+			add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true');
154 154
 		}
155 155
 
156 156
 		// Invoice addons.
157
-		if ( $this->supports( 'addons' ) ) {
158
-			add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
157
+		if ($this->supports('addons')) {
158
+			add_filter("getpaid_{$this->id}_supports_addons", '__return_true');
159
+			add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2);
160 160
 		}
161 161
 
162 162
 		// Gateway settings.
163
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
163
+		add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings'));
164 164
 		
165 165
 
166 166
 		// Gateway checkout fiellds.
167
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
167
+		add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2);
168 168
 
169 169
 		// Process payment.
170
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
170
+		add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3);
171 171
 
172 172
 		// Change the checkout button text.
173
-		if ( ! empty( $this->checkout_button_text ) ) {
174
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
173
+		if (!empty($this->checkout_button_text)) {
174
+			add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button'));
175 175
 		}
176 176
 
177 177
 		// Check if a gateway is valid for a given currency.
178
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
178
+		add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2);
179 179
 
180 180
 		// Generate the transaction url.
181
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
181
+		add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2);
182 182
 
183 183
 		// Generate the subscription url.
184
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
184
+		add_filter("getpaid_gateway_{$this->id}_subscription_url", array($this, 'filter_subscription_url'), 10, 2);
185 185
 
186 186
 		// Confirm payments.
187
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
187
+		add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2);
188 188
 
189 189
 		// Verify IPNs.
190
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
190
+		add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn'));
191 191
 
192 192
 	}
193 193
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * @since 1.0.19
198 198
 	 * @return bool
199 199
 	 */
200
-	public function is( $gateway ) {
200
+	public function is($gateway) {
201 201
 		return $gateway == $this->id;
202 202
 	}
203 203
 
@@ -207,23 +207,23 @@  discard block
 block discarded – undo
207 207
 	 * @since 1.0.19
208 208
 	 * @return array
209 209
 	 */
210
-	public function get_tokens( $sandbox = null ) {
210
+	public function get_tokens($sandbox = null) {
211 211
 
212
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
212
+		if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) {
213
+			$tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true);
214 214
 
215
-			if ( is_array( $tokens ) ) {
215
+			if (is_array($tokens)) {
216 216
 				$this->tokens = $tokens;
217 217
 			}
218 218
 
219 219
 		}
220 220
 
221
-		if ( ! is_bool( $sandbox ) ) {
221
+		if (!is_bool($sandbox)) {
222 222
 			return $this->tokens;
223 223
 		}
224 224
 
225
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
-		return wp_list_filter( $this->tokens, $args );
225
+		$args = array('type' => $sandbox ? 'sandbox' : 'live');
226
+		return wp_list_filter($this->tokens, $args);
227 227
 
228 228
 	}
229 229
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 	 *
233 233
 	 * @since 1.0.19
234 234
 	 */
235
-	public function save_token( $token ) {
235
+	public function save_token($token) {
236 236
 
237 237
 		$tokens   = $this->get_tokens();
238 238
 		$tokens[] = $token;
239 239
 
240
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
240
+		update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens);
241 241
 
242 242
 		$this->tokens = $tokens;
243 243
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @return string
250 250
 	 */
251 251
 	public function get_method_title() {
252
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
252
+		return apply_filters('getpaid_gateway_method_title', $this->method_title, $this);
253 253
 	}
254 254
 
255 255
 	/**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 * @return string
259 259
 	 */
260 260
 	public function get_method_description() {
261
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
261
+		return apply_filters('getpaid_gateway_method_description', $this->method_description, $this);
262 262
 	}
263 263
 
264 264
 	/**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @param WPInv_Invoice $invoice Invoice object.
268 268
 	 * @return string
269 269
 	 */
270
-	public function get_return_url( $invoice ) {
270
+	public function get_return_url($invoice) {
271 271
 
272 272
 		// Payment success url
273 273
 		$return_url = add_query_arg(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			wpinv_get_success_page_uri()
280 280
 		);
281 281
 
282
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
282
+		return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this);
283 283
 	}
284 284
 
285 285
 	/**
@@ -288,24 +288,24 @@  discard block
 block discarded – undo
288 288
 	 * @param string $content Success page content.
289 289
 	 * @return string
290 290
 	 */
291
-	public function confirm_payment( $content ) {
291
+	public function confirm_payment($content) {
292 292
 
293 293
 		// Retrieve the invoice.
294 294
 		$invoice_id = getpaid_get_current_invoice_id();
295
-		$invoice    = wpinv_get_invoice( $invoice_id );
295
+		$invoice    = wpinv_get_invoice($invoice_id);
296 296
 
297 297
 		// Ensure that it exists and that it is pending payment.
298
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
298
+		if (empty($invoice_id) || !$invoice->needs_payment()) {
299 299
 			return $content;
300 300
 		}
301 301
 
302 302
 		// Can the user view this invoice??
303
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
303
+		if (!wpinv_user_can_view_invoice($invoice)) {
304 304
 			return $content;
305 305
 		}
306 306
 
307 307
 		// Show payment processing indicator.
308
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
308
+		return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice'));
309 309
 	}
310 310
 
311 311
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param GetPaid_Form_Item[] $items
323 323
 	 * @return WPInv_Invoice
324 324
 	 */
325
-	public function process_addons( $invoice, $items ) {
325
+	public function process_addons($invoice, $items) {
326 326
 
327 327
 	}
328 328
 
@@ -333,14 +333,14 @@  discard block
 block discarded – undo
333 333
 	 * @param WPInv_Invoice $invoice Invoice object.
334 334
 	 * @return string transaction URL, or empty string.
335 335
 	 */
336
-	public function filter_transaction_url( $transaction_url, $invoice ) {
336
+	public function filter_transaction_url($transaction_url, $invoice) {
337 337
 
338
-		$transaction_id  = $invoice->get_transaction_id();
338
+		$transaction_id = $invoice->get_transaction_id();
339 339
 
340
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
340
+		if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
341
+			$transaction_url = sprintf($this->view_transaction_url, $transaction_id);
342
+			$replace         = $this->is_sandbox($invoice) ? 'sandbox' : '';
343
+			$transaction_url = str_replace('{sandbox}', $replace, $transaction_url);
344 344
 		}
345 345
 
346 346
 		return $transaction_url;
@@ -353,15 +353,15 @@  discard block
 block discarded – undo
353 353
 	 * @param WPInv_Invoice $invoice Invoice object.
354 354
 	 * @return string subscription URL, or empty string.
355 355
 	 */
356
-	public function filter_subscription_url( $subscription_url, $invoice ) {
356
+	public function filter_subscription_url($subscription_url, $invoice) {
357 357
 
358
-		$profile_id      = $invoice->get_subscription_id();
358
+		$profile_id = $invoice->get_subscription_id();
359 359
 
360
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
360
+		if (!empty($this->view_subscription_url) && !empty($profile_id)) {
361 361
 
362
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
364
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
+			$subscription_url = sprintf($this->view_subscription_url, $profile_id);
363
+			$replace          = $this->is_sandbox($invoice) ? 'sandbox' : '';
364
+			$subscription_url = str_replace('{sandbox}', $replace, $subscription_url);
365 365
 
366 366
 		}
367 367
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 	 * @return bool
375 375
 	 */
376 376
 	public function is_available() {
377
-		return ! empty( $this->enabled );
377
+		return !empty($this->enabled);
378 378
 	}
379 379
 
380 380
 	/**
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 * @return string
384 384
 	 */
385 385
 	public function get_title() {
386
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
386
+		return apply_filters('getpaid_gateway_title', $this->title, $this);
387 387
 	}
388 388
 
389 389
 	/**
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	 * @return string
393 393
 	 */
394 394
 	public function get_description() {
395
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
395
+		return apply_filters('getpaid_gateway_description', $this->description, $this);
396 396
 	}
397 397
 
398 398
 	/**
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405 405
 	 * @return void
406 406
 	 */
407
-	public function process_payment( $invoice, $submission_data, $submission ) {
407
+	public function process_payment($invoice, $submission_data, $submission) {
408 408
 		// Process the payment then either redirect to the success page or the gateway.
409
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
409
+		do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission);
410 410
 	}
411 411
 
412 412
 	/**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $reason Refund reason.
421 421
 	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
422 422
 	 */
423
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
423
+	public function process_refund($invoice, $amount = null, $reason = '') {
424
+		return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason);
425 425
 	}
426 426
 
427 427
 	/**
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	 * @param int $invoice_id 0 or invoice id.
431 431
 	 * @param GetPaid_Payment_Form $form Current payment form.
432 432
 	 */
433
-	public function payment_fields( $invoice_id, $form ) {
434
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
433
+	public function payment_fields($invoice_id, $form) {
434
+		do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form);
435 435
 	}
436 436
 
437 437
 	/**
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	 * 
440 440
 	 * @param array $admin_settings
441 441
 	 */
442
-	public function admin_settings( $admin_settings ) {
442
+	public function admin_settings($admin_settings) {
443 443
 		return $admin_settings;
444 444
 	}
445 445
 
@@ -448,8 +448,8 @@  discard block
 block discarded – undo
448 448
 	 * 
449 449
 	 * @param string $option
450 450
 	 */
451
-	public function get_option( $option, $default = false ) {
452
-		return wpinv_get_option( $this->id . '_' . $option, $default );
451
+	public function get_option($option, $default = false) {
452
+		return wpinv_get_option($this->id . '_' . $option, $default);
453 453
 	}
454 454
 
455 455
 	/**
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 	 * @return bool True if the gateway supports the feature, false otherwise.
463 463
 	 * @since 1.0.19
464 464
 	 */
465
-	public function supports( $feature ) {
466
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
465
+	public function supports($feature) {
466
+		return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this);
467 467
 	}
468 468
 
469 469
 	/**
@@ -471,36 +471,36 @@  discard block
 block discarded – undo
471 471
 	 * 
472 472
 	 * @param bool $save whether or not to display the save button.
473 473
 	 */
474
-    public function get_cc_form( $save = false ) {
474
+    public function get_cc_form($save = false) {
475 475
 
476 476
 		ob_start();
477 477
 
478
-        $id_prefix = esc_attr( uniqid( $this->id ) );
478
+        $id_prefix = esc_attr(uniqid($this->id));
479 479
 
480 480
         $months = array(
481
-            '01' => __( 'January', 'invoicing' ),
482
-            '02' => __( 'February', 'invoicing' ),
483
-            '03' => __( 'March', 'invoicing' ),
484
-            '04' => __( 'April', 'invoicing' ),
485
-            '05' => __( 'May', 'invoicing' ),
486
-            '06' => __( 'June', 'invoicing' ),
487
-            '07' => __( 'July', 'invoicing' ),
488
-            '08' => __( 'August', 'invoicing' ),
489
-            '09' => __( 'September', 'invoicing' ),
490
-            '10' => __( 'October', 'invoicing' ),
491
-            '11' => __( 'November', 'invoicing' ),
492
-            '12' => __( 'December', 'invoicing' ),
481
+            '01' => __('January', 'invoicing'),
482
+            '02' => __('February', 'invoicing'),
483
+            '03' => __('March', 'invoicing'),
484
+            '04' => __('April', 'invoicing'),
485
+            '05' => __('May', 'invoicing'),
486
+            '06' => __('June', 'invoicing'),
487
+            '07' => __('July', 'invoicing'),
488
+            '08' => __('August', 'invoicing'),
489
+            '09' => __('September', 'invoicing'),
490
+            '10' => __('October', 'invoicing'),
491
+            '11' => __('November', 'invoicing'),
492
+            '12' => __('December', 'invoicing'),
493 493
         );
494 494
 
495
-        $year  = (int) date( 'Y', current_time( 'timestamp' ) );
495
+        $year  = (int) date('Y', current_time('timestamp'));
496 496
         $years = array();
497 497
 
498
-        for ( $i = 0; $i <= 10; $i++ ) {
499
-            $years[ $year + $i ] = $year + $i;
498
+        for ($i = 0; $i <= 10; $i++) {
499
+            $years[$year + $i] = $year + $i;
500 500
         }
501 501
 
502 502
         ?>
503
-            <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1">
503
+            <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1">
504 504
 
505 505
 
506 506
                 <div class="getpaid-cc-card-inner">
@@ -509,14 +509,14 @@  discard block
 block discarded – undo
509 509
                         <div class="col-12">
510 510
 
511 511
 							<div class="form-group">
512
-								<label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label>
512
+								<label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label>
513 513
 								<div class="input-group input-group-sm">
514 514
 									<div class="input-group-prepend ">
515 515
 										<span class="input-group-text">
516 516
 											<i class="fa fa-credit-card"></i>
517 517
 										</span>
518 518
 									</div>
519
-									<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">
519
+									<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">
520 520
 								</div>
521 521
 							</div>
522 522
 
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
                         <div class="col-12">
526 526
                             <div class="form-group">
527
-                                <label><?php _e( 'Expiration', 'invoicing' ); ?></label>
527
+                                <label><?php _e('Expiration', 'invoicing'); ?></label>
528 528
                                 <div class="form-row">
529 529
 
530 530
                                     <div class="col">
531
-                                        <select class="form-control form-control-sm" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]">
532
-                                            <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option>
531
+                                        <select class="form-control form-control-sm" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]">
532
+                                            <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option>
533 533
 
534 534
                                             <?php
535
-                                                foreach ( $months as $key => $month ) {
536
-                                                    $key   = esc_attr( $key );
537
-                                                    $month = wpinv_clean( $month );
535
+                                                foreach ($months as $key => $month) {
536
+                                                    $key   = esc_attr($key);
537
+                                                    $month = wpinv_clean($month);
538 538
                                                     echo "<option value='$key'>$month</option>" . PHP_EOL;
539 539
                                                 }
540 540
                                             ?>
@@ -543,13 +543,13 @@  discard block
 block discarded – undo
543 543
                                     </div>
544 544
 
545 545
                                     <div class="col">
546
-                                        <select class="form-control form-control-sm" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]">
547
-                                            <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option>
546
+                                        <select class="form-control form-control-sm" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]">
547
+                                            <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option>
548 548
 
549 549
                                             <?php
550
-                                                foreach ( $years as $key => $year ) {
551
-                                                    $key   = esc_attr( $key );
552
-                                                    $year  = wpinv_clean( $year );
550
+                                                foreach ($years as $key => $year) {
551
+                                                    $key   = esc_attr($key);
552
+                                                    $year  = wpinv_clean($year);
553 553
                                                     echo "<option value='$key'>$year</option>" . PHP_EOL;
554 554
                                                 }
555 555
                                             ?>
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                                     array(
568 568
                                         'name'              => $this->id . '[cc_cvv2]',
569 569
                                         'id'                => "$id_prefix-cc-cvv2",
570
-                                        'label'             => __( 'CCV', 'invoicing' ),
570
+                                        'label'             => __('CCV', 'invoicing'),
571 571
 										'label_type'        => 'vertical',
572 572
 										'class'             => 'form-control-sm',
573 573
                                     )
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 					
580 580
 					<?php
581 581
 
582
-						if ( $save ) {
582
+						if ($save) {
583 583
 							echo $this->save_payment_method_checkbox();
584 584
 						}
585 585
 
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 *
599 599
 	 * @since 1.0.19
600 600
 	 */
601
-	public function new_payment_method_entry( $form ) {
601
+	public function new_payment_method_entry($form) {
602 602
 		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
603 603
 	}
604 604
 
@@ -608,16 +608,16 @@  discard block
 block discarded – undo
608 608
 	 * @since 1.0.19
609 609
 	 */
610 610
 	public function saved_payment_methods() {
611
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
611
+		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">';
612 612
 
613
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
614
-			$html .= $this->get_saved_payment_method_option_html( $token );
613
+		foreach ($this->get_tokens($this->is_sandbox()) as $token) {
614
+			$html .= $this->get_saved_payment_method_option_html($token);
615 615
 		}
616 616
 
617 617
 		$html .= $this->get_new_payment_method_option_html();
618 618
 		$html .= '</ul>';
619 619
 
620
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
620
+		echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this);
621 621
 	}
622 622
 
623 623
 	/**
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 * @param  array $token Payment Token.
628 628
 	 * @return string Generated payment method HTML
629 629
 	 */
630
-	public function get_saved_payment_method_option_html( $token ) {
630
+	public function get_saved_payment_method_option_html($token) {
631 631
 
632 632
 		return sprintf(
633 633
 			'<li class="getpaid-payment-method form-group">
@@ -636,10 +636,10 @@  discard block
 block discarded – undo
636 636
 					<span>%3$s</span>
637 637
 				</label>
638 638
 			</li>',
639
-			esc_attr( $this->id ),
640
-			esc_attr( $token['id'] ),
641
-			esc_html( $token['name'] ),
642
-			checked( empty( $token['default'] ), false, false )
639
+			esc_attr($this->id),
640
+			esc_attr($token['id']),
641
+			esc_html($token['name']),
642
+			checked(empty($token['default']), false, false)
643 643
 		);
644 644
 
645 645
 	}
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 	 */
652 652
 	public function get_new_payment_method_option_html() {
653 653
 
654
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
654
+		$label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this);
655 655
 
656 656
 		return sprintf(
657 657
 			'<li class="getpaid-new-payment-method">
@@ -660,8 +660,8 @@  discard block
 block discarded – undo
660 660
 					<span>%2$s</span>
661 661
 				</label>
662 662
 			</li>',
663
-			esc_attr( $this->id ),
664
-			esc_html( $label )
663
+			esc_attr($this->id),
664
+			esc_html($label)
665 665
 		);
666 666
 
667 667
 	}
@@ -680,8 +680,8 @@  discard block
 block discarded – undo
680 680
 					<span>%2$s</span>
681 681
 				</label>
682 682
 			</p>',
683
-			esc_attr( $this->id ),
684
-			esc_html__( 'Save payment method', 'invoicing' )
683
+			esc_attr($this->id),
684
+			esc_html__('Save payment method', 'invoicing')
685 685
 		);
686 686
 
687 687
 	}
@@ -691,9 +691,9 @@  discard block
 block discarded – undo
691 691
 	 *
692 692
 	 * @return array
693 693
 	 */
694
-	public function register_gateway( $gateways ) {
694
+	public function register_gateway($gateways) {
695 695
 
696
-		$gateways[ $this->id ] = array(
696
+		$gateways[$this->id] = array(
697 697
 
698 698
 			'admin_label'    => $this->method_title,
699 699
             'checkout_label' => $this->title,
@@ -711,13 +711,13 @@  discard block
 block discarded – undo
711 711
 	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
712 712
 	 * @return bool
713 713
 	 */
714
-	public function is_sandbox( $invoice = null ) {
714
+	public function is_sandbox($invoice = null) {
715 715
 
716
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
716
+		if (!empty($invoice) && !$invoice->needs_payment()) {
717 717
 			return $invoice->get_mode() == 'test';
718 718
 		}
719 719
 
720
-		return wpinv_is_test_mode( $this->id );
720
+		return wpinv_is_test_mode($this->id);
721 721
 
722 722
 	}
723 723
 
@@ -735,15 +735,15 @@  discard block
 block discarded – undo
735 735
 	 *
736 736
 	 * @return bool
737 737
 	 */
738
-	public function validate_currency( $validation, $currency ) {
738
+	public function validate_currency($validation, $currency) {
739 739
 
740 740
 		// Required currencies.
741
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
741
+		if (!empty($this->currencies) && !in_array($currency, $this->currencies)) {
742 742
 			return false;
743 743
 		}
744 744
 
745 745
 		// Excluded currencies.
746
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
746
+		if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) {
747 747
 			return false;
748 748
 		}
749 749
 
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $checkout_page    = wpinv_get_option( 'checkout_page' );
20
-    $is_checkout      = ! empty( $checkout_page ) && is_page( $checkout_page );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $checkout_page    = wpinv_get_option('checkout_page');
20
+    $is_checkout      = !empty($checkout_page) && is_page($checkout_page);
21 21
 
22
-    if ( !$is_object_set ) {
23
-        unset( $wp_query->queried_object );
22
+    if (!$is_object_set) {
23
+        unset($wp_query->queried_object);
24 24
     }
25 25
 
26
-    if ( !$is_object_id_set ) {
27
-        unset( $wp_query->queried_object_id );
26
+    if (!$is_object_id_set) {
27
+        unset($wp_query->queried_object_id);
28 28
     }
29 29
 
30
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
30
+    return apply_filters('wpinv_is_checkout', $is_checkout);
31 31
 }
32 32
 
33 33
 function wpinv_can_checkout() {
34 34
 	$can_checkout = true; // Always true for now
35 35
 
36
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
36
+	return (bool) apply_filters('wpinv_can_checkout', $can_checkout);
37 37
 }
38 38
 
39 39
 function wpinv_get_success_page_uri() {
40
-	$page_id = wpinv_get_option( 'success_page', 0 );
41
-	$page_id = absint( $page_id );
40
+	$page_id = wpinv_get_option('success_page', 0);
41
+	$page_id = absint($page_id);
42 42
 
43
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
43
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
44 44
 }
45 45
 
46 46
 /**
@@ -49,139 +49,139 @@  discard block
 block discarded – undo
49 49
  * @param string $post_type The post type or invoice type.
50 50
  * @return string The history page URL.
51 51
  */
52
-function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) {
53
-    $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) );
54
-	$page_id   = wpinv_get_option( "{$post_type}_history_page", 0 );
55
-	$page_id   = absint( $page_id );
56
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type );
52
+function wpinv_get_history_page_uri($post_type = 'wpi_invoice') {
53
+    $post_type = sanitize_key(str_replace('wpi_', '', $post_type));
54
+	$page_id   = wpinv_get_option("{$post_type}_history_page", 0);
55
+	$page_id   = absint($page_id);
56
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type);
57 57
 }
58 58
 
59 59
 function wpinv_is_success_page() {
60
-	$is_success_page = wpinv_get_option( 'success_page', false );
61
-	$is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false;
60
+	$is_success_page = wpinv_get_option('success_page', false);
61
+	$is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false;
62 62
 
63
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
63
+	return apply_filters('wpinv_is_success_page', $is_success_page);
64 64
 }
65 65
 
66 66
 function wpinv_is_invoice_history_page() {
67
-	$ret = wpinv_get_option( 'invoice_history_page', false );
68
-	$ret = $ret ? is_page( $ret ) : false;
69
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
67
+	$ret = wpinv_get_option('invoice_history_page', false);
68
+	$ret = $ret ? is_page($ret) : false;
69
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
70 70
 }
71 71
 
72 72
 function wpinv_is_subscriptions_history_page() {
73
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
74
-    $ret = $ret ? is_page( $ret ) : false;
75
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
73
+    $ret = wpinv_get_option('invoice_subscription_page', false);
74
+    $ret = $ret ? is_page($ret) : false;
75
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
76 76
 }
77 77
 
78 78
 /**
79 79
  * Redirects a user the success page.
80 80
  */
81
-function wpinv_send_to_success_page( $args = array() ) {
81
+function wpinv_send_to_success_page($args = array()) {
82 82
 
83 83
     $redirect = add_query_arg(
84
-        wp_parse_args( $args ),
84
+        wp_parse_args($args),
85 85
         wpinv_get_success_page_uri()
86 86
     );
87 87
 
88
-    $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args );
88
+    $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args);
89 89
 
90
-    wp_redirect( $redirect );
90
+    wp_redirect($redirect);
91 91
     exit;
92 92
 }
93 93
 
94
-function wpinv_send_to_failed_page( $args = null ) {
94
+function wpinv_send_to_failed_page($args = null) {
95 95
 	$redirect = wpinv_get_failed_transaction_uri();
96 96
     
97
-    if ( !empty( $args ) ) {
97
+    if (!empty($args)) {
98 98
         // Check for backward compatibility
99
-        if ( is_string( $args ) )
100
-            $args = str_replace( '?', '', $args );
99
+        if (is_string($args))
100
+            $args = str_replace('?', '', $args);
101 101
 
102
-        $args = wp_parse_args( $args );
102
+        $args = wp_parse_args($args);
103 103
 
104
-        $redirect = add_query_arg( $args, $redirect );
104
+        $redirect = add_query_arg($args, $redirect);
105 105
     }
106 106
 
107
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
107
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
108 108
     
109
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
110
-    wp_redirect( $redirect );
109
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
110
+    wp_redirect($redirect);
111 111
     exit;
112 112
 }
113 113
 
114
-function wpinv_get_checkout_uri( $args = array() ) {
115
-	$uri = wpinv_get_option( 'checkout_page', false );
116
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
114
+function wpinv_get_checkout_uri($args = array()) {
115
+	$uri = wpinv_get_option('checkout_page', false);
116
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
117 117
 
118
-	if ( !empty( $args ) ) {
118
+	if (!empty($args)) {
119 119
 		// Check for backward compatibility
120
-		if ( is_string( $args ) )
121
-			$args = str_replace( '?', '', $args );
120
+		if (is_string($args))
121
+			$args = str_replace('?', '', $args);
122 122
 
123
-		$args = wp_parse_args( $args );
123
+		$args = wp_parse_args($args);
124 124
 
125
-		$uri = add_query_arg( $args, $uri );
125
+		$uri = add_query_arg($args, $uri);
126 126
 	}
127 127
 
128
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
128
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
129 129
 
130
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
130
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
131 131
 
132
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
133
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
132
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
133
+		$uri = preg_replace('/^http:/', 'https:', $uri);
134 134
 	}
135 135
 
136
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
136
+	return apply_filters('wpinv_get_checkout_uri', $uri);
137 137
 }
138 138
 
139
-function wpinv_get_success_page_url( $query_string = null ) {
140
-	$success_page = wpinv_get_option( 'success_page', 0 );
141
-	$success_page = get_permalink( $success_page );
139
+function wpinv_get_success_page_url($query_string = null) {
140
+	$success_page = wpinv_get_option('success_page', 0);
141
+	$success_page = get_permalink($success_page);
142 142
 
143
-	if ( $query_string )
143
+	if ($query_string)
144 144
 		$success_page .= $query_string;
145 145
 
146
-	return apply_filters( 'wpinv_success_page_url', $success_page );
146
+	return apply_filters('wpinv_success_page_url', $success_page);
147 147
 }
148 148
 
149
-function wpinv_get_failed_transaction_uri( $extras = false ) {
150
-	$uri = wpinv_get_option( 'failure_page', '' );
151
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
149
+function wpinv_get_failed_transaction_uri($extras = false) {
150
+	$uri = wpinv_get_option('failure_page', '');
151
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
152 152
 
153
-	if ( $extras )
153
+	if ($extras)
154 154
 		$uri .= $extras;
155 155
 
156
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
156
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
157 157
 }
158 158
 
159 159
 function wpinv_is_failed_transaction_page() {
160
-	$ret = wpinv_get_option( 'failure_page', false );
161
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
160
+	$ret = wpinv_get_option('failure_page', false);
161
+	$ret = isset($ret) ? is_page($ret) : false;
162 162
 
163
-	return apply_filters( 'wpinv_is_failure_page', $ret );
163
+	return apply_filters('wpinv_is_failure_page', $ret);
164 164
 }
165 165
 
166
-function wpinv_transaction_query( $type = 'start' ) {
166
+function wpinv_transaction_query($type = 'start') {
167 167
     global $wpdb;
168 168
 
169 169
     $wpdb->hide_errors();
170 170
 
171
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
172
-        define( 'WPINV_USE_TRANSACTIONS', true );
171
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
172
+        define('WPINV_USE_TRANSACTIONS', true);
173 173
     }
174 174
 
175
-    if ( WPINV_USE_TRANSACTIONS ) {
176
-        switch ( $type ) {
175
+    if (WPINV_USE_TRANSACTIONS) {
176
+        switch ($type) {
177 177
             case 'commit' :
178
-                $wpdb->query( 'COMMIT' );
178
+                $wpdb->query('COMMIT');
179 179
                 break;
180 180
             case 'rollback' :
181
-                $wpdb->query( 'ROLLBACK' );
181
+                $wpdb->query('ROLLBACK');
182 182
                 break;
183 183
             default :
184
-                $wpdb->query( 'START TRANSACTION' );
184
+                $wpdb->query('START TRANSACTION');
185 185
             break;
186 186
         }
187 187
     }
@@ -190,141 +190,141 @@  discard block
 block discarded – undo
190 190
 function wpinv_get_prefix() {
191 191
     $invoice_prefix = 'INV-';
192 192
     
193
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
193
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
194 194
 }
195 195
 
196 196
 function wpinv_get_business_logo() {
197
-    $business_logo = wpinv_get_option( 'logo' );
198
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
197
+    $business_logo = wpinv_get_option('logo');
198
+    return apply_filters('wpinv_get_business_logo', $business_logo);
199 199
 }
200 200
 
201 201
 function wpinv_get_business_name() {
202 202
     $business_name = wpinv_get_option('store_name');
203
-    return apply_filters( 'wpinv_get_business_name', $business_name );
203
+    return apply_filters('wpinv_get_business_name', $business_name);
204 204
 }
205 205
 
206 206
 function wpinv_get_blogname() {
207
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
207
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
208 208
 }
209 209
 
210 210
 function wpinv_get_admin_email() {
211
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
212
-    return apply_filters( 'wpinv_admin_email', $admin_email );
211
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
212
+    return apply_filters('wpinv_admin_email', $admin_email);
213 213
 }
214 214
 
215 215
 function wpinv_get_business_website() {
216
-    $business_website = home_url( '/' );
217
-    return apply_filters( 'wpinv_get_business_website', $business_website );
216
+    $business_website = home_url('/');
217
+    return apply_filters('wpinv_get_business_website', $business_website);
218 218
 }
219 219
 
220
-function wpinv_get_terms_text( $invoice_id = 0 ) {
220
+function wpinv_get_terms_text($invoice_id = 0) {
221 221
     $terms_text = '';
222
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
222
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
223 223
 }
224 224
 
225 225
 function wpinv_get_business_footer() {
226
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
227
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
228
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
226
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
227
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
228
+    return apply_filters('wpinv_get_business_footer', $business_footer);
229 229
 }
230 230
 
231 231
 function wpinv_checkout_required_fields() {
232 232
     $required_fields = array();
233 233
     
234 234
     // Let payment gateways and other extensions determine if address fields should be required
235
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
235
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
236 236
     
237
-    if ( $require_billing_details ) {
238
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
237
+    if ($require_billing_details) {
238
+		if ((bool) wpinv_get_option('fname_mandatory')) {
239 239
 			$required_fields['first_name'] = array(
240 240
 				'error_id' => 'invalid_first_name',
241
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
241
+				'error_message' => __('Please enter your first name', 'invoicing')
242 242
 			);
243 243
 		}
244
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
244
+		if ((bool) wpinv_get_option('address_mandatory')) {
245 245
 			$required_fields['address'] = array(
246 246
 				'error_id' => 'invalid_address',
247
-				'error_message' => __( 'Please enter your address', 'invoicing' )
247
+				'error_message' => __('Please enter your address', 'invoicing')
248 248
 			);
249 249
 		}
250
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
250
+		if ((bool) wpinv_get_option('city_mandatory')) {
251 251
 			$required_fields['city'] = array(
252 252
 				'error_id' => 'invalid_city',
253
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
253
+				'error_message' => __('Please enter your billing city', 'invoicing')
254 254
 			);
255 255
 		}
256
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
256
+		if ((bool) wpinv_get_option('state_mandatory')) {
257 257
 			$required_fields['state'] = array(
258 258
 				'error_id' => 'invalid_state',
259
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
259
+				'error_message' => __('Please enter billing state / province', 'invoicing')
260 260
 			);
261 261
 		}
262
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
262
+		if ((bool) wpinv_get_option('country_mandatory')) {
263 263
 			$required_fields['country'] = array(
264 264
 				'error_id' => 'invalid_country',
265
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
265
+				'error_message' => __('Please select your billing country', 'invoicing')
266 266
 			);
267 267
 		}
268 268
     }
269 269
 
270
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
270
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
271 271
 }
272 272
 
273 273
 function wpinv_is_ssl_enforced() {
274
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
275
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
274
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
275
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
276 276
 }
277 277
 
278 278
 function wpinv_schedule_event_twicedaily() {
279 279
     wpinv_email_payment_reminders();
280 280
 }
281
-add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' );
281
+add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily');
282 282
 
283 283
 function wpinv_require_login_to_checkout() {
284
-    $return = wpinv_get_option( 'login_to_checkout', false );
285
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
284
+    $return = wpinv_get_option('login_to_checkout', false);
285
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
286 286
 }
287 287
 
288
-function wpinv_sequential_number_active( $type = '' ) {
289
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
290
-    if ( null !== $check ) {
288
+function wpinv_sequential_number_active($type = '') {
289
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
290
+    if (null !== $check) {
291 291
         return $check;
292 292
     }
293 293
     
294
-    return wpinv_get_option( 'sequential_invoice_number' );
294
+    return wpinv_get_option('sequential_invoice_number');
295 295
 }
296 296
 
297
-function wpinv_switch_to_locale( $locale = NULL ) {
297
+function wpinv_switch_to_locale($locale = NULL) {
298 298
     global $invoicing, $wpi_switch_locale;
299 299
 
300
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
301
-        $locale = empty( $locale ) ? get_locale() : $locale;
300
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
301
+        $locale = empty($locale) ? get_locale() : $locale;
302 302
 
303
-        switch_to_locale( $locale );
303
+        switch_to_locale($locale);
304 304
 
305 305
         $wpi_switch_locale = $locale;
306 306
 
307
-        add_filter( 'plugin_locale', 'get_locale' );
307
+        add_filter('plugin_locale', 'get_locale');
308 308
 
309 309
         $invoicing->load_textdomain();
310 310
 
311
-        do_action( 'wpinv_switch_to_locale', $locale );
311
+        do_action('wpinv_switch_to_locale', $locale);
312 312
     }
313 313
 }
314 314
 
315 315
 function wpinv_restore_locale() {
316 316
     global $invoicing, $wpi_switch_locale;
317 317
     
318
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
318
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
319 319
         restore_previous_locale();
320 320
 
321 321
         $wpi_switch_locale = NULL;
322 322
 
323
-        remove_filter( 'plugin_locale', 'get_locale' );
323
+        remove_filter('plugin_locale', 'get_locale');
324 324
 
325 325
         $invoicing->load_textdomain();
326 326
 
327
-        do_action( 'wpinv_restore_locale' );
327
+        do_action('wpinv_restore_locale');
328 328
     }
329 329
 }
330 330
 
@@ -332,22 +332,22 @@  discard block
 block discarded – undo
332 332
  * Returns the default form's id.
333 333
  */
334 334
 function wpinv_get_default_payment_form() {
335
-    $form = get_option( 'wpinv_default_payment_form' );
335
+    $form = get_option('wpinv_default_payment_form');
336 336
 
337
-    if ( empty( $form ) || 'publish' != get_post_status( $form ) ) {
337
+    if (empty($form) || 'publish' != get_post_status($form)) {
338 338
         $form = wp_insert_post(
339 339
             array(
340 340
                 'post_type'   => 'wpi_payment_form',
341
-                'post_title'  => __( 'Checkout (default)', 'invoicing' ),
341
+                'post_title'  => __('Checkout (default)', 'invoicing'),
342 342
                 'post_status' => 'publish',
343 343
                 'meta_input'  => array(
344
-                    'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ),
344
+                    'wpinv_form_elements' => wpinv_get_data('default-payment-form'),
345 345
                     'wpinv_form_items'    => array(),
346 346
                 )
347 347
             )
348 348
         );
349 349
 
350
-        update_option( 'wpinv_default_payment_form', $form );
350
+        update_option('wpinv_default_payment_form', $form);
351 351
     }
352 352
 
353 353
     return $form;
@@ -358,19 +358,19 @@  discard block
 block discarded – undo
358 358
  * 
359 359
  * @param int $payment_form
360 360
  */
361
-function getpaid_get_payment_form_elements( $payment_form ) {
361
+function getpaid_get_payment_form_elements($payment_form) {
362 362
 
363
-    if ( empty( $payment_form ) ) {
364
-        return wpinv_get_data( 'sample-payment-form' );
363
+    if (empty($payment_form)) {
364
+        return wpinv_get_data('sample-payment-form');
365 365
     }
366 366
 
367
-    $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true );
367
+    $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true);
368 368
 
369
-    if ( is_array( $form_elements ) ) {
369
+    if (is_array($form_elements)) {
370 370
         return $form_elements;
371 371
     }
372 372
 
373
-    return wpinv_get_data( 'sample-payment-form' );
373
+    return wpinv_get_data('sample-payment-form');
374 374
 
375 375
 }
376 376
 
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
  * 
380 380
  * @param int $payment_form
381 381
  */
382
-function gepaid_get_form_items( $id ) {
383
-    $form = new GetPaid_Payment_Form( $id );
382
+function gepaid_get_form_items($id) {
383
+    $form = new GetPaid_Payment_Form($id);
384 384
 
385 385
     // Is this a default form?
386
-    if ( $form->is_default() ) {
386
+    if ($form->is_default()) {
387 387
         return array();
388 388
     }
389 389
 
390
-    return $form->get_items( 'view', 'arrays' );
390
+    return $form->get_items('view', 'arrays');
391 391
 }
Please login to merge, or discard this patch.