Passed
Push — master ( f4e65e...f09852 )
by Brian
05:33
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -12,285 +12,285 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$this->add_totals( $submission );
37
-		$this->add_texts( $submission );
38
-		$this->add_items( $submission );
39
-		$this->add_fees( $submission );
40
-		$this->add_discounts( $submission );
41
-		$this->add_taxes( $submission );
42
-		$this->add_gateways( $submission );
43
-		$this->add_data( $submission );
44
-
45
-	}
46
-
47
-	/**
48
-	 * Adds totals to a response for submission refresh prices.
49
-	 *
50
-	 * @param GetPaid_Payment_Form_Submission $submission
51
-	 */
52
-	public function add_totals( $submission ) {
53
-
54
-		$this->response = array_merge(
55
-			$this->response,
56
-			array(
57
-
58
-				'totals'        => array(
59
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
61
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
62
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
63
-					'total'     => $submission->format_amount( $submission->get_total() ),
64
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
-				),
66
-
67
-				'recurring'     => array(
68
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
-				),
74
-
75
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
-				'currency'      => $submission->get_currency(),
77
-
78
-			)
79
-		);
80
-
81
-	}
82
-
83
-	/**
84
-	 * Adds texts to a response for submission refresh prices.
85
-	 *
86
-	 * @param GetPaid_Payment_Form_Submission $submission
87
-	 */
88
-	public function add_texts( $submission ) {
89
-
90
-		$payable = $submission->format_amount( $submission->get_total() );
91
-		$groups  = getpaid_get_subscription_groups( $submission );
92
-
93
-		if ( $submission->has_recurring != 0 && 2 > $groups ) {
94
-
95
-			$recurring = new WPInv_Item( $submission->has_recurring );
96
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
-
98
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
99
-				$payable = "$payable / $period";
100
-			} else {
101
-				$payable = sprintf(
102
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
103
-					$submission->format_amount( $submission->get_total() ),
104
-					$submission->format_amount( $submission->get_recurring_total() ),
105
-					$period
106
-				);
107
-			}
108
-
109
-		}
110
-
111
-		$texts = array(
112
-			'.getpaid-checkout-total-payable' => $payable,
113
-		);
114
-
115
-		foreach ( $submission->get_items() as $item ) {
116
-			$item_id                                               = $item->get_id();
117
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
118
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
119
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
120
-		}
121
-
122
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
123
-
124
-	}
125
-
126
-	/**
127
-	 * Adds items to a response for submission refresh prices.
128
-	 *
129
-	 * @param GetPaid_Payment_Form_Submission $submission
130
-	 */
131
-	public function add_items( $submission ) {
132
-
133
-		// Add items.
134
-		$items = array();
34
+        );
35
+
36
+        $this->add_totals( $submission );
37
+        $this->add_texts( $submission );
38
+        $this->add_items( $submission );
39
+        $this->add_fees( $submission );
40
+        $this->add_discounts( $submission );
41
+        $this->add_taxes( $submission );
42
+        $this->add_gateways( $submission );
43
+        $this->add_data( $submission );
44
+
45
+    }
46
+
47
+    /**
48
+     * Adds totals to a response for submission refresh prices.
49
+     *
50
+     * @param GetPaid_Payment_Form_Submission $submission
51
+     */
52
+    public function add_totals( $submission ) {
53
+
54
+        $this->response = array_merge(
55
+            $this->response,
56
+            array(
57
+
58
+                'totals'        => array(
59
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
61
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
62
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
63
+                    'total'     => $submission->format_amount( $submission->get_total() ),
64
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
+                ),
66
+
67
+                'recurring'     => array(
68
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
+                ),
74
+
75
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
+                'currency'      => $submission->get_currency(),
77
+
78
+            )
79
+        );
80
+
81
+    }
82
+
83
+    /**
84
+     * Adds texts to a response for submission refresh prices.
85
+     *
86
+     * @param GetPaid_Payment_Form_Submission $submission
87
+     */
88
+    public function add_texts( $submission ) {
89
+
90
+        $payable = $submission->format_amount( $submission->get_total() );
91
+        $groups  = getpaid_get_subscription_groups( $submission );
92
+
93
+        if ( $submission->has_recurring != 0 && 2 > $groups ) {
94
+
95
+            $recurring = new WPInv_Item( $submission->has_recurring );
96
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
+
98
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
99
+                $payable = "$payable / $period";
100
+            } else {
101
+                $payable = sprintf(
102
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
103
+                    $submission->format_amount( $submission->get_total() ),
104
+                    $submission->format_amount( $submission->get_recurring_total() ),
105
+                    $period
106
+                );
107
+            }
108
+
109
+        }
110
+
111
+        $texts = array(
112
+            '.getpaid-checkout-total-payable' => $payable,
113
+        );
114
+
115
+        foreach ( $submission->get_items() as $item ) {
116
+            $item_id                                               = $item->get_id();
117
+            $initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
118
+            $recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
119
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
120
+        }
121
+
122
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
123
+
124
+    }
125
+
126
+    /**
127
+     * Adds items to a response for submission refresh prices.
128
+     *
129
+     * @param GetPaid_Payment_Form_Submission $submission
130
+     */
131
+    public function add_items( $submission ) {
132
+
133
+        // Add items.
134
+        $items = array();
135 135
 
136 136
         foreach ( $submission->get_items() as $item ) {
137
-			$item_id           = $item->get_id();
138
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
139
-		}
137
+            $item_id           = $item->get_id();
138
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
139
+        }
140 140
 
141
-		$this->response = array_merge(
142
-			$this->response,
143
-			array( 'items' => $items )
144
-		);
141
+        $this->response = array_merge(
142
+            $this->response,
143
+            array( 'items' => $items )
144
+        );
145 145
 
146
-	}
146
+    }
147 147
 
148
-	/**
149
-	 * Adds fees to a response for submission refresh prices.
150
-	 *
151
-	 * @param GetPaid_Payment_Form_Submission $submission
152
-	 */
153
-	public function add_fees( $submission ) {
148
+    /**
149
+     * Adds fees to a response for submission refresh prices.
150
+     *
151
+     * @param GetPaid_Payment_Form_Submission $submission
152
+     */
153
+    public function add_fees( $submission ) {
154 154
 
155
-		$fees = array();
155
+        $fees = array();
156 156
 
157 157
         foreach ( $submission->get_fees() as $name => $data ) {
158
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
159
-		}
158
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
159
+        }
160 160
 
161
-		$this->response = array_merge(
162
-			$this->response,
163
-			array( 'fees' => $fees )
164
-		);
161
+        $this->response = array_merge(
162
+            $this->response,
163
+            array( 'fees' => $fees )
164
+        );
165 165
 
166
-	}
166
+    }
167 167
 
168
-	/**
169
-	 * Adds discounts to a response for submission refresh prices.
170
-	 *
171
-	 * @param GetPaid_Payment_Form_Submission $submission
172
-	 */
173
-	public function add_discounts( $submission ) {
168
+    /**
169
+     * Adds discounts to a response for submission refresh prices.
170
+     *
171
+     * @param GetPaid_Payment_Form_Submission $submission
172
+     */
173
+    public function add_discounts( $submission ) {
174 174
 
175
-		$discounts = array();
175
+        $discounts = array();
176 176
 
177 177
         foreach ( $submission->get_discounts() as $name => $data ) {
178
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
179
-		}
180
-
181
-		$this->response = array_merge(
182
-			$this->response,
183
-			array( 'discounts' => $discounts )
184
-		);
178
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
179
+        }
185 180
 
186
-	}
181
+        $this->response = array_merge(
182
+            $this->response,
183
+            array( 'discounts' => $discounts )
184
+        );
187 185
 
188
-	/**
189
-	 * Adds taxes to a response for submission refresh prices.
190
-	 *
191
-	 * @param GetPaid_Payment_Form_Submission $submission
192
-	 */
193
-	public function add_taxes( $submission ) {
186
+    }
194 187
 
195
-		$taxes  = array();
196
-		$markup = '';
188
+    /**
189
+     * Adds taxes to a response for submission refresh prices.
190
+     *
191
+     * @param GetPaid_Payment_Form_Submission $submission
192
+     */
193
+    public function add_taxes( $submission ) {
194
+
195
+        $taxes  = array();
196
+        $markup = '';
197 197
         foreach ( $submission->get_taxes() as $name => $data ) {
198
-			$name          = sanitize_text_field( $name );
199
-			$amount        = $submission->format_amount( $data['initial_tax'] );
200
-			$taxes[$name]  = $amount;
201
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
202
-		}
203
-
204
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
205
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
206
-		}
207
-
208
-		$this->response = array_merge(
209
-			$this->response,
210
-			array( 'taxes' => $taxes )
211
-		);
212
-
213
-	}
214
-
215
-	/**
216
-	 * Adds gateways to a response for submission refresh prices.
217
-	 *
218
-	 * @param GetPaid_Payment_Form_Submission $submission
219
-	 */
220
-	public function add_gateways( $submission ) {
221
-
222
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
223
-
224
-		if ( $this->response['has_recurring'] ) {
225
-
226
-			foreach ( $gateways as $i => $gateway ) {
227
-
228
-				if (
229
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
230
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
231
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
232
-					unset( $gateways[ $i ] );
233
-				}
234
-
235
-			}
236
-
237
-		}
238
-
239
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
240
-		$this->response = array_merge(
241
-			$this->response,
242
-			array( 'gateways' => $gateways )
243
-		);
244
-
245
-	}
246
-
247
-	/**
248
-	 * Standardizes prices.
249
-	 *
250
-	 * @param int $item_id
251
-	 * @param float $item_total
252
-	 * @param string $discount_code
253
-	 * @param bool $recurring
254
-	 */
255
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
256
-
257
-		$standardadized_price = $item_total;
258
-
259
-		// Do we have a $discount_code?
260
-		if ( ! empty( $discount_code ) ) {
261
-
262
-			$discount = new WPInv_Discount( $discount_code );
263
-
264
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
265
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
266
-			}
267
-
268
-		}
269
-
270
-    	return max( 0, $standardadized_price );
271
-
272
-	}
273
-
274
-	/**
275
-	 * Adds data to a response for submission refresh prices.
276
-	 *
277
-	 * @param GetPaid_Payment_Form_Submission $submission
278
-	 */
279
-	public function add_data( $submission ) {
280
-
281
-		$this->response = array_merge(
282
-			$this->response,
283
-			array(
284
-				'js_data' => apply_filters(
285
-					'getpaid_submission_js_data',
286
-					array(
287
-						'is_recurring' => $this->response['has_recurring'],
288
-					),
289
-					$submission
290
-				)
291
-			)
292
-		);
293
-
294
-	}
198
+            $name          = sanitize_text_field( $name );
199
+            $amount        = $submission->format_amount( $data['initial_tax'] );
200
+            $taxes[$name]  = $amount;
201
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
202
+        }
203
+
204
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
205
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
206
+        }
207
+
208
+        $this->response = array_merge(
209
+            $this->response,
210
+            array( 'taxes' => $taxes )
211
+        );
212
+
213
+    }
214
+
215
+    /**
216
+     * Adds gateways to a response for submission refresh prices.
217
+     *
218
+     * @param GetPaid_Payment_Form_Submission $submission
219
+     */
220
+    public function add_gateways( $submission ) {
221
+
222
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
223
+
224
+        if ( $this->response['has_recurring'] ) {
225
+
226
+            foreach ( $gateways as $i => $gateway ) {
227
+
228
+                if (
229
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
230
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
231
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
232
+                    unset( $gateways[ $i ] );
233
+                }
234
+
235
+            }
236
+
237
+        }
238
+
239
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
240
+        $this->response = array_merge(
241
+            $this->response,
242
+            array( 'gateways' => $gateways )
243
+        );
244
+
245
+    }
246
+
247
+    /**
248
+     * Standardizes prices.
249
+     *
250
+     * @param int $item_id
251
+     * @param float $item_total
252
+     * @param string $discount_code
253
+     * @param bool $recurring
254
+     */
255
+    public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
256
+
257
+        $standardadized_price = $item_total;
258
+
259
+        // Do we have a $discount_code?
260
+        if ( ! empty( $discount_code ) ) {
261
+
262
+            $discount = new WPInv_Discount( $discount_code );
263
+
264
+            if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
265
+                $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
266
+            }
267
+
268
+        }
269
+
270
+        return max( 0, $standardadized_price );
271
+
272
+    }
273
+
274
+    /**
275
+     * Adds data to a response for submission refresh prices.
276
+     *
277
+     * @param GetPaid_Payment_Form_Submission $submission
278
+     */
279
+    public function add_data( $submission ) {
280
+
281
+        $this->response = array_merge(
282
+            $this->response,
283
+            array(
284
+                'js_data' => apply_filters(
285
+                    'getpaid_submission_js_data',
286
+                    array(
287
+                        'is_recurring' => $this->response['has_recurring'],
288
+                    ),
289
+                    $submission
290
+                )
291
+            )
292
+        );
293
+
294
+    }
295 295
 
296 296
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +818 added lines, -818 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,198 +10,198 @@  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
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-	/**
127
-	 * The last error code.
128
-	 *
129
-	 * @var string
130
-	 */
131
-	public $last_error_code = null;
132
-
133
-    /**
134
-	 * Class constructor.
135
-	 *
136
-	 */
137
-	public function __construct() {
138
-
139
-		// Set the state and country to the default state and country.
140
-		$this->country = wpinv_default_billing_country();
141
-		$this->state   = wpinv_get_default_state();
142
-
143
-		// Do we have an actual submission?
144
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
-			$this->load_data( $_POST );
146
-		}
147
-
148
-	}
149
-
150
-	/**
151
-	 * Loads submission data.
152
-	 *
153
-	 * @param array $data
154
-	 */
155
-	public function load_data( $data ) {
156
-
157
-		// Remove slashes from the submitted data...
158
-		$data       = wp_unslash( $data );
159
-
160
-		// Allow plugins to filter the data.
161
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
-
163
-		// Cache it...
164
-		$this->data = $data;
165
-
166
-		// Then generate a unique id from the data.
167
-		$this->id   = md5( wp_json_encode( $data ) );
168
-
169
-		// Finally, process the submission.
170
-		try {
171
-
172
-			// Each process is passed an instance of the class (with reference)
173
-			// and should throw an Exception whenever it encounters one.
174
-			$processors = apply_filters(
175
-				'getpaid_payment_form_submission_processors',
176
-				array(
177
-					array( $this, 'process_payment_form' ),
178
-					array( $this, 'process_invoice' ),
179
-					array( $this, 'process_fees' ),
180
-					array( $this, 'process_items' ),
181
-					array( $this, 'process_discount' ),
182
-					array( $this, 'process_taxes' ),
183
-				),
184
-				$this		
185
-			);
186
-
187
-			foreach ( $processors as $processor ) {
188
-				call_user_func_array( $processor, array( &$this ) );
189
-			}
190
-
191
-		} catch( GetPaid_Payment_Exception $e ) {
192
-			$this->last_error      = $e->getMessage();
193
-			$this->last_error_code = $e->getErrorCode();
194
-		} catch ( Exception $e ) {
195
-			$this->last_error      = $e->getMessage();
196
-			$this->last_error_code = $e->getCode();
197
-		}
198
-
199
-		// Fired when we are done processing a submission.
200
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
-
202
-	}
203
-
204
-	/*
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
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * The last error code.
128
+     *
129
+     * @var string
130
+     */
131
+    public $last_error_code = null;
132
+
133
+    /**
134
+     * Class constructor.
135
+     *
136
+     */
137
+    public function __construct() {
138
+
139
+        // Set the state and country to the default state and country.
140
+        $this->country = wpinv_default_billing_country();
141
+        $this->state   = wpinv_get_default_state();
142
+
143
+        // Do we have an actual submission?
144
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
+            $this->load_data( $_POST );
146
+        }
147
+
148
+    }
149
+
150
+    /**
151
+     * Loads submission data.
152
+     *
153
+     * @param array $data
154
+     */
155
+    public function load_data( $data ) {
156
+
157
+        // Remove slashes from the submitted data...
158
+        $data       = wp_unslash( $data );
159
+
160
+        // Allow plugins to filter the data.
161
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
+
163
+        // Cache it...
164
+        $this->data = $data;
165
+
166
+        // Then generate a unique id from the data.
167
+        $this->id   = md5( wp_json_encode( $data ) );
168
+
169
+        // Finally, process the submission.
170
+        try {
171
+
172
+            // Each process is passed an instance of the class (with reference)
173
+            // and should throw an Exception whenever it encounters one.
174
+            $processors = apply_filters(
175
+                'getpaid_payment_form_submission_processors',
176
+                array(
177
+                    array( $this, 'process_payment_form' ),
178
+                    array( $this, 'process_invoice' ),
179
+                    array( $this, 'process_fees' ),
180
+                    array( $this, 'process_items' ),
181
+                    array( $this, 'process_discount' ),
182
+                    array( $this, 'process_taxes' ),
183
+                ),
184
+                $this		
185
+            );
186
+
187
+            foreach ( $processors as $processor ) {
188
+                call_user_func_array( $processor, array( &$this ) );
189
+            }
190
+
191
+        } catch( GetPaid_Payment_Exception $e ) {
192
+            $this->last_error      = $e->getMessage();
193
+            $this->last_error_code = $e->getErrorCode();
194
+        } catch ( Exception $e ) {
195
+            $this->last_error      = $e->getMessage();
196
+            $this->last_error_code = $e->getCode();
197
+        }
198
+
199
+        // Fired when we are done processing a submission.
200
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
+
202
+    }
203
+
204
+    /*
205 205
 	|--------------------------------------------------------------------------
206 206
 	| Payment Forms.
207 207
 	|--------------------------------------------------------------------------
@@ -210,39 +210,39 @@  discard block
 block discarded – undo
210 210
 	| submission has an active payment form etc.
211 211
     */
212 212
 
213
-	/**
214
-	 * Prepares the submission's payment form.
215
-	 *
216
-	 * @since 1.0.19
217
-	 */
218
-	public function process_payment_form() {
213
+    /**
214
+     * Prepares the submission's payment form.
215
+     *
216
+     * @since 1.0.19
217
+     */
218
+    public function process_payment_form() {
219 219
 
220
-		// Every submission needs an active payment form.
221
-		if ( empty( $this->data['form_id'] ) ) {
222
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
-		}
220
+        // Every submission needs an active payment form.
221
+        if ( empty( $this->data['form_id'] ) ) {
222
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
+        }
224 224
 
225
-		// Fetch the payment form.
226
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
225
+        // Fetch the payment form.
226
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
227 227
 
228
-		if ( ! $this->payment_form->is_active() ) {
229
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
-		}
228
+        if ( ! $this->payment_form->is_active() ) {
229
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
+        }
231 231
 
232
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
-	}
232
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
+    }
234 234
 
235 235
     /**
236
-	 * Returns the payment form.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return GetPaid_Payment_Form
240
-	 */
241
-	public function get_payment_form() {
242
-		return $this->payment_form;
243
-	}
236
+     * Returns the payment form.
237
+     *
238
+     * @since 1.0.19
239
+     * @return GetPaid_Payment_Form
240
+     */
241
+    public function get_payment_form() {
242
+        return $this->payment_form;
243
+    }
244 244
 
245
-	/*
245
+    /*
246 246
 	|--------------------------------------------------------------------------
247 247
 	| Invoices.
248 248
 	|--------------------------------------------------------------------------
@@ -251,84 +251,84 @@  discard block
 block discarded – undo
251 251
 	| might be for an existing invoice.
252 252
 	*/
253 253
 
254
-	/**
255
-	 * Prepares the submission's invoice.
256
-	 *
257
-	 * @since 1.0.19
258
-	 */
259
-	public function process_invoice() {
254
+    /**
255
+     * Prepares the submission's invoice.
256
+     *
257
+     * @since 1.0.19
258
+     */
259
+    public function process_invoice() {
260 260
 
261
-		// Abort if there is no invoice.
262
-		if ( empty( $this->data['invoice_id'] ) ) {
263
-			return;
264
-		}
261
+        // Abort if there is no invoice.
262
+        if ( empty( $this->data['invoice_id'] ) ) {
263
+            return;
264
+        }
265 265
 
266
-		// If the submission is for an existing invoice, ensure that it exists
267
-		// and that it is not paid for.
268
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
266
+        // If the submission is for an existing invoice, ensure that it exists
267
+        // and that it is not paid for.
268
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
269 269
 
270 270
         if ( empty( $invoice ) ) {
271
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
-		}
271
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
+        }
273 273
 
274
-		if ( $invoice->is_paid() ) {
275
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
-		}
274
+        if ( $invoice->is_paid() ) {
275
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
+        }
277 277
 
278
-		$this->payment_form->invoice = $invoice;
279
-		if ( ! $this->payment_form->is_default() ) {
278
+        $this->payment_form->invoice = $invoice;
279
+        if ( ! $this->payment_form->is_default() ) {
280 280
 
281
-			$items    = array();
282
-			$item_ids = array();
281
+            $items    = array();
282
+            $item_ids = array();
283 283
 	
284
-			foreach ( $invoice->get_items() as $item ) {
285
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
-					$item_ids[] = $item->get_id();
287
-					$items[]    = $item;
288
-				}
289
-			}
284
+            foreach ( $invoice->get_items() as $item ) {
285
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
+                    $item_ids[] = $item->get_id();
287
+                    $items[]    = $item;
288
+                }
289
+            }
290 290
 	
291
-			foreach ( $this->payment_form->get_items() as $item ) {
292
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
-					$item_ids[] = $item->get_id();
294
-					$items[]    = $item;
295
-				}
296
-			}
291
+            foreach ( $this->payment_form->get_items() as $item ) {
292
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
+                    $item_ids[] = $item->get_id();
294
+                    $items[]    = $item;
295
+                }
296
+            }
297 297
 	
298
-			$this->payment_form->set_items( $items );
298
+            $this->payment_form->set_items( $items );
299 299
 	
300
-		} else {
301
-			$this->payment_form->set_items( $invoice->get_items() );
302
-		}
303
-
304
-		$this->country = $invoice->get_country();
305
-		$this->state   = $invoice->get_state();
306
-		$this->invoice = $invoice;
307
-
308
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
-	}
310
-
311
-	/**
312
-	 * Returns the associated invoice.
313
-	 *
314
-	 * @since 1.0.19
315
-	 * @return WPInv_Invoice
316
-	 */
317
-	public function get_invoice() {
318
-		return $this->invoice;
319
-	}
320
-
321
-	/**
322
-	 * Checks whether there is an invoice associated with this submission.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @return bool
326
-	 */
327
-	public function has_invoice() {
328
-		return ! empty( $this->invoice );
329
-	}
330
-
331
-	/*
300
+        } else {
301
+            $this->payment_form->set_items( $invoice->get_items() );
302
+        }
303
+
304
+        $this->country = $invoice->get_country();
305
+        $this->state   = $invoice->get_state();
306
+        $this->invoice = $invoice;
307
+
308
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
+    }
310
+
311
+    /**
312
+     * Returns the associated invoice.
313
+     *
314
+     * @since 1.0.19
315
+     * @return WPInv_Invoice
316
+     */
317
+    public function get_invoice() {
318
+        return $this->invoice;
319
+    }
320
+
321
+    /**
322
+     * Checks whether there is an invoice associated with this submission.
323
+     *
324
+     * @since 1.0.19
325
+     * @return bool
326
+     */
327
+    public function has_invoice() {
328
+        return ! empty( $this->invoice );
329
+    }
330
+
331
+    /*
332 332
 	|--------------------------------------------------------------------------
333 333
 	| Items.
334 334
 	|--------------------------------------------------------------------------
@@ -337,129 +337,129 @@  discard block
 block discarded – undo
337 337
 	| recurring item. But can have an unlimited number of non-recurring items.
338 338
 	*/
339 339
 
340
-	/**
341
-	 * Prepares the submission's items.
342
-	 *
343
-	 * @since 1.0.19
344
-	 */
345
-	public function process_items() {
346
-
347
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
-
349
-		foreach ( $processor->items as $item ) {
350
-			$this->add_item( $item );
351
-		}
352
-
353
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
-	}
355
-
356
-	/**
357
-	 * Adds an item to the submission.
358
-	 *
359
-	 * @since 1.0.19
360
-	 * @param GetPaid_Form_Item $item
361
-	 */
362
-	public function add_item( $item ) {
363
-
364
-		// Make sure that it is available for purchase.
365
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
-			return;
367
-		}
368
-
369
-		// Each submission can only contain one recurring item.
370
-		if ( $item->is_recurring() ) {
371
-			$this->has_recurring = $item->get_id();
372
-		}
373
-
374
-		// Update the items and totals.
375
-		$this->items[ $item->get_id() ]         = $item;
376
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
377
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
-
379
-	}
380
-
381
-	/**
382
-	 * Removes a specific item.
383
-	 * 
384
-	 * You should not call this method after the discounts and taxes
385
-	 * have been calculated.
386
-	 *
387
-	 * @since 1.0.19
388
-	 */
389
-	public function remove_item( $item_id ) {
390
-
391
-		if ( isset( $this->items[ $item_id ] ) ) {
392
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
-
395
-			if ( $this->items[ $item_id ]->is_recurring() ) {
396
-				$this->has_recurring = 0;
397
-			}
398
-
399
-			unset( $this->items[ $item_id ] );
400
-		}
401
-
402
-	}
403
-
404
-	/**
405
-	 * Returns the subtotal.
406
-	 *
407
-	 * @since 1.0.19
408
-	 */
409
-	public function get_subtotal() {
410
-
411
-		if ( wpinv_prices_include_tax() ) {
412
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
-		}
414
-
415
-		return $this->totals['subtotal']['initial'];
416
-	}
417
-
418
-	/**
419
-	 * Returns the recurring subtotal.
420
-	 *
421
-	 * @since 1.0.19
422
-	 */
423
-	public function get_recurring_subtotal() {
424
-
425
-		if ( wpinv_prices_include_tax() ) {
426
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
-		}
428
-
429
-		return $this->totals['subtotal']['recurring'];
430
-	}
431
-
432
-	/**
433
-	 * Returns all items.
434
-	 *
435
-	 * @since 1.0.19
436
-	 * @return GetPaid_Form_Item[]
437
-	 */
438
-	public function get_items() {
439
-		return $this->items;
440
-	}
441
-
442
-	/**
443
-	 * Checks if there's a single subscription group in the submission.
444
-	 *
445
-	 * @since 2.3.0
446
-	 * @return bool
447
-	 */
448
-	public function has_subscription_group() {
449
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
-	}
451
-
452
-	/**
453
-	 * Checks if there are multipe subscription groups in the submission.
454
-	 *
455
-	 * @since 2.3.0
456
-	 * @return bool
457
-	 */
458
-	public function has_multiple_subscription_groups() {
459
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
-	}
461
-
462
-	/*
340
+    /**
341
+     * Prepares the submission's items.
342
+     *
343
+     * @since 1.0.19
344
+     */
345
+    public function process_items() {
346
+
347
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
+
349
+        foreach ( $processor->items as $item ) {
350
+            $this->add_item( $item );
351
+        }
352
+
353
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
+    }
355
+
356
+    /**
357
+     * Adds an item to the submission.
358
+     *
359
+     * @since 1.0.19
360
+     * @param GetPaid_Form_Item $item
361
+     */
362
+    public function add_item( $item ) {
363
+
364
+        // Make sure that it is available for purchase.
365
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
+            return;
367
+        }
368
+
369
+        // Each submission can only contain one recurring item.
370
+        if ( $item->is_recurring() ) {
371
+            $this->has_recurring = $item->get_id();
372
+        }
373
+
374
+        // Update the items and totals.
375
+        $this->items[ $item->get_id() ]         = $item;
376
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
377
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
+
379
+    }
380
+
381
+    /**
382
+     * Removes a specific item.
383
+     * 
384
+     * You should not call this method after the discounts and taxes
385
+     * have been calculated.
386
+     *
387
+     * @since 1.0.19
388
+     */
389
+    public function remove_item( $item_id ) {
390
+
391
+        if ( isset( $this->items[ $item_id ] ) ) {
392
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
+
395
+            if ( $this->items[ $item_id ]->is_recurring() ) {
396
+                $this->has_recurring = 0;
397
+            }
398
+
399
+            unset( $this->items[ $item_id ] );
400
+        }
401
+
402
+    }
403
+
404
+    /**
405
+     * Returns the subtotal.
406
+     *
407
+     * @since 1.0.19
408
+     */
409
+    public function get_subtotal() {
410
+
411
+        if ( wpinv_prices_include_tax() ) {
412
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
+        }
414
+
415
+        return $this->totals['subtotal']['initial'];
416
+    }
417
+
418
+    /**
419
+     * Returns the recurring subtotal.
420
+     *
421
+     * @since 1.0.19
422
+     */
423
+    public function get_recurring_subtotal() {
424
+
425
+        if ( wpinv_prices_include_tax() ) {
426
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
+        }
428
+
429
+        return $this->totals['subtotal']['recurring'];
430
+    }
431
+
432
+    /**
433
+     * Returns all items.
434
+     *
435
+     * @since 1.0.19
436
+     * @return GetPaid_Form_Item[]
437
+     */
438
+    public function get_items() {
439
+        return $this->items;
440
+    }
441
+
442
+    /**
443
+     * Checks if there's a single subscription group in the submission.
444
+     *
445
+     * @since 2.3.0
446
+     * @return bool
447
+     */
448
+    public function has_subscription_group() {
449
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
+    }
451
+
452
+    /**
453
+     * Checks if there are multipe subscription groups in the submission.
454
+     *
455
+     * @since 2.3.0
456
+     * @return bool
457
+     */
458
+    public function has_multiple_subscription_groups() {
459
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
+    }
461
+
462
+    /*
463 463
 	|--------------------------------------------------------------------------
464 464
 	| Taxes
465 465
 	|--------------------------------------------------------------------------
@@ -468,128 +468,128 @@  discard block
 block discarded – undo
468 468
 	| or only one-time.
469 469
     */
470 470
 
471
-	/**
472
-	 * Prepares the submission's taxes.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function process_taxes() {
477
-
478
-		// Abort if we're not using taxes.
479
-		if ( ! $this->use_taxes() ) {
480
-			return;
481
-		}
482
-
483
-		// If a custom country && state has been passed in, use it to calculate taxes.
484
-		$country = $this->get_field( 'wpinv_country', 'billing' );
485
-		if ( ! empty( $country ) ) {
486
-			$this->country = $country;
487
-		}
488
-
489
-		$state = $this->get_field( 'wpinv_state', 'billing' );
490
-		if ( ! empty( $state ) ) {
491
-			$this->state = $state;
492
-		}
493
-
494
-		// Confirm if the provided country and the ip country are similar.
495
-		$address_confirmed = $this->get_field( 'confirm-address' );
496
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
-			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' ) );
498
-		}
499
-
500
-		// Abort if the country is not taxable.
501
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
-			return;
503
-		}
504
-
505
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
-
507
-		foreach ( $processor->taxes as $tax ) {
508
-			$this->add_tax( $tax );
509
-		}
510
-
511
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
-	}
513
-
514
-	/**
515
-	 * Adds a tax to the submission.
516
-	 *
517
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
-	 * @since 1.0.19
519
-	 */
520
-	public function add_tax( $tax ) {
521
-
522
-		if ( wpinv_round_tax_per_tax_rate() ) {
523
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
-		}
526
-
527
-		$this->taxes[ $tax['name'] ]         = $tax;
528
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
-
531
-	}
532
-
533
-	/**
534
-	 * Removes a specific tax.
535
-	 *
536
-	 * @since 1.0.19
537
-	 */
538
-	public function remove_tax( $tax_name ) {
539
-
540
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
541
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
-			unset( $this->taxes[ $tax_name ] );
544
-		}
545
-
546
-	}
547
-
548
-	/**
549
-	 * Whether or not we'll use taxes for the submission.
550
-	 *
551
-	 * @since 1.0.19
552
-	 */
553
-	public function use_taxes() {
554
-
555
-		$use_taxes = wpinv_use_taxes();
556
-
557
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
-			$use_taxes = false;
559
-		}
560
-
561
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
-
563
-	}
564
-
565
-	/**
566
-	 * Returns the tax.
567
-	 *
568
-	 * @since 1.0.19
569
-	 */
570
-	public function get_tax() {
571
-		return $this->totals['taxes']['initial'];
572
-	}
573
-
574
-	/**
575
-	 * Returns the recurring tax.
576
-	 *
577
-	 * @since 1.0.19
578
-	 */
579
-	public function get_recurring_tax() {
580
-		return $this->totals['taxes']['recurring'];
581
-	}
582
-
583
-	/**
584
-	 * Returns all taxes.
585
-	 *
586
-	 * @since 1.0.19
587
-	 */
588
-	public function get_taxes() {
589
-		return $this->taxes;
590
-	}
591
-
592
-	/*
471
+    /**
472
+     * Prepares the submission's taxes.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function process_taxes() {
477
+
478
+        // Abort if we're not using taxes.
479
+        if ( ! $this->use_taxes() ) {
480
+            return;
481
+        }
482
+
483
+        // If a custom country && state has been passed in, use it to calculate taxes.
484
+        $country = $this->get_field( 'wpinv_country', 'billing' );
485
+        if ( ! empty( $country ) ) {
486
+            $this->country = $country;
487
+        }
488
+
489
+        $state = $this->get_field( 'wpinv_state', 'billing' );
490
+        if ( ! empty( $state ) ) {
491
+            $this->state = $state;
492
+        }
493
+
494
+        // Confirm if the provided country and the ip country are similar.
495
+        $address_confirmed = $this->get_field( 'confirm-address' );
496
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
+            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' ) );
498
+        }
499
+
500
+        // Abort if the country is not taxable.
501
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
+            return;
503
+        }
504
+
505
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
+
507
+        foreach ( $processor->taxes as $tax ) {
508
+            $this->add_tax( $tax );
509
+        }
510
+
511
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
+    }
513
+
514
+    /**
515
+     * Adds a tax to the submission.
516
+     *
517
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
+     * @since 1.0.19
519
+     */
520
+    public function add_tax( $tax ) {
521
+
522
+        if ( wpinv_round_tax_per_tax_rate() ) {
523
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
+        }
526
+
527
+        $this->taxes[ $tax['name'] ]         = $tax;
528
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
+
531
+    }
532
+
533
+    /**
534
+     * Removes a specific tax.
535
+     *
536
+     * @since 1.0.19
537
+     */
538
+    public function remove_tax( $tax_name ) {
539
+
540
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
541
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
+            unset( $this->taxes[ $tax_name ] );
544
+        }
545
+
546
+    }
547
+
548
+    /**
549
+     * Whether or not we'll use taxes for the submission.
550
+     *
551
+     * @since 1.0.19
552
+     */
553
+    public function use_taxes() {
554
+
555
+        $use_taxes = wpinv_use_taxes();
556
+
557
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
+            $use_taxes = false;
559
+        }
560
+
561
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
+
563
+    }
564
+
565
+    /**
566
+     * Returns the tax.
567
+     *
568
+     * @since 1.0.19
569
+     */
570
+    public function get_tax() {
571
+        return $this->totals['taxes']['initial'];
572
+    }
573
+
574
+    /**
575
+     * Returns the recurring tax.
576
+     *
577
+     * @since 1.0.19
578
+     */
579
+    public function get_recurring_tax() {
580
+        return $this->totals['taxes']['recurring'];
581
+    }
582
+
583
+    /**
584
+     * Returns all taxes.
585
+     *
586
+     * @since 1.0.19
587
+     */
588
+    public function get_taxes() {
589
+        return $this->taxes;
590
+    }
591
+
592
+    /*
593 593
 	|--------------------------------------------------------------------------
594 594
 	| Discounts
595 595
 	|--------------------------------------------------------------------------
@@ -598,99 +598,99 @@  discard block
 block discarded – undo
598 598
 	| or only one-time. They also do not have to come from a discount code.
599 599
     */
600 600
 
601
-	/**
602
-	 * Prepares the submission's discount.
603
-	 *
604
-	 * @since 1.0.19
605
-	 */
606
-	public function process_discount() {
607
-
608
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
-
612
-		foreach ( $processor->discounts as $discount ) {
613
-			$this->add_discount( $discount );
614
-		}
615
-
616
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
-	}
618
-
619
-	/**
620
-	 * Adds a discount to the submission.
621
-	 *
622
-	 * @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.
623
-	 * @since 1.0.19
624
-	 */
625
-	public function add_discount( $discount ) {
626
-		$this->discounts[ $discount['name'] ]   = $discount;
627
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
-	}
630
-
631
-	/**
632
-	 * Removes a discount from the submission.
633
-	 *
634
-	 * @since 1.0.19
635
-	 */
636
-	public function remove_discount( $name ) {
637
-
638
-		if ( isset( $this->discounts[ $name ] ) ) {
639
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
-			unset( $this->discounts[ $name ] );
642
-		}
643
-
644
-	}
645
-
646
-	/**
647
-	 * Checks whether there is a discount code associated with this submission.
648
-	 *
649
-	 * @since 1.0.19
650
-	 * @return bool
651
-	 */
652
-	public function has_discount_code() {
653
-		return ! empty( $this->discounts['discount_code'] );
654
-	}
655
-
656
-	/**
657
-	 * Returns the discount code.
658
-	 *
659
-	 * @since 1.0.19
660
-	 * @return string
661
-	 */
662
-	public function get_discount_code() {
663
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
-	}
665
-
666
-	/**
667
-	 * Returns the discount.
668
-	 *
669
-	 * @since 1.0.19
670
-	 */
671
-	public function get_discount() {
672
-		return $this->totals['discount']['initial'];
673
-	}
674
-
675
-	/**
676
-	 * Returns the recurring discount.
677
-	 *
678
-	 * @since 1.0.19
679
-	 */
680
-	public function get_recurring_discount() {
681
-		return $this->totals['discount']['recurring'];
682
-	}
683
-
684
-	/**
685
-	 * Returns all discounts.
686
-	 *
687
-	 * @since 1.0.19
688
-	 */
689
-	public function get_discounts() {
690
-		return $this->discounts;
691
-	}
692
-
693
-	/*
601
+    /**
602
+     * Prepares the submission's discount.
603
+     *
604
+     * @since 1.0.19
605
+     */
606
+    public function process_discount() {
607
+
608
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
+
612
+        foreach ( $processor->discounts as $discount ) {
613
+            $this->add_discount( $discount );
614
+        }
615
+
616
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
+    }
618
+
619
+    /**
620
+     * Adds a discount to the submission.
621
+     *
622
+     * @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.
623
+     * @since 1.0.19
624
+     */
625
+    public function add_discount( $discount ) {
626
+        $this->discounts[ $discount['name'] ]   = $discount;
627
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
+    }
630
+
631
+    /**
632
+     * Removes a discount from the submission.
633
+     *
634
+     * @since 1.0.19
635
+     */
636
+    public function remove_discount( $name ) {
637
+
638
+        if ( isset( $this->discounts[ $name ] ) ) {
639
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
+            unset( $this->discounts[ $name ] );
642
+        }
643
+
644
+    }
645
+
646
+    /**
647
+     * Checks whether there is a discount code associated with this submission.
648
+     *
649
+     * @since 1.0.19
650
+     * @return bool
651
+     */
652
+    public function has_discount_code() {
653
+        return ! empty( $this->discounts['discount_code'] );
654
+    }
655
+
656
+    /**
657
+     * Returns the discount code.
658
+     *
659
+     * @since 1.0.19
660
+     * @return string
661
+     */
662
+    public function get_discount_code() {
663
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
+    }
665
+
666
+    /**
667
+     * Returns the discount.
668
+     *
669
+     * @since 1.0.19
670
+     */
671
+    public function get_discount() {
672
+        return $this->totals['discount']['initial'];
673
+    }
674
+
675
+    /**
676
+     * Returns the recurring discount.
677
+     *
678
+     * @since 1.0.19
679
+     */
680
+    public function get_recurring_discount() {
681
+        return $this->totals['discount']['recurring'];
682
+    }
683
+
684
+    /**
685
+     * Returns all discounts.
686
+     *
687
+     * @since 1.0.19
688
+     */
689
+    public function get_discounts() {
690
+        return $this->discounts;
691
+    }
692
+
693
+    /*
694 694
 	|--------------------------------------------------------------------------
695 695
 	| Fees
696 696
 	|--------------------------------------------------------------------------
@@ -700,89 +700,89 @@  discard block
 block discarded – undo
700 700
 	| fees.
701 701
     */
702 702
 
703
-	/**
704
-	 * Prepares the submission's fees.
705
-	 *
706
-	 * @since 1.0.19
707
-	 */
708
-	public function process_fees() {
709
-
710
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
-
712
-		foreach ( $fees_processor->fees as $fee ) {
713
-			$this->add_fee( $fee );
714
-		}
715
-
716
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
-	}
718
-
719
-	/**
720
-	 * Adds a fee to the submission.
721
-	 *
722
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
-	 * @since 1.0.19
724
-	 */
725
-	public function add_fee( $fee ) {
726
-
727
-		$this->fees[ $fee['name'] ]         = $fee;
728
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
-
731
-	}
732
-
733
-	/**
734
-	 * Removes a fee from the submission.
735
-	 *
736
-	 * @since 1.0.19
737
-	 */
738
-	public function remove_fee( $name ) {
739
-
740
-		if ( isset( $this->fees[ $name ] ) ) {
741
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
-			unset( $this->fees[ $name ] );
744
-		}
745
-
746
-	}
747
-
748
-	/**
749
-	 * Returns the fees.
750
-	 *
751
-	 * @since 1.0.19
752
-	 */
753
-	public function get_fee() {
754
-		return $this->totals['fees']['initial'];
755
-	}
756
-
757
-	/**
758
-	 * Returns the recurring fees.
759
-	 *
760
-	 * @since 1.0.19
761
-	 */
762
-	public function get_recurring_fee() {
763
-		return $this->totals['fees']['recurring'];
764
-	}
765
-
766
-	/**
767
-	 * Returns all fees.
768
-	 *
769
-	 * @since 1.0.19
770
-	 */
771
-	public function get_fees() {
772
-		return $this->fees;
773
-	}
774
-
775
-	/**
776
-	 * Checks if there are any fees for the form.
777
-	 *
778
-	 * @return bool
779
-	 * @since 1.0.19
780
-	 */
781
-	public function has_fees() {
782
-		return count( $this->fees ) !== 0;
783
-	}
784
-
785
-	/*
703
+    /**
704
+     * Prepares the submission's fees.
705
+     *
706
+     * @since 1.0.19
707
+     */
708
+    public function process_fees() {
709
+
710
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
+
712
+        foreach ( $fees_processor->fees as $fee ) {
713
+            $this->add_fee( $fee );
714
+        }
715
+
716
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
+    }
718
+
719
+    /**
720
+     * Adds a fee to the submission.
721
+     *
722
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
+     * @since 1.0.19
724
+     */
725
+    public function add_fee( $fee ) {
726
+
727
+        $this->fees[ $fee['name'] ]         = $fee;
728
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
+
731
+    }
732
+
733
+    /**
734
+     * Removes a fee from the submission.
735
+     *
736
+     * @since 1.0.19
737
+     */
738
+    public function remove_fee( $name ) {
739
+
740
+        if ( isset( $this->fees[ $name ] ) ) {
741
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
+            unset( $this->fees[ $name ] );
744
+        }
745
+
746
+    }
747
+
748
+    /**
749
+     * Returns the fees.
750
+     *
751
+     * @since 1.0.19
752
+     */
753
+    public function get_fee() {
754
+        return $this->totals['fees']['initial'];
755
+    }
756
+
757
+    /**
758
+     * Returns the recurring fees.
759
+     *
760
+     * @since 1.0.19
761
+     */
762
+    public function get_recurring_fee() {
763
+        return $this->totals['fees']['recurring'];
764
+    }
765
+
766
+    /**
767
+     * Returns all fees.
768
+     *
769
+     * @since 1.0.19
770
+     */
771
+    public function get_fees() {
772
+        return $this->fees;
773
+    }
774
+
775
+    /**
776
+     * Checks if there are any fees for the form.
777
+     *
778
+     * @return bool
779
+     * @since 1.0.19
780
+     */
781
+    public function has_fees() {
782
+        return count( $this->fees ) !== 0;
783
+    }
784
+
785
+    /*
786 786
 	|--------------------------------------------------------------------------
787 787
 	| MISC
788 788
 	|--------------------------------------------------------------------------
@@ -790,119 +790,119 @@  discard block
 block discarded – undo
790 790
 	| Extra submission functions.
791 791
     */
792 792
 
793
-	/**
794
-	 * Checks if this is the initial fetch.
795
-	 *
796
-	 * @return bool
797
-	 * @since 1.0.19
798
-	 */
799
-	public function is_initial_fetch() {
800
-		return empty( $this->data['initial_state'] );
801
-	}
802
-
803
-	/**
804
-	 * Returns the total amount to collect for this submission.
805
-	 *
806
-	 * @since 1.0.19
807
-	 */
808
-	public function get_total() {
809
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
-		return max( $total, 0 );
811
-	}
812
-
813
-	/**
814
-	 * Returns the recurring total amount to collect for this submission.
815
-	 *
816
-	 * @since 1.0.19
817
-	 */
818
-	public function get_recurring_total() {
819
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
-		return max( $total, 0 );
821
-	}
822
-
823
-	/**
824
-	 * Whether payment details should be collected for this submission.
825
-	 *
826
-	 * @since 1.0.19
827
-	 */
828
-	public function should_collect_payment_details() {
829
-		$initial   = $this->get_total();
830
-		$recurring = $this->get_recurring_total();
831
-
832
-		if ( $this->has_recurring == 0 ) {
833
-			$recurring = 0;
834
-		}
835
-
836
-		$collect = $initial > 0 || $recurring > 0;
837
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
-	}
839
-
840
-	/**
841
-	 * Returns the billing email of the user.
842
-	 *
843
-	 * @since 1.0.19
844
-	 */
845
-	public function get_billing_email() {
846
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
-	}
848
-
849
-	/**
850
-	 * Checks if the submitter has a billing email.
851
-	 *
852
-	 * @since 1.0.19
853
-	 */
854
-	public function has_billing_email() {
855
-		$billing_email = $this->get_billing_email();
856
-		return ! empty( $billing_email ) && is_email( $billing_email );
857
-	}
858
-
859
-	/**
860
-	 * Returns the appropriate currency for the submission.
861
-	 *
862
-	 * @since 1.0.19
863
-	 * @return string
864
-	 */
865
-	public function get_currency() {
866
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
-    }
868
-
869
-    /**
870
-	 * Returns the raw submission data.
871
-	 *
872
-	 * @since 1.0.19
873
-	 * @return array
874
-	 */
875
-	public function get_data() {
876
-		return $this->data;
877
-	}
878
-
879
-	/**
880
-	 * Returns a field from the submission data
881
-	 *
882
-	 * @param string $field
883
-	 * @since 1.0.19
884
-	 * @return mixed|null
885
-	 */
886
-	public function get_field( $field, $sub_array_key = null ) {
887
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
-	}
889
-
890
-	/**
891
-	 * Checks if a required field is set.
892
-	 *
893
-	 * @since 1.0.19
894
-	 */
895
-	public function is_required_field_set( $field ) {
896
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
-	}
898
-
899
-	/**
900
-	 * Formats an amount
901
-	 *
902
-	 * @since 1.0.19
903
-	 */
904
-	public function format_amount( $amount ) {
905
-		return wpinv_price( $amount, $this->get_currency() );
906
-	}
793
+    /**
794
+     * Checks if this is the initial fetch.
795
+     *
796
+     * @return bool
797
+     * @since 1.0.19
798
+     */
799
+    public function is_initial_fetch() {
800
+        return empty( $this->data['initial_state'] );
801
+    }
802
+
803
+    /**
804
+     * Returns the total amount to collect for this submission.
805
+     *
806
+     * @since 1.0.19
807
+     */
808
+    public function get_total() {
809
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
+        return max( $total, 0 );
811
+    }
812
+
813
+    /**
814
+     * Returns the recurring total amount to collect for this submission.
815
+     *
816
+     * @since 1.0.19
817
+     */
818
+    public function get_recurring_total() {
819
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
+        return max( $total, 0 );
821
+    }
822
+
823
+    /**
824
+     * Whether payment details should be collected for this submission.
825
+     *
826
+     * @since 1.0.19
827
+     */
828
+    public function should_collect_payment_details() {
829
+        $initial   = $this->get_total();
830
+        $recurring = $this->get_recurring_total();
831
+
832
+        if ( $this->has_recurring == 0 ) {
833
+            $recurring = 0;
834
+        }
835
+
836
+        $collect = $initial > 0 || $recurring > 0;
837
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
+    }
839
+
840
+    /**
841
+     * Returns the billing email of the user.
842
+     *
843
+     * @since 1.0.19
844
+     */
845
+    public function get_billing_email() {
846
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
+    }
848
+
849
+    /**
850
+     * Checks if the submitter has a billing email.
851
+     *
852
+     * @since 1.0.19
853
+     */
854
+    public function has_billing_email() {
855
+        $billing_email = $this->get_billing_email();
856
+        return ! empty( $billing_email ) && is_email( $billing_email );
857
+    }
858
+
859
+    /**
860
+     * Returns the appropriate currency for the submission.
861
+     *
862
+     * @since 1.0.19
863
+     * @return string
864
+     */
865
+    public function get_currency() {
866
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
+    }
868
+
869
+    /**
870
+     * Returns the raw submission data.
871
+     *
872
+     * @since 1.0.19
873
+     * @return array
874
+     */
875
+    public function get_data() {
876
+        return $this->data;
877
+    }
878
+
879
+    /**
880
+     * Returns a field from the submission data
881
+     *
882
+     * @param string $field
883
+     * @since 1.0.19
884
+     * @return mixed|null
885
+     */
886
+    public function get_field( $field, $sub_array_key = null ) {
887
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
+    }
889
+
890
+    /**
891
+     * Checks if a required field is set.
892
+     *
893
+     * @since 1.0.19
894
+     */
895
+    public function is_required_field_set( $field ) {
896
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
+    }
898
+
899
+    /**
900
+     * Formats an amount
901
+     *
902
+     * @since 1.0.19
903
+     */
904
+    public function format_amount( $amount ) {
905
+        return wpinv_price( $amount, $this->get_currency() );
906
+    }
907 907
 
908 908
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'manual';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 11;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 11;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title        = __( 'Test Gateway', 'invoicing' );
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Process Payment.
50
-	 *
51
-	 *
52
-	 * @param WPInv_Invoice $invoice Invoice.
53
-	 * @param array $submission_data Posted checkout fields.
54
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
-	 * @return array
56
-	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
49
+     * Process Payment.
50
+     *
51
+     *
52
+     * @param WPInv_Invoice $invoice Invoice.
53
+     * @param array $submission_data Posted checkout fields.
54
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
+     * @return array
56
+     */
57
+    public function process_payment( $invoice, $submission_data, $submission ) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
     }
80 80
 
81 81
     /**
82
-	 * (Maybe) renews a manual subscription profile.
83
-	 *
84
-	 *
85
-	 * @param bool $should_expire
82
+     * (Maybe) renews a manual subscription profile.
83
+     *
84
+     *
85
+     * @param bool $should_expire
86 86
      * @param WPInv_Subscription $subscription
87
-	 */
88
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
87
+     */
88
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
89 89
 
90 90
         // Ensure its our subscription && it's active.
91 91
         if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
     }
114 114
 
115 115
     /**
116
-	 * Processes invoice addons.
117
-	 *
118
-	 * @param WPInv_Invoice $invoice
119
-	 * @param GetPaid_Form_Item[] $items
120
-	 * @return WPInv_Invoice
121
-	 */
122
-	public function process_addons( $invoice, $items ) {
116
+     * Processes invoice addons.
117
+     *
118
+     * @param WPInv_Invoice $invoice
119
+     * @param GetPaid_Form_Item[] $items
120
+     * @return WPInv_Invoice
121
+     */
122
+    public function process_addons( $invoice, $items ) {
123 123
 
124 124
         foreach ( $items as $item ) {
125 125
             $invoice->add_item( $item );
Please login to merge, or discard this patch.