Passed
Push — master ( 0fd3da...d47925 )
by Brian
05:32
created
templates/subscriptions/subscription-details.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -46,64 +46,64 @@  discard block
 block discarded – undo
46 46
 				<td style="width: 65%">
47 47
 					<?php
48 48
 
49
-						switch ( $key ) {
49
+                        switch ( $key ) {
50 50
 
51
-							case 'status':
52
-								echo sanitize_text_field( $subscription->get_status_label() );
53
-								break;
51
+                            case 'status':
52
+                                echo sanitize_text_field( $subscription->get_status_label() );
53
+                                break;
54 54
 
55
-							case 'start_date':
56
-								echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) );
57
-								break;
55
+                            case 'start_date':
56
+                                echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) );
57
+                                break;
58 58
 
59
-							case 'expiry_date':
60
-								echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
61
-								break;
59
+                            case 'expiry_date':
60
+                                echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
61
+                                break;
62 62
 
63
-							case 'initial_amount':
64
-								echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
63
+                            case 'initial_amount':
64
+                                echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
65 65
 
66
-								if ( $subscription->has_trial_period() ) {
66
+                                if ( $subscription->has_trial_period() ) {
67 67
 
68
-									echo "<small class='text-muted'>&nbsp;";
69
-									printf(
70
-										_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
71
-										sanitize_text_field( $subscription->get_trial_period() )
72
-									);
73
-									echo '</small>';
68
+                                    echo "<small class='text-muted'>&nbsp;";
69
+                                    printf(
70
+                                        _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
71
+                                        sanitize_text_field( $subscription->get_trial_period() )
72
+                                    );
73
+                                    echo '</small>';
74 74
 
75
-								}
75
+                                }
76 76
 
77
-								break;
77
+                                break;
78 78
 
79
-							case 'recurring_amount':
80
-								$frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
81
-								$amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
82
-								echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" );
83
-								break;
79
+                            case 'recurring_amount':
80
+                                $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
81
+                                $amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
82
+                                echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" );
83
+                                break;
84 84
 
85
-							case 'item':
85
+                            case 'item':
86 86
 
87
-								if ( empty( $subscription_group ) ) {
88
-									echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
89
-								} else {
90
-									$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
91
-									echo implode( ' | ', $markup );
92
-								}
87
+                                if ( empty( $subscription_group ) ) {
88
+                                    echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
89
+                                } else {
90
+                                    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
91
+                                    echo implode( ' | ', $markup );
92
+                                }
93 93
 
94
-								break;
94
+                                break;
95 95
 
96
-							case 'payments':
96
+                            case 'payments':
97 97
 
98
-								$max_activations = (int) $subscription->get_bill_times();
99
-								echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
98
+                                $max_activations = (int) $subscription->get_bill_times();
99
+                                echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
100 100
 
101
-								break;
101
+                                break;
102 102
 
103
-						}
104
-						do_action( "getpaid_render_single_subscription_column_$key", $subscription );
103
+                        }
104
+                        do_action( "getpaid_render_single_subscription_column_$key", $subscription );
105 105
 
106
-					?>
106
+                    ?>
107 107
 				</td>
108 108
 
109 109
 			</tr>
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
 <span class="form-text">
131 131
 
132 132
 	<?php
133
-		if ( $subscription->can_cancel() ) {
134
-			printf(
135
-				'<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
136
-				esc_url( $subscription->get_cancel_url() ),
137
-				esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
138
-				__( 'Cancel Subscription', 'invoicing' )
139
-			);
140
-		}
141
-
142
-		do_action( 'getpaid-single-subscription-page-actions', $subscription );
143
-	?>
133
+        if ( $subscription->can_cancel() ) {
134
+            printf(
135
+                '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
136
+                esc_url( $subscription->get_cancel_url() ),
137
+                esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
138
+                __( 'Cancel Subscription', 'invoicing' )
139
+            );
140
+        }
141
+
142
+        do_action( 'getpaid-single-subscription-page-actions', $subscription );
143
+    ?>
144 144
 
145 145
 	<a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a>
146 146
 </span>
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +807 added lines, -807 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,206 +10,206 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * The subscription groups. If more than 2, ensure the gateway
93
-	 * supports multiple subscriptions.
94
-	 *
95
-	 * @var array
96
-	 */
97
-	public $subscription_groups = array();
98
-
99
-	/**
100
-	 * An array of fees for the submission.
101
-	 *
102
-	 * @var array
103
-	 */
104
-	protected $fees = array();
105
-
106
-	/**
107
-	 * An array of discounts for the submission.
108
-	 *
109
-	 * @var array
110
-	 */
111
-	protected $discounts = array();
112
-
113
-	/**
114
-	 * An array of taxes for the submission.
115
-	 *
116
-	 * @var array
117
-	 */
118
-	protected $taxes = array();
119
-
120
-	/**
121
-	 * An array of items for the submission.
122
-	 *
123
-	 * @var GetPaid_Form_Item[]
124
-	 */
125
-	protected $items = array();
126
-
127
-	/**
128
-	 * The last error.
129
-	 *
130
-	 * @var string
131
-	 */
132
-	public $last_error = null;
133
-
134
-	/**
135
-	 * The last error code.
136
-	 *
137
-	 * @var string
138
-	 */
139
-	public $last_error_code = null;
140
-
141
-    /**
142
-	 * Class constructor.
143
-	 *
144
-	 */
145
-	public function __construct() {
146
-
147
-		// Set the state and country to the default state and country.
148
-		$this->country = wpinv_default_billing_country();
149
-		$this->state   = wpinv_get_default_state();
150
-
151
-		// Do we have an actual submission?
152
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
153
-			$this->load_data( $_POST );
154
-		}
155
-
156
-	}
157
-
158
-	/**
159
-	 * Loads submission data.
160
-	 *
161
-	 * @param array $data
162
-	 */
163
-	public function load_data( $data ) {
164
-
165
-		// Remove slashes from the submitted data...
166
-		$data       = wp_unslash( $data );
167
-
168
-		// Allow plugins to filter the data.
169
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
170
-
171
-		// Cache it...
172
-		$this->data = $data;
173
-
174
-		// Then generate a unique id from the data.
175
-		$this->id   = md5( wp_json_encode( $data ) );
176
-
177
-		// Finally, process the submission.
178
-		try {
179
-
180
-			// Each process is passed an instance of the class (with reference)
181
-			// and should throw an Exception whenever it encounters one.
182
-			$processors = apply_filters(
183
-				'getpaid_payment_form_submission_processors',
184
-				array(
185
-					array( $this, 'process_payment_form' ),
186
-					array( $this, 'process_invoice' ),
187
-					array( $this, 'process_fees' ),
188
-					array( $this, 'process_items' ),
189
-					array( $this, 'process_discount' ),
190
-					array( $this, 'process_taxes' ),
191
-				),
192
-				$this		
193
-			);
194
-
195
-			foreach ( $processors as $processor ) {
196
-				call_user_func_array( $processor, array( &$this ) );
197
-			}
198
-
199
-		} catch( GetPaid_Payment_Exception $e ) {
200
-			$this->last_error      = $e->getMessage();
201
-			$this->last_error_code = $e->getErrorCode();
202
-		} catch ( Exception $e ) {
203
-			$this->last_error      = $e->getMessage();
204
-			$this->last_error_code = $e->getCode();
205
-		}
206
-
207
-		// Fired when we are done processing a submission.
208
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
209
-
210
-	}
211
-
212
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * The subscription groups. If more than 2, ensure the gateway
93
+     * supports multiple subscriptions.
94
+     *
95
+     * @var array
96
+     */
97
+    public $subscription_groups = array();
98
+
99
+    /**
100
+     * An array of fees for the submission.
101
+     *
102
+     * @var array
103
+     */
104
+    protected $fees = array();
105
+
106
+    /**
107
+     * An array of discounts for the submission.
108
+     *
109
+     * @var array
110
+     */
111
+    protected $discounts = array();
112
+
113
+    /**
114
+     * An array of taxes for the submission.
115
+     *
116
+     * @var array
117
+     */
118
+    protected $taxes = array();
119
+
120
+    /**
121
+     * An array of items for the submission.
122
+     *
123
+     * @var GetPaid_Form_Item[]
124
+     */
125
+    protected $items = array();
126
+
127
+    /**
128
+     * The last error.
129
+     *
130
+     * @var string
131
+     */
132
+    public $last_error = null;
133
+
134
+    /**
135
+     * The last error code.
136
+     *
137
+     * @var string
138
+     */
139
+    public $last_error_code = null;
140
+
141
+    /**
142
+     * Class constructor.
143
+     *
144
+     */
145
+    public function __construct() {
146
+
147
+        // Set the state and country to the default state and country.
148
+        $this->country = wpinv_default_billing_country();
149
+        $this->state   = wpinv_get_default_state();
150
+
151
+        // Do we have an actual submission?
152
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
153
+            $this->load_data( $_POST );
154
+        }
155
+
156
+    }
157
+
158
+    /**
159
+     * Loads submission data.
160
+     *
161
+     * @param array $data
162
+     */
163
+    public function load_data( $data ) {
164
+
165
+        // Remove slashes from the submitted data...
166
+        $data       = wp_unslash( $data );
167
+
168
+        // Allow plugins to filter the data.
169
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
170
+
171
+        // Cache it...
172
+        $this->data = $data;
173
+
174
+        // Then generate a unique id from the data.
175
+        $this->id   = md5( wp_json_encode( $data ) );
176
+
177
+        // Finally, process the submission.
178
+        try {
179
+
180
+            // Each process is passed an instance of the class (with reference)
181
+            // and should throw an Exception whenever it encounters one.
182
+            $processors = apply_filters(
183
+                'getpaid_payment_form_submission_processors',
184
+                array(
185
+                    array( $this, 'process_payment_form' ),
186
+                    array( $this, 'process_invoice' ),
187
+                    array( $this, 'process_fees' ),
188
+                    array( $this, 'process_items' ),
189
+                    array( $this, 'process_discount' ),
190
+                    array( $this, 'process_taxes' ),
191
+                ),
192
+                $this		
193
+            );
194
+
195
+            foreach ( $processors as $processor ) {
196
+                call_user_func_array( $processor, array( &$this ) );
197
+            }
198
+
199
+        } catch( GetPaid_Payment_Exception $e ) {
200
+            $this->last_error      = $e->getMessage();
201
+            $this->last_error_code = $e->getErrorCode();
202
+        } catch ( Exception $e ) {
203
+            $this->last_error      = $e->getMessage();
204
+            $this->last_error_code = $e->getCode();
205
+        }
206
+
207
+        // Fired when we are done processing a submission.
208
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
209
+
210
+    }
211
+
212
+    /*
213 213
 	|--------------------------------------------------------------------------
214 214
 	| Payment Forms.
215 215
 	|--------------------------------------------------------------------------
@@ -218,39 +218,39 @@  discard block
 block discarded – undo
218 218
 	| submission has an active payment form etc.
219 219
     */
220 220
 
221
-	/**
222
-	 * Prepares the submission's payment form.
223
-	 *
224
-	 * @since 1.0.19
225
-	 */
226
-	public function process_payment_form() {
221
+    /**
222
+     * Prepares the submission's payment form.
223
+     *
224
+     * @since 1.0.19
225
+     */
226
+    public function process_payment_form() {
227 227
 
228
-		// Every submission needs an active payment form.
229
-		if ( empty( $this->data['form_id'] ) ) {
230
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
231
-		}
228
+        // Every submission needs an active payment form.
229
+        if ( empty( $this->data['form_id'] ) ) {
230
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
231
+        }
232 232
 
233
-		// Fetch the payment form.
234
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
233
+        // Fetch the payment form.
234
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
235 235
 
236
-		if ( ! $this->payment_form->is_active() ) {
237
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
238
-		}
236
+        if ( ! $this->payment_form->is_active() ) {
237
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
238
+        }
239 239
 
240
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
241
-	}
240
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
241
+    }
242 242
 
243 243
     /**
244
-	 * Returns the payment form.
245
-	 *
246
-	 * @since 1.0.19
247
-	 * @return GetPaid_Payment_Form
248
-	 */
249
-	public function get_payment_form() {
250
-		return $this->payment_form;
251
-	}
244
+     * Returns the payment form.
245
+     *
246
+     * @since 1.0.19
247
+     * @return GetPaid_Payment_Form
248
+     */
249
+    public function get_payment_form() {
250
+        return $this->payment_form;
251
+    }
252 252
 
253
-	/*
253
+    /*
254 254
 	|--------------------------------------------------------------------------
255 255
 	| Invoices.
256 256
 	|--------------------------------------------------------------------------
@@ -259,84 +259,84 @@  discard block
 block discarded – undo
259 259
 	| might be for an existing invoice.
260 260
 	*/
261 261
 
262
-	/**
263
-	 * Prepares the submission's invoice.
264
-	 *
265
-	 * @since 1.0.19
266
-	 */
267
-	public function process_invoice() {
262
+    /**
263
+     * Prepares the submission's invoice.
264
+     *
265
+     * @since 1.0.19
266
+     */
267
+    public function process_invoice() {
268 268
 
269
-		// Abort if there is no invoice.
270
-		if ( empty( $this->data['invoice_id'] ) ) {
271
-			return;
272
-		}
269
+        // Abort if there is no invoice.
270
+        if ( empty( $this->data['invoice_id'] ) ) {
271
+            return;
272
+        }
273 273
 
274
-		// If the submission is for an existing invoice, ensure that it exists
275
-		// and that it is not paid for.
276
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
274
+        // If the submission is for an existing invoice, ensure that it exists
275
+        // and that it is not paid for.
276
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
277 277
 
278 278
         if ( empty( $invoice ) ) {
279
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
-		}
279
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
+        }
281 281
 
282
-		if ( $invoice->is_paid() ) {
283
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
-		}
282
+        if ( $invoice->is_paid() ) {
283
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
+        }
285 285
 
286
-		$this->payment_form->invoice = $invoice;
287
-		if ( ! $this->payment_form->is_default() ) {
286
+        $this->payment_form->invoice = $invoice;
287
+        if ( ! $this->payment_form->is_default() ) {
288 288
 
289
-			$items    = array();
290
-			$item_ids = array();
289
+            $items    = array();
290
+            $item_ids = array();
291 291
 	
292
-			foreach ( $invoice->get_items() as $item ) {
293
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
-					$item_ids[] = $item->get_id();
295
-					$items[]    = $item;
296
-				}
297
-			}
292
+            foreach ( $invoice->get_items() as $item ) {
293
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
+                    $item_ids[] = $item->get_id();
295
+                    $items[]    = $item;
296
+                }
297
+            }
298 298
 	
299
-			foreach ( $this->payment_form->get_items() as $item ) {
300
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
-					$item_ids[] = $item->get_id();
302
-					$items[]    = $item;
303
-				}
304
-			}
299
+            foreach ( $this->payment_form->get_items() as $item ) {
300
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
+                    $item_ids[] = $item->get_id();
302
+                    $items[]    = $item;
303
+                }
304
+            }
305 305
 	
306
-			$this->payment_form->set_items( $items );
306
+            $this->payment_form->set_items( $items );
307 307
 	
308
-		} else {
309
-			$this->payment_form->set_items( $invoice->get_items() );
310
-		}
311
-
312
-		$this->country = $invoice->get_country();
313
-		$this->state   = $invoice->get_state();
314
-		$this->invoice = $invoice;
315
-
316
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
317
-	}
318
-
319
-	/**
320
-	 * Returns the associated invoice.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @return WPInv_Invoice
324
-	 */
325
-	public function get_invoice() {
326
-		return $this->invoice;
327
-	}
328
-
329
-	/**
330
-	 * Checks whether there is an invoice associated with this submission.
331
-	 *
332
-	 * @since 1.0.19
333
-	 * @return bool
334
-	 */
335
-	public function has_invoice() {
336
-		return ! empty( $this->invoice );
337
-	}
338
-
339
-	/*
308
+        } else {
309
+            $this->payment_form->set_items( $invoice->get_items() );
310
+        }
311
+
312
+        $this->country = $invoice->get_country();
313
+        $this->state   = $invoice->get_state();
314
+        $this->invoice = $invoice;
315
+
316
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
317
+    }
318
+
319
+    /**
320
+     * Returns the associated invoice.
321
+     *
322
+     * @since 1.0.19
323
+     * @return WPInv_Invoice
324
+     */
325
+    public function get_invoice() {
326
+        return $this->invoice;
327
+    }
328
+
329
+    /**
330
+     * Checks whether there is an invoice associated with this submission.
331
+     *
332
+     * @since 1.0.19
333
+     * @return bool
334
+     */
335
+    public function has_invoice() {
336
+        return ! empty( $this->invoice );
337
+    }
338
+
339
+    /*
340 340
 	|--------------------------------------------------------------------------
341 341
 	| Items.
342 342
 	|--------------------------------------------------------------------------
@@ -345,110 +345,110 @@  discard block
 block discarded – undo
345 345
 	| recurring item. But can have an unlimited number of non-recurring items.
346 346
 	*/
347 347
 
348
-	/**
349
-	 * Prepares the submission's items.
350
-	 *
351
-	 * @since 1.0.19
352
-	 */
353
-	public function process_items() {
354
-
355
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
356
-
357
-		foreach ( $processor->items as $item ) {
358
-			$this->add_item( $item );
359
-		}
360
-
361
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
362
-	}
363
-
364
-	/**
365
-	 * Adds an item to the submission.
366
-	 *
367
-	 * @since 1.0.19
368
-	 * @param GetPaid_Form_Item $item
369
-	 */
370
-	public function add_item( $item ) {
371
-
372
-		// Make sure that it is available for purchase.
373
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Each submission can only contain one recurring item.
378
-		if ( $item->is_recurring() ) {
379
-			$this->has_recurring = $item->get_id();
380
-		}
381
-
382
-		// Update the items and totals.
383
-		$this->items[ $item->get_id() ]         = $item;
384
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
385
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
386
-
387
-		$this->subscription_groups = getpaid_calculate_subscription_totals( $this );
388
-	}
389
-
390
-	/**
391
-	 * Removes a specific item.
392
-	 * 
393
-	 * You should not call this method after the discounts and taxes
394
-	 * have been calculated.
395
-	 *
396
-	 * @since 1.0.19
397
-	 */
398
-	public function remove_item( $item_id ) {
399
-
400
-		if ( isset( $this->items[ $item_id ] ) ) {
401
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
402
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
403
-
404
-			if ( $this->items[ $item_id ]->is_recurring() ) {
405
-				$this->has_recurring = 0;
406
-			}
407
-
408
-			unset( $this->items[ $item_id ] );
409
-		}
410
-
411
-	}
412
-
413
-	/**
414
-	 * Returns the subtotal.
415
-	 *
416
-	 * @since 1.0.19
417
-	 */
418
-	public function get_subtotal() {
419
-
420
-		if ( wpinv_prices_include_tax() ) {
421
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
422
-		}
423
-
424
-		return $this->totals['subtotal']['initial'];
425
-	}
426
-
427
-	/**
428
-	 * Returns the recurring subtotal.
429
-	 *
430
-	 * @since 1.0.19
431
-	 */
432
-	public function get_recurring_subtotal() {
433
-
434
-		if ( wpinv_prices_include_tax() ) {
435
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
436
-		}
437
-
438
-		return $this->totals['subtotal']['recurring'];
439
-	}
440
-
441
-	/**
442
-	 * Returns all items.
443
-	 *
444
-	 * @since 1.0.19
445
-	 * @return GetPaid_Form_Item[]
446
-	 */
447
-	public function get_items() {
448
-		return $this->items;
449
-	}
450
-
451
-	/*
348
+    /**
349
+     * Prepares the submission's items.
350
+     *
351
+     * @since 1.0.19
352
+     */
353
+    public function process_items() {
354
+
355
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
356
+
357
+        foreach ( $processor->items as $item ) {
358
+            $this->add_item( $item );
359
+        }
360
+
361
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
362
+    }
363
+
364
+    /**
365
+     * Adds an item to the submission.
366
+     *
367
+     * @since 1.0.19
368
+     * @param GetPaid_Form_Item $item
369
+     */
370
+    public function add_item( $item ) {
371
+
372
+        // Make sure that it is available for purchase.
373
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Each submission can only contain one recurring item.
378
+        if ( $item->is_recurring() ) {
379
+            $this->has_recurring = $item->get_id();
380
+        }
381
+
382
+        // Update the items and totals.
383
+        $this->items[ $item->get_id() ]         = $item;
384
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
385
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
386
+
387
+        $this->subscription_groups = getpaid_calculate_subscription_totals( $this );
388
+    }
389
+
390
+    /**
391
+     * Removes a specific item.
392
+     * 
393
+     * You should not call this method after the discounts and taxes
394
+     * have been calculated.
395
+     *
396
+     * @since 1.0.19
397
+     */
398
+    public function remove_item( $item_id ) {
399
+
400
+        if ( isset( $this->items[ $item_id ] ) ) {
401
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
402
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
403
+
404
+            if ( $this->items[ $item_id ]->is_recurring() ) {
405
+                $this->has_recurring = 0;
406
+            }
407
+
408
+            unset( $this->items[ $item_id ] );
409
+        }
410
+
411
+    }
412
+
413
+    /**
414
+     * Returns the subtotal.
415
+     *
416
+     * @since 1.0.19
417
+     */
418
+    public function get_subtotal() {
419
+
420
+        if ( wpinv_prices_include_tax() ) {
421
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
422
+        }
423
+
424
+        return $this->totals['subtotal']['initial'];
425
+    }
426
+
427
+    /**
428
+     * Returns the recurring subtotal.
429
+     *
430
+     * @since 1.0.19
431
+     */
432
+    public function get_recurring_subtotal() {
433
+
434
+        if ( wpinv_prices_include_tax() ) {
435
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
436
+        }
437
+
438
+        return $this->totals['subtotal']['recurring'];
439
+    }
440
+
441
+    /**
442
+     * Returns all items.
443
+     *
444
+     * @since 1.0.19
445
+     * @return GetPaid_Form_Item[]
446
+     */
447
+    public function get_items() {
448
+        return $this->items;
449
+    }
450
+
451
+    /*
452 452
 	|--------------------------------------------------------------------------
453 453
 	| Taxes
454 454
 	|--------------------------------------------------------------------------
@@ -457,128 +457,128 @@  discard block
 block discarded – undo
457 457
 	| or only one-time.
458 458
     */
459 459
 
460
-	/**
461
-	 * Prepares the submission's taxes.
462
-	 *
463
-	 * @since 1.0.19
464
-	 */
465
-	public function process_taxes() {
466
-
467
-		// Abort if we're not using taxes.
468
-		if ( ! $this->use_taxes() ) {
469
-			return;
470
-		}
471
-
472
-		// If a custom country && state has been passed in, use it to calculate taxes.
473
-		$country = $this->get_field( 'wpinv_country', 'billing' );
474
-		if ( ! empty( $country ) ) {
475
-			$this->country = $country;
476
-		}
477
-
478
-		$state = $this->get_field( 'wpinv_state', 'billing' );
479
-		if ( ! empty( $state ) ) {
480
-			$this->state = $state;
481
-		}
482
-
483
-		// Confirm if the provided country and the ip country are similar.
484
-		$address_confirmed = $this->get_field( 'confirm-address' );
485
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
486
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
487
-		}
488
-
489
-		// Abort if the country is not taxable.
490
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
491
-			return;
492
-		}
493
-
494
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
495
-
496
-		foreach ( $processor->taxes as $tax ) {
497
-			$this->add_tax( $tax );
498
-		}
499
-
500
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
501
-	}
502
-
503
-	/**
504
-	 * Adds a tax to the submission.
505
-	 *
506
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
507
-	 * @since 1.0.19
508
-	 */
509
-	public function add_tax( $tax ) {
510
-
511
-		if ( wpinv_round_tax_per_tax_rate() ) {
512
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
513
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
514
-		}
515
-
516
-		$this->taxes[ $tax['name'] ]         = $tax;
517
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
518
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
519
-
520
-	}
521
-
522
-	/**
523
-	 * Removes a specific tax.
524
-	 *
525
-	 * @since 1.0.19
526
-	 */
527
-	public function remove_tax( $tax_name ) {
528
-
529
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
530
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
531
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
532
-			unset( $this->taxes[ $tax_name ] );
533
-		}
534
-
535
-	}
536
-
537
-	/**
538
-	 * Whether or not we'll use taxes for the submission.
539
-	 *
540
-	 * @since 1.0.19
541
-	 */
542
-	public function use_taxes() {
543
-
544
-		$use_taxes = wpinv_use_taxes();
545
-
546
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
547
-			$use_taxes = false;
548
-		}
549
-
550
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
551
-
552
-	}
553
-
554
-	/**
555
-	 * Returns the tax.
556
-	 *
557
-	 * @since 1.0.19
558
-	 */
559
-	public function get_tax() {
560
-		return $this->totals['taxes']['initial'];
561
-	}
562
-
563
-	/**
564
-	 * Returns the recurring tax.
565
-	 *
566
-	 * @since 1.0.19
567
-	 */
568
-	public function get_recurring_tax() {
569
-		return $this->totals['taxes']['recurring'];
570
-	}
571
-
572
-	/**
573
-	 * Returns all taxes.
574
-	 *
575
-	 * @since 1.0.19
576
-	 */
577
-	public function get_taxes() {
578
-		return $this->taxes;
579
-	}
580
-
581
-	/*
460
+    /**
461
+     * Prepares the submission's taxes.
462
+     *
463
+     * @since 1.0.19
464
+     */
465
+    public function process_taxes() {
466
+
467
+        // Abort if we're not using taxes.
468
+        if ( ! $this->use_taxes() ) {
469
+            return;
470
+        }
471
+
472
+        // If a custom country && state has been passed in, use it to calculate taxes.
473
+        $country = $this->get_field( 'wpinv_country', 'billing' );
474
+        if ( ! empty( $country ) ) {
475
+            $this->country = $country;
476
+        }
477
+
478
+        $state = $this->get_field( 'wpinv_state', 'billing' );
479
+        if ( ! empty( $state ) ) {
480
+            $this->state = $state;
481
+        }
482
+
483
+        // Confirm if the provided country and the ip country are similar.
484
+        $address_confirmed = $this->get_field( 'confirm-address' );
485
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
486
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
487
+        }
488
+
489
+        // Abort if the country is not taxable.
490
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
491
+            return;
492
+        }
493
+
494
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
495
+
496
+        foreach ( $processor->taxes as $tax ) {
497
+            $this->add_tax( $tax );
498
+        }
499
+
500
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
501
+    }
502
+
503
+    /**
504
+     * Adds a tax to the submission.
505
+     *
506
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
507
+     * @since 1.0.19
508
+     */
509
+    public function add_tax( $tax ) {
510
+
511
+        if ( wpinv_round_tax_per_tax_rate() ) {
512
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
513
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
514
+        }
515
+
516
+        $this->taxes[ $tax['name'] ]         = $tax;
517
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
518
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
519
+
520
+    }
521
+
522
+    /**
523
+     * Removes a specific tax.
524
+     *
525
+     * @since 1.0.19
526
+     */
527
+    public function remove_tax( $tax_name ) {
528
+
529
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
530
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
531
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
532
+            unset( $this->taxes[ $tax_name ] );
533
+        }
534
+
535
+    }
536
+
537
+    /**
538
+     * Whether or not we'll use taxes for the submission.
539
+     *
540
+     * @since 1.0.19
541
+     */
542
+    public function use_taxes() {
543
+
544
+        $use_taxes = wpinv_use_taxes();
545
+
546
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
547
+            $use_taxes = false;
548
+        }
549
+
550
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
551
+
552
+    }
553
+
554
+    /**
555
+     * Returns the tax.
556
+     *
557
+     * @since 1.0.19
558
+     */
559
+    public function get_tax() {
560
+        return $this->totals['taxes']['initial'];
561
+    }
562
+
563
+    /**
564
+     * Returns the recurring tax.
565
+     *
566
+     * @since 1.0.19
567
+     */
568
+    public function get_recurring_tax() {
569
+        return $this->totals['taxes']['recurring'];
570
+    }
571
+
572
+    /**
573
+     * Returns all taxes.
574
+     *
575
+     * @since 1.0.19
576
+     */
577
+    public function get_taxes() {
578
+        return $this->taxes;
579
+    }
580
+
581
+    /*
582 582
 	|--------------------------------------------------------------------------
583 583
 	| Discounts
584 584
 	|--------------------------------------------------------------------------
@@ -587,99 +587,99 @@  discard block
 block discarded – undo
587 587
 	| or only one-time. They also do not have to come from a discount code.
588 588
     */
589 589
 
590
-	/**
591
-	 * Prepares the submission's discount.
592
-	 *
593
-	 * @since 1.0.19
594
-	 */
595
-	public function process_discount() {
596
-
597
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
598
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
599
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
600
-
601
-		foreach ( $processor->discounts as $discount ) {
602
-			$this->add_discount( $discount );
603
-		}
604
-
605
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
606
-	}
607
-
608
-	/**
609
-	 * Adds a discount to the submission.
610
-	 *
611
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
612
-	 * @since 1.0.19
613
-	 */
614
-	public function add_discount( $discount ) {
615
-		$this->discounts[ $discount['name'] ]   = $discount;
616
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
617
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
618
-	}
619
-
620
-	/**
621
-	 * Removes a discount from the submission.
622
-	 *
623
-	 * @since 1.0.19
624
-	 */
625
-	public function remove_discount( $name ) {
626
-
627
-		if ( isset( $this->discounts[ $name ] ) ) {
628
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
629
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
630
-			unset( $this->discounts[ $name ] );
631
-		}
632
-
633
-	}
634
-
635
-	/**
636
-	 * Checks whether there is a discount code associated with this submission.
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @return bool
640
-	 */
641
-	public function has_discount_code() {
642
-		return ! empty( $this->discounts['discount_code'] );
643
-	}
644
-
645
-	/**
646
-	 * Returns the discount code.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @return string
650
-	 */
651
-	public function get_discount_code() {
652
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
653
-	}
654
-
655
-	/**
656
-	 * Returns the discount.
657
-	 *
658
-	 * @since 1.0.19
659
-	 */
660
-	public function get_discount() {
661
-		return $this->totals['discount']['initial'];
662
-	}
663
-
664
-	/**
665
-	 * Returns the recurring discount.
666
-	 *
667
-	 * @since 1.0.19
668
-	 */
669
-	public function get_recurring_discount() {
670
-		return $this->totals['discount']['recurring'];
671
-	}
672
-
673
-	/**
674
-	 * Returns all discounts.
675
-	 *
676
-	 * @since 1.0.19
677
-	 */
678
-	public function get_discounts() {
679
-		return $this->discounts;
680
-	}
681
-
682
-	/*
590
+    /**
591
+     * Prepares the submission's discount.
592
+     *
593
+     * @since 1.0.19
594
+     */
595
+    public function process_discount() {
596
+
597
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
598
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
599
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
600
+
601
+        foreach ( $processor->discounts as $discount ) {
602
+            $this->add_discount( $discount );
603
+        }
604
+
605
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
606
+    }
607
+
608
+    /**
609
+     * Adds a discount to the submission.
610
+     *
611
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
612
+     * @since 1.0.19
613
+     */
614
+    public function add_discount( $discount ) {
615
+        $this->discounts[ $discount['name'] ]   = $discount;
616
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
617
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
618
+    }
619
+
620
+    /**
621
+     * Removes a discount from the submission.
622
+     *
623
+     * @since 1.0.19
624
+     */
625
+    public function remove_discount( $name ) {
626
+
627
+        if ( isset( $this->discounts[ $name ] ) ) {
628
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
629
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
630
+            unset( $this->discounts[ $name ] );
631
+        }
632
+
633
+    }
634
+
635
+    /**
636
+     * Checks whether there is a discount code associated with this submission.
637
+     *
638
+     * @since 1.0.19
639
+     * @return bool
640
+     */
641
+    public function has_discount_code() {
642
+        return ! empty( $this->discounts['discount_code'] );
643
+    }
644
+
645
+    /**
646
+     * Returns the discount code.
647
+     *
648
+     * @since 1.0.19
649
+     * @return string
650
+     */
651
+    public function get_discount_code() {
652
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
653
+    }
654
+
655
+    /**
656
+     * Returns the discount.
657
+     *
658
+     * @since 1.0.19
659
+     */
660
+    public function get_discount() {
661
+        return $this->totals['discount']['initial'];
662
+    }
663
+
664
+    /**
665
+     * Returns the recurring discount.
666
+     *
667
+     * @since 1.0.19
668
+     */
669
+    public function get_recurring_discount() {
670
+        return $this->totals['discount']['recurring'];
671
+    }
672
+
673
+    /**
674
+     * Returns all discounts.
675
+     *
676
+     * @since 1.0.19
677
+     */
678
+    public function get_discounts() {
679
+        return $this->discounts;
680
+    }
681
+
682
+    /*
683 683
 	|--------------------------------------------------------------------------
684 684
 	| Fees
685 685
 	|--------------------------------------------------------------------------
@@ -689,89 +689,89 @@  discard block
 block discarded – undo
689 689
 	| fees.
690 690
     */
691 691
 
692
-	/**
693
-	 * Prepares the submission's fees.
694
-	 *
695
-	 * @since 1.0.19
696
-	 */
697
-	public function process_fees() {
698
-
699
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
700
-
701
-		foreach ( $fees_processor->fees as $fee ) {
702
-			$this->add_fee( $fee );
703
-		}
704
-
705
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
706
-	}
707
-
708
-	/**
709
-	 * Adds a fee to the submission.
710
-	 *
711
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
712
-	 * @since 1.0.19
713
-	 */
714
-	public function add_fee( $fee ) {
715
-
716
-		$this->fees[ $fee['name'] ]         = $fee;
717
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
718
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
719
-
720
-	}
721
-
722
-	/**
723
-	 * Removes a fee from the submission.
724
-	 *
725
-	 * @since 1.0.19
726
-	 */
727
-	public function remove_fee( $name ) {
728
-
729
-		if ( isset( $this->fees[ $name ] ) ) {
730
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
731
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
732
-			unset( $this->fees[ $name ] );
733
-		}
734
-
735
-	}
736
-
737
-	/**
738
-	 * Returns the fees.
739
-	 *
740
-	 * @since 1.0.19
741
-	 */
742
-	public function get_fee() {
743
-		return $this->totals['fees']['initial'];
744
-	}
745
-
746
-	/**
747
-	 * Returns the recurring fees.
748
-	 *
749
-	 * @since 1.0.19
750
-	 */
751
-	public function get_recurring_fee() {
752
-		return $this->totals['fees']['recurring'];
753
-	}
754
-
755
-	/**
756
-	 * Returns all fees.
757
-	 *
758
-	 * @since 1.0.19
759
-	 */
760
-	public function get_fees() {
761
-		return $this->fees;
762
-	}
763
-
764
-	/**
765
-	 * Checks if there are any fees for the form.
766
-	 *
767
-	 * @return bool
768
-	 * @since 1.0.19
769
-	 */
770
-	public function has_fees() {
771
-		return count( $this->fees ) !== 0;
772
-	}
773
-
774
-	/*
692
+    /**
693
+     * Prepares the submission's fees.
694
+     *
695
+     * @since 1.0.19
696
+     */
697
+    public function process_fees() {
698
+
699
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
700
+
701
+        foreach ( $fees_processor->fees as $fee ) {
702
+            $this->add_fee( $fee );
703
+        }
704
+
705
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
706
+    }
707
+
708
+    /**
709
+     * Adds a fee to the submission.
710
+     *
711
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
712
+     * @since 1.0.19
713
+     */
714
+    public function add_fee( $fee ) {
715
+
716
+        $this->fees[ $fee['name'] ]         = $fee;
717
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
718
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
719
+
720
+    }
721
+
722
+    /**
723
+     * Removes a fee from the submission.
724
+     *
725
+     * @since 1.0.19
726
+     */
727
+    public function remove_fee( $name ) {
728
+
729
+        if ( isset( $this->fees[ $name ] ) ) {
730
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
731
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
732
+            unset( $this->fees[ $name ] );
733
+        }
734
+
735
+    }
736
+
737
+    /**
738
+     * Returns the fees.
739
+     *
740
+     * @since 1.0.19
741
+     */
742
+    public function get_fee() {
743
+        return $this->totals['fees']['initial'];
744
+    }
745
+
746
+    /**
747
+     * Returns the recurring fees.
748
+     *
749
+     * @since 1.0.19
750
+     */
751
+    public function get_recurring_fee() {
752
+        return $this->totals['fees']['recurring'];
753
+    }
754
+
755
+    /**
756
+     * Returns all fees.
757
+     *
758
+     * @since 1.0.19
759
+     */
760
+    public function get_fees() {
761
+        return $this->fees;
762
+    }
763
+
764
+    /**
765
+     * Checks if there are any fees for the form.
766
+     *
767
+     * @return bool
768
+     * @since 1.0.19
769
+     */
770
+    public function has_fees() {
771
+        return count( $this->fees ) !== 0;
772
+    }
773
+
774
+    /*
775 775
 	|--------------------------------------------------------------------------
776 776
 	| MISC
777 777
 	|--------------------------------------------------------------------------
@@ -779,119 +779,119 @@  discard block
 block discarded – undo
779 779
 	| Extra submission functions.
780 780
     */
781 781
 
782
-	/**
783
-	 * Checks if this is the initial fetch.
784
-	 *
785
-	 * @return bool
786
-	 * @since 1.0.19
787
-	 */
788
-	public function is_initial_fetch() {
789
-		return empty( $this->data['initial_state'] );
790
-	}
791
-
792
-	/**
793
-	 * Returns the total amount to collect for this submission.
794
-	 *
795
-	 * @since 1.0.19
796
-	 */
797
-	public function get_total() {
798
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
799
-		return max( $total, 0 );
800
-	}
801
-
802
-	/**
803
-	 * Returns the recurring total amount to collect for this submission.
804
-	 *
805
-	 * @since 1.0.19
806
-	 */
807
-	public function get_recurring_total() {
808
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
809
-		return max( $total, 0 );
810
-	}
811
-
812
-	/**
813
-	 * Whether payment details should be collected for this submission.
814
-	 *
815
-	 * @since 1.0.19
816
-	 */
817
-	public function should_collect_payment_details() {
818
-		$initial   = $this->get_total();
819
-		$recurring = $this->get_recurring_total();
820
-
821
-		if ( $this->has_recurring == 0 ) {
822
-			$recurring = 0;
823
-		}
824
-
825
-		$collect = $initial > 0 || $recurring > 0;
826
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
827
-	}
828
-
829
-	/**
830
-	 * Returns the billing email of the user.
831
-	 *
832
-	 * @since 1.0.19
833
-	 */
834
-	public function get_billing_email() {
835
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
836
-	}
837
-
838
-	/**
839
-	 * Checks if the submitter has a billing email.
840
-	 *
841
-	 * @since 1.0.19
842
-	 */
843
-	public function has_billing_email() {
844
-		$billing_email = $this->get_billing_email();
845
-		return ! empty( $billing_email ) && is_email( $billing_email );
846
-	}
847
-
848
-	/**
849
-	 * Returns the appropriate currency for the submission.
850
-	 *
851
-	 * @since 1.0.19
852
-	 * @return string
853
-	 */
854
-	public function get_currency() {
855
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
856
-    }
857
-
858
-    /**
859
-	 * Returns the raw submission data.
860
-	 *
861
-	 * @since 1.0.19
862
-	 * @return array
863
-	 */
864
-	public function get_data() {
865
-		return $this->data;
866
-	}
867
-
868
-	/**
869
-	 * Returns a field from the submission data
870
-	 *
871
-	 * @param string $field
872
-	 * @since 1.0.19
873
-	 * @return mixed|null
874
-	 */
875
-	public function get_field( $field, $sub_array_key = null ) {
876
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
877
-	}
878
-
879
-	/**
880
-	 * Checks if a required field is set.
881
-	 *
882
-	 * @since 1.0.19
883
-	 */
884
-	public function is_required_field_set( $field ) {
885
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
886
-	}
887
-
888
-	/**
889
-	 * Formats an amount
890
-	 *
891
-	 * @since 1.0.19
892
-	 */
893
-	public function format_amount( $amount ) {
894
-		return wpinv_price( $amount, $this->get_currency() );
895
-	}
782
+    /**
783
+     * Checks if this is the initial fetch.
784
+     *
785
+     * @return bool
786
+     * @since 1.0.19
787
+     */
788
+    public function is_initial_fetch() {
789
+        return empty( $this->data['initial_state'] );
790
+    }
791
+
792
+    /**
793
+     * Returns the total amount to collect for this submission.
794
+     *
795
+     * @since 1.0.19
796
+     */
797
+    public function get_total() {
798
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
799
+        return max( $total, 0 );
800
+    }
801
+
802
+    /**
803
+     * Returns the recurring total amount to collect for this submission.
804
+     *
805
+     * @since 1.0.19
806
+     */
807
+    public function get_recurring_total() {
808
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
809
+        return max( $total, 0 );
810
+    }
811
+
812
+    /**
813
+     * Whether payment details should be collected for this submission.
814
+     *
815
+     * @since 1.0.19
816
+     */
817
+    public function should_collect_payment_details() {
818
+        $initial   = $this->get_total();
819
+        $recurring = $this->get_recurring_total();
820
+
821
+        if ( $this->has_recurring == 0 ) {
822
+            $recurring = 0;
823
+        }
824
+
825
+        $collect = $initial > 0 || $recurring > 0;
826
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
827
+    }
828
+
829
+    /**
830
+     * Returns the billing email of the user.
831
+     *
832
+     * @since 1.0.19
833
+     */
834
+    public function get_billing_email() {
835
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
836
+    }
837
+
838
+    /**
839
+     * Checks if the submitter has a billing email.
840
+     *
841
+     * @since 1.0.19
842
+     */
843
+    public function has_billing_email() {
844
+        $billing_email = $this->get_billing_email();
845
+        return ! empty( $billing_email ) && is_email( $billing_email );
846
+    }
847
+
848
+    /**
849
+     * Returns the appropriate currency for the submission.
850
+     *
851
+     * @since 1.0.19
852
+     * @return string
853
+     */
854
+    public function get_currency() {
855
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
856
+    }
857
+
858
+    /**
859
+     * Returns the raw submission data.
860
+     *
861
+     * @since 1.0.19
862
+     * @return array
863
+     */
864
+    public function get_data() {
865
+        return $this->data;
866
+    }
867
+
868
+    /**
869
+     * Returns a field from the submission data
870
+     *
871
+     * @param string $field
872
+     * @since 1.0.19
873
+     * @return mixed|null
874
+     */
875
+    public function get_field( $field, $sub_array_key = null ) {
876
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
877
+    }
878
+
879
+    /**
880
+     * Checks if a required field is set.
881
+     *
882
+     * @since 1.0.19
883
+     */
884
+    public function is_required_field_set( $field ) {
885
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
886
+    }
887
+
888
+    /**
889
+     * Formats an amount
890
+     *
891
+     * @since 1.0.19
892
+     */
893
+    public function format_amount( $amount ) {
894
+        return wpinv_price( $amount, $this->get_currency() );
895
+    }
896 896
 
897 897
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -12,281 +12,281 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'              => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'              => $submission->id,
30 30
             'has_recurring'              => $submission->has_recurring,
31
-			'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ),
31
+            'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ),
32 32
             'is_free'                    => ! $submission->should_collect_payment_details(),
33
-		);
34
-
35
-		$this->add_totals( $submission );
36
-		$this->add_texts( $submission );
37
-		$this->add_items( $submission );
38
-		$this->add_fees( $submission );
39
-		$this->add_discounts( $submission );
40
-		$this->add_taxes( $submission );
41
-		$this->add_gateways( $submission );
42
-		$this->add_data( $submission );
43
-
44
-	}
45
-
46
-	/**
47
-	 * Adds totals to a response for submission refresh prices.
48
-	 *
49
-	 * @param GetPaid_Payment_Form_Submission $submission
50
-	 */
51
-	public function add_totals( $submission ) {
52
-
53
-		$this->response = array_merge(
54
-			$this->response,
55
-			array(
56
-
57
-				'totals'        => array(
58
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
59
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
60
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
61
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
62
-					'total'     => $submission->format_amount( $submission->get_total() ),
63
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
64
-				),
65
-
66
-				'recurring'     => array(
67
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
68
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
69
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
70
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
71
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
72
-				),
73
-
74
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
75
-				'currency'      => $submission->get_currency(),
76
-
77
-			)
78
-		);
79
-
80
-	}
81
-
82
-	/**
83
-	 * Adds texts to a response for submission refresh prices.
84
-	 *
85
-	 * @param GetPaid_Payment_Form_Submission $submission
86
-	 */
87
-	public function add_texts( $submission ) {
88
-
89
-		$payable = $submission->format_amount( $submission->get_total() );
90
-		$groups  = getpaid_get_subscription_groups( $submission );
91
-
92
-		if ( $submission->has_recurring != 0 && 2 > $groups ) {
93
-
94
-			$recurring = new WPInv_Item( $submission->has_recurring );
95
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
96
-
97
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
98
-				$payable = "$payable / $period";
99
-			} else {
100
-				$payable = sprintf(
101
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
102
-					$submission->format_amount( $submission->get_total() ),
103
-					$submission->format_amount( $submission->get_recurring_total() ),
104
-					$period
105
-				);
106
-			}
107
-
108
-		}
109
-
110
-		$texts = array(
111
-			'.getpaid-checkout-total-payable' => $payable,
112
-		);
113
-
114
-		foreach ( $submission->get_items() as $item ) {
115
-			$item_id                                               = $item->get_id();
116
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
117
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
118
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
119
-		}
120
-
121
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
122
-
123
-	}
124
-
125
-	/**
126
-	 * Adds items to a response for submission refresh prices.
127
-	 *
128
-	 * @param GetPaid_Payment_Form_Submission $submission
129
-	 */
130
-	public function add_items( $submission ) {
131
-
132
-		// Add items.
133
-		$items = array();
33
+        );
34
+
35
+        $this->add_totals( $submission );
36
+        $this->add_texts( $submission );
37
+        $this->add_items( $submission );
38
+        $this->add_fees( $submission );
39
+        $this->add_discounts( $submission );
40
+        $this->add_taxes( $submission );
41
+        $this->add_gateways( $submission );
42
+        $this->add_data( $submission );
43
+
44
+    }
45
+
46
+    /**
47
+     * Adds totals to a response for submission refresh prices.
48
+     *
49
+     * @param GetPaid_Payment_Form_Submission $submission
50
+     */
51
+    public function add_totals( $submission ) {
52
+
53
+        $this->response = array_merge(
54
+            $this->response,
55
+            array(
56
+
57
+                'totals'        => array(
58
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
59
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
60
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
61
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
62
+                    'total'     => $submission->format_amount( $submission->get_total() ),
63
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
64
+                ),
65
+
66
+                'recurring'     => array(
67
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
68
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
69
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
70
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
71
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
72
+                ),
73
+
74
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
75
+                'currency'      => $submission->get_currency(),
76
+
77
+            )
78
+        );
79
+
80
+    }
81
+
82
+    /**
83
+     * Adds texts to a response for submission refresh prices.
84
+     *
85
+     * @param GetPaid_Payment_Form_Submission $submission
86
+     */
87
+    public function add_texts( $submission ) {
88
+
89
+        $payable = $submission->format_amount( $submission->get_total() );
90
+        $groups  = getpaid_get_subscription_groups( $submission );
91
+
92
+        if ( $submission->has_recurring != 0 && 2 > $groups ) {
93
+
94
+            $recurring = new WPInv_Item( $submission->has_recurring );
95
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
96
+
97
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
98
+                $payable = "$payable / $period";
99
+            } else {
100
+                $payable = sprintf(
101
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
102
+                    $submission->format_amount( $submission->get_total() ),
103
+                    $submission->format_amount( $submission->get_recurring_total() ),
104
+                    $period
105
+                );
106
+            }
107
+
108
+        }
109
+
110
+        $texts = array(
111
+            '.getpaid-checkout-total-payable' => $payable,
112
+        );
134 113
 
135 114
         foreach ( $submission->get_items() as $item ) {
136
-			$item_id           = $item->get_id();
137
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
138
-		}
115
+            $item_id                                               = $item->get_id();
116
+            $initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
117
+            $recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
118
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
119
+        }
139 120
 
140
-		$this->response = array_merge(
141
-			$this->response,
142
-			array( 'items' => $items )
143
-		);
121
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
144 122
 
145
-	}
123
+    }
146 124
 
147
-	/**
148
-	 * Adds fees to a response for submission refresh prices.
149
-	 *
150
-	 * @param GetPaid_Payment_Form_Submission $submission
151
-	 */
152
-	public function add_fees( $submission ) {
125
+    /**
126
+     * Adds items to a response for submission refresh prices.
127
+     *
128
+     * @param GetPaid_Payment_Form_Submission $submission
129
+     */
130
+    public function add_items( $submission ) {
153 131
 
154
-		$fees = array();
132
+        // Add items.
133
+        $items = array();
155 134
 
156
-        foreach ( $submission->get_fees() as $name => $data ) {
157
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
158
-		}
135
+        foreach ( $submission->get_items() as $item ) {
136
+            $item_id           = $item->get_id();
137
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
138
+        }
159 139
 
160
-		$this->response = array_merge(
161
-			$this->response,
162
-			array( 'fees' => $fees )
163
-		);
140
+        $this->response = array_merge(
141
+            $this->response,
142
+            array( 'items' => $items )
143
+        );
164 144
 
165
-	}
145
+    }
166 146
 
167
-	/**
168
-	 * Adds discounts to a response for submission refresh prices.
169
-	 *
170
-	 * @param GetPaid_Payment_Form_Submission $submission
171
-	 */
172
-	public function add_discounts( $submission ) {
147
+    /**
148
+     * Adds fees to a response for submission refresh prices.
149
+     *
150
+     * @param GetPaid_Payment_Form_Submission $submission
151
+     */
152
+    public function add_fees( $submission ) {
173 153
 
174
-		$discounts = array();
154
+        $fees = array();
175 155
 
176
-        foreach ( $submission->get_discounts() as $name => $data ) {
177
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
178
-		}
156
+        foreach ( $submission->get_fees() as $name => $data ) {
157
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
158
+        }
179 159
 
180
-		$this->response = array_merge(
181
-			$this->response,
182
-			array( 'discounts' => $discounts )
183
-		);
160
+        $this->response = array_merge(
161
+            $this->response,
162
+            array( 'fees' => $fees )
163
+        );
184 164
 
185
-	}
165
+    }
186 166
 
187
-	/**
188
-	 * Adds taxes to a response for submission refresh prices.
189
-	 *
190
-	 * @param GetPaid_Payment_Form_Submission $submission
191
-	 */
192
-	public function add_taxes( $submission ) {
167
+    /**
168
+     * Adds discounts to a response for submission refresh prices.
169
+     *
170
+     * @param GetPaid_Payment_Form_Submission $submission
171
+     */
172
+    public function add_discounts( $submission ) {
193 173
 
194
-		$taxes  = array();
195
-		$markup = '';
196
-        foreach ( $submission->get_taxes() as $name => $data ) {
197
-			$name          = sanitize_text_field( $name );
198
-			$amount        = $submission->format_amount( $data['initial_tax'] );
199
-			$taxes[$name]  = $amount;
200
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
201
-		}
174
+        $discounts = array();
175
+
176
+        foreach ( $submission->get_discounts() as $name => $data ) {
177
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
178
+        }
202 179
 
203
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
204
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
205
-		}
180
+        $this->response = array_merge(
181
+            $this->response,
182
+            array( 'discounts' => $discounts )
183
+        );
206 184
 
207
-		$this->response = array_merge(
208
-			$this->response,
209
-			array( 'taxes' => $taxes )
210
-		);
185
+    }
211 186
 
212
-	}
187
+    /**
188
+     * Adds taxes to a response for submission refresh prices.
189
+     *
190
+     * @param GetPaid_Payment_Form_Submission $submission
191
+     */
192
+    public function add_taxes( $submission ) {
193
+
194
+        $taxes  = array();
195
+        $markup = '';
196
+        foreach ( $submission->get_taxes() as $name => $data ) {
197
+            $name          = sanitize_text_field( $name );
198
+            $amount        = $submission->format_amount( $data['initial_tax'] );
199
+            $taxes[$name]  = $amount;
200
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
201
+        }
213 202
 
214
-	/**
215
-	 * Adds gateways to a response for submission refresh prices.
216
-	 *
217
-	 * @param GetPaid_Payment_Form_Submission $submission
218
-	 */
219
-	public function add_gateways( $submission ) {
203
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
204
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
205
+        }
220 206
 
221
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
207
+        $this->response = array_merge(
208
+            $this->response,
209
+            array( 'taxes' => $taxes )
210
+        );
222 211
 
223
-		if ( $this->response['has_recurring'] ) {
212
+    }
224 213
 
225
-			foreach ( $gateways as $i => $gateway ) {
214
+    /**
215
+     * Adds gateways to a response for submission refresh prices.
216
+     *
217
+     * @param GetPaid_Payment_Form_Submission $submission
218
+     */
219
+    public function add_gateways( $submission ) {
226 220
 
227
-				if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) {
228
-					unset( $gateways[ $i ] );
229
-				}
221
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
230 222
 
231
-			}
223
+        if ( $this->response['has_recurring'] ) {
232 224
 
233
-		}
225
+            foreach ( $gateways as $i => $gateway ) {
234 226
 
235
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
236
-		$this->response = array_merge(
237
-			$this->response,
238
-			array( 'gateways' => $gateways )
239
-		);
227
+                if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) {
228
+                    unset( $gateways[ $i ] );
229
+                }
240 230
 
241
-	}
231
+            }
242 232
 
243
-	/**
244
-	 * Standardizes prices.
245
-	 *
246
-	 * @param int $item_id
247
-	 * @param float $item_total
248
-	 * @param string $discount_code
249
-	 * @param bool $recurring
250
-	 */
251
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
233
+        }
252 234
 
253
-		$standardadized_price = $item_total;
235
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
236
+        $this->response = array_merge(
237
+            $this->response,
238
+            array( 'gateways' => $gateways )
239
+        );
254 240
 
255
-		// Do we have a $discount_code?
256
-		if ( ! empty( $discount_code ) ) {
241
+    }
257 242
 
258
-			$discount = new WPInv_Discount( $discount_code );
243
+    /**
244
+     * Standardizes prices.
245
+     *
246
+     * @param int $item_id
247
+     * @param float $item_total
248
+     * @param string $discount_code
249
+     * @param bool $recurring
250
+     */
251
+    public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
252
+
253
+        $standardadized_price = $item_total;
259 254
 
260
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
261
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
262
-			}
255
+        // Do we have a $discount_code?
256
+        if ( ! empty( $discount_code ) ) {
263 257
 
264
-		}
258
+            $discount = new WPInv_Discount( $discount_code );
265 259
 
266
-    	return max( 0, $standardadized_price );
260
+            if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
261
+                $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
262
+            }
267 263
 
268
-	}
264
+        }
269 265
 
270
-	/**
271
-	 * Adds data to a response for submission refresh prices.
272
-	 *
273
-	 * @param GetPaid_Payment_Form_Submission $submission
274
-	 */
275
-	public function add_data( $submission ) {
266
+        return max( 0, $standardadized_price );
276 267
 
277
-		$this->response = array_merge(
278
-			$this->response,
279
-			array(
280
-				'js_data' => apply_filters(
281
-					'getpaid_submission_js_data',
282
-					array(
283
-						'is_recurring' => $this->response['has_recurring'],
284
-					),
285
-					$submission
286
-				)
287
-			)
288
-		);
268
+    }
289 269
 
290
-	}
270
+    /**
271
+     * Adds data to a response for submission refresh prices.
272
+     *
273
+     * @param GetPaid_Payment_Form_Submission $submission
274
+     */
275
+    public function add_data( $submission ) {
276
+
277
+        $this->response = array_merge(
278
+            $this->response,
279
+            array(
280
+                'js_data' => apply_filters(
281
+                    'getpaid_submission_js_data',
282
+                    array(
283
+                        'is_recurring' => $this->response['has_recurring'],
284
+                    ),
285
+                    $submission
286
+                )
287
+            )
288
+        );
289
+
290
+    }
291 291
 
292 292
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
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', 'multiple_subscriptions' );
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        = __( 'Test Gateway', '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.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +601 added lines, -601 removed lines patch added patch discarded remove patch
@@ -13,461 +13,461 @@  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
-		// Add support for various features.
147
-		foreach ( $this->supports as $feature ) {
148
-			add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
149
-		}
150
-
151
-		// Invoice addons.
152
-		if ( $this->supports( 'addons' ) ) {
153
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
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
+        // Add support for various features.
147
+        foreach ( $this->supports as $feature ) {
148
+            add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
149
+        }
150
+
151
+        // Invoice addons.
152
+        if ( $this->supports( 'addons' ) ) {
153
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
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_remote_subscription_profile_url', array( $this, 'generate_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
+     * Processes invoice addons.
314
+     *
315
+     * @param WPInv_Invoice $invoice
316
+     * @param GetPaid_Form_Item[] $items
317
+     * @return WPInv_Invoice
318
+     */
319
+    public function process_addons( $invoice, $items ) {
320
+
321
+    }
322
+
323
+    /**
324
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
325
+     *
326
+     * @param string $transaction_url transaction url.
327
+     * @param WPInv_Invoice $invoice Invoice object.
328
+     * @return string transaction URL, or empty string.
329
+     */
330
+    public function filter_transaction_url( $transaction_url, $invoice ) {
331
+
332
+        $transaction_id  = $invoice->get_transaction_id();
333
+
334
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
335
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
336
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
337
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
338
+        }
339
+
340
+        return $transaction_url;
341
+    }
342
+
343
+    /**
344
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
345
+     *
346
+     * @param string $subscription_url transaction url.
347
+     * @param WPInv_Subscription $subscription Subscription objectt.
348
+     * @return string subscription URL, or empty string.
349
+     */
350
+    public function generate_subscription_url( $subscription_url, $subscription ) {
351
+
352
+        $profile_id      = $subscription->get_profile_id();
165 353
 
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_remote_subscription_profile_url', array( $this, 'generate_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
-	 * Processes invoice addons.
314
-	 *
315
-	 * @param WPInv_Invoice $invoice
316
-	 * @param GetPaid_Form_Item[] $items
317
-	 * @return WPInv_Invoice
318
-	 */
319
-	public function process_addons( $invoice, $items ) {
320
-
321
-	}
322
-
323
-	/**
324
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
325
-	 *
326
-	 * @param string $transaction_url transaction url.
327
-	 * @param WPInv_Invoice $invoice Invoice object.
328
-	 * @return string transaction URL, or empty string.
329
-	 */
330
-	public function filter_transaction_url( $transaction_url, $invoice ) {
331
-
332
-		$transaction_id  = $invoice->get_transaction_id();
333
-
334
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
335
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
336
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
337
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
338
-		}
339
-
340
-		return $transaction_url;
341
-	}
342
-
343
-	/**
344
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
345
-	 *
346
-	 * @param string $subscription_url transaction url.
347
-	 * @param WPInv_Subscription $subscription Subscription objectt.
348
-	 * @return string subscription URL, or empty string.
349
-	 */
350
-	public function generate_subscription_url( $subscription_url, $subscription ) {
351
-
352
-		$profile_id      = $subscription->get_profile_id();
353
-
354
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
355
-
356
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
357
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
358
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
359
-
360
-		}
361
-
362
-		return $subscription_url;
363
-	}
364
-
365
-	/**
366
-	 * Check if the gateway is available for use.
367
-	 *
368
-	 * @return bool
369
-	 */
370
-	public function is_available() {
371
-		return ! empty( $this->enabled );
372
-	}
373
-
374
-	/**
375
-	 * Return the gateway's title.
376
-	 *
377
-	 * @return string
378
-	 */
379
-	public function get_title() {
380
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
381
-	}
382
-
383
-	/**
384
-	 * Return the gateway's description.
385
-	 *
386
-	 * @return string
387
-	 */
388
-	public function get_description() {
389
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
390
-	}
391
-
392
-	/**
393
-	 * Process Payment.
394
-	 *
395
-	 *
396
-	 * @param WPInv_Invoice $invoice Invoice.
397
-	 * @param array $submission_data Posted checkout fields.
398
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
399
-	 * @return void
400
-	 */
401
-	public function process_payment( $invoice, $submission_data, $submission ) {
402
-		// Process the payment then either redirect to the success page or the gateway.
403
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
404
-	}
405
-
406
-	/**
407
-	 * Process refund.
408
-	 *
409
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
410
-	 * a passed in amount.
411
-	 *
412
-	 * @param WPInv_Invoice $invoice Invoice.
413
-	 * @param  float  $amount Refund amount.
414
-	 * @param  string $reason Refund reason.
415
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
416
-	 */
417
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
418
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
419
-	}
420
-
421
-	/**
422
-	 * Displays the payment fields, credit cards etc.
423
-	 * 
424
-	 * @param int $invoice_id 0 or invoice id.
425
-	 * @param GetPaid_Payment_Form $form Current payment form.
426
-	 */
427
-	public function payment_fields( $invoice_id, $form ) {
428
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
429
-	}
430
-
431
-	/**
432
-	 * Filters the gateway settings.
433
-	 * 
434
-	 * @param array $admin_settings
435
-	 */
436
-	public function admin_settings( $admin_settings ) {
437
-		return $admin_settings;
438
-	}
439
-
440
-	/**
441
-	 * Retrieves the value of a gateway setting.
442
-	 * 
443
-	 * @param string $option
444
-	 */
445
-	public function get_option( $option, $default = false ) {
446
-		return wpinv_get_option( $this->id . '_' . $option, $default );
447
-	}
448
-
449
-	/**
450
-	 * Check if a gateway supports a given feature.
451
-	 *
452
-	 * Gateways should override this to declare support (or lack of support) for a feature.
453
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
454
-	 *
455
-	 * @param string $feature string The name of a feature to test support for.
456
-	 * @return bool True if the gateway supports the feature, false otherwise.
457
-	 * @since 1.0.19
458
-	 */
459
-	public function supports( $feature ) {
460
-		return getpaid_payment_gateway_supports( $this->id, $feature );
461
-	}
462
-
463
-	/**
464
-	 * Returns the credit card form html.
465
-	 * 
466
-	 * @param bool $save whether or not to display the save button.
467
-	 */
354
+        if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
355
+
356
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
357
+            $replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
358
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
359
+
360
+        }
361
+
362
+        return $subscription_url;
363
+    }
364
+
365
+    /**
366
+     * Check if the gateway is available for use.
367
+     *
368
+     * @return bool
369
+     */
370
+    public function is_available() {
371
+        return ! empty( $this->enabled );
372
+    }
373
+
374
+    /**
375
+     * Return the gateway's title.
376
+     *
377
+     * @return string
378
+     */
379
+    public function get_title() {
380
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
381
+    }
382
+
383
+    /**
384
+     * Return the gateway's description.
385
+     *
386
+     * @return string
387
+     */
388
+    public function get_description() {
389
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
390
+    }
391
+
392
+    /**
393
+     * Process Payment.
394
+     *
395
+     *
396
+     * @param WPInv_Invoice $invoice Invoice.
397
+     * @param array $submission_data Posted checkout fields.
398
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
399
+     * @return void
400
+     */
401
+    public function process_payment( $invoice, $submission_data, $submission ) {
402
+        // Process the payment then either redirect to the success page or the gateway.
403
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
404
+    }
405
+
406
+    /**
407
+     * Process refund.
408
+     *
409
+     * If the gateway declares 'refunds' support, this will allow it to refund.
410
+     * a passed in amount.
411
+     *
412
+     * @param WPInv_Invoice $invoice Invoice.
413
+     * @param  float  $amount Refund amount.
414
+     * @param  string $reason Refund reason.
415
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
416
+     */
417
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
418
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
419
+    }
420
+
421
+    /**
422
+     * Displays the payment fields, credit cards etc.
423
+     * 
424
+     * @param int $invoice_id 0 or invoice id.
425
+     * @param GetPaid_Payment_Form $form Current payment form.
426
+     */
427
+    public function payment_fields( $invoice_id, $form ) {
428
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
429
+    }
430
+
431
+    /**
432
+     * Filters the gateway settings.
433
+     * 
434
+     * @param array $admin_settings
435
+     */
436
+    public function admin_settings( $admin_settings ) {
437
+        return $admin_settings;
438
+    }
439
+
440
+    /**
441
+     * Retrieves the value of a gateway setting.
442
+     * 
443
+     * @param string $option
444
+     */
445
+    public function get_option( $option, $default = false ) {
446
+        return wpinv_get_option( $this->id . '_' . $option, $default );
447
+    }
448
+
449
+    /**
450
+     * Check if a gateway supports a given feature.
451
+     *
452
+     * Gateways should override this to declare support (or lack of support) for a feature.
453
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
454
+     *
455
+     * @param string $feature string The name of a feature to test support for.
456
+     * @return bool True if the gateway supports the feature, false otherwise.
457
+     * @since 1.0.19
458
+     */
459
+    public function supports( $feature ) {
460
+        return getpaid_payment_gateway_supports( $this->id, $feature );
461
+    }
462
+
463
+    /**
464
+     * Returns the credit card form html.
465
+     * 
466
+     * @param bool $save whether or not to display the save button.
467
+     */
468 468
     public function get_cc_form( $save = false ) {
469 469
 
470
-		ob_start();
470
+        ob_start();
471 471
 
472 472
         $id_prefix = esc_attr( uniqid( $this->id ) );
473 473
 
@@ -562,11 +562,11 @@  discard block
 block discarded – undo
562 562
                                         'name'              => $this->id . '[cc_cvv2]',
563 563
                                         'id'                => "$id_prefix-cc-cvv2",
564 564
                                         'label'             => __( 'CCV', 'invoicing' ),
565
-										'label_type'        => 'vertical',
566
-										'class'             => 'form-control-sm',
567
-										'extra_attributes'  => array(
568
-											'autocomplete'  => "cc-csc",
569
-										),
565
+                                        'label_type'        => 'vertical',
566
+                                        'class'             => 'form-control-sm',
567
+                                        'extra_attributes'  => array(
568
+                                            'autocomplete'  => "cc-csc",
569
+                                        ),
570 570
                                     )
571 571
                                 );
572 572
                             ?>
@@ -576,191 +576,191 @@  discard block
 block discarded – undo
576 576
 					
577 577
 					<?php
578 578
 
579
-						if ( $save ) {
580
-							echo $this->save_payment_method_checkbox();
581
-						}
579
+                        if ( $save ) {
580
+                            echo $this->save_payment_method_checkbox();
581
+                        }
582 582
 
583
-					?>
583
+                    ?>
584 584
                 </div>
585 585
 
586 586
             </div>
587 587
 		<?php
588 588
 		
589
-		return ob_get_clean();
589
+        return ob_get_clean();
590
+
591
+    }
592
+
593
+    /**
594
+     * Displays a new payment method entry form.
595
+     *
596
+     * @since 1.0.19
597
+     */
598
+    public function new_payment_method_entry( $form ) {
599
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
600
+    }
601
+
602
+    /**
603
+     * Grab and display our saved payment methods.
604
+     *
605
+     * @since 1.0.19
606
+     */
607
+    public function saved_payment_methods() {
608
+        $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
609
+
610
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
611
+            $html .= $this->get_saved_payment_method_option_html( $token );
612
+        }
590 613
 
614
+        $html .= $this->get_new_payment_method_option_html();
615
+        $html .= '</ul>';
616
+
617
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
591 618
     }
592 619
 
593
-	/**
594
-	 * Displays a new payment method entry form.
595
-	 *
596
-	 * @since 1.0.19
597
-	 */
598
-	public function new_payment_method_entry( $form ) {
599
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
600
-	}
601
-
602
-	/**
603
-	 * Grab and display our saved payment methods.
604
-	 *
605
-	 * @since 1.0.19
606
-	 */
607
-	public function saved_payment_methods() {
608
-		$html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
609
-
610
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
611
-			$html .= $this->get_saved_payment_method_option_html( $token );
612
-		}
613
-
614
-		$html .= $this->get_new_payment_method_option_html();
615
-		$html .= '</ul>';
616
-
617
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
618
-	}
619
-
620
-	/**
621
-	 * Gets saved payment method HTML from a token.
622
-	 *
623
-	 * @since 1.0.19
624
-	 * @param  array $token Payment Token.
625
-	 * @return string Generated payment method HTML
626
-	 */
627
-	public function get_saved_payment_method_option_html( $token ) {
628
-
629
-		return sprintf(
630
-			'<li class="getpaid-payment-method form-group">
620
+    /**
621
+     * Gets saved payment method HTML from a token.
622
+     *
623
+     * @since 1.0.19
624
+     * @param  array $token Payment Token.
625
+     * @return string Generated payment method HTML
626
+     */
627
+    public function get_saved_payment_method_option_html( $token ) {
628
+
629
+        return sprintf(
630
+            '<li class="getpaid-payment-method form-group">
631 631
 				<label>
632 632
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
633 633
 					<span>%3$s</span>
634 634
 				</label>
635 635
 			</li>',
636
-			esc_attr( $this->id ),
637
-			esc_attr( $token['id'] ),
638
-			esc_html( $token['name'] ),
639
-			checked( empty( $token['default'] ), false, false )
640
-		);
636
+            esc_attr( $this->id ),
637
+            esc_attr( $token['id'] ),
638
+            esc_html( $token['name'] ),
639
+            checked( empty( $token['default'] ), false, false )
640
+        );
641 641
 
642
-	}
642
+    }
643 643
 
644
-	/**
645
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
646
-	 *
647
-	 * @since 1.0.19
648
-	 */
649
-	public function get_new_payment_method_option_html() {
644
+    /**
645
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
646
+     *
647
+     * @since 1.0.19
648
+     */
649
+    public function get_new_payment_method_option_html() {
650 650
 
651
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
651
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
652 652
 
653
-		return sprintf(
654
-			'<li class="getpaid-new-payment-method">
653
+        return sprintf(
654
+            '<li class="getpaid-new-payment-method">
655 655
 				<label>
656 656
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
657 657
 					<span>%2$s</span>
658 658
 				</label>
659 659
 			</li>',
660
-			esc_attr( $this->id ),
661
-			esc_html( $label )
662
-		);
663
-
664
-	}
665
-
666
-	/**
667
-	 * Outputs a checkbox for saving a new payment method to the database.
668
-	 *
669
-	 * @since 1.0.19
670
-	 */
671
-	public function save_payment_method_checkbox() {
672
-
673
-		return aui()->input(
674
-			array(
675
-				'type'       => 'checkbox',
676
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
677
-				'id'         => esc_attr( uniqid( $this->id ) ),
678
-				'required'   => false,
679
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
680
-				'value'      => 'true',
681
-				'checked'    => true,
682
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
683
-			)
684
-		);
685
-
686
-	}
687
-
688
-	/**
689
-	 * Registers the gateway.
690
-	 *
691
-	 * @return array
692
-	 */
693
-	public function register_gateway( $gateways ) {
694
-
695
-		$gateways[ $this->id ] = array(
696
-
697
-			'admin_label'    => $this->method_title,
660
+            esc_attr( $this->id ),
661
+            esc_html( $label )
662
+        );
663
+
664
+    }
665
+
666
+    /**
667
+     * Outputs a checkbox for saving a new payment method to the database.
668
+     *
669
+     * @since 1.0.19
670
+     */
671
+    public function save_payment_method_checkbox() {
672
+
673
+        return aui()->input(
674
+            array(
675
+                'type'       => 'checkbox',
676
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
677
+                'id'         => esc_attr( uniqid( $this->id ) ),
678
+                'required'   => false,
679
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
680
+                'value'      => 'true',
681
+                'checked'    => true,
682
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
683
+            )
684
+        );
685
+
686
+    }
687
+
688
+    /**
689
+     * Registers the gateway.
690
+     *
691
+     * @return array
692
+     */
693
+    public function register_gateway( $gateways ) {
694
+
695
+        $gateways[ $this->id ] = array(
696
+
697
+            'admin_label'    => $this->method_title,
698 698
             'checkout_label' => $this->title,
699
-			'ordering'       => $this->order,
699
+            'ordering'       => $this->order,
700 700
 
701
-		);
701
+        );
702 702
 
703
-		return $gateways;
703
+        return $gateways;
704 704
 
705
-	}
705
+    }
706 706
 
707
-	/**
708
-	 * Checks whether or not this is a sandbox request.
709
-	 *
710
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
711
-	 * @return bool
712
-	 */
713
-	public function is_sandbox( $invoice = null ) {
707
+    /**
708
+     * Checks whether or not this is a sandbox request.
709
+     *
710
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
711
+     * @return bool
712
+     */
713
+    public function is_sandbox( $invoice = null ) {
714 714
 
715
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
716
-			return $invoice->get_mode() == 'test';
717
-		}
715
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
716
+            return $invoice->get_mode() == 'test';
717
+        }
718 718
 
719
-		return wpinv_is_test_mode( $this->id );
719
+        return wpinv_is_test_mode( $this->id );
720 720
 
721
-	}
721
+    }
722 722
 
723
-	/**
724
-	 * Renames the checkout button
725
-	 *
726
-	 * @return string
727
-	 */
728
-	public function rename_checkout_button() {
729
-		return $this->checkout_button_text;
730
-	}
723
+    /**
724
+     * Renames the checkout button
725
+     *
726
+     * @return string
727
+     */
728
+    public function rename_checkout_button() {
729
+        return $this->checkout_button_text;
730
+    }
731 731
 
732
-	/**
733
-	 * Validate gateway currency
734
-	 *
735
-	 * @return bool
736
-	 */
737
-	public function validate_currency( $validation, $currency ) {
732
+    /**
733
+     * Validate gateway currency
734
+     *
735
+     * @return bool
736
+     */
737
+    public function validate_currency( $validation, $currency ) {
738 738
 
739
-		// Required currencies.
740
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
741
-			return false;
742
-		}
739
+        // Required currencies.
740
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
741
+            return false;
742
+        }
743 743
 
744
-		// Excluded currencies.
745
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
746
-			return false;
747
-		}
744
+        // Excluded currencies.
745
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
746
+            return false;
747
+        }
748 748
 
749
-		return $validation;
750
-	}
749
+        return $validation;
750
+    }
751 751
 
752
-	/**
753
-	 * Displays an error
754
-	 *
755
-	 */
756
-	public function show_error( $code, $message, $type ) {
752
+    /**
753
+     * Displays an error
754
+     *
755
+     */
756
+    public function show_error( $code, $message, $type ) {
757 757
 
758
-		if ( is_admin() ) {
759
-			getpaid_admin()->{"show_$type"}( $message );
760
-		}
758
+        if ( is_admin() ) {
759
+            getpaid_admin()->{"show_$type"}( $message );
760
+        }
761 761
 
762
-		wpinv_set_error( $code, $message, $type );
762
+        wpinv_set_error( $code, $message, $type );
763 763
 
764
-	}
764
+    }
765 765
 
766 766
 }
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 class WPInv_Subscriptions {
13 13
 
14 14
     /**
15
-	 * Class constructor.
16
-	 */
15
+     * Class constructor.
16
+     */
17 17
     public function __construct(){
18 18
 
19 19
         // Fire gateway specific hooks when a subscription changes.
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-	 * Processes subscription status changes.
92
+     * Processes subscription status changes.
93 93
      *
94 94
      * @param WPInv_Subscription $subscription
95 95
      * @param string $from
96 96
      * @param string $to
97
-	 */
97
+     */
98 98
     public function process_subscription_status_change( $subscription, $from, $to ) {
99 99
 
100 100
         $gateway = $subscription->get_gateway();
Please login to merge, or discard this patch.