Passed
Push — master ( 45fbdf...2b14f3 )
by Brian
04:53
created
includes/wpinv-discount-functions.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -160,51 +160,51 @@
 block discarded – undo
160 160
  */
161 161
 function getpaid_calculate_invoice_discount( $invoice, $discount ) {
162 162
 
163
-	$initial_discount   = 0;
164
-	$recurring_discount = 0;
163
+    $initial_discount   = 0;
164
+    $recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+    foreach ( $invoice->get_items() as $item ) {
167 167
 
168
-		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
-			continue;
171
-		}
168
+        // Abort if it is not valid for this item.
169
+        if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
+            continue;
171
+        }
172 172
 
173
-		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
-		$recurring_item_discount = 0;
173
+        // Calculate the initial amount...
174
+        $item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
+        $recurring_item_discount = 0;
176 176
 
177
-		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
-		}
177
+        // ... and maybe the recurring amount.
178
+        if ( $item->is_recurring() && $discount->is_recurring() ) {
179
+            $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
+        }
181 181
 
182
-		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
182
+        // Discount should not exceed discounted amount.
183
+        if ( ! $discount->is_type( 'percent' ) ) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
-				$item_discount = $discount->get_amount() - $initial_discount;
187
-			}
185
+            if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
+                $item_discount = $discount->get_amount() - $initial_discount;
187
+            }
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
-				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
-			}
189
+            if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
+                $recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
+            }
192 192
 
193
-		}
193
+        }
194 194
 
195
-		$initial_discount             += $item_discount;
196
-		$recurring_discount           += $recurring_item_discount;
197
-		$item->item_discount           = $item_discount;
198
-		$item->recurring_item_discount = $recurring_item_discount;
195
+        $initial_discount             += $item_discount;
196
+        $recurring_discount           += $recurring_item_discount;
197
+        $item->item_discount           = $item_discount;
198
+        $item->recurring_item_discount = $recurring_item_discount;
199 199
 
200
-	}
200
+    }
201 201
 
202
-	return array(
203
-		'name'               => 'discount_code',
204
-		'discount_code'      => $discount->get_code(),
205
-		'initial_discount'   => $initial_discount,
206
-		'recurring_discount' => $recurring_discount,
207
-	);
202
+    return array(
203
+        'name'               => 'discount_code',
204
+        'discount_code'      => $discount->get_code(),
205
+        'initial_discount'   => $initial_discount,
206
+        'recurring_discount' => $recurring_discount,
207
+    );
208 208
 
209 209
 }
210 210
 
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
19 19
 
20
-	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
22
-		$args['fields'] = 'id';
23
-		$args['number'] = 1;
24
-	}
20
+    // Do not retrieve all fields if we just want the count.
21
+    if ( 'count' == $return ) {
22
+        $args['fields'] = 'id';
23
+        $args['number'] = 1;
24
+    }
25 25
 
26
-	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
28
-		$args['count_total'] = false;
29
-	}
26
+    // Do not count all matches if we just want the results.
27
+    if ( 'results' == $return ) {
28
+        $args['count_total'] = false;
29
+    }
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+    $query = new GetPaid_Subscriptions_Query( $args );
32 32
 
33
-	if ( 'results' == $return ) {
34
-		return $query->get_results();
35
-	}
33
+    if ( 'results' == $return ) {
34
+        return $query->get_results();
35
+    }
36 36
 
37
-	if ( 'count' == $return ) {
38
-		return $query->get_total();
39
-	}
37
+    if ( 'count' == $return ) {
38
+        return $query->get_total();
39
+    }
40 40
 
41
-	return $query;
41
+    return $query;
42 42
 }
43 43
 
44 44
 /**
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function getpaid_get_subscription_statuses() {
50 50
 
51
-	return apply_filters(
52
-		'getpaid_get_subscription_statuses',
53
-		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
-		)
62
-	);
51
+    return apply_filters(
52
+        'getpaid_get_subscription_statuses',
53
+        array(
54
+            'pending'    => __( 'Pending', 'invoicing' ),
55
+            'trialling'  => __( 'Trialing', 'invoicing' ),
56
+            'active'     => __( 'Active', 'invoicing' ),
57
+            'failing'    => __( 'Failing', 'invoicing' ),
58
+            'expired'    => __( 'Expired', 'invoicing' ),
59
+            'completed'  => __( 'Complete', 'invoicing' ),
60
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
+        )
62
+    );
63 63
 
64 64
 }
65 65
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
  * @return string
70 70
  */
71 71
 function getpaid_get_subscription_status_label( $status ) {
72
-	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
72
+    $statuses = getpaid_get_subscription_statuses();
73
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
74 74
 }
75 75
 
76 76
 /**
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function getpaid_get_subscription_status_classes() {
82 82
 
83
-	return apply_filters(
84
-		'getpaid_get_subscription_status_classes',
85
-		array(
86
-			'pending'    => 'badge-dark',
87
-			'trialling'  => 'badge-info',
88
-			'active'     => 'badge-success',
89
-			'failing'    => 'badge-warning',
90
-			'expired'    => 'badge-danger',
91
-			'completed'  => 'badge-primary',
92
-			'cancelled'  => 'badge-secondary',
93
-		)
94
-	);
83
+    return apply_filters(
84
+        'getpaid_get_subscription_status_classes',
85
+        array(
86
+            'pending'    => 'badge-dark',
87
+            'trialling'  => 'badge-info',
88
+            'active'     => 'badge-success',
89
+            'failing'    => 'badge-warning',
90
+            'expired'    => 'badge-danger',
91
+            'completed'  => 'badge-primary',
92
+            'cancelled'  => 'badge-secondary',
93
+        )
94
+    );
95 95
 
96 96
 }
97 97
 
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function getpaid_get_subscription_status_counts( $args = array() ) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
106
-	$counts   = array();
105
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
106
+    $counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
-	}
108
+    foreach ( $statuses as $status ) {
109
+        $_args             = wp_parse_args( "status=$status", $args );
110
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
+    }
112 112
 
113
-	return $counts;
113
+    return $counts;
114 114
 
115 115
 }
116 116
 
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
  */
122 122
 function getpaid_get_subscription_periods() {
123 123
 
124
-	return apply_filters(
125
-		'getpaid_get_subscription_periods',
126
-		array(
124
+    return apply_filters(
125
+        'getpaid_get_subscription_periods',
126
+        array(
127 127
 
128
-			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
131
-			),
128
+            'day'   => array(
129
+                'singular' => __( '%s day', 'invoicing' ),
130
+                'plural'   => __( '%d days', 'invoicing' ),
131
+            ),
132 132
 
133
-			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
136
-			),
133
+            'week'   => array(
134
+                'singular' => __( '%s week', 'invoicing' ),
135
+                'plural'   => __( '%d weeks', 'invoicing' ),
136
+            ),
137 137
 
138
-			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
141
-			),
138
+            'month'   => array(
139
+                'singular' => __( '%s month', 'invoicing' ),
140
+                'plural'   => __( '%d months', 'invoicing' ),
141
+            ),
142 142
 
143
-			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
146
-			),
143
+            'year'   => array(
144
+                'singular' => __( '%s year', 'invoicing' ),
145
+                'plural'   => __( '%d years', 'invoicing' ),
146
+            ),
147 147
 
148
-		)
149
-	);
148
+        )
149
+    );
150 150
 
151 151
 }
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  * @return int
158 158
  */
159 159
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
160
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
161 161
 }
162 162
 
163 163
 /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * @return string
168 168
  */
169 169
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
170
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
171 171
 }
172 172
 
173 173
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  * @return string
179 179
  */
180 180
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
181
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
+    return strtolower( sanitize_text_field( $label ) );
183 183
 }
184 184
 
185 185
 /**
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
192 192
 
193
-	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
193
+    $periods = getpaid_get_subscription_periods();
194
+    $period  = strtolower( $period );
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
-	}
196
+    if ( isset( $periods[ $period ] ) ) {
197
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
+    }
199 199
 
200
-	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
204
-		}
205
-	}
200
+    // Backwards compatibility.
201
+    foreach ( $periods as $key => $data ) {
202
+        if ( strpos( $key, $period ) === 0 ) {
203
+            return sprintf( $data['singular'], $singular_prefix );
204
+        }
205
+    }
206 206
 
207
-	// Invalid string.
208
-	return '';
207
+    // Invalid string.
208
+    return '';
209 209
 }
210 210
 
211 211
 /**
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
219 219
 
220
-	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
220
+    $periods = getpaid_get_subscription_periods();
221
+    $period  = strtolower( $period );
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
225
-	}
223
+    if ( isset( $periods[ $period ] ) ) {
224
+        return sprintf( $periods[ $period ]['plural'], $interval );
225
+    }
226 226
 
227
-	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
231
-		}
232
-	}
227
+    // Backwards compatibility.
228
+    foreach ( $periods as $key => $data ) {
229
+        if ( strpos( $key, $period ) === 0 ) {
230
+            return sprintf( $data['plural'], $interval );
231
+        }
232
+    }
233 233
 
234
-	// Invalid string.
235
-	return '';
234
+    // Invalid string.
235
+    return '';
236 236
 }
237 237
 
238 238
 /**
@@ -243,101 +243,101 @@  discard block
 block discarded – undo
243 243
  */
244 244
 function getpaid_get_formatted_subscription_amount( $subscription ) {
245 245
 
246
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
-	$bill_times = $subscription->get_bill_times();
246
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
+    $bill_times = $subscription->get_bill_times();
250 250
 
251
-	if ( ! empty( $bill_times ) ) {
252
-		$bill_times = $subscription->get_frequency() * $bill_times;
253
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
-	}
251
+    if ( ! empty( $bill_times ) ) {
252
+        $bill_times = $subscription->get_frequency() * $bill_times;
253
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
+    }
255 255
 
256
-	// Trial periods.
257
-	if ( $subscription->has_trial_period() ) {
256
+    // Trial periods.
257
+    if ( $subscription->has_trial_period() ) {
258 258
 
259
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
259
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
261 261
 
262
-		if ( empty( $bill_times ) ) {
262
+        if ( empty( $bill_times ) ) {
263 263
 
264
-			return sprintf(
264
+            return sprintf(
265 265
 
266
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
-				$initial,
269
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
-				$recurring,
271
-				$period
266
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
+                $initial,
269
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
+                $recurring,
271
+                $period
272 272
 	
273
-			);
273
+            );
274 274
 
275
-		}
275
+        }
276 276
 
277
-		return sprintf(
277
+        return sprintf(
278 278
 
279
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
-			$initial,
282
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
-			$recurring,
284
-			$period,
285
-			$bill_times
286
-		);
279
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
+            $initial,
282
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
+            $recurring,
284
+            $period,
285
+            $bill_times
286
+        );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	if ( $initial != $recurring ) {
290
+    if ( $initial != $recurring ) {
291 291
 
292
-		if ( empty( $bill_times ) ) {
292
+        if ( empty( $bill_times ) ) {
293 293
 
294
-			return sprintf(
294
+            return sprintf(
295 295
 
296
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
-				$initial,
299
-				$recurring,
300
-				$period
296
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
+                $initial,
299
+                $recurring,
300
+                $period
301 301
 	
302
-			);
302
+            );
303 303
 
304
-		}
304
+        }
305 305
 
306
-		return sprintf(
306
+        return sprintf(
307 307
 
308
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
-			$initial,
311
-			$recurring,
312
-			$period,
313
-			$bill_times
308
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
+            $initial,
311
+            $recurring,
312
+            $period,
313
+            $bill_times
314 314
 
315
-		);
315
+        );
316 316
 
317
-	}
317
+    }
318 318
 
319
-	if ( empty( $bill_times ) ) {
319
+    if ( empty( $bill_times ) ) {
320 320
 
321
-		return sprintf(
321
+        return sprintf(
322 322
 
323
-			// translators: $1: is the recurring amount, $2: is the recurring period
324
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
-			$initial,
326
-			$period
323
+            // translators: $1: is the recurring amount, $2: is the recurring period
324
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
+            $initial,
326
+            $period
327 327
 	
328
-		);
328
+        );
329 329
 
330
-	}
330
+    }
331 331
 
332
-	return sprintf(
332
+    return sprintf(
333 333
 
334
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
-		$bill_times,
337
-		$initial,
338
-		$period
334
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
+        $bill_times,
337
+        $initial,
338
+        $period
339 339
 
340
-	);
340
+    );
341 341
 
342 342
 }
343 343
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return WPInv_Subscription|bool
349 349
  */
350 350
 function getpaid_get_invoice_subscription( $invoice ) {
351
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
351
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
352 352
 }
353 353
 
354 354
 /**
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
  * @param WPInv_Invoice $invoice
358 358
  */
359 359
 function getpaid_activate_invoice_subscription( $invoice ) {
360
-	$subscription = getpaid_get_invoice_subscription( $invoice );
361
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
-		$subscription->activate();
363
-	}
360
+    $subscription = getpaid_get_invoice_subscription( $invoice );
361
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
+        $subscription->activate();
363
+    }
364 364
 }
365 365
 
366 366
 /**
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return WPInv_Subscriptions
370 370
  */
371 371
 function getpaid_subscriptions() {
372
-	return getpaid()->get( 'subscriptions' );
372
+    return getpaid()->get( 'subscriptions' );
373 373
 }
374 374
 
375 375
 /**
@@ -387,15 +387,15 @@  discard block
 block discarded – undo
387 387
         return false;
388 388
     }
389 389
 
390
-	// Fetch the invoiec subscription.
391
-	$subscription = getpaid_get_subscriptions(
392
-		array(
393
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
-			'number'     => 1,
395
-		)
396
-	);
390
+    // Fetch the invoiec subscription.
391
+    $subscription = getpaid_get_subscriptions(
392
+        array(
393
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
+            'number'     => 1,
395
+        )
396
+    );
397 397
 
398
-	return empty( $subscription ) ? false : $subscription[0];
398
+    return empty( $subscription ) ? false : $subscription[0];
399 399
 
400 400
 }
401 401
 
@@ -412,48 +412,48 @@  discard block
 block discarded – undo
412 412
  */
413 413
 function getpaid_get_recurring_item_key( $cart_item ) {
414 414
 
415
-	$cart_key     = 'renews_';
416
-	$interval     = $cart_item->get_recurring_interval();
417
-	$period       = $cart_item->get_recurring_period( true );
418
-	$length       = $cart_item->get_recurring_limit() * $interval;
419
-	$trial_period = $cart_item->get_trial_period( true );
420
-	$trial_length = $cart_item->get_trial_interval();
421
-
422
-	// First start with the billing interval and period
423
-	switch ( $interval ) {
424
-		case 1 :
425
-			if ( 'day' == $period ) {
426
-				$cart_key .= 'daily';
427
-			} else {
428
-				$cart_key .= sprintf( '%sly', $period );
429
-			}
430
-			break;
431
-		case 2 :
432
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
433
-			break;
434
-		case 3 :
435
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
436
-		break;
437
-		default:
438
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
439
-			break;
440
-	}
441
-
442
-	// Maybe add the optional maximum billing periods...
443
-	if ( $length > 0 ) {
444
-		$cart_key .= '_for_';
445
-		$cart_key .= sprintf( '%d_%s', $length, $period );
446
-		if ( $length > 1 ) {
447
-			$cart_key .= 's';
448
-		}
449
-	}
450
-
451
-	// And an optional free trial.
452
-	if ( $cart_item->has_free_trial() ) {
453
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
454
-	}
455
-
456
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
415
+    $cart_key     = 'renews_';
416
+    $interval     = $cart_item->get_recurring_interval();
417
+    $period       = $cart_item->get_recurring_period( true );
418
+    $length       = $cart_item->get_recurring_limit() * $interval;
419
+    $trial_period = $cart_item->get_trial_period( true );
420
+    $trial_length = $cart_item->get_trial_interval();
421
+
422
+    // First start with the billing interval and period
423
+    switch ( $interval ) {
424
+        case 1 :
425
+            if ( 'day' == $period ) {
426
+                $cart_key .= 'daily';
427
+            } else {
428
+                $cart_key .= sprintf( '%sly', $period );
429
+            }
430
+            break;
431
+        case 2 :
432
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
433
+            break;
434
+        case 3 :
435
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
436
+        break;
437
+        default:
438
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
439
+            break;
440
+    }
441
+
442
+    // Maybe add the optional maximum billing periods...
443
+    if ( $length > 0 ) {
444
+        $cart_key .= '_for_';
445
+        $cart_key .= sprintf( '%d_%s', $length, $period );
446
+        if ( $length > 1 ) {
447
+            $cart_key .= 's';
448
+        }
449
+    }
450
+
451
+    // And an optional free trial.
452
+    if ( $cart_item->has_free_trial() ) {
453
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
454
+    }
455
+
456
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
457 457
 }
458 458
 
459 459
 /**
@@ -464,17 +464,17 @@  discard block
 block discarded – undo
464 464
  */
465 465
 function getpaid_get_subscription_groups( $invoice ) {
466 466
 
467
-	// Generate subscription groups.
468
-	$subscription_groups = array();
469
-	foreach ( $invoice->get_items() as $item ) {
467
+    // Generate subscription groups.
468
+    $subscription_groups = array();
469
+    foreach ( $invoice->get_items() as $item ) {
470 470
 
471
-		if ( $item->is_recurring() ) {
472
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
473
-		}
471
+        if ( $item->is_recurring() ) {
472
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
473
+        }
474 474
 
475
-	}
475
+    }
476 476
 
477
-	return $subscription_groups;
477
+    return $subscription_groups;
478 478
 }
479 479
 
480 480
 /**
@@ -488,51 +488,51 @@  discard block
 block discarded – undo
488 488
  */
489 489
 function getpaid_calculate_subscription_totals( $invoice ) {
490 490
 
491
-	// Generate subscription groups.
492
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
491
+    // Generate subscription groups.
492
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
493 493
 
494
-	// Now let's calculate the totals for each group of subscriptions
495
-	$subscription_totals = array();
494
+    // Now let's calculate the totals for each group of subscriptions
495
+    $subscription_totals = array();
496 496
 
497
-	foreach ( $subscription_groups as $subscription_key => $items ) {
497
+    foreach ( $subscription_groups as $subscription_key => $items ) {
498 498
 
499
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
499
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
500 500
 
501
-			$subscription_totals[ $subscription_key ] = array(
502
-				'initial_total'   => 0,
503
-				'recurring_total' => 0,
504
-				'items'           => array(),
505
-				'trialling'       => false,
506
-			);
501
+            $subscription_totals[ $subscription_key ] = array(
502
+                'initial_total'   => 0,
503
+                'recurring_total' => 0,
504
+                'items'           => array(),
505
+                'trialling'       => false,
506
+            );
507 507
 
508
-		}
508
+        }
509 509
 
510
-		// Get the totals of the group.
511
-		foreach ( $items as $item ) {
510
+        // Get the totals of the group.
511
+        foreach ( $items as $item ) {
512 512
 
513
-			$subscription_totals[ $subscription_key ]['items'][]          = $item->get_id();
514
-			$subscription_totals[ $subscription_key ]['item_id']          = $item->get_id();
515
-			$subscription_totals[ $subscription_key ]['period']           = $item->get_recurring_period( true );
516
-			$subscription_totals[ $subscription_key ]['interval']         = $item->get_recurring_interval();
517
-			$subscription_totals[ $subscription_key ]['initial_total']   += $item->get_sub_total();
518
-			$subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total();
513
+            $subscription_totals[ $subscription_key ]['items'][]          = $item->get_id();
514
+            $subscription_totals[ $subscription_key ]['item_id']          = $item->get_id();
515
+            $subscription_totals[ $subscription_key ]['period']           = $item->get_recurring_period( true );
516
+            $subscription_totals[ $subscription_key ]['interval']         = $item->get_recurring_interval();
517
+            $subscription_totals[ $subscription_key ]['initial_total']   += $item->get_sub_total();
518
+            $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total();
519 519
 
520
-			// Calculate the next renewal date.
521
-			$period       = $item->get_recurring_period( true );
522
-			$interval     = $item->get_recurring_interval();
520
+            // Calculate the next renewal date.
521
+            $period       = $item->get_recurring_period( true );
522
+            $interval     = $item->get_recurring_interval();
523 523
 
524
-			// If the subscription item has a trial period...
525
-			if ( $item->has_free_trial() ) {
526
-				$period   = $item->get_trial_period( true );
527
-				$interval = $item->get_trial_interval();
528
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
529
-			}
524
+            // If the subscription item has a trial period...
525
+            if ( $item->has_free_trial() ) {
526
+                $period   = $item->get_trial_period( true );
527
+                $interval = $item->get_trial_interval();
528
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
529
+            }
530 530
 
531
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
531
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
532 532
 
533
-		}
533
+        }
534 534
 
535
-	}
535
+    }
536 536
 
537
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
537
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
538 538
 }
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
17 17
  */
18
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
18
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
19 19
 
20 20
 	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
21
+	if ('count' == $return) {
22 22
 		$args['fields'] = 'id';
23 23
 		$args['number'] = 1;
24 24
 	}
25 25
 
26 26
 	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
27
+	if ('results' == $return) {
28 28
 		$args['count_total'] = false;
29 29
 	}
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+	$query = new GetPaid_Subscriptions_Query($args);
32 32
 
33
-	if ( 'results' == $return ) {
33
+	if ('results' == $return) {
34 34
 		return $query->get_results();
35 35
 	}
36 36
 
37
-	if ( 'count' == $return ) {
37
+	if ('count' == $return) {
38 38
 		return $query->get_total();
39 39
 	}
40 40
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	return apply_filters(
52 52
 		'getpaid_get_subscription_statuses',
53 53
 		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
54
+			'pending'    => __('Pending', 'invoicing'),
55
+			'trialling'  => __('Trialing', 'invoicing'),
56
+			'active'     => __('Active', 'invoicing'),
57
+			'failing'    => __('Failing', 'invoicing'),
58
+			'expired'    => __('Expired', 'invoicing'),
59
+			'completed'  => __('Complete', 'invoicing'),
60
+			'cancelled'  => __('Cancelled', 'invoicing'),
61 61
 		)
62 62
 	);
63 63
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return string
70 70
  */
71
-function getpaid_get_subscription_status_label( $status ) {
71
+function getpaid_get_subscription_status_label($status) {
72 72
 	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
73
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
74 74
 }
75 75
 
76 76
 /**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
  *
101 101
  * @return array
102 102
  */
103
-function getpaid_get_subscription_status_counts( $args = array() ) {
103
+function getpaid_get_subscription_status_counts($args = array()) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
105
+	$statuses = array_keys(getpaid_get_subscription_statuses());
106 106
 	$counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
108
+	foreach ($statuses as $status) {
109
+		$_args             = wp_parse_args("status=$status", $args);
110
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
111 111
 	}
112 112
 
113 113
 	return $counts;
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		array(
127 127
 
128 128
 			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
129
+				'singular' => __('%s day', 'invoicing'),
130
+				'plural'   => __('%d days', 'invoicing'),
131 131
 			),
132 132
 
133 133
 			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
134
+				'singular' => __('%s week', 'invoicing'),
135
+				'plural'   => __('%d weeks', 'invoicing'),
136 136
 			),
137 137
 
138 138
 			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
139
+				'singular' => __('%s month', 'invoicing'),
140
+				'plural'   => __('%d months', 'invoicing'),
141 141
 			),
142 142
 
143 143
 			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
144
+				'singular' => __('%s year', 'invoicing'),
145
+				'plural'   => __('%d years', 'invoicing'),
146 146
 			),
147 147
 
148 148
 		)
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * @param string $trial_period
157 157
  * @return int
158 158
  */
159
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
159
+function getpaid_get_subscription_trial_period_interval($trial_period) {
160
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
161 161
 }
162 162
 
163 163
 /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  * @param string $trial_period
167 167
  * @return string
168 168
  */
169
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
169
+function getpaid_get_subscription_trial_period_period($trial_period) {
170
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
171 171
 }
172 172
 
173 173
 /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
  * @param int $interval
178 178
  * @return string
179 179
  */
180
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
180
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
181
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
182
+	return strtolower(sanitize_text_field($label));
183 183
 }
184 184
 
185 185
 /**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
  * @param string $period
189 189
  * @return string
190 190
  */
191
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
191
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
192 192
 
193 193
 	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
194
+	$period  = strtolower($period);
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
196
+	if (isset($periods[$period])) {
197
+		return sprintf($periods[$period]['singular'], $singular_prefix);
198 198
 	}
199 199
 
200 200
 	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
201
+	foreach ($periods as $key => $data) {
202
+		if (strpos($key, $period) === 0) {
203
+			return sprintf($data['singular'], $singular_prefix);
204 204
 		}
205 205
 	}
206 206
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
  * @param int $interval
216 216
  * @return string
217 217
  */
218
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
218
+function getpaid_get_plural_subscription_period_label($period, $interval) {
219 219
 
220 220
 	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
221
+	$period  = strtolower($period);
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
223
+	if (isset($periods[$period])) {
224
+		return sprintf($periods[$period]['plural'], $interval);
225 225
 	}
226 226
 
227 227
 	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
228
+	foreach ($periods as $key => $data) {
229
+		if (strpos($key, $period) === 0) {
230
+			return sprintf($data['plural'], $interval);
231 231
 		}
232 232
 	}
233 233
 
@@ -241,32 +241,32 @@  discard block
 block discarded – undo
241 241
  * @param WPInv_Subscription $subscription
242 242
  * @return string
243 243
  */
244
-function getpaid_get_formatted_subscription_amount( $subscription ) {
244
+function getpaid_get_formatted_subscription_amount($subscription) {
245 245
 
246
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
247
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
248
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
249 249
 	$bill_times = $subscription->get_bill_times();
250 250
 
251
-	if ( ! empty( $bill_times ) ) {
251
+	if (!empty($bill_times)) {
252 252
 		$bill_times = $subscription->get_frequency() * $bill_times;
253
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
253
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
254 254
 	}
255 255
 
256 256
 	// Trial periods.
257
-	if ( $subscription->has_trial_period() ) {
257
+	if ($subscription->has_trial_period()) {
258 258
 
259
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
259
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
260
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
261 261
 
262
-		if ( empty( $bill_times ) ) {
262
+		if (empty($bill_times)) {
263 263
 
264 264
 			return sprintf(
265 265
 
266 266
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
267
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
268 268
 				$initial,
269
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
269
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
270 270
 				$recurring,
271 271
 				$period
272 272
 	
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 		return sprintf(
278 278
 
279 279
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
280
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
281 281
 			$initial,
282
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
282
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
283 283
 			$recurring,
284 284
 			$period,
285 285
 			$bill_times
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 
288 288
 	}
289 289
 
290
-	if ( $initial != $recurring ) {
290
+	if ($initial != $recurring) {
291 291
 
292
-		if ( empty( $bill_times ) ) {
292
+		if (empty($bill_times)) {
293 293
 
294 294
 			return sprintf(
295 295
 
296 296
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
297
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
298 298
 				$initial,
299 299
 				$recurring,
300 300
 				$period
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		return sprintf(
307 307
 
308 308
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
309
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
310 310
 			$initial,
311 311
 			$recurring,
312 312
 			$period,
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 
317 317
 	}
318 318
 
319
-	if ( empty( $bill_times ) ) {
319
+	if (empty($bill_times)) {
320 320
 
321 321
 		return sprintf(
322 322
 
323 323
 			// translators: $1: is the recurring amount, $2: is the recurring period
324
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
324
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
325 325
 			$initial,
326 326
 			$period
327 327
 	
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	return sprintf(
333 333
 
334 334
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
335
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
336 336
 		$bill_times,
337 337
 		$initial,
338 338
 		$period
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
  * @param WPInv_Invoice $invoice
348 348
  * @return WPInv_Subscription|bool
349 349
  */
350
-function getpaid_get_invoice_subscription( $invoice ) {
351
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
350
+function getpaid_get_invoice_subscription($invoice) {
351
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
352 352
 }
353 353
 
354 354
 /**
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
  *
357 357
  * @param WPInv_Invoice $invoice
358 358
  */
359
-function getpaid_activate_invoice_subscription( $invoice ) {
360
-	$subscription = getpaid_get_invoice_subscription( $invoice );
361
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
359
+function getpaid_activate_invoice_subscription($invoice) {
360
+	$subscription = getpaid_get_invoice_subscription($invoice);
361
+	if (is_a($subscription, 'WPInv_Subscription')) {
362 362
 		$subscription->activate();
363 363
 	}
364 364
 }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return WPInv_Subscriptions
370 370
  */
371 371
 function getpaid_subscriptions() {
372
-	return getpaid()->get( 'subscriptions' );
372
+	return getpaid()->get('subscriptions');
373 373
 }
374 374
 
375 375
 /**
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
  *
378 378
  * @return WPInv_Subscription|bool
379 379
  */
380
-function wpinv_get_subscription( $invoice ) {
380
+function wpinv_get_subscription($invoice) {
381 381
 
382 382
     // Retrieve the invoice.
383
-    $invoice = new WPInv_Invoice( $invoice );
383
+    $invoice = new WPInv_Invoice($invoice);
384 384
 
385 385
     // Ensure it is a recurring invoice.
386
-    if ( ! $invoice->is_recurring() ) {
386
+    if (!$invoice->is_recurring()) {
387 387
         return false;
388 388
     }
389 389
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 		)
396 396
 	);
397 397
 
398
-	return empty( $subscription ) ? false : $subscription[0];
398
+	return empty($subscription) ? false : $subscription[0];
399 399
 
400 400
 }
401 401
 
@@ -410,50 +410,50 @@  discard block
 block discarded – undo
410 410
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
411 411
  * @return string
412 412
  */
413
-function getpaid_get_recurring_item_key( $cart_item ) {
413
+function getpaid_get_recurring_item_key($cart_item) {
414 414
 
415 415
 	$cart_key     = 'renews_';
416 416
 	$interval     = $cart_item->get_recurring_interval();
417
-	$period       = $cart_item->get_recurring_period( true );
417
+	$period       = $cart_item->get_recurring_period(true);
418 418
 	$length       = $cart_item->get_recurring_limit() * $interval;
419
-	$trial_period = $cart_item->get_trial_period( true );
419
+	$trial_period = $cart_item->get_trial_period(true);
420 420
 	$trial_length = $cart_item->get_trial_interval();
421 421
 
422 422
 	// First start with the billing interval and period
423
-	switch ( $interval ) {
423
+	switch ($interval) {
424 424
 		case 1 :
425
-			if ( 'day' == $period ) {
425
+			if ('day' == $period) {
426 426
 				$cart_key .= 'daily';
427 427
 			} else {
428
-				$cart_key .= sprintf( '%sly', $period );
428
+				$cart_key .= sprintf('%sly', $period);
429 429
 			}
430 430
 			break;
431 431
 		case 2 :
432
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
432
+			$cart_key .= sprintf('every_2nd_%s', $period);
433 433
 			break;
434 434
 		case 3 :
435
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
435
+			$cart_key .= sprintf('every_3rd_%s', $period);
436 436
 		break;
437 437
 		default:
438
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
438
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
439 439
 			break;
440 440
 	}
441 441
 
442 442
 	// Maybe add the optional maximum billing periods...
443
-	if ( $length > 0 ) {
443
+	if ($length > 0) {
444 444
 		$cart_key .= '_for_';
445
-		$cart_key .= sprintf( '%d_%s', $length, $period );
446
-		if ( $length > 1 ) {
445
+		$cart_key .= sprintf('%d_%s', $length, $period);
446
+		if ($length > 1) {
447 447
 			$cart_key .= 's';
448 448
 		}
449 449
 	}
450 450
 
451 451
 	// And an optional free trial.
452
-	if ( $cart_item->has_free_trial() ) {
453
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
452
+	if ($cart_item->has_free_trial()) {
453
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
454 454
 	}
455 455
 
456
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
456
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
457 457
 }
458 458
 
459 459
 /**
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
463 463
  * @return array
464 464
  */
465
-function getpaid_get_subscription_groups( $invoice ) {
465
+function getpaid_get_subscription_groups($invoice) {
466 466
 
467 467
 	// Generate subscription groups.
468 468
 	$subscription_groups = array();
469
-	foreach ( $invoice->get_items() as $item ) {
469
+	foreach ($invoice->get_items() as $item) {
470 470
 
471
-		if ( $item->is_recurring() ) {
472
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
471
+		if ($item->is_recurring()) {
472
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
473 473
 		}
474 474
 
475 475
 	}
@@ -486,19 +486,19 @@  discard block
 block discarded – undo
486 486
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
487 487
  * @return array
488 488
  */
489
-function getpaid_calculate_subscription_totals( $invoice ) {
489
+function getpaid_calculate_subscription_totals($invoice) {
490 490
 
491 491
 	// Generate subscription groups.
492
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
492
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
493 493
 
494 494
 	// Now let's calculate the totals for each group of subscriptions
495 495
 	$subscription_totals = array();
496 496
 
497
-	foreach ( $subscription_groups as $subscription_key => $items ) {
497
+	foreach ($subscription_groups as $subscription_key => $items) {
498 498
 
499
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
499
+		if (empty($subscription_totals[$subscription_key])) {
500 500
 
501
-			$subscription_totals[ $subscription_key ] = array(
501
+			$subscription_totals[$subscription_key] = array(
502 502
 				'initial_total'   => 0,
503 503
 				'recurring_total' => 0,
504 504
 				'items'           => array(),
@@ -508,31 +508,31 @@  discard block
 block discarded – undo
508 508
 		}
509 509
 
510 510
 		// Get the totals of the group.
511
-		foreach ( $items as $item ) {
511
+		foreach ($items as $item) {
512 512
 
513
-			$subscription_totals[ $subscription_key ]['items'][]          = $item->get_id();
514
-			$subscription_totals[ $subscription_key ]['item_id']          = $item->get_id();
515
-			$subscription_totals[ $subscription_key ]['period']           = $item->get_recurring_period( true );
516
-			$subscription_totals[ $subscription_key ]['interval']         = $item->get_recurring_interval();
517
-			$subscription_totals[ $subscription_key ]['initial_total']   += $item->get_sub_total();
518
-			$subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total();
513
+			$subscription_totals[$subscription_key]['items'][]          = $item->get_id();
514
+			$subscription_totals[$subscription_key]['item_id']          = $item->get_id();
515
+			$subscription_totals[$subscription_key]['period']           = $item->get_recurring_period(true);
516
+			$subscription_totals[$subscription_key]['interval']         = $item->get_recurring_interval();
517
+			$subscription_totals[$subscription_key]['initial_total']   += $item->get_sub_total();
518
+			$subscription_totals[$subscription_key]['recurring_total'] += $item->get_recurring_sub_total();
519 519
 
520 520
 			// Calculate the next renewal date.
521
-			$period       = $item->get_recurring_period( true );
521
+			$period       = $item->get_recurring_period(true);
522 522
 			$interval     = $item->get_recurring_interval();
523 523
 
524 524
 			// If the subscription item has a trial period...
525
-			if ( $item->has_free_trial() ) {
526
-				$period   = $item->get_trial_period( true );
525
+			if ($item->has_free_trial()) {
526
+				$period   = $item->get_trial_period(true);
527 527
 				$interval = $item->get_trial_interval();
528
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
528
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
529 529
 			}
530 530
 
531
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
531
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
532 532
 
533 533
 		}
534 534
 
535 535
 	}
536 536
 
537
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
537
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
538 538
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +813 added lines, -813 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,116 +345,116 @@  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
-
380
-			if ( $this->has_recurring != 0 ) {
381
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
382
-			}
383
-
384
-			$this->has_recurring = $item->get_id();
385
-
386
-		}
387
-
388
-		// Update the items and totals.
389
-		$this->items[ $item->get_id() ]         = $item;
390
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
391
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
392
-
393
-		$this->subscription_groups = getpaid_calculate_subscription_totals( $this );
394
-	}
395
-
396
-	/**
397
-	 * Removes a specific item.
398
-	 * 
399
-	 * You should not call this method after the discounts and taxes
400
-	 * have been calculated.
401
-	 *
402
-	 * @since 1.0.19
403
-	 */
404
-	public function remove_item( $item_id ) {
405
-
406
-		if ( isset( $this->items[ $item_id ] ) ) {
407
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
408
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
409
-
410
-			if ( $this->items[ $item_id ]->is_recurring() ) {
411
-				$this->has_recurring = 0;
412
-			}
413
-
414
-			unset( $this->items[ $item_id ] );
415
-		}
416
-
417
-	}
418
-
419
-	/**
420
-	 * Returns the subtotal.
421
-	 *
422
-	 * @since 1.0.19
423
-	 */
424
-	public function get_subtotal() {
425
-
426
-		if ( wpinv_prices_include_tax() ) {
427
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
428
-		}
429
-
430
-		return $this->totals['subtotal']['initial'];
431
-	}
432
-
433
-	/**
434
-	 * Returns the recurring subtotal.
435
-	 *
436
-	 * @since 1.0.19
437
-	 */
438
-	public function get_recurring_subtotal() {
439
-
440
-		if ( wpinv_prices_include_tax() ) {
441
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
442
-		}
443
-
444
-		return $this->totals['subtotal']['recurring'];
445
-	}
446
-
447
-	/**
448
-	 * Returns all items.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @return GetPaid_Form_Item[]
452
-	 */
453
-	public function get_items() {
454
-		return $this->items;
455
-	}
456
-
457
-	/*
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
+
380
+            if ( $this->has_recurring != 0 ) {
381
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
382
+            }
383
+
384
+            $this->has_recurring = $item->get_id();
385
+
386
+        }
387
+
388
+        // Update the items and totals.
389
+        $this->items[ $item->get_id() ]         = $item;
390
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
391
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
392
+
393
+        $this->subscription_groups = getpaid_calculate_subscription_totals( $this );
394
+    }
395
+
396
+    /**
397
+     * Removes a specific item.
398
+     * 
399
+     * You should not call this method after the discounts and taxes
400
+     * have been calculated.
401
+     *
402
+     * @since 1.0.19
403
+     */
404
+    public function remove_item( $item_id ) {
405
+
406
+        if ( isset( $this->items[ $item_id ] ) ) {
407
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
408
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
409
+
410
+            if ( $this->items[ $item_id ]->is_recurring() ) {
411
+                $this->has_recurring = 0;
412
+            }
413
+
414
+            unset( $this->items[ $item_id ] );
415
+        }
416
+
417
+    }
418
+
419
+    /**
420
+     * Returns the subtotal.
421
+     *
422
+     * @since 1.0.19
423
+     */
424
+    public function get_subtotal() {
425
+
426
+        if ( wpinv_prices_include_tax() ) {
427
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
428
+        }
429
+
430
+        return $this->totals['subtotal']['initial'];
431
+    }
432
+
433
+    /**
434
+     * Returns the recurring subtotal.
435
+     *
436
+     * @since 1.0.19
437
+     */
438
+    public function get_recurring_subtotal() {
439
+
440
+        if ( wpinv_prices_include_tax() ) {
441
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
442
+        }
443
+
444
+        return $this->totals['subtotal']['recurring'];
445
+    }
446
+
447
+    /**
448
+     * Returns all items.
449
+     *
450
+     * @since 1.0.19
451
+     * @return GetPaid_Form_Item[]
452
+     */
453
+    public function get_items() {
454
+        return $this->items;
455
+    }
456
+
457
+    /*
458 458
 	|--------------------------------------------------------------------------
459 459
 	| Taxes
460 460
 	|--------------------------------------------------------------------------
@@ -463,128 +463,128 @@  discard block
 block discarded – undo
463 463
 	| or only one-time.
464 464
     */
465 465
 
466
-	/**
467
-	 * Prepares the submission's taxes.
468
-	 *
469
-	 * @since 1.0.19
470
-	 */
471
-	public function process_taxes() {
472
-
473
-		// Abort if we're not using taxes.
474
-		if ( ! $this->use_taxes() ) {
475
-			return;
476
-		}
477
-
478
-		// If a custom country && state has been passed in, use it to calculate taxes.
479
-		$country = $this->get_field( 'wpinv_country', 'billing' );
480
-		if ( ! empty( $country ) ) {
481
-			$this->country = $country;
482
-		}
483
-
484
-		$state = $this->get_field( 'wpinv_state', 'billing' );
485
-		if ( ! empty( $state ) ) {
486
-			$this->state = $state;
487
-		}
488
-
489
-		// Confirm if the provided country and the ip country are similar.
490
-		$address_confirmed = $this->get_field( 'confirm-address' );
491
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
492
-			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' ) );
493
-		}
494
-
495
-		// Abort if the country is not taxable.
496
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
497
-			return;
498
-		}
499
-
500
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
501
-
502
-		foreach ( $processor->taxes as $tax ) {
503
-			$this->add_tax( $tax );
504
-		}
505
-
506
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
507
-	}
508
-
509
-	/**
510
-	 * Adds a tax to the submission.
511
-	 *
512
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
513
-	 * @since 1.0.19
514
-	 */
515
-	public function add_tax( $tax ) {
516
-
517
-		if ( wpinv_round_tax_per_tax_rate() ) {
518
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
519
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
520
-		}
521
-
522
-		$this->taxes[ $tax['name'] ]         = $tax;
523
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
524
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
525
-
526
-	}
527
-
528
-	/**
529
-	 * Removes a specific tax.
530
-	 *
531
-	 * @since 1.0.19
532
-	 */
533
-	public function remove_tax( $tax_name ) {
534
-
535
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
536
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
537
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
538
-			unset( $this->taxes[ $tax_name ] );
539
-		}
540
-
541
-	}
542
-
543
-	/**
544
-	 * Whether or not we'll use taxes for the submission.
545
-	 *
546
-	 * @since 1.0.19
547
-	 */
548
-	public function use_taxes() {
549
-
550
-		$use_taxes = wpinv_use_taxes();
551
-
552
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
553
-			$use_taxes = false;
554
-		}
555
-
556
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
557
-
558
-	}
559
-
560
-	/**
561
-	 * Returns the tax.
562
-	 *
563
-	 * @since 1.0.19
564
-	 */
565
-	public function get_tax() {
566
-		return $this->totals['taxes']['initial'];
567
-	}
568
-
569
-	/**
570
-	 * Returns the recurring tax.
571
-	 *
572
-	 * @since 1.0.19
573
-	 */
574
-	public function get_recurring_tax() {
575
-		return $this->totals['taxes']['recurring'];
576
-	}
577
-
578
-	/**
579
-	 * Returns all taxes.
580
-	 *
581
-	 * @since 1.0.19
582
-	 */
583
-	public function get_taxes() {
584
-		return $this->taxes;
585
-	}
586
-
587
-	/*
466
+    /**
467
+     * Prepares the submission's taxes.
468
+     *
469
+     * @since 1.0.19
470
+     */
471
+    public function process_taxes() {
472
+
473
+        // Abort if we're not using taxes.
474
+        if ( ! $this->use_taxes() ) {
475
+            return;
476
+        }
477
+
478
+        // If a custom country && state has been passed in, use it to calculate taxes.
479
+        $country = $this->get_field( 'wpinv_country', 'billing' );
480
+        if ( ! empty( $country ) ) {
481
+            $this->country = $country;
482
+        }
483
+
484
+        $state = $this->get_field( 'wpinv_state', 'billing' );
485
+        if ( ! empty( $state ) ) {
486
+            $this->state = $state;
487
+        }
488
+
489
+        // Confirm if the provided country and the ip country are similar.
490
+        $address_confirmed = $this->get_field( 'confirm-address' );
491
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
492
+            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' ) );
493
+        }
494
+
495
+        // Abort if the country is not taxable.
496
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
497
+            return;
498
+        }
499
+
500
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
501
+
502
+        foreach ( $processor->taxes as $tax ) {
503
+            $this->add_tax( $tax );
504
+        }
505
+
506
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
507
+    }
508
+
509
+    /**
510
+     * Adds a tax to the submission.
511
+     *
512
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
513
+     * @since 1.0.19
514
+     */
515
+    public function add_tax( $tax ) {
516
+
517
+        if ( wpinv_round_tax_per_tax_rate() ) {
518
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
519
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
520
+        }
521
+
522
+        $this->taxes[ $tax['name'] ]         = $tax;
523
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
524
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
525
+
526
+    }
527
+
528
+    /**
529
+     * Removes a specific tax.
530
+     *
531
+     * @since 1.0.19
532
+     */
533
+    public function remove_tax( $tax_name ) {
534
+
535
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
536
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
537
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
538
+            unset( $this->taxes[ $tax_name ] );
539
+        }
540
+
541
+    }
542
+
543
+    /**
544
+     * Whether or not we'll use taxes for the submission.
545
+     *
546
+     * @since 1.0.19
547
+     */
548
+    public function use_taxes() {
549
+
550
+        $use_taxes = wpinv_use_taxes();
551
+
552
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
553
+            $use_taxes = false;
554
+        }
555
+
556
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
557
+
558
+    }
559
+
560
+    /**
561
+     * Returns the tax.
562
+     *
563
+     * @since 1.0.19
564
+     */
565
+    public function get_tax() {
566
+        return $this->totals['taxes']['initial'];
567
+    }
568
+
569
+    /**
570
+     * Returns the recurring tax.
571
+     *
572
+     * @since 1.0.19
573
+     */
574
+    public function get_recurring_tax() {
575
+        return $this->totals['taxes']['recurring'];
576
+    }
577
+
578
+    /**
579
+     * Returns all taxes.
580
+     *
581
+     * @since 1.0.19
582
+     */
583
+    public function get_taxes() {
584
+        return $this->taxes;
585
+    }
586
+
587
+    /*
588 588
 	|--------------------------------------------------------------------------
589 589
 	| Discounts
590 590
 	|--------------------------------------------------------------------------
@@ -593,99 +593,99 @@  discard block
 block discarded – undo
593 593
 	| or only one-time. They also do not have to come from a discount code.
594 594
     */
595 595
 
596
-	/**
597
-	 * Prepares the submission's discount.
598
-	 *
599
-	 * @since 1.0.19
600
-	 */
601
-	public function process_discount() {
602
-
603
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
604
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
605
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
606
-
607
-		foreach ( $processor->discounts as $discount ) {
608
-			$this->add_discount( $discount );
609
-		}
610
-
611
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
612
-	}
613
-
614
-	/**
615
-	 * Adds a discount to the submission.
616
-	 *
617
-	 * @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.
618
-	 * @since 1.0.19
619
-	 */
620
-	public function add_discount( $discount ) {
621
-		$this->discounts[ $discount['name'] ]   = $discount;
622
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
623
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
624
-	}
625
-
626
-	/**
627
-	 * Removes a discount from the submission.
628
-	 *
629
-	 * @since 1.0.19
630
-	 */
631
-	public function remove_discount( $name ) {
632
-
633
-		if ( isset( $this->discounts[ $name ] ) ) {
634
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
635
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
636
-			unset( $this->discounts[ $name ] );
637
-		}
638
-
639
-	}
640
-
641
-	/**
642
-	 * Checks whether there is a discount code associated with this submission.
643
-	 *
644
-	 * @since 1.0.19
645
-	 * @return bool
646
-	 */
647
-	public function has_discount_code() {
648
-		return ! empty( $this->discounts['discount_code'] );
649
-	}
650
-
651
-	/**
652
-	 * Returns the discount code.
653
-	 *
654
-	 * @since 1.0.19
655
-	 * @return string
656
-	 */
657
-	public function get_discount_code() {
658
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
659
-	}
660
-
661
-	/**
662
-	 * Returns the discount.
663
-	 *
664
-	 * @since 1.0.19
665
-	 */
666
-	public function get_discount() {
667
-		return $this->totals['discount']['initial'];
668
-	}
669
-
670
-	/**
671
-	 * Returns the recurring discount.
672
-	 *
673
-	 * @since 1.0.19
674
-	 */
675
-	public function get_recurring_discount() {
676
-		return $this->totals['discount']['recurring'];
677
-	}
678
-
679
-	/**
680
-	 * Returns all discounts.
681
-	 *
682
-	 * @since 1.0.19
683
-	 */
684
-	public function get_discounts() {
685
-		return $this->discounts;
686
-	}
687
-
688
-	/*
596
+    /**
597
+     * Prepares the submission's discount.
598
+     *
599
+     * @since 1.0.19
600
+     */
601
+    public function process_discount() {
602
+
603
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
604
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
605
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
606
+
607
+        foreach ( $processor->discounts as $discount ) {
608
+            $this->add_discount( $discount );
609
+        }
610
+
611
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
612
+    }
613
+
614
+    /**
615
+     * Adds a discount to the submission.
616
+     *
617
+     * @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.
618
+     * @since 1.0.19
619
+     */
620
+    public function add_discount( $discount ) {
621
+        $this->discounts[ $discount['name'] ]   = $discount;
622
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
623
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
624
+    }
625
+
626
+    /**
627
+     * Removes a discount from the submission.
628
+     *
629
+     * @since 1.0.19
630
+     */
631
+    public function remove_discount( $name ) {
632
+
633
+        if ( isset( $this->discounts[ $name ] ) ) {
634
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
635
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
636
+            unset( $this->discounts[ $name ] );
637
+        }
638
+
639
+    }
640
+
641
+    /**
642
+     * Checks whether there is a discount code associated with this submission.
643
+     *
644
+     * @since 1.0.19
645
+     * @return bool
646
+     */
647
+    public function has_discount_code() {
648
+        return ! empty( $this->discounts['discount_code'] );
649
+    }
650
+
651
+    /**
652
+     * Returns the discount code.
653
+     *
654
+     * @since 1.0.19
655
+     * @return string
656
+     */
657
+    public function get_discount_code() {
658
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
659
+    }
660
+
661
+    /**
662
+     * Returns the discount.
663
+     *
664
+     * @since 1.0.19
665
+     */
666
+    public function get_discount() {
667
+        return $this->totals['discount']['initial'];
668
+    }
669
+
670
+    /**
671
+     * Returns the recurring discount.
672
+     *
673
+     * @since 1.0.19
674
+     */
675
+    public function get_recurring_discount() {
676
+        return $this->totals['discount']['recurring'];
677
+    }
678
+
679
+    /**
680
+     * Returns all discounts.
681
+     *
682
+     * @since 1.0.19
683
+     */
684
+    public function get_discounts() {
685
+        return $this->discounts;
686
+    }
687
+
688
+    /*
689 689
 	|--------------------------------------------------------------------------
690 690
 	| Fees
691 691
 	|--------------------------------------------------------------------------
@@ -695,89 +695,89 @@  discard block
 block discarded – undo
695 695
 	| fees.
696 696
     */
697 697
 
698
-	/**
699
-	 * Prepares the submission's fees.
700
-	 *
701
-	 * @since 1.0.19
702
-	 */
703
-	public function process_fees() {
704
-
705
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
706
-
707
-		foreach ( $fees_processor->fees as $fee ) {
708
-			$this->add_fee( $fee );
709
-		}
710
-
711
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
712
-	}
713
-
714
-	/**
715
-	 * Adds a fee to the submission.
716
-	 *
717
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
718
-	 * @since 1.0.19
719
-	 */
720
-	public function add_fee( $fee ) {
721
-
722
-		$this->fees[ $fee['name'] ]         = $fee;
723
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
724
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
725
-
726
-	}
727
-
728
-	/**
729
-	 * Removes a fee from the submission.
730
-	 *
731
-	 * @since 1.0.19
732
-	 */
733
-	public function remove_fee( $name ) {
734
-
735
-		if ( isset( $this->fees[ $name ] ) ) {
736
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
737
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
738
-			unset( $this->fees[ $name ] );
739
-		}
740
-
741
-	}
742
-
743
-	/**
744
-	 * Returns the fees.
745
-	 *
746
-	 * @since 1.0.19
747
-	 */
748
-	public function get_fee() {
749
-		return $this->totals['fees']['initial'];
750
-	}
751
-
752
-	/**
753
-	 * Returns the recurring fees.
754
-	 *
755
-	 * @since 1.0.19
756
-	 */
757
-	public function get_recurring_fee() {
758
-		return $this->totals['fees']['recurring'];
759
-	}
760
-
761
-	/**
762
-	 * Returns all fees.
763
-	 *
764
-	 * @since 1.0.19
765
-	 */
766
-	public function get_fees() {
767
-		return $this->fees;
768
-	}
769
-
770
-	/**
771
-	 * Checks if there are any fees for the form.
772
-	 *
773
-	 * @return bool
774
-	 * @since 1.0.19
775
-	 */
776
-	public function has_fees() {
777
-		return count( $this->fees ) !== 0;
778
-	}
779
-
780
-	/*
698
+    /**
699
+     * Prepares the submission's fees.
700
+     *
701
+     * @since 1.0.19
702
+     */
703
+    public function process_fees() {
704
+
705
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
706
+
707
+        foreach ( $fees_processor->fees as $fee ) {
708
+            $this->add_fee( $fee );
709
+        }
710
+
711
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
712
+    }
713
+
714
+    /**
715
+     * Adds a fee to the submission.
716
+     *
717
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
718
+     * @since 1.0.19
719
+     */
720
+    public function add_fee( $fee ) {
721
+
722
+        $this->fees[ $fee['name'] ]         = $fee;
723
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
724
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
725
+
726
+    }
727
+
728
+    /**
729
+     * Removes a fee from the submission.
730
+     *
731
+     * @since 1.0.19
732
+     */
733
+    public function remove_fee( $name ) {
734
+
735
+        if ( isset( $this->fees[ $name ] ) ) {
736
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
737
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
738
+            unset( $this->fees[ $name ] );
739
+        }
740
+
741
+    }
742
+
743
+    /**
744
+     * Returns the fees.
745
+     *
746
+     * @since 1.0.19
747
+     */
748
+    public function get_fee() {
749
+        return $this->totals['fees']['initial'];
750
+    }
751
+
752
+    /**
753
+     * Returns the recurring fees.
754
+     *
755
+     * @since 1.0.19
756
+     */
757
+    public function get_recurring_fee() {
758
+        return $this->totals['fees']['recurring'];
759
+    }
760
+
761
+    /**
762
+     * Returns all fees.
763
+     *
764
+     * @since 1.0.19
765
+     */
766
+    public function get_fees() {
767
+        return $this->fees;
768
+    }
769
+
770
+    /**
771
+     * Checks if there are any fees for the form.
772
+     *
773
+     * @return bool
774
+     * @since 1.0.19
775
+     */
776
+    public function has_fees() {
777
+        return count( $this->fees ) !== 0;
778
+    }
779
+
780
+    /*
781 781
 	|--------------------------------------------------------------------------
782 782
 	| MISC
783 783
 	|--------------------------------------------------------------------------
@@ -785,119 +785,119 @@  discard block
 block discarded – undo
785 785
 	| Extra submission functions.
786 786
     */
787 787
 
788
-	/**
789
-	 * Checks if this is the initial fetch.
790
-	 *
791
-	 * @return bool
792
-	 * @since 1.0.19
793
-	 */
794
-	public function is_initial_fetch() {
795
-		return empty( $this->data['initial_state'] );
796
-	}
797
-
798
-	/**
799
-	 * Returns the total amount to collect for this submission.
800
-	 *
801
-	 * @since 1.0.19
802
-	 */
803
-	public function get_total() {
804
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
805
-		return max( $total, 0 );
806
-	}
807
-
808
-	/**
809
-	 * Returns the recurring total amount to collect for this submission.
810
-	 *
811
-	 * @since 1.0.19
812
-	 */
813
-	public function get_recurring_total() {
814
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
815
-		return max( $total, 0 );
816
-	}
817
-
818
-	/**
819
-	 * Whether payment details should be collected for this submission.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function should_collect_payment_details() {
824
-		$initial   = $this->get_total();
825
-		$recurring = $this->get_recurring_total();
826
-
827
-		if ( $this->has_recurring == 0 ) {
828
-			$recurring = 0;
829
-		}
830
-
831
-		$collect = $initial > 0 || $recurring > 0;
832
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
833
-	}
834
-
835
-	/**
836
-	 * Returns the billing email of the user.
837
-	 *
838
-	 * @since 1.0.19
839
-	 */
840
-	public function get_billing_email() {
841
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
842
-	}
843
-
844
-	/**
845
-	 * Checks if the submitter has a billing email.
846
-	 *
847
-	 * @since 1.0.19
848
-	 */
849
-	public function has_billing_email() {
850
-		$billing_email = $this->get_billing_email();
851
-		return ! empty( $billing_email ) && is_email( $billing_email );
852
-	}
853
-
854
-	/**
855
-	 * Returns the appropriate currency for the submission.
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @return string
859
-	 */
860
-	public function get_currency() {
861
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
862
-    }
863
-
864
-    /**
865
-	 * Returns the raw submission data.
866
-	 *
867
-	 * @since 1.0.19
868
-	 * @return array
869
-	 */
870
-	public function get_data() {
871
-		return $this->data;
872
-	}
873
-
874
-	/**
875
-	 * Returns a field from the submission data
876
-	 *
877
-	 * @param string $field
878
-	 * @since 1.0.19
879
-	 * @return mixed|null
880
-	 */
881
-	public function get_field( $field, $sub_array_key = null ) {
882
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
883
-	}
884
-
885
-	/**
886
-	 * Checks if a required field is set.
887
-	 *
888
-	 * @since 1.0.19
889
-	 */
890
-	public function is_required_field_set( $field ) {
891
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
892
-	}
893
-
894
-	/**
895
-	 * Formats an amount
896
-	 *
897
-	 * @since 1.0.19
898
-	 */
899
-	public function format_amount( $amount ) {
900
-		return wpinv_price( $amount, $this->get_currency() );
901
-	}
788
+    /**
789
+     * Checks if this is the initial fetch.
790
+     *
791
+     * @return bool
792
+     * @since 1.0.19
793
+     */
794
+    public function is_initial_fetch() {
795
+        return empty( $this->data['initial_state'] );
796
+    }
797
+
798
+    /**
799
+     * Returns the total amount to collect for this submission.
800
+     *
801
+     * @since 1.0.19
802
+     */
803
+    public function get_total() {
804
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
805
+        return max( $total, 0 );
806
+    }
807
+
808
+    /**
809
+     * Returns the recurring total amount to collect for this submission.
810
+     *
811
+     * @since 1.0.19
812
+     */
813
+    public function get_recurring_total() {
814
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
815
+        return max( $total, 0 );
816
+    }
817
+
818
+    /**
819
+     * Whether payment details should be collected for this submission.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function should_collect_payment_details() {
824
+        $initial   = $this->get_total();
825
+        $recurring = $this->get_recurring_total();
826
+
827
+        if ( $this->has_recurring == 0 ) {
828
+            $recurring = 0;
829
+        }
830
+
831
+        $collect = $initial > 0 || $recurring > 0;
832
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
833
+    }
834
+
835
+    /**
836
+     * Returns the billing email of the user.
837
+     *
838
+     * @since 1.0.19
839
+     */
840
+    public function get_billing_email() {
841
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
842
+    }
843
+
844
+    /**
845
+     * Checks if the submitter has a billing email.
846
+     *
847
+     * @since 1.0.19
848
+     */
849
+    public function has_billing_email() {
850
+        $billing_email = $this->get_billing_email();
851
+        return ! empty( $billing_email ) && is_email( $billing_email );
852
+    }
853
+
854
+    /**
855
+     * Returns the appropriate currency for the submission.
856
+     *
857
+     * @since 1.0.19
858
+     * @return string
859
+     */
860
+    public function get_currency() {
861
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
862
+    }
863
+
864
+    /**
865
+     * Returns the raw submission data.
866
+     *
867
+     * @since 1.0.19
868
+     * @return array
869
+     */
870
+    public function get_data() {
871
+        return $this->data;
872
+    }
873
+
874
+    /**
875
+     * Returns a field from the submission data
876
+     *
877
+     * @param string $field
878
+     * @since 1.0.19
879
+     * @return mixed|null
880
+     */
881
+    public function get_field( $field, $sub_array_key = null ) {
882
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
883
+    }
884
+
885
+    /**
886
+     * Checks if a required field is set.
887
+     *
888
+     * @since 1.0.19
889
+     */
890
+    public function is_required_field_set( $field ) {
891
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
892
+    }
893
+
894
+    /**
895
+     * Formats an amount
896
+     *
897
+     * @since 1.0.19
898
+     */
899
+    public function format_amount( $amount ) {
900
+        return wpinv_price( $amount, $this->get_currency() );
901
+    }
902 902
 
903 903
 }
Please login to merge, or discard this patch.
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
 		$this->state   = wpinv_get_default_state();
150 150
 
151 151
 		// Do we have an actual submission?
152
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
153
-			$this->load_data( $_POST );
152
+		if (isset($_POST['getpaid_payment_form_submission'])) {
153
+			$this->load_data($_POST);
154 154
 		}
155 155
 
156 156
 	}
@@ -160,19 +160,19 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @param array $data
162 162
 	 */
163
-	public function load_data( $data ) {
163
+	public function load_data($data) {
164 164
 
165 165
 		// Remove slashes from the submitted data...
166
-		$data       = wp_unslash( $data );
166
+		$data       = wp_unslash($data);
167 167
 
168 168
 		// Allow plugins to filter the data.
169
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
169
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
170 170
 
171 171
 		// Cache it...
172 172
 		$this->data = $data;
173 173
 
174 174
 		// Then generate a unique id from the data.
175
-		$this->id   = md5( wp_json_encode( $data ) );
175
+		$this->id   = md5(wp_json_encode($data));
176 176
 
177 177
 		// Finally, process the submission.
178 178
 		try {
@@ -182,30 +182,30 @@  discard block
 block discarded – undo
182 182
 			$processors = apply_filters(
183 183
 				'getpaid_payment_form_submission_processors',
184 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' ),
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 191
 				),
192 192
 				$this		
193 193
 			);
194 194
 
195
-			foreach ( $processors as $processor ) {
196
-				call_user_func_array( $processor, array( &$this ) );
195
+			foreach ($processors as $processor) {
196
+				call_user_func_array($processor, array(&$this));
197 197
 			}
198 198
 
199
-		} catch( GetPaid_Payment_Exception $e ) {
199
+		} catch (GetPaid_Payment_Exception $e) {
200 200
 			$this->last_error      = $e->getMessage();
201 201
 			$this->last_error_code = $e->getErrorCode();
202
-		} catch ( Exception $e ) {
202
+		} catch (Exception $e) {
203 203
 			$this->last_error      = $e->getMessage();
204 204
 			$this->last_error_code = $e->getCode();
205 205
 		}
206 206
 
207 207
 		// Fired when we are done processing a submission.
208
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
208
+		do_action_ref_array('getpaid_process_submission', array(&$this));
209 209
 
210 210
 	}
211 211
 
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
 	public function process_payment_form() {
227 227
 
228 228
 		// Every submission needs an active payment form.
229
-		if ( empty( $this->data['form_id'] ) ) {
230
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
229
+		if (empty($this->data['form_id'])) {
230
+			throw new Exception(__('Missing payment form', 'invoicing'));
231 231
 		}
232 232
 
233 233
 		// Fetch the payment form.
234
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
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' ) );
236
+		if (!$this->payment_form->is_active()) {
237
+			throw new Exception(__('Payment form not active', 'invoicing'));
238 238
 		}
239 239
 
240
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
240
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
241 241
 	}
242 242
 
243 243
     /**
@@ -267,53 +267,53 @@  discard block
 block discarded – undo
267 267
 	public function process_invoice() {
268 268
 
269 269
 		// Abort if there is no invoice.
270
-		if ( empty( $this->data['invoice_id'] ) ) {
270
+		if (empty($this->data['invoice_id'])) {
271 271
 			return;
272 272
 		}
273 273
 
274 274
 		// If the submission is for an existing invoice, ensure that it exists
275 275
 		// and that it is not paid for.
276
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
276
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
277 277
 
278
-        if ( empty( $invoice ) ) {
279
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
278
+        if (empty($invoice)) {
279
+			throw new Exception(__('Invalid invoice', 'invoicing'));
280 280
 		}
281 281
 
282
-		if ( $invoice->is_paid() ) {
283
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
282
+		if ($invoice->is_paid()) {
283
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
284 284
 		}
285 285
 
286 286
 		$this->payment_form->invoice = $invoice;
287
-		if ( ! $this->payment_form->is_default() ) {
287
+		if (!$this->payment_form->is_default()) {
288 288
 
289 289
 			$items    = array();
290 290
 			$item_ids = array();
291 291
 	
292
-			foreach ( $invoice->get_items() as $item ) {
293
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
292
+			foreach ($invoice->get_items() as $item) {
293
+				if (!in_array($item->get_id(), $item_ids)) {
294 294
 					$item_ids[] = $item->get_id();
295 295
 					$items[]    = $item;
296 296
 				}
297 297
 			}
298 298
 	
299
-			foreach ( $this->payment_form->get_items() as $item ) {
300
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
299
+			foreach ($this->payment_form->get_items() as $item) {
300
+				if (!in_array($item->get_id(), $item_ids)) {
301 301
 					$item_ids[] = $item->get_id();
302 302
 					$items[]    = $item;
303 303
 				}
304 304
 			}
305 305
 	
306
-			$this->payment_form->set_items( $items );
306
+			$this->payment_form->set_items($items);
307 307
 	
308 308
 		} else {
309
-			$this->payment_form->set_items( $invoice->get_items() );
309
+			$this->payment_form->set_items($invoice->get_items());
310 310
 		}
311 311
 
312 312
 		$this->country = $invoice->get_country();
313 313
 		$this->state   = $invoice->get_state();
314 314
 		$this->invoice = $invoice;
315 315
 
316
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
316
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
317 317
 	}
318 318
 
319 319
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return bool
334 334
 	 */
335 335
 	public function has_invoice() {
336
-		return ! empty( $this->invoice );
336
+		return !empty($this->invoice);
337 337
 	}
338 338
 
339 339
 	/*
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 	 */
353 353
 	public function process_items() {
354 354
 
355
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
355
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
356 356
 
357
-		foreach ( $processor->items as $item ) {
358
-			$this->add_item( $item );
357
+		foreach ($processor->items as $item) {
358
+			$this->add_item($item);
359 359
 		}
360 360
 
361
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
361
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
362 362
 	}
363 363
 
364 364
 	/**
@@ -367,18 +367,18 @@  discard block
 block discarded – undo
367 367
 	 * @since 1.0.19
368 368
 	 * @param GetPaid_Form_Item $item
369 369
 	 */
370
-	public function add_item( $item ) {
370
+	public function add_item($item) {
371 371
 
372 372
 		// Make sure that it is available for purchase.
373
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
373
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
374 374
 			return;
375 375
 		}
376 376
 
377 377
 		// Each submission can only contain one recurring item.
378
-		if ( $item->is_recurring() ) {
378
+		if ($item->is_recurring()) {
379 379
 
380
-			if ( $this->has_recurring != 0 ) {
381
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
380
+			if ($this->has_recurring != 0) {
381
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
382 382
 			}
383 383
 
384 384
 			$this->has_recurring = $item->get_id();
@@ -386,11 +386,11 @@  discard block
 block discarded – undo
386 386
 		}
387 387
 
388 388
 		// Update the items and totals.
389
-		$this->items[ $item->get_id() ]         = $item;
389
+		$this->items[$item->get_id()]         = $item;
390 390
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
391 391
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
392 392
 
393
-		$this->subscription_groups = getpaid_calculate_subscription_totals( $this );
393
+		$this->subscription_groups = getpaid_calculate_subscription_totals($this);
394 394
 	}
395 395
 
396 396
 	/**
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
401 401
 	 *
402 402
 	 * @since 1.0.19
403 403
 	 */
404
-	public function remove_item( $item_id ) {
404
+	public function remove_item($item_id) {
405 405
 
406
-		if ( isset( $this->items[ $item_id ] ) ) {
407
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
408
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
406
+		if (isset($this->items[$item_id])) {
407
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
408
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
409 409
 
410
-			if ( $this->items[ $item_id ]->is_recurring() ) {
410
+			if ($this->items[$item_id]->is_recurring()) {
411 411
 				$this->has_recurring = 0;
412 412
 			}
413 413
 
414
-			unset( $this->items[ $item_id ] );
414
+			unset($this->items[$item_id]);
415 415
 		}
416 416
 
417 417
 	}
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 	 */
424 424
 	public function get_subtotal() {
425 425
 
426
-		if ( wpinv_prices_include_tax() ) {
426
+		if (wpinv_prices_include_tax()) {
427 427
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
428 428
 		}
429 429
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 */
438 438
 	public function get_recurring_subtotal() {
439 439
 
440
-		if ( wpinv_prices_include_tax() ) {
440
+		if (wpinv_prices_include_tax()) {
441 441
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
442 442
 		}
443 443
 
@@ -471,39 +471,39 @@  discard block
 block discarded – undo
471 471
 	public function process_taxes() {
472 472
 
473 473
 		// Abort if we're not using taxes.
474
-		if ( ! $this->use_taxes() ) {
474
+		if (!$this->use_taxes()) {
475 475
 			return;
476 476
 		}
477 477
 
478 478
 		// If a custom country && state has been passed in, use it to calculate taxes.
479
-		$country = $this->get_field( 'wpinv_country', 'billing' );
480
-		if ( ! empty( $country ) ) {
479
+		$country = $this->get_field('wpinv_country', 'billing');
480
+		if (!empty($country)) {
481 481
 			$this->country = $country;
482 482
 		}
483 483
 
484
-		$state = $this->get_field( 'wpinv_state', 'billing' );
485
-		if ( ! empty( $state ) ) {
484
+		$state = $this->get_field('wpinv_state', 'billing');
485
+		if (!empty($state)) {
486 486
 			$this->state = $state;
487 487
 		}
488 488
 
489 489
 		// Confirm if the provided country and the ip country are similar.
490
-		$address_confirmed = $this->get_field( 'confirm-address' );
491
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
492
-			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' ) );
490
+		$address_confirmed = $this->get_field('confirm-address');
491
+		if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
492
+			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'));
493 493
 		}
494 494
 
495 495
 		// Abort if the country is not taxable.
496
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
496
+		if (!wpinv_is_country_taxable($this->country)) {
497 497
 			return;
498 498
 		}
499 499
 
500
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
500
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
501 501
 
502
-		foreach ( $processor->taxes as $tax ) {
503
-			$this->add_tax( $tax );
502
+		foreach ($processor->taxes as $tax) {
503
+			$this->add_tax($tax);
504 504
 		}
505 505
 
506
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
506
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
507 507
 	}
508 508
 
509 509
 	/**
@@ -512,16 +512,16 @@  discard block
 block discarded – undo
512 512
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
513 513
 	 * @since 1.0.19
514 514
 	 */
515
-	public function add_tax( $tax ) {
515
+	public function add_tax($tax) {
516 516
 
517
-		if ( wpinv_round_tax_per_tax_rate() ) {
518
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
519
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
517
+		if (wpinv_round_tax_per_tax_rate()) {
518
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
519
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
520 520
 		}
521 521
 
522
-		$this->taxes[ $tax['name'] ]         = $tax;
523
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
524
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
522
+		$this->taxes[$tax['name']]         = $tax;
523
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
524
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
525 525
 
526 526
 	}
527 527
 
@@ -530,12 +530,12 @@  discard block
 block discarded – undo
530 530
 	 *
531 531
 	 * @since 1.0.19
532 532
 	 */
533
-	public function remove_tax( $tax_name ) {
533
+	public function remove_tax($tax_name) {
534 534
 
535
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
536
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
537
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
538
-			unset( $this->taxes[ $tax_name ] );
535
+		if (isset($this->taxes[$tax_name])) {
536
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
537
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
538
+			unset($this->taxes[$tax_name]);
539 539
 		}
540 540
 
541 541
 	}
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
 
550 550
 		$use_taxes = wpinv_use_taxes();
551 551
 
552
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
552
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
553 553
 			$use_taxes = false;
554 554
 		}
555 555
 
556
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
556
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
557 557
 
558 558
 	}
559 559
 
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
 
603 603
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
604 604
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
605
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
605
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
606 606
 
607
-		foreach ( $processor->discounts as $discount ) {
608
-			$this->add_discount( $discount );
607
+		foreach ($processor->discounts as $discount) {
608
+			$this->add_discount($discount);
609 609
 		}
610 610
 
611
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
611
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
612 612
 	}
613 613
 
614 614
 	/**
@@ -617,10 +617,10 @@  discard block
 block discarded – undo
617 617
 	 * @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.
618 618
 	 * @since 1.0.19
619 619
 	 */
620
-	public function add_discount( $discount ) {
621
-		$this->discounts[ $discount['name'] ]   = $discount;
622
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
623
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
620
+	public function add_discount($discount) {
621
+		$this->discounts[$discount['name']]   = $discount;
622
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
623
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
624 624
 	}
625 625
 
626 626
 	/**
@@ -628,12 +628,12 @@  discard block
 block discarded – undo
628 628
 	 *
629 629
 	 * @since 1.0.19
630 630
 	 */
631
-	public function remove_discount( $name ) {
631
+	public function remove_discount($name) {
632 632
 
633
-		if ( isset( $this->discounts[ $name ] ) ) {
634
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
635
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
636
-			unset( $this->discounts[ $name ] );
633
+		if (isset($this->discounts[$name])) {
634
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
635
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
636
+			unset($this->discounts[$name]);
637 637
 		}
638 638
 
639 639
 	}
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	 * @return bool
646 646
 	 */
647 647
 	public function has_discount_code() {
648
-		return ! empty( $this->discounts['discount_code'] );
648
+		return !empty($this->discounts['discount_code']);
649 649
 	}
650 650
 
651 651
 	/**
@@ -702,13 +702,13 @@  discard block
 block discarded – undo
702 702
 	 */
703 703
 	public function process_fees() {
704 704
 
705
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
705
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
706 706
 
707
-		foreach ( $fees_processor->fees as $fee ) {
708
-			$this->add_fee( $fee );
707
+		foreach ($fees_processor->fees as $fee) {
708
+			$this->add_fee($fee);
709 709
 		}
710 710
 
711
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
711
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
712 712
 	}
713 713
 
714 714
 	/**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
718 718
 	 * @since 1.0.19
719 719
 	 */
720
-	public function add_fee( $fee ) {
720
+	public function add_fee($fee) {
721 721
 
722
-		$this->fees[ $fee['name'] ]         = $fee;
723
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
724
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
722
+		$this->fees[$fee['name']]         = $fee;
723
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
724
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
725 725
 
726 726
 	}
727 727
 
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
 	 *
731 731
 	 * @since 1.0.19
732 732
 	 */
733
-	public function remove_fee( $name ) {
733
+	public function remove_fee($name) {
734 734
 
735
-		if ( isset( $this->fees[ $name ] ) ) {
736
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
737
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
738
-			unset( $this->fees[ $name ] );
735
+		if (isset($this->fees[$name])) {
736
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
737
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
738
+			unset($this->fees[$name]);
739 739
 		}
740 740
 
741 741
 	}
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 	 * @since 1.0.19
775 775
 	 */
776 776
 	public function has_fees() {
777
-		return count( $this->fees ) !== 0;
777
+		return count($this->fees) !== 0;
778 778
 	}
779 779
 
780 780
 	/*
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 * @since 1.0.19
793 793
 	 */
794 794
 	public function is_initial_fetch() {
795
-		return empty( $this->data['initial_state'] );
795
+		return empty($this->data['initial_state']);
796 796
 	}
797 797
 
798 798
 	/**
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	 */
803 803
 	public function get_total() {
804 804
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
805
-		return max( $total, 0 );
805
+		return max($total, 0);
806 806
 	}
807 807
 
808 808
 	/**
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 	 */
813 813
 	public function get_recurring_total() {
814 814
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
815
-		return max( $total, 0 );
815
+		return max($total, 0);
816 816
 	}
817 817
 
818 818
 	/**
@@ -824,12 +824,12 @@  discard block
 block discarded – undo
824 824
 		$initial   = $this->get_total();
825 825
 		$recurring = $this->get_recurring_total();
826 826
 
827
-		if ( $this->has_recurring == 0 ) {
827
+		if ($this->has_recurring == 0) {
828 828
 			$recurring = 0;
829 829
 		}
830 830
 
831 831
 		$collect = $initial > 0 || $recurring > 0;
832
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
832
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
833 833
 	}
834 834
 
835 835
 	/**
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 */
840 840
 	public function get_billing_email() {
841
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
841
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
842 842
 	}
843 843
 
844 844
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 */
849 849
 	public function has_billing_email() {
850 850
 		$billing_email = $this->get_billing_email();
851
-		return ! empty( $billing_email ) && is_email( $billing_email );
851
+		return !empty($billing_email) && is_email($billing_email);
852 852
 	}
853 853
 
854 854
 	/**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 * @since 1.0.19
879 879
 	 * @return mixed|null
880 880
 	 */
881
-	public function get_field( $field, $sub_array_key = null ) {
882
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
881
+	public function get_field($field, $sub_array_key = null) {
882
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
883 883
 	}
884 884
 
885 885
 	/**
@@ -887,8 +887,8 @@  discard block
 block discarded – undo
887 887
 	 *
888 888
 	 * @since 1.0.19
889 889
 	 */
890
-	public function is_required_field_set( $field ) {
891
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
890
+	public function is_required_field_set($field) {
891
+		return empty($field['required']) || !empty($this->data[$field['id']]);
892 892
 	}
893 893
 
894 894
 	/**
@@ -896,8 +896,8 @@  discard block
 block discarded – undo
896 896
 	 *
897 897
 	 * @since 1.0.19
898 898
 	 */
899
-	public function format_amount( $amount ) {
900
-		return wpinv_price( $amount, $this->get_currency() );
899
+	public function format_amount($amount) {
900
+		return wpinv_price($amount, $this->get_currency());
901 901
 	}
902 902
 
903 903
 }
Please login to merge, or discard this patch.