Passed
Push — master ( 9c638d...a63e48 )
by Brian
10:33
created
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +575 added lines, -575 removed lines patch added patch discarded remove patch
@@ -13,450 +13,450 @@  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
-		// Gateway settings.
157
-		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
+        // Gateway settings.
157
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
158 158
 		
159 159
 
160
-		// Gateway checkout fiellds.
161
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
162
-
163
-		// Process payment.
164
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
160
+        // Gateway checkout fiellds.
161
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
162
+
163
+        // Process payment.
164
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
165
+
166
+        // Change the checkout button text.
167
+        if ( ! empty( $this->checkout_button_text ) ) {
168
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
169
+        }
170
+
171
+        // Check if a gateway is valid for a given currency.
172
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
173
+
174
+        // Generate the transaction url.
175
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
176
+
177
+        // Generate the subscription url.
178
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
179
+
180
+        // Confirm payments.
181
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
182
+
183
+        // Verify IPNs.
184
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
185
+
186
+    }
187
+
188
+    /**
189
+     * Checks if this gateway is a given gateway.
190
+     *
191
+     * @since 1.0.19
192
+     * @return bool
193
+     */
194
+    public function is( $gateway ) {
195
+        return $gateway == $this->id;
196
+    }
197
+
198
+    /**
199
+     * Returns a users saved tokens for this gateway.
200
+     *
201
+     * @since 1.0.19
202
+     * @return array
203
+     */
204
+    public function get_tokens( $sandbox = null ) {
205
+
206
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
207
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
208
+
209
+            if ( is_array( $tokens ) ) {
210
+                $this->tokens = $tokens;
211
+            }
212
+
213
+        }
214
+
215
+        if ( ! is_bool( $sandbox ) ) {
216
+            return $this->tokens;
217
+        }
218
+
219
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
220
+        return wp_list_filter( $this->tokens, $args );
221
+
222
+    }
223
+
224
+    /**
225
+     * Saves a token for this gateway.
226
+     *
227
+     * @since 1.0.19
228
+     */
229
+    public function save_token( $token ) {
230
+
231
+        $tokens   = $this->get_tokens();
232
+        $tokens[] = $token;
233
+
234
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
235
+
236
+        $this->tokens = $tokens;
237
+
238
+    }
239
+
240
+    /**
241
+     * Return the title for admin screens.
242
+     *
243
+     * @return string
244
+     */
245
+    public function get_method_title() {
246
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
247
+    }
248
+
249
+    /**
250
+     * Return the description for admin screens.
251
+     *
252
+     * @return string
253
+     */
254
+    public function get_method_description() {
255
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
256
+    }
257
+
258
+    /**
259
+     * Get the success url.
260
+     *
261
+     * @param WPInv_Invoice $invoice Invoice object.
262
+     * @return string
263
+     */
264
+    public function get_return_url( $invoice ) {
265
+
266
+        // Payment success url
267
+        $return_url = add_query_arg(
268
+            array(
269
+                'payment-confirm' => $this->id,
270
+                'invoice_key'     => $invoice->get_key(),
271
+                'utm_nooverride'  => 1
272
+            ),
273
+            wpinv_get_success_page_uri()
274
+        );
275
+
276
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
277
+    }
278
+
279
+    /**
280
+     * Confirms payments when rendering the success page.
281
+     *
282
+     * @param string $content Success page content.
283
+     * @return string
284
+     */
285
+    public function confirm_payment( $content ) {
286
+
287
+        // Retrieve the invoice.
288
+        $invoice_id = getpaid_get_current_invoice_id();
289
+        $invoice    = wpinv_get_invoice( $invoice_id );
290
+
291
+        // Ensure that it exists and that it is pending payment.
292
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
293
+            return $content;
294
+        }
295
+
296
+        // Can the user view this invoice??
297
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
298
+            return $content;
299
+        }
300
+
301
+        // Show payment processing indicator.
302
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
303
+    }
304
+
305
+    /**
306
+     * Processes ipns and marks payments as complete.
307
+     *
308
+     * @return void
309
+     */
310
+    public function verify_ipn() {}
311
+
312
+    /**
313
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
314
+     *
315
+     * @param string $transaction_url transaction url.
316
+     * @param WPInv_Invoice $invoice Invoice object.
317
+     * @return string transaction URL, or empty string.
318
+     */
319
+    public function filter_transaction_url( $transaction_url, $invoice ) {
320
+
321
+        $transaction_id  = $invoice->get_transaction_id();
322
+
323
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
324
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
325
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
326
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
327
+        }
328
+
329
+        return $transaction_url;
330
+    }
331
+
332
+    /**
333
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
334
+     *
335
+     * @param string $subscription_url transaction url.
336
+     * @param WPInv_Invoice $invoice Invoice object.
337
+     * @return string subscription URL, or empty string.
338
+     */
339
+    public function filter_subscription_url( $subscription_url, $invoice ) {
340
+
341
+        $profile_id      = $invoice->get_subscription_id();
342
+
343
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
344
+
345
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
346
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
347
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
348
+
349
+        }
350
+
351
+        return $subscription_url;
352
+    }
353
+
354
+    /**
355
+     * Check if the gateway is available for use.
356
+     *
357
+     * @return bool
358
+     */
359
+    public function is_available() {
360
+        return ! empty( $this->enabled );
361
+    }
362
+
363
+    /**
364
+     * Return the gateway's title.
365
+     *
366
+     * @return string
367
+     */
368
+    public function get_title() {
369
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
370
+    }
371
+
372
+    /**
373
+     * Return the gateway's description.
374
+     *
375
+     * @return string
376
+     */
377
+    public function get_description() {
378
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
379
+    }
380
+
381
+    /**
382
+     * Process Payment.
383
+     *
384
+     *
385
+     * @param WPInv_Invoice $invoice Invoice.
386
+     * @param array $submission_data Posted checkout fields.
387
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
388
+     * @return void
389
+     */
390
+    public function process_payment( $invoice, $submission_data, $submission ) {
391
+        // Process the payment then either redirect to the success page or the gateway.
392
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
393
+    }
394
+
395
+    /**
396
+     * Process refund.
397
+     *
398
+     * If the gateway declares 'refunds' support, this will allow it to refund.
399
+     * a passed in amount.
400
+     *
401
+     * @param WPInv_Invoice $invoice Invoice.
402
+     * @param  float  $amount Refund amount.
403
+     * @param  string $reason Refund reason.
404
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
405
+     */
406
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
407
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
408
+    }
409
+
410
+    /**
411
+     * Displays the payment fields, credit cards etc.
412
+     * 
413
+     * @param int $invoice_id 0 or invoice id.
414
+     * @param GetPaid_Payment_Form $form Current payment form.
415
+     */
416
+    public function payment_fields( $invoice_id, $form ) {
417
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
418
+    }
419
+
420
+    /**
421
+     * Filters the gateway settings.
422
+     * 
423
+     * @param array $admin_settings
424
+     */
425
+    public function admin_settings( $admin_settings ) {
426
+        return $admin_settings;
427
+    }
428
+
429
+    /**
430
+     * Retrieves the value of a gateway setting.
431
+     * 
432
+     * @param string $option
433
+     */
434
+    public function get_option( $option, $default = false ) {
435
+        return wpinv_get_option( $this->id . '_' . $option, $default );
436
+    }
437
+
438
+    /**
439
+     * Check if a gateway supports a given feature.
440
+     *
441
+     * Gateways should override this to declare support (or lack of support) for a feature.
442
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
443
+     *
444
+     * @param string $feature string The name of a feature to test support for.
445
+     * @return bool True if the gateway supports the feature, false otherwise.
446
+     * @since 1.0.19
447
+     */
448
+    public function supports( $feature ) {
449
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
450
+    }
165 451
 
166
-		// Change the checkout button text.
167
-		if ( ! empty( $this->checkout_button_text ) ) {
168
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
169
-		}
170
-
171
-		// Check if a gateway is valid for a given currency.
172
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
173
-
174
-		// Generate the transaction url.
175
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
176
-
177
-		// Generate the subscription url.
178
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
179
-
180
-		// Confirm payments.
181
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
182
-
183
-		// Verify IPNs.
184
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
185
-
186
-	}
187
-
188
-	/**
189
-	 * Checks if this gateway is a given gateway.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @return bool
193
-	 */
194
-	public function is( $gateway ) {
195
-		return $gateway == $this->id;
196
-	}
197
-
198
-	/**
199
-	 * Returns a users saved tokens for this gateway.
200
-	 *
201
-	 * @since 1.0.19
202
-	 * @return array
203
-	 */
204
-	public function get_tokens( $sandbox = null ) {
205
-
206
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
207
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
208
-
209
-			if ( is_array( $tokens ) ) {
210
-				$this->tokens = $tokens;
211
-			}
212
-
213
-		}
214
-
215
-		if ( ! is_bool( $sandbox ) ) {
216
-			return $this->tokens;
217
-		}
218
-
219
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
220
-		return wp_list_filter( $this->tokens, $args );
221
-
222
-	}
223
-
224
-	/**
225
-	 * Saves a token for this gateway.
226
-	 *
227
-	 * @since 1.0.19
228
-	 */
229
-	public function save_token( $token ) {
230
-
231
-		$tokens   = $this->get_tokens();
232
-		$tokens[] = $token;
233
-
234
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
235
-
236
-		$this->tokens = $tokens;
237
-
238
-	}
239
-
240
-	/**
241
-	 * Return the title for admin screens.
242
-	 *
243
-	 * @return string
244
-	 */
245
-	public function get_method_title() {
246
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
247
-	}
248
-
249
-	/**
250
-	 * Return the description for admin screens.
251
-	 *
252
-	 * @return string
253
-	 */
254
-	public function get_method_description() {
255
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
256
-	}
257
-
258
-	/**
259
-	 * Get the success url.
260
-	 *
261
-	 * @param WPInv_Invoice $invoice Invoice object.
262
-	 * @return string
263
-	 */
264
-	public function get_return_url( $invoice ) {
265
-
266
-		// Payment success url
267
-		$return_url = add_query_arg(
268
-			array(
269
-				'payment-confirm' => $this->id,
270
-				'invoice_key'     => $invoice->get_key(),
271
-				'utm_nooverride'  => 1
272
-			),
273
-			wpinv_get_success_page_uri()
274
-		);
275
-
276
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
277
-	}
278
-
279
-	/**
280
-	 * Confirms payments when rendering the success page.
281
-	 *
282
-	 * @param string $content Success page content.
283
-	 * @return string
284
-	 */
285
-	public function confirm_payment( $content ) {
286
-
287
-		// Retrieve the invoice.
288
-		$invoice_id = getpaid_get_current_invoice_id();
289
-		$invoice    = wpinv_get_invoice( $invoice_id );
290
-
291
-		// Ensure that it exists and that it is pending payment.
292
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
293
-			return $content;
294
-		}
295
-
296
-		// Can the user view this invoice??
297
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
298
-			return $content;
299
-		}
300
-
301
-		// Show payment processing indicator.
302
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
303
-	}
304
-
305
-	/**
306
-	 * Processes ipns and marks payments as complete.
307
-	 *
308
-	 * @return void
309
-	 */
310
-	public function verify_ipn() {}
311
-
312
-	/**
313
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
314
-	 *
315
-	 * @param string $transaction_url transaction url.
316
-	 * @param WPInv_Invoice $invoice Invoice object.
317
-	 * @return string transaction URL, or empty string.
318
-	 */
319
-	public function filter_transaction_url( $transaction_url, $invoice ) {
320
-
321
-		$transaction_id  = $invoice->get_transaction_id();
322
-
323
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
324
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
325
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
326
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
327
-		}
328
-
329
-		return $transaction_url;
330
-	}
331
-
332
-	/**
333
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
334
-	 *
335
-	 * @param string $subscription_url transaction url.
336
-	 * @param WPInv_Invoice $invoice Invoice object.
337
-	 * @return string subscription URL, or empty string.
338
-	 */
339
-	public function filter_subscription_url( $subscription_url, $invoice ) {
340
-
341
-		$profile_id      = $invoice->get_subscription_id();
342
-
343
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
344
-
345
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
346
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
347
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
348
-
349
-		}
350
-
351
-		return $subscription_url;
352
-	}
353
-
354
-	/**
355
-	 * Check if the gateway is available for use.
356
-	 *
357
-	 * @return bool
358
-	 */
359
-	public function is_available() {
360
-		return ! empty( $this->enabled );
361
-	}
362
-
363
-	/**
364
-	 * Return the gateway's title.
365
-	 *
366
-	 * @return string
367
-	 */
368
-	public function get_title() {
369
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
370
-	}
371
-
372
-	/**
373
-	 * Return the gateway's description.
374
-	 *
375
-	 * @return string
376
-	 */
377
-	public function get_description() {
378
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
379
-	}
380
-
381
-	/**
382
-	 * Process Payment.
383
-	 *
384
-	 *
385
-	 * @param WPInv_Invoice $invoice Invoice.
386
-	 * @param array $submission_data Posted checkout fields.
387
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
388
-	 * @return void
389
-	 */
390
-	public function process_payment( $invoice, $submission_data, $submission ) {
391
-		// Process the payment then either redirect to the success page or the gateway.
392
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
393
-	}
394
-
395
-	/**
396
-	 * Process refund.
397
-	 *
398
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
399
-	 * a passed in amount.
400
-	 *
401
-	 * @param WPInv_Invoice $invoice Invoice.
402
-	 * @param  float  $amount Refund amount.
403
-	 * @param  string $reason Refund reason.
404
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
405
-	 */
406
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
407
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
408
-	}
409
-
410
-	/**
411
-	 * Displays the payment fields, credit cards etc.
412
-	 * 
413
-	 * @param int $invoice_id 0 or invoice id.
414
-	 * @param GetPaid_Payment_Form $form Current payment form.
415
-	 */
416
-	public function payment_fields( $invoice_id, $form ) {
417
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
418
-	}
419
-
420
-	/**
421
-	 * Filters the gateway settings.
422
-	 * 
423
-	 * @param array $admin_settings
424
-	 */
425
-	public function admin_settings( $admin_settings ) {
426
-		return $admin_settings;
427
-	}
428
-
429
-	/**
430
-	 * Retrieves the value of a gateway setting.
431
-	 * 
432
-	 * @param string $option
433
-	 */
434
-	public function get_option( $option, $default = false ) {
435
-		return wpinv_get_option( $this->id . '_' . $option, $default );
436
-	}
437
-
438
-	/**
439
-	 * Check if a gateway supports a given feature.
440
-	 *
441
-	 * Gateways should override this to declare support (or lack of support) for a feature.
442
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
443
-	 *
444
-	 * @param string $feature string The name of a feature to test support for.
445
-	 * @return bool True if the gateway supports the feature, false otherwise.
446
-	 * @since 1.0.19
447
-	 */
448
-	public function supports( $feature ) {
449
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
450
-	}
451
-
452
-	/**
453
-	 * Returns the credit card form html.
454
-	 * 
455
-	 * @param bool $save whether or not to display the save button.
456
-	 */
452
+    /**
453
+     * Returns the credit card form html.
454
+     * 
455
+     * @param bool $save whether or not to display the save button.
456
+     */
457 457
     public function get_cc_form( $save = false ) {
458 458
 
459
-		ob_start();
459
+        ob_start();
460 460
 
461 461
         $id_prefix = esc_attr( uniqid( $this->id ) );
462 462
 
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
                                         'name'              => $this->id . '[cc_cvv2]',
552 552
                                         'id'                => "$id_prefix-cc-cvv2",
553 553
                                         'label'             => __( 'CCV', 'invoicing' ),
554
-										'label_type'        => 'vertical',
555
-										'class'             => 'form-control-sm',
554
+                                        'label_type'        => 'vertical',
555
+                                        'class'             => 'form-control-sm',
556 556
                                     )
557 557
                                 );
558 558
                             ?>
@@ -562,175 +562,175 @@  discard block
 block discarded – undo
562 562
 					
563 563
 					<?php
564 564
 
565
-						if ( $save ) {
566
-							echo $this->save_payment_method_checkbox();
567
-						}
565
+                        if ( $save ) {
566
+                            echo $this->save_payment_method_checkbox();
567
+                        }
568 568
 
569
-					?>
569
+                    ?>
570 570
                 </div>
571 571
 
572 572
             </div>
573 573
 		<?php
574 574
 		
575
-		return ob_get_clean();
575
+        return ob_get_clean();
576 576
 
577 577
     }
578 578
 
579
-	/**
580
-	 * Displays a new payment method entry form.
581
-	 *
582
-	 * @since 1.0.19
583
-	 */
584
-	public function new_payment_method_entry( $form ) {
585
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
586
-	}
587
-
588
-	/**
589
-	 * Grab and display our saved payment methods.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function saved_payment_methods() {
594
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
595
-
596
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
597
-			$html .= $this->get_saved_payment_method_option_html( $token );
598
-		}
599
-
600
-		$html .= $this->get_new_payment_method_option_html();
601
-		$html .= '</ul>';
602
-
603
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
604
-	}
605
-
606
-	/**
607
-	 * Gets saved payment method HTML from a token.
608
-	 *
609
-	 * @since 1.0.19
610
-	 * @param  array $token Payment Token.
611
-	 * @return string Generated payment method HTML
612
-	 */
613
-	public function get_saved_payment_method_option_html( $token ) {
614
-
615
-		return sprintf(
616
-			'<li class="getpaid-payment-method form-group">
579
+    /**
580
+     * Displays a new payment method entry form.
581
+     *
582
+     * @since 1.0.19
583
+     */
584
+    public function new_payment_method_entry( $form ) {
585
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
586
+    }
587
+
588
+    /**
589
+     * Grab and display our saved payment methods.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function saved_payment_methods() {
594
+        $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
595
+
596
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
597
+            $html .= $this->get_saved_payment_method_option_html( $token );
598
+        }
599
+
600
+        $html .= $this->get_new_payment_method_option_html();
601
+        $html .= '</ul>';
602
+
603
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
604
+    }
605
+
606
+    /**
607
+     * Gets saved payment method HTML from a token.
608
+     *
609
+     * @since 1.0.19
610
+     * @param  array $token Payment Token.
611
+     * @return string Generated payment method HTML
612
+     */
613
+    public function get_saved_payment_method_option_html( $token ) {
614
+
615
+        return sprintf(
616
+            '<li class="getpaid-payment-method form-group">
617 617
 				<label>
618 618
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
619 619
 					<span>%3$s</span>
620 620
 				</label>
621 621
 			</li>',
622
-			esc_attr( $this->id ),
623
-			esc_attr( $token['id'] ),
624
-			esc_html( $token['name'] ),
625
-			checked( empty( $token['default'] ), false, false )
626
-		);
622
+            esc_attr( $this->id ),
623
+            esc_attr( $token['id'] ),
624
+            esc_html( $token['name'] ),
625
+            checked( empty( $token['default'] ), false, false )
626
+        );
627 627
 
628
-	}
628
+    }
629 629
 
630
-	/**
631
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
632
-	 *
633
-	 * @since 1.0.19
634
-	 */
635
-	public function get_new_payment_method_option_html() {
630
+    /**
631
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
632
+     *
633
+     * @since 1.0.19
634
+     */
635
+    public function get_new_payment_method_option_html() {
636 636
 
637
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
637
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
638 638
 
639
-		return sprintf(
640
-			'<li class="getpaid-new-payment-method">
639
+        return sprintf(
640
+            '<li class="getpaid-new-payment-method">
641 641
 				<label>
642 642
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
643 643
 					<span>%2$s</span>
644 644
 				</label>
645 645
 			</li>',
646
-			esc_attr( $this->id ),
647
-			esc_html( $label )
648
-		);
646
+            esc_attr( $this->id ),
647
+            esc_html( $label )
648
+        );
649 649
 
650
-	}
650
+    }
651 651
 
652
-	/**
653
-	 * Outputs a checkbox for saving a new payment method to the database.
654
-	 *
655
-	 * @since 1.0.19
656
-	 */
657
-	public function save_payment_method_checkbox() {
652
+    /**
653
+     * Outputs a checkbox for saving a new payment method to the database.
654
+     *
655
+     * @since 1.0.19
656
+     */
657
+    public function save_payment_method_checkbox() {
658 658
 
659
-		return sprintf(
660
-			'<p class="form-group getpaid-save-payment-method">
659
+        return sprintf(
660
+            '<p class="form-group getpaid-save-payment-method">
661 661
 				<label>
662 662
 					<input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
663 663
 					<span>%2$s</span>
664 664
 				</label>
665 665
 			</p>',
666
-			esc_attr( $this->id ),
667
-			esc_html__( 'Save payment method', 'invoicing' )
668
-		);
666
+            esc_attr( $this->id ),
667
+            esc_html__( 'Save payment method', 'invoicing' )
668
+        );
669 669
 
670
-	}
670
+    }
671 671
 
672
-	/**
673
-	 * Registers the gateway.
674
-	 *
675
-	 * @return array
676
-	 */
677
-	public function register_gateway( $gateways ) {
672
+    /**
673
+     * Registers the gateway.
674
+     *
675
+     * @return array
676
+     */
677
+    public function register_gateway( $gateways ) {
678 678
 
679
-		$gateways[ $this->id ] = array(
679
+        $gateways[ $this->id ] = array(
680 680
 
681
-			'admin_label'    => $this->method_title,
681
+            'admin_label'    => $this->method_title,
682 682
             'checkout_label' => $this->title,
683
-			'ordering'       => $this->order,
684
-
685
-		);
686
-
687
-		return $gateways;
688
-
689
-	}
690
-
691
-	/**
692
-	 * Checks whether or not this is a sandbox request.
693
-	 *
694
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
695
-	 * @return bool
696
-	 */
697
-	public function is_sandbox( $invoice = null ) {
698
-
699
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
700
-			return $invoice->get_mode() == 'test';
701
-		}
702
-
703
-		return wpinv_is_test_mode( $this->id );
704
-
705
-	}
706
-
707
-	/**
708
-	 * Renames the checkout button
709
-	 *
710
-	 * @return string
711
-	 */
712
-	public function rename_checkout_button() {
713
-		return $this->checkout_button_text;
714
-	}
715
-
716
-	/**
717
-	 * Validate gateway currency
718
-	 *
719
-	 * @return bool
720
-	 */
721
-	public function validate_currency( $validation, $currency ) {
722
-
723
-		// Required currencies.
724
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
725
-			return false;
726
-		}
727
-
728
-		// Excluded currencies.
729
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
730
-			return false;
731
-		}
732
-
733
-		return $validation;
734
-	}
683
+            'ordering'       => $this->order,
684
+
685
+        );
686
+
687
+        return $gateways;
688
+
689
+    }
690
+
691
+    /**
692
+     * Checks whether or not this is a sandbox request.
693
+     *
694
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
695
+     * @return bool
696
+     */
697
+    public function is_sandbox( $invoice = null ) {
698
+
699
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
700
+            return $invoice->get_mode() == 'test';
701
+        }
702
+
703
+        return wpinv_is_test_mode( $this->id );
704
+
705
+    }
706
+
707
+    /**
708
+     * Renames the checkout button
709
+     *
710
+     * @return string
711
+     */
712
+    public function rename_checkout_button() {
713
+        return $this->checkout_button_text;
714
+    }
715
+
716
+    /**
717
+     * Validate gateway currency
718
+     *
719
+     * @return bool
720
+     */
721
+    public function validate_currency( $validation, $currency ) {
722
+
723
+        // Required currencies.
724
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
725
+            return false;
726
+        }
727
+
728
+        // Excluded currencies.
729
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
730
+            return false;
731
+        }
732
+
733
+        return $validation;
734
+    }
735 735
 
736 736
 }
Please login to merge, or discard this patch.