@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,395 +10,395 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Sets the associated payment form. |
|
21 | - * |
|
22 | - * @var GetPaid_Payment_Form |
|
23 | - */ |
|
19 | + /** |
|
20 | + * Sets the associated payment form. |
|
21 | + * |
|
22 | + * @var GetPaid_Payment_Form |
|
23 | + */ |
|
24 | 24 | protected $payment_form = null; |
25 | 25 | |
26 | 26 | /** |
27 | - * The country for the submission. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - public $country = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * The state for the submission. |
|
35 | - * |
|
36 | - * @since 1.0.19 |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $state = null; |
|
40 | - |
|
41 | - /** |
|
42 | - * The invoice associated with the submission. |
|
43 | - * |
|
44 | - * @var WPInv_Invoice |
|
45 | - */ |
|
46 | - protected $invoice = null; |
|
47 | - |
|
48 | - /** |
|
49 | - * The raw submission data. |
|
50 | - * |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $data = null; |
|
54 | - |
|
55 | - /** |
|
56 | - * Whether this submission contains a recurring item. |
|
57 | - * |
|
58 | - * @var bool |
|
59 | - */ |
|
60 | - public $has_recurring = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * The sub total amount for the submission. |
|
64 | - * |
|
65 | - * @var float |
|
66 | - */ |
|
67 | - public $subtotal_amount = 0; |
|
68 | - |
|
69 | - /** |
|
70 | - * The total discount amount for the submission. |
|
71 | - * |
|
72 | - * @var float |
|
73 | - */ |
|
74 | - protected $total_discount_amount = 0; |
|
75 | - |
|
76 | - /** |
|
77 | - * The total recurring discount amount for the submission. |
|
78 | - * |
|
79 | - * @var float |
|
80 | - */ |
|
81 | - protected $total_recurring_discount_amount = 0; |
|
82 | - |
|
83 | - /** |
|
84 | - * The total tax amount for the submission. |
|
85 | - * |
|
86 | - * @var float |
|
87 | - */ |
|
88 | - protected $total_tax_amount = 0; |
|
89 | - |
|
90 | - /** |
|
91 | - * The total recurring tax amount for the submission. |
|
92 | - * |
|
93 | - * @var float |
|
94 | - */ |
|
95 | - protected $total_recurring_tax_amount = 0; |
|
96 | - |
|
97 | - /** |
|
98 | - * An array of fees for the submission. |
|
99 | - * |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - protected $fees = array(); |
|
103 | - |
|
104 | - /** |
|
105 | - * The total fees amount for the submission. |
|
106 | - * |
|
107 | - * @var float |
|
108 | - */ |
|
109 | - protected $total_fees_amount = 0; |
|
110 | - |
|
111 | - /** |
|
112 | - * The total fees amount for the submission. |
|
113 | - * |
|
114 | - * @var float |
|
115 | - */ |
|
116 | - protected $total_recurring_fees_amount = 0; |
|
117 | - |
|
118 | - /** |
|
119 | - * An array of discounts for the submission. |
|
120 | - * |
|
121 | - * @var array |
|
122 | - */ |
|
123 | - protected $discounts = array(); |
|
124 | - |
|
125 | - /** |
|
126 | - * An array of taxes for the submission. |
|
127 | - * |
|
128 | - * @var array |
|
129 | - */ |
|
130 | - protected $taxes = array(); |
|
131 | - |
|
132 | - /** |
|
133 | - * An array of items for the submission. |
|
134 | - * |
|
135 | - * @var GetPaid_Form_Item[] |
|
136 | - */ |
|
137 | - protected $items = array(); |
|
138 | - |
|
139 | - /** |
|
140 | - * The last error. |
|
141 | - * |
|
142 | - * @var string |
|
143 | - */ |
|
144 | - public $last_error = null; |
|
145 | - |
|
146 | - /** |
|
147 | - * Is the discount valid? |
|
148 | - * |
|
149 | - * @var bool |
|
150 | - */ |
|
151 | - public $is_discount_valid = true; |
|
152 | - |
|
153 | - /** |
|
154 | - * Class constructor. |
|
155 | - * |
|
156 | - */ |
|
157 | - public function __construct() { |
|
158 | - |
|
159 | - // Set the state and country to the default state and country. |
|
160 | - $this->country = wpinv_default_billing_country(); |
|
161 | - $this->state = wpinv_get_default_state(); |
|
162 | - |
|
163 | - // Do we have an actual submission? |
|
164 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
165 | - $this->load_data( $_POST ); |
|
166 | - } |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Loads submission data. |
|
172 | - * |
|
173 | - * @param array $data |
|
174 | - */ |
|
175 | - public function load_data( $data ) { |
|
176 | - |
|
177 | - // Prepare submitted data... |
|
178 | - $data = wp_unslash( $data ); |
|
179 | - |
|
180 | - // Filter the data. |
|
181 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
182 | - |
|
183 | - $this->data = $data; |
|
184 | - |
|
185 | - $this->id = md5( wp_json_encode( $data ) ); |
|
186 | - |
|
187 | - // Every submission needs an active payment form. |
|
188 | - if ( empty( $data['form_id'] ) ) { |
|
189 | - $this->last_error = __( 'Missing payment form', 'invoicing' ); |
|
27 | + * The country for the submission. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + public $country = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * The state for the submission. |
|
35 | + * |
|
36 | + * @since 1.0.19 |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $state = null; |
|
40 | + |
|
41 | + /** |
|
42 | + * The invoice associated with the submission. |
|
43 | + * |
|
44 | + * @var WPInv_Invoice |
|
45 | + */ |
|
46 | + protected $invoice = null; |
|
47 | + |
|
48 | + /** |
|
49 | + * The raw submission data. |
|
50 | + * |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $data = null; |
|
54 | + |
|
55 | + /** |
|
56 | + * Whether this submission contains a recurring item. |
|
57 | + * |
|
58 | + * @var bool |
|
59 | + */ |
|
60 | + public $has_recurring = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * The sub total amount for the submission. |
|
64 | + * |
|
65 | + * @var float |
|
66 | + */ |
|
67 | + public $subtotal_amount = 0; |
|
68 | + |
|
69 | + /** |
|
70 | + * The total discount amount for the submission. |
|
71 | + * |
|
72 | + * @var float |
|
73 | + */ |
|
74 | + protected $total_discount_amount = 0; |
|
75 | + |
|
76 | + /** |
|
77 | + * The total recurring discount amount for the submission. |
|
78 | + * |
|
79 | + * @var float |
|
80 | + */ |
|
81 | + protected $total_recurring_discount_amount = 0; |
|
82 | + |
|
83 | + /** |
|
84 | + * The total tax amount for the submission. |
|
85 | + * |
|
86 | + * @var float |
|
87 | + */ |
|
88 | + protected $total_tax_amount = 0; |
|
89 | + |
|
90 | + /** |
|
91 | + * The total recurring tax amount for the submission. |
|
92 | + * |
|
93 | + * @var float |
|
94 | + */ |
|
95 | + protected $total_recurring_tax_amount = 0; |
|
96 | + |
|
97 | + /** |
|
98 | + * An array of fees for the submission. |
|
99 | + * |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + protected $fees = array(); |
|
103 | + |
|
104 | + /** |
|
105 | + * The total fees amount for the submission. |
|
106 | + * |
|
107 | + * @var float |
|
108 | + */ |
|
109 | + protected $total_fees_amount = 0; |
|
110 | + |
|
111 | + /** |
|
112 | + * The total fees amount for the submission. |
|
113 | + * |
|
114 | + * @var float |
|
115 | + */ |
|
116 | + protected $total_recurring_fees_amount = 0; |
|
117 | + |
|
118 | + /** |
|
119 | + * An array of discounts for the submission. |
|
120 | + * |
|
121 | + * @var array |
|
122 | + */ |
|
123 | + protected $discounts = array(); |
|
124 | + |
|
125 | + /** |
|
126 | + * An array of taxes for the submission. |
|
127 | + * |
|
128 | + * @var array |
|
129 | + */ |
|
130 | + protected $taxes = array(); |
|
131 | + |
|
132 | + /** |
|
133 | + * An array of items for the submission. |
|
134 | + * |
|
135 | + * @var GetPaid_Form_Item[] |
|
136 | + */ |
|
137 | + protected $items = array(); |
|
138 | + |
|
139 | + /** |
|
140 | + * The last error. |
|
141 | + * |
|
142 | + * @var string |
|
143 | + */ |
|
144 | + public $last_error = null; |
|
145 | + |
|
146 | + /** |
|
147 | + * Is the discount valid? |
|
148 | + * |
|
149 | + * @var bool |
|
150 | + */ |
|
151 | + public $is_discount_valid = true; |
|
152 | + |
|
153 | + /** |
|
154 | + * Class constructor. |
|
155 | + * |
|
156 | + */ |
|
157 | + public function __construct() { |
|
158 | + |
|
159 | + // Set the state and country to the default state and country. |
|
160 | + $this->country = wpinv_default_billing_country(); |
|
161 | + $this->state = wpinv_get_default_state(); |
|
162 | + |
|
163 | + // Do we have an actual submission? |
|
164 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
165 | + $this->load_data( $_POST ); |
|
166 | + } |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Loads submission data. |
|
172 | + * |
|
173 | + * @param array $data |
|
174 | + */ |
|
175 | + public function load_data( $data ) { |
|
176 | + |
|
177 | + // Prepare submitted data... |
|
178 | + $data = wp_unslash( $data ); |
|
179 | + |
|
180 | + // Filter the data. |
|
181 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
182 | + |
|
183 | + $this->data = $data; |
|
184 | + |
|
185 | + $this->id = md5( wp_json_encode( $data ) ); |
|
186 | + |
|
187 | + // Every submission needs an active payment form. |
|
188 | + if ( empty( $data['form_id'] ) ) { |
|
189 | + $this->last_error = __( 'Missing payment form', 'invoicing' ); |
|
190 | 190 | return; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - // Fetch the payment form. |
|
194 | - $form = new GetPaid_Payment_Form( $data['form_id'] ); |
|
193 | + // Fetch the payment form. |
|
194 | + $form = new GetPaid_Payment_Form( $data['form_id'] ); |
|
195 | 195 | |
196 | - if ( ! $form->is_active() ) { |
|
197 | - $this->last_error = __( 'Payment form not active', 'invoicing' ); |
|
198 | - return; |
|
199 | - } |
|
196 | + if ( ! $form->is_active() ) { |
|
197 | + $this->last_error = __( 'Payment form not active', 'invoicing' ); |
|
198 | + return; |
|
199 | + } |
|
200 | 200 | |
201 | - // Fetch the payment form. |
|
202 | - $this->payment_form = $form; |
|
201 | + // Fetch the payment form. |
|
202 | + $this->payment_form = $form; |
|
203 | 203 | |
204 | - // For existing invoices, make sure that it is valid. |
|
204 | + // For existing invoices, make sure that it is valid. |
|
205 | 205 | if ( ! empty( $data['invoice_id'] ) ) { |
206 | 206 | $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
207 | 207 | |
208 | 208 | if ( empty( $invoice ) ) { |
209 | - $this->last_error = __( 'Invalid invoice', 'invoicing' ); |
|
209 | + $this->last_error = __( 'Invalid invoice', 'invoicing' ); |
|
210 | 210 | return; |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - if ( $invoice->is_paid() ) { |
|
214 | - $this->last_error = __( 'This invoice is already paid for.', 'invoicing' ); |
|
213 | + if ( $invoice->is_paid() ) { |
|
214 | + $this->last_error = __( 'This invoice is already paid for.', 'invoicing' ); |
|
215 | 215 | return; |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
218 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
219 | 219 | |
220 | - $this->country = $invoice->get_country(); |
|
221 | - $this->state = $invoice->get_state(); |
|
222 | - $this->invoice = $invoice; |
|
220 | + $this->country = $invoice->get_country(); |
|
221 | + $this->state = $invoice->get_state(); |
|
222 | + $this->invoice = $invoice; |
|
223 | 223 | |
224 | - // Default forms do not have items. |
|
224 | + // Default forms do not have items. |
|
225 | 225 | } else if ( $form->is_default() && isset( $data['getpaid-items'] ) ) { |
226 | - $this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) ); |
|
227 | - } |
|
228 | - |
|
229 | - // User's country. |
|
230 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
231 | - $this->country = $data['wpinv_country']; |
|
232 | - } |
|
233 | - |
|
234 | - // User's state. |
|
235 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
236 | - $this->country = $data['wpinv_state']; |
|
237 | - } |
|
238 | - |
|
239 | - // Handle items. |
|
240 | - $selected_items = array(); |
|
241 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
242 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
243 | - } |
|
244 | - |
|
245 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
246 | - |
|
247 | - // Continue if this is an optional item and it has not been selected. |
|
248 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
249 | - continue; |
|
250 | - } |
|
251 | - |
|
252 | - // (maybe) let customers change the quantities and prices. |
|
253 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
254 | - |
|
255 | - // Maybe change the quantities. |
|
256 | - if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) { |
|
257 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
258 | - } |
|
259 | - |
|
260 | - // Maybe change the price. |
|
261 | - if ( $item->user_can_set_their_price() ) { |
|
262 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
263 | - |
|
264 | - // But don't get lower than the minimum price. |
|
265 | - if ( $price < $item->get_minimum_price() ) { |
|
266 | - $price = $item->get_minimum_price(); |
|
267 | - } |
|
268 | - |
|
269 | - $item->set_price( $price ); |
|
270 | - |
|
271 | - } |
|
272 | - |
|
273 | - } |
|
274 | - |
|
275 | - // Add the item to the form. |
|
276 | - $this->add_item( $item ); |
|
277 | - |
|
278 | - } |
|
279 | - |
|
280 | - // Fired when we are done processing a submission. |
|
281 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
282 | - |
|
283 | - // Handle discounts. |
|
284 | - $this->process_discount(); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns the payment form. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return GetPaid_Payment_Form |
|
293 | - */ |
|
294 | - public function get_payment_form() { |
|
295 | - return $this->payment_form; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the associated invoice. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @return WPInv_Invoice |
|
303 | - */ |
|
304 | - public function get_invoice() { |
|
305 | - return $this->invoice; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Checks whether there is an invoice associated with this submission. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @return bool |
|
313 | - */ |
|
314 | - public function has_invoice() { |
|
315 | - return ! empty( $this->invoice ); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns the appropriate currency for the submission. |
|
320 | - * |
|
321 | - * @since 1.0.19 |
|
322 | - * @return string |
|
323 | - */ |
|
324 | - public function get_currency() { |
|
325 | - if ( $this->has_invoice() ) { |
|
326 | - return $this->invoice->get_currency(); |
|
327 | - } |
|
328 | - return wpinv_get_currency(); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Returns the raw submission data. |
|
333 | - * |
|
334 | - * @since 1.0.19 |
|
335 | - * @return array |
|
336 | - */ |
|
337 | - public function get_data() { |
|
338 | - return $this->data; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Checks if a required field is set. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - */ |
|
346 | - public function is_required_field_set( $field ) { |
|
347 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
348 | - } |
|
349 | - |
|
350 | - ///////// Items ////////////// |
|
351 | - |
|
352 | - /** |
|
353 | - * Adds an item to the submission. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param GetPaid_Form_Item $item |
|
357 | - */ |
|
358 | - public function add_item( $item ) { |
|
359 | - |
|
360 | - // Make sure that it is available for purchase. |
|
361 | - if ( ! $item->can_purchase() ) { |
|
362 | - return; |
|
363 | - } |
|
364 | - |
|
365 | - // Do we have a recurring item? |
|
366 | - if ( $item->is_recurring() ) { |
|
367 | - |
|
368 | - if ( $this->has_recurring ) { |
|
369 | - $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' ); |
|
370 | - } |
|
371 | - |
|
372 | - $this->has_recurring = true; |
|
373 | - |
|
374 | - } |
|
375 | - |
|
376 | - $this->items[ $item->get_id() ] = $item; |
|
377 | - |
|
378 | - $this->subtotal_amount += $item->get_sub_total(); |
|
379 | - |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Retrieves a specific item. |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - */ |
|
387 | - public function get_item( $item_id ) { |
|
388 | - return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Returns all items. |
|
393 | - * |
|
394 | - * @since 1.0.19 |
|
395 | - * @return GetPaid_Form_Item[] |
|
396 | - */ |
|
397 | - public function get_items() { |
|
398 | - return $this->items; |
|
399 | - } |
|
400 | - |
|
401 | - /* |
|
226 | + $this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) ); |
|
227 | + } |
|
228 | + |
|
229 | + // User's country. |
|
230 | + if ( ! empty( $data['wpinv_country'] ) ) { |
|
231 | + $this->country = $data['wpinv_country']; |
|
232 | + } |
|
233 | + |
|
234 | + // User's state. |
|
235 | + if ( ! empty( $data['wpinv_state'] ) ) { |
|
236 | + $this->country = $data['wpinv_state']; |
|
237 | + } |
|
238 | + |
|
239 | + // Handle items. |
|
240 | + $selected_items = array(); |
|
241 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
242 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
243 | + } |
|
244 | + |
|
245 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
246 | + |
|
247 | + // Continue if this is an optional item and it has not been selected. |
|
248 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
249 | + continue; |
|
250 | + } |
|
251 | + |
|
252 | + // (maybe) let customers change the quantities and prices. |
|
253 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
254 | + |
|
255 | + // Maybe change the quantities. |
|
256 | + if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) { |
|
257 | + $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
258 | + } |
|
259 | + |
|
260 | + // Maybe change the price. |
|
261 | + if ( $item->user_can_set_their_price() ) { |
|
262 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
263 | + |
|
264 | + // But don't get lower than the minimum price. |
|
265 | + if ( $price < $item->get_minimum_price() ) { |
|
266 | + $price = $item->get_minimum_price(); |
|
267 | + } |
|
268 | + |
|
269 | + $item->set_price( $price ); |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + } |
|
274 | + |
|
275 | + // Add the item to the form. |
|
276 | + $this->add_item( $item ); |
|
277 | + |
|
278 | + } |
|
279 | + |
|
280 | + // Fired when we are done processing a submission. |
|
281 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
282 | + |
|
283 | + // Handle discounts. |
|
284 | + $this->process_discount(); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns the payment form. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return GetPaid_Payment_Form |
|
293 | + */ |
|
294 | + public function get_payment_form() { |
|
295 | + return $this->payment_form; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the associated invoice. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @return WPInv_Invoice |
|
303 | + */ |
|
304 | + public function get_invoice() { |
|
305 | + return $this->invoice; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Checks whether there is an invoice associated with this submission. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @return bool |
|
313 | + */ |
|
314 | + public function has_invoice() { |
|
315 | + return ! empty( $this->invoice ); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns the appropriate currency for the submission. |
|
320 | + * |
|
321 | + * @since 1.0.19 |
|
322 | + * @return string |
|
323 | + */ |
|
324 | + public function get_currency() { |
|
325 | + if ( $this->has_invoice() ) { |
|
326 | + return $this->invoice->get_currency(); |
|
327 | + } |
|
328 | + return wpinv_get_currency(); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Returns the raw submission data. |
|
333 | + * |
|
334 | + * @since 1.0.19 |
|
335 | + * @return array |
|
336 | + */ |
|
337 | + public function get_data() { |
|
338 | + return $this->data; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Checks if a required field is set. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + */ |
|
346 | + public function is_required_field_set( $field ) { |
|
347 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
348 | + } |
|
349 | + |
|
350 | + ///////// Items ////////////// |
|
351 | + |
|
352 | + /** |
|
353 | + * Adds an item to the submission. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param GetPaid_Form_Item $item |
|
357 | + */ |
|
358 | + public function add_item( $item ) { |
|
359 | + |
|
360 | + // Make sure that it is available for purchase. |
|
361 | + if ( ! $item->can_purchase() ) { |
|
362 | + return; |
|
363 | + } |
|
364 | + |
|
365 | + // Do we have a recurring item? |
|
366 | + if ( $item->is_recurring() ) { |
|
367 | + |
|
368 | + if ( $this->has_recurring ) { |
|
369 | + $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' ); |
|
370 | + } |
|
371 | + |
|
372 | + $this->has_recurring = true; |
|
373 | + |
|
374 | + } |
|
375 | + |
|
376 | + $this->items[ $item->get_id() ] = $item; |
|
377 | + |
|
378 | + $this->subtotal_amount += $item->get_sub_total(); |
|
379 | + |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Retrieves a specific item. |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + */ |
|
387 | + public function get_item( $item_id ) { |
|
388 | + return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Returns all items. |
|
393 | + * |
|
394 | + * @since 1.0.19 |
|
395 | + * @return GetPaid_Form_Item[] |
|
396 | + */ |
|
397 | + public function get_items() { |
|
398 | + return $this->items; |
|
399 | + } |
|
400 | + |
|
401 | + /* |
|
402 | 402 | |-------------------------------------------------------------------------- |
403 | 403 | | Taxes |
404 | 404 | |-------------------------------------------------------------------------- |
@@ -407,86 +407,86 @@ discard block |
||
407 | 407 | | or only one-time. |
408 | 408 | */ |
409 | 409 | |
410 | - /** |
|
411 | - * Prepares the submission's taxes. |
|
412 | - * |
|
413 | - * @since 1.0.19 |
|
414 | - */ |
|
415 | - public function process_taxes() { |
|
416 | - |
|
417 | - $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
418 | - |
|
419 | - if ( ! empty( $tax_processor->tax_error) ) { |
|
420 | - $this->last_error = $tax_processor->tax_error; |
|
421 | - return; |
|
422 | - } |
|
423 | - |
|
424 | - foreach ( $tax_processor->taxes as $tax ) { |
|
425 | - $this->add_tax( $tax ); |
|
426 | - } |
|
427 | - |
|
428 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Adds a tax to the submission. |
|
433 | - * |
|
434 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
435 | - * @since 1.0.19 |
|
436 | - */ |
|
437 | - public function add_tax( $tax ) { |
|
438 | - |
|
439 | - $this->total_tax_amount += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
440 | - $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
441 | - $this->taxes[ $tax['name'] ] = $tax; |
|
442 | - |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Whether or not we'll use taxes for the submission. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - */ |
|
450 | - public function use_taxes() { |
|
451 | - |
|
452 | - $use_taxes = wpinv_use_taxes(); |
|
453 | - |
|
454 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
455 | - $use_taxes = false; |
|
456 | - } |
|
457 | - |
|
458 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
459 | - |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Returns the total tax amount. |
|
464 | - * |
|
465 | - * @since 1.0.19 |
|
466 | - */ |
|
467 | - public function get_total_tax() { |
|
468 | - return $this->total_tax_amount; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Returns the total recurring tax amount. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function get_total_recurring_tax() { |
|
477 | - return $this->total_recurring_tax_amount; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Returns all taxes. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - */ |
|
485 | - public function get_taxes() { |
|
486 | - return $this->taxes; |
|
487 | - } |
|
488 | - |
|
489 | - /* |
|
410 | + /** |
|
411 | + * Prepares the submission's taxes. |
|
412 | + * |
|
413 | + * @since 1.0.19 |
|
414 | + */ |
|
415 | + public function process_taxes() { |
|
416 | + |
|
417 | + $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
418 | + |
|
419 | + if ( ! empty( $tax_processor->tax_error) ) { |
|
420 | + $this->last_error = $tax_processor->tax_error; |
|
421 | + return; |
|
422 | + } |
|
423 | + |
|
424 | + foreach ( $tax_processor->taxes as $tax ) { |
|
425 | + $this->add_tax( $tax ); |
|
426 | + } |
|
427 | + |
|
428 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Adds a tax to the submission. |
|
433 | + * |
|
434 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
435 | + * @since 1.0.19 |
|
436 | + */ |
|
437 | + public function add_tax( $tax ) { |
|
438 | + |
|
439 | + $this->total_tax_amount += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
440 | + $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
441 | + $this->taxes[ $tax['name'] ] = $tax; |
|
442 | + |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Whether or not we'll use taxes for the submission. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + */ |
|
450 | + public function use_taxes() { |
|
451 | + |
|
452 | + $use_taxes = wpinv_use_taxes(); |
|
453 | + |
|
454 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
455 | + $use_taxes = false; |
|
456 | + } |
|
457 | + |
|
458 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
459 | + |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Returns the total tax amount. |
|
464 | + * |
|
465 | + * @since 1.0.19 |
|
466 | + */ |
|
467 | + public function get_total_tax() { |
|
468 | + return $this->total_tax_amount; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Returns the total recurring tax amount. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function get_total_recurring_tax() { |
|
477 | + return $this->total_recurring_tax_amount; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Returns all taxes. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + */ |
|
485 | + public function get_taxes() { |
|
486 | + return $this->taxes; |
|
487 | + } |
|
488 | + |
|
489 | + /* |
|
490 | 490 | |-------------------------------------------------------------------------- |
491 | 491 | | Discounts |
492 | 492 | |-------------------------------------------------------------------------- |
@@ -495,116 +495,116 @@ discard block |
||
495 | 495 | | or only one-time. They also do not have to come from a discount code. |
496 | 496 | */ |
497 | 497 | |
498 | - /** |
|
499 | - * Prepares the submission's discount. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - */ |
|
503 | - public function process_discount() { |
|
504 | - |
|
505 | - $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax(); |
|
506 | - $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total ); |
|
507 | - |
|
508 | - if ( ! $discount_handler->is_discount_valid ) { |
|
509 | - $this->last_error = $discount_handler->discount_error; |
|
510 | - return; |
|
511 | - } |
|
512 | - |
|
513 | - // Process any existing invoice discounts. |
|
514 | - if ( $this->has_invoice() ) { |
|
515 | - $discounts = $this->get_invoice()->get_discounts(); |
|
516 | - |
|
517 | - foreach ( $discounts as $discount ) { |
|
518 | - $this->add_discount( $discount ); |
|
519 | - } |
|
520 | - |
|
521 | - } |
|
522 | - |
|
523 | - if ( $discount_handler->has_discount ) { |
|
524 | - $this->add_discount( $discount_handler->calculate_discount( $this ) ); |
|
525 | - } |
|
526 | - |
|
527 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Adds a discount to the submission. |
|
532 | - * |
|
533 | - * @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. |
|
534 | - * @since 1.0.19 |
|
535 | - */ |
|
536 | - public function add_discount( $discount ) { |
|
537 | - |
|
538 | - $this->total_discount_amount += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
539 | - $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
540 | - $this->discounts[ $discount['name'] ] = $discount; |
|
541 | - |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Removes a discount from the submission. |
|
546 | - * |
|
547 | - * @since 1.0.19 |
|
548 | - */ |
|
549 | - public function remove_discount( $name ) { |
|
550 | - |
|
551 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
552 | - $discount = $this->discounts[ $name ]; |
|
553 | - $this->total_discount_amount -= $discount['initial_discount']; |
|
554 | - $this->total_recurring_discount_amount -= $discount['recurring_discount']; |
|
555 | - unset( $this->discounts[ $name ] ); |
|
556 | - } |
|
557 | - |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Checks whether there is a discount code associated with this submission. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @return bool |
|
565 | - */ |
|
566 | - public function has_discount_code() { |
|
567 | - return ! empty( $this->discounts['discount_code'] ); |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Returns the discount code. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - * @return string |
|
575 | - */ |
|
576 | - public function get_discount_code() { |
|
577 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Returns the total discount amount. |
|
582 | - * |
|
583 | - * @since 1.0.19 |
|
584 | - */ |
|
585 | - public function get_total_discount() { |
|
586 | - return $this->total_discount_amount; |
|
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Returns the total recurring discount amount. |
|
591 | - * |
|
592 | - * @since 1.0.19 |
|
593 | - */ |
|
594 | - public function get_total_recurring_discount() { |
|
595 | - return $this->total_recurring_discount_amount; |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Returns all discounts. |
|
600 | - * |
|
601 | - * @since 1.0.19 |
|
602 | - */ |
|
603 | - public function get_discounts() { |
|
604 | - return $this->discounts; |
|
605 | - } |
|
606 | - |
|
607 | - /* |
|
498 | + /** |
|
499 | + * Prepares the submission's discount. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + */ |
|
503 | + public function process_discount() { |
|
504 | + |
|
505 | + $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax(); |
|
506 | + $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total ); |
|
507 | + |
|
508 | + if ( ! $discount_handler->is_discount_valid ) { |
|
509 | + $this->last_error = $discount_handler->discount_error; |
|
510 | + return; |
|
511 | + } |
|
512 | + |
|
513 | + // Process any existing invoice discounts. |
|
514 | + if ( $this->has_invoice() ) { |
|
515 | + $discounts = $this->get_invoice()->get_discounts(); |
|
516 | + |
|
517 | + foreach ( $discounts as $discount ) { |
|
518 | + $this->add_discount( $discount ); |
|
519 | + } |
|
520 | + |
|
521 | + } |
|
522 | + |
|
523 | + if ( $discount_handler->has_discount ) { |
|
524 | + $this->add_discount( $discount_handler->calculate_discount( $this ) ); |
|
525 | + } |
|
526 | + |
|
527 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Adds a discount to the submission. |
|
532 | + * |
|
533 | + * @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. |
|
534 | + * @since 1.0.19 |
|
535 | + */ |
|
536 | + public function add_discount( $discount ) { |
|
537 | + |
|
538 | + $this->total_discount_amount += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
539 | + $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
540 | + $this->discounts[ $discount['name'] ] = $discount; |
|
541 | + |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Removes a discount from the submission. |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + */ |
|
549 | + public function remove_discount( $name ) { |
|
550 | + |
|
551 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
552 | + $discount = $this->discounts[ $name ]; |
|
553 | + $this->total_discount_amount -= $discount['initial_discount']; |
|
554 | + $this->total_recurring_discount_amount -= $discount['recurring_discount']; |
|
555 | + unset( $this->discounts[ $name ] ); |
|
556 | + } |
|
557 | + |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Checks whether there is a discount code associated with this submission. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @return bool |
|
565 | + */ |
|
566 | + public function has_discount_code() { |
|
567 | + return ! empty( $this->discounts['discount_code'] ); |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Returns the discount code. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + * @return string |
|
575 | + */ |
|
576 | + public function get_discount_code() { |
|
577 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Returns the total discount amount. |
|
582 | + * |
|
583 | + * @since 1.0.19 |
|
584 | + */ |
|
585 | + public function get_total_discount() { |
|
586 | + return $this->total_discount_amount; |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Returns the total recurring discount amount. |
|
591 | + * |
|
592 | + * @since 1.0.19 |
|
593 | + */ |
|
594 | + public function get_total_recurring_discount() { |
|
595 | + return $this->total_recurring_discount_amount; |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Returns all discounts. |
|
600 | + * |
|
601 | + * @since 1.0.19 |
|
602 | + */ |
|
603 | + public function get_discounts() { |
|
604 | + return $this->discounts; |
|
605 | + } |
|
606 | + |
|
607 | + /* |
|
608 | 608 | |-------------------------------------------------------------------------- |
609 | 609 | | Fees |
610 | 610 | |-------------------------------------------------------------------------- |
@@ -614,131 +614,131 @@ discard block |
||
614 | 614 | | fees. |
615 | 615 | */ |
616 | 616 | |
617 | - /** |
|
618 | - * Prepares the submission's fees. |
|
619 | - * |
|
620 | - * @since 1.0.19 |
|
621 | - */ |
|
622 | - public function process_fees() { |
|
623 | - |
|
624 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
625 | - |
|
626 | - if ( ! empty( $fees_processor->fee_error) ) { |
|
627 | - $this->last_error = $fees_processor->fee_error; |
|
628 | - return; |
|
629 | - } |
|
630 | - |
|
631 | - foreach ( $fees_processor->fees as $fee ) { |
|
632 | - $this->add_fee( $fee ); |
|
633 | - } |
|
634 | - |
|
635 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Adds a fee to the submission. |
|
640 | - * |
|
641 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
642 | - * @since 1.0.19 |
|
643 | - */ |
|
644 | - public function add_fee( $fee ) { |
|
645 | - |
|
646 | - $this->total_fees_amount += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
647 | - $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
648 | - $this->fees[ $fee['name'] ] = $fee; |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Removes a fee from the submission. |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - */ |
|
657 | - public function remove_fee( $name ) { |
|
658 | - |
|
659 | - if ( isset( $this->fees[ $name ] ) ) { |
|
660 | - $fee = $this->fees[ $name ]; |
|
661 | - $this->total_fees_amount -= $fee['initial_fee']; |
|
662 | - $this->total_recurring_fees_amount -= $fee['recurring_fee']; |
|
663 | - unset( $this->fees[ $name ] ); |
|
664 | - } |
|
665 | - |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Returns the total fees amount. |
|
670 | - * |
|
671 | - * @since 1.0.19 |
|
672 | - */ |
|
673 | - public function get_total_fees() { |
|
674 | - return $this->total_fees_amount; |
|
675 | - } |
|
676 | - |
|
677 | - /** |
|
678 | - * Returns the total recurring fees amount. |
|
679 | - * |
|
680 | - * @since 1.0.19 |
|
681 | - */ |
|
682 | - public function get_total_recurring_fees() { |
|
683 | - return $this->total_recurring_fees_amount; |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * Returns all fees. |
|
688 | - * |
|
689 | - * @since 1.0.19 |
|
690 | - */ |
|
691 | - public function get_fees() { |
|
692 | - return $this->fees; |
|
693 | - } |
|
694 | - |
|
695 | - // MISC // |
|
696 | - |
|
697 | - /** |
|
698 | - * Returns the total amount to collect for this submission. |
|
699 | - * |
|
700 | - * @since 1.0.19 |
|
701 | - */ |
|
702 | - public function get_total() { |
|
703 | - $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
704 | - $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this ); |
|
705 | - return wpinv_sanitize_amount( $total ); |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Whether payment details should be collected for this submission. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - */ |
|
713 | - public function get_payment_details() { |
|
714 | - $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
715 | - |
|
716 | - if ( $this->has_recurring ) { |
|
717 | - $collect = true; |
|
718 | - } |
|
719 | - |
|
720 | - $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this ); |
|
721 | - return $collect; |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Returns the billing email of the user. |
|
726 | - * |
|
727 | - * @since 1.0.19 |
|
728 | - */ |
|
729 | - public function get_billing_email() { |
|
730 | - $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email']; |
|
731 | - return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this ); |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * Checks if the submitter has a billing email. |
|
736 | - * |
|
737 | - * @since 1.0.19 |
|
738 | - */ |
|
739 | - public function has_billing_email() { |
|
740 | - $billing_email = $this->get_billing_email(); |
|
741 | - return ! empty( $billing_email ); |
|
742 | - } |
|
617 | + /** |
|
618 | + * Prepares the submission's fees. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + */ |
|
622 | + public function process_fees() { |
|
623 | + |
|
624 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
625 | + |
|
626 | + if ( ! empty( $fees_processor->fee_error) ) { |
|
627 | + $this->last_error = $fees_processor->fee_error; |
|
628 | + return; |
|
629 | + } |
|
630 | + |
|
631 | + foreach ( $fees_processor->fees as $fee ) { |
|
632 | + $this->add_fee( $fee ); |
|
633 | + } |
|
634 | + |
|
635 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Adds a fee to the submission. |
|
640 | + * |
|
641 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
642 | + * @since 1.0.19 |
|
643 | + */ |
|
644 | + public function add_fee( $fee ) { |
|
645 | + |
|
646 | + $this->total_fees_amount += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
647 | + $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
648 | + $this->fees[ $fee['name'] ] = $fee; |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Removes a fee from the submission. |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + */ |
|
657 | + public function remove_fee( $name ) { |
|
658 | + |
|
659 | + if ( isset( $this->fees[ $name ] ) ) { |
|
660 | + $fee = $this->fees[ $name ]; |
|
661 | + $this->total_fees_amount -= $fee['initial_fee']; |
|
662 | + $this->total_recurring_fees_amount -= $fee['recurring_fee']; |
|
663 | + unset( $this->fees[ $name ] ); |
|
664 | + } |
|
665 | + |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Returns the total fees amount. |
|
670 | + * |
|
671 | + * @since 1.0.19 |
|
672 | + */ |
|
673 | + public function get_total_fees() { |
|
674 | + return $this->total_fees_amount; |
|
675 | + } |
|
676 | + |
|
677 | + /** |
|
678 | + * Returns the total recurring fees amount. |
|
679 | + * |
|
680 | + * @since 1.0.19 |
|
681 | + */ |
|
682 | + public function get_total_recurring_fees() { |
|
683 | + return $this->total_recurring_fees_amount; |
|
684 | + } |
|
685 | + |
|
686 | + /** |
|
687 | + * Returns all fees. |
|
688 | + * |
|
689 | + * @since 1.0.19 |
|
690 | + */ |
|
691 | + public function get_fees() { |
|
692 | + return $this->fees; |
|
693 | + } |
|
694 | + |
|
695 | + // MISC // |
|
696 | + |
|
697 | + /** |
|
698 | + * Returns the total amount to collect for this submission. |
|
699 | + * |
|
700 | + * @since 1.0.19 |
|
701 | + */ |
|
702 | + public function get_total() { |
|
703 | + $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
704 | + $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this ); |
|
705 | + return wpinv_sanitize_amount( $total ); |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Whether payment details should be collected for this submission. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + */ |
|
713 | + public function get_payment_details() { |
|
714 | + $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
715 | + |
|
716 | + if ( $this->has_recurring ) { |
|
717 | + $collect = true; |
|
718 | + } |
|
719 | + |
|
720 | + $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this ); |
|
721 | + return $collect; |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Returns the billing email of the user. |
|
726 | + * |
|
727 | + * @since 1.0.19 |
|
728 | + */ |
|
729 | + public function get_billing_email() { |
|
730 | + $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email']; |
|
731 | + return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this ); |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * Checks if the submitter has a billing email. |
|
736 | + * |
|
737 | + * @since 1.0.19 |
|
738 | + */ |
|
739 | + public function has_billing_email() { |
|
740 | + $billing_email = $this->get_billing_email(); |
|
741 | + return ! empty( $billing_email ); |
|
742 | + } |
|
743 | 743 | |
744 | 744 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | $this->state = wpinv_get_default_state(); |
162 | 162 | |
163 | 163 | // Do we have an actual submission? |
164 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
165 | - $this->load_data( $_POST ); |
|
164 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
165 | + $this->load_data($_POST); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | } |
@@ -172,29 +172,29 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @param array $data |
174 | 174 | */ |
175 | - public function load_data( $data ) { |
|
175 | + public function load_data($data) { |
|
176 | 176 | |
177 | 177 | // Prepare submitted data... |
178 | - $data = wp_unslash( $data ); |
|
178 | + $data = wp_unslash($data); |
|
179 | 179 | |
180 | 180 | // Filter the data. |
181 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
181 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
182 | 182 | |
183 | 183 | $this->data = $data; |
184 | 184 | |
185 | - $this->id = md5( wp_json_encode( $data ) ); |
|
185 | + $this->id = md5(wp_json_encode($data)); |
|
186 | 186 | |
187 | 187 | // Every submission needs an active payment form. |
188 | - if ( empty( $data['form_id'] ) ) { |
|
189 | - $this->last_error = __( 'Missing payment form', 'invoicing' ); |
|
188 | + if (empty($data['form_id'])) { |
|
189 | + $this->last_error = __('Missing payment form', 'invoicing'); |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Fetch the payment form. |
194 | - $form = new GetPaid_Payment_Form( $data['form_id'] ); |
|
194 | + $form = new GetPaid_Payment_Form($data['form_id']); |
|
195 | 195 | |
196 | - if ( ! $form->is_active() ) { |
|
197 | - $this->last_error = __( 'Payment form not active', 'invoicing' ); |
|
196 | + if (!$form->is_active()) { |
|
197 | + $this->last_error = __('Payment form not active', 'invoicing'); |
|
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
@@ -202,83 +202,83 @@ discard block |
||
202 | 202 | $this->payment_form = $form; |
203 | 203 | |
204 | 204 | // For existing invoices, make sure that it is valid. |
205 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
205 | + if (!empty($data['invoice_id'])) { |
|
206 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
207 | 207 | |
208 | - if ( empty( $invoice ) ) { |
|
209 | - $this->last_error = __( 'Invalid invoice', 'invoicing' ); |
|
208 | + if (empty($invoice)) { |
|
209 | + $this->last_error = __('Invalid invoice', 'invoicing'); |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - if ( $invoice->is_paid() ) { |
|
214 | - $this->last_error = __( 'This invoice is already paid for.', 'invoicing' ); |
|
213 | + if ($invoice->is_paid()) { |
|
214 | + $this->last_error = __('This invoice is already paid for.', 'invoicing'); |
|
215 | 215 | return; |
216 | 216 | } |
217 | 217 | |
218 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
218 | + $this->payment_form->set_items($invoice->get_items()); |
|
219 | 219 | |
220 | 220 | $this->country = $invoice->get_country(); |
221 | 221 | $this->state = $invoice->get_state(); |
222 | 222 | $this->invoice = $invoice; |
223 | 223 | |
224 | 224 | // Default forms do not have items. |
225 | - } else if ( $form->is_default() && isset( $data['getpaid-items'] ) ) { |
|
226 | - $this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) ); |
|
225 | + } else if ($form->is_default() && isset($data['getpaid-items'])) { |
|
226 | + $this->payment_form->set_items(wpinv_clean($data['getpaid-items'])); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // User's country. |
230 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
230 | + if (!empty($data['wpinv_country'])) { |
|
231 | 231 | $this->country = $data['wpinv_country']; |
232 | 232 | } |
233 | 233 | |
234 | 234 | // User's state. |
235 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
235 | + if (!empty($data['wpinv_state'])) { |
|
236 | 236 | $this->country = $data['wpinv_state']; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Handle items. |
240 | 240 | $selected_items = array(); |
241 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
242 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
241 | + if (!empty($data['getpaid-items'])) { |
|
242 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
243 | 243 | } |
244 | 244 | |
245 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
245 | + foreach ($this->payment_form->get_items() as $item) { |
|
246 | 246 | |
247 | 247 | // Continue if this is an optional item and it has not been selected. |
248 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
248 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
249 | 249 | continue; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // (maybe) let customers change the quantities and prices. |
253 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
253 | + if (isset($selected_items[$item->get_id()])) { |
|
254 | 254 | |
255 | 255 | // Maybe change the quantities. |
256 | - if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) { |
|
257 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
256 | + if ($item->allows_quantities() && is_numeric($selected_items[$item->get_id()]['quantity'])) { |
|
257 | + $item->set_quantity((int) $selected_items[$item->get_id()]['quantity']); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | // Maybe change the price. |
261 | - if ( $item->user_can_set_their_price() ) { |
|
262 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
261 | + if ($item->user_can_set_their_price()) { |
|
262 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
263 | 263 | |
264 | 264 | // But don't get lower than the minimum price. |
265 | - if ( $price < $item->get_minimum_price() ) { |
|
265 | + if ($price < $item->get_minimum_price()) { |
|
266 | 266 | $price = $item->get_minimum_price(); |
267 | 267 | } |
268 | 268 | |
269 | - $item->set_price( $price ); |
|
269 | + $item->set_price($price); |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | |
273 | 273 | } |
274 | 274 | |
275 | 275 | // Add the item to the form. |
276 | - $this->add_item( $item ); |
|
276 | + $this->add_item($item); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | 280 | // Fired when we are done processing a submission. |
281 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
281 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
282 | 282 | |
283 | 283 | // Handle discounts. |
284 | 284 | $this->process_discount(); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @return bool |
313 | 313 | */ |
314 | 314 | public function has_invoice() { |
315 | - return ! empty( $this->invoice ); |
|
315 | + return !empty($this->invoice); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | public function get_currency() { |
325 | - if ( $this->has_invoice() ) { |
|
325 | + if ($this->has_invoice()) { |
|
326 | 326 | return $this->invoice->get_currency(); |
327 | 327 | } |
328 | 328 | return wpinv_get_currency(); |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * |
344 | 344 | * @since 1.0.19 |
345 | 345 | */ |
346 | - public function is_required_field_set( $field ) { |
|
347 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
346 | + public function is_required_field_set($field) { |
|
347 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | ///////// Items ////////////// |
@@ -355,25 +355,25 @@ discard block |
||
355 | 355 | * @since 1.0.19 |
356 | 356 | * @param GetPaid_Form_Item $item |
357 | 357 | */ |
358 | - public function add_item( $item ) { |
|
358 | + public function add_item($item) { |
|
359 | 359 | |
360 | 360 | // Make sure that it is available for purchase. |
361 | - if ( ! $item->can_purchase() ) { |
|
361 | + if (!$item->can_purchase()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Do we have a recurring item? |
366 | - if ( $item->is_recurring() ) { |
|
366 | + if ($item->is_recurring()) { |
|
367 | 367 | |
368 | - if ( $this->has_recurring ) { |
|
369 | - $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' ); |
|
368 | + if ($this->has_recurring) { |
|
369 | + $this->last_error = __('You can only buy one recurring item at a time.', 'invoicing'); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | $this->has_recurring = true; |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - $this->items[ $item->get_id() ] = $item; |
|
376 | + $this->items[$item->get_id()] = $item; |
|
377 | 377 | |
378 | 378 | $this->subtotal_amount += $item->get_sub_total(); |
379 | 379 | |
@@ -384,8 +384,8 @@ discard block |
||
384 | 384 | * |
385 | 385 | * @since 1.0.19 |
386 | 386 | */ |
387 | - public function get_item( $item_id ) { |
|
388 | - return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null; |
|
387 | + public function get_item($item_id) { |
|
388 | + return isset($this->items[$item_id]) ? $this->items[$item_id] : null; |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
@@ -414,18 +414,18 @@ discard block |
||
414 | 414 | */ |
415 | 415 | public function process_taxes() { |
416 | 416 | |
417 | - $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
417 | + $tax_processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
418 | 418 | |
419 | - if ( ! empty( $tax_processor->tax_error) ) { |
|
419 | + if (!empty($tax_processor->tax_error)) { |
|
420 | 420 | $this->last_error = $tax_processor->tax_error; |
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | - foreach ( $tax_processor->taxes as $tax ) { |
|
425 | - $this->add_tax( $tax ); |
|
424 | + foreach ($tax_processor->taxes as $tax) { |
|
425 | + $this->add_tax($tax); |
|
426 | 426 | } |
427 | 427 | |
428 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
428 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
435 | 435 | * @since 1.0.19 |
436 | 436 | */ |
437 | - public function add_tax( $tax ) { |
|
437 | + public function add_tax($tax) { |
|
438 | 438 | |
439 | - $this->total_tax_amount += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
440 | - $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
441 | - $this->taxes[ $tax['name'] ] = $tax; |
|
439 | + $this->total_tax_amount += wpinv_sanitize_amount($tax['initial_tax']); |
|
440 | + $this->total_recurring_tax_amount += wpinv_sanitize_amount($tax['recurring_tax']); |
|
441 | + $this->taxes[$tax['name']] = $tax; |
|
442 | 442 | |
443 | 443 | } |
444 | 444 | |
@@ -451,11 +451,11 @@ discard block |
||
451 | 451 | |
452 | 452 | $use_taxes = wpinv_use_taxes(); |
453 | 453 | |
454 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
454 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
455 | 455 | $use_taxes = false; |
456 | 456 | } |
457 | 457 | |
458 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
458 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
459 | 459 | |
460 | 460 | } |
461 | 461 | |
@@ -503,28 +503,28 @@ discard block |
||
503 | 503 | public function process_discount() { |
504 | 504 | |
505 | 505 | $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax(); |
506 | - $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total ); |
|
506 | + $discount_handler = new GetPaid_Payment_Form_Submission_Discount($this, $total); |
|
507 | 507 | |
508 | - if ( ! $discount_handler->is_discount_valid ) { |
|
508 | + if (!$discount_handler->is_discount_valid) { |
|
509 | 509 | $this->last_error = $discount_handler->discount_error; |
510 | 510 | return; |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Process any existing invoice discounts. |
514 | - if ( $this->has_invoice() ) { |
|
514 | + if ($this->has_invoice()) { |
|
515 | 515 | $discounts = $this->get_invoice()->get_discounts(); |
516 | 516 | |
517 | - foreach ( $discounts as $discount ) { |
|
518 | - $this->add_discount( $discount ); |
|
517 | + foreach ($discounts as $discount) { |
|
518 | + $this->add_discount($discount); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | } |
522 | 522 | |
523 | - if ( $discount_handler->has_discount ) { |
|
524 | - $this->add_discount( $discount_handler->calculate_discount( $this ) ); |
|
523 | + if ($discount_handler->has_discount) { |
|
524 | + $this->add_discount($discount_handler->calculate_discount($this)); |
|
525 | 525 | } |
526 | 526 | |
527 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
527 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | * @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. |
534 | 534 | * @since 1.0.19 |
535 | 535 | */ |
536 | - public function add_discount( $discount ) { |
|
536 | + public function add_discount($discount) { |
|
537 | 537 | |
538 | - $this->total_discount_amount += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
539 | - $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
540 | - $this->discounts[ $discount['name'] ] = $discount; |
|
538 | + $this->total_discount_amount += wpinv_sanitize_amount($discount['initial_discount']); |
|
539 | + $this->total_recurring_discount_amount += wpinv_sanitize_amount($discount['recurring_discount']); |
|
540 | + $this->discounts[$discount['name']] = $discount; |
|
541 | 541 | |
542 | 542 | } |
543 | 543 | |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @since 1.0.19 |
548 | 548 | */ |
549 | - public function remove_discount( $name ) { |
|
549 | + public function remove_discount($name) { |
|
550 | 550 | |
551 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
552 | - $discount = $this->discounts[ $name ]; |
|
551 | + if (isset($this->discounts[$name])) { |
|
552 | + $discount = $this->discounts[$name]; |
|
553 | 553 | $this->total_discount_amount -= $discount['initial_discount']; |
554 | 554 | $this->total_recurring_discount_amount -= $discount['recurring_discount']; |
555 | - unset( $this->discounts[ $name ] ); |
|
555 | + unset($this->discounts[$name]); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | } |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | * @return bool |
565 | 565 | */ |
566 | 566 | public function has_discount_code() { |
567 | - return ! empty( $this->discounts['discount_code'] ); |
|
567 | + return !empty($this->discounts['discount_code']); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -621,18 +621,18 @@ discard block |
||
621 | 621 | */ |
622 | 622 | public function process_fees() { |
623 | 623 | |
624 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
624 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
625 | 625 | |
626 | - if ( ! empty( $fees_processor->fee_error) ) { |
|
626 | + if (!empty($fees_processor->fee_error)) { |
|
627 | 627 | $this->last_error = $fees_processor->fee_error; |
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - foreach ( $fees_processor->fees as $fee ) { |
|
632 | - $this->add_fee( $fee ); |
|
631 | + foreach ($fees_processor->fees as $fee) { |
|
632 | + $this->add_fee($fee); |
|
633 | 633 | } |
634 | 634 | |
635 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
635 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -641,11 +641,11 @@ discard block |
||
641 | 641 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
642 | 642 | * @since 1.0.19 |
643 | 643 | */ |
644 | - public function add_fee( $fee ) { |
|
644 | + public function add_fee($fee) { |
|
645 | 645 | |
646 | - $this->total_fees_amount += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
647 | - $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
648 | - $this->fees[ $fee['name'] ] = $fee; |
|
646 | + $this->total_fees_amount += wpinv_sanitize_amount($fee['initial_fee']); |
|
647 | + $this->total_recurring_fees_amount += wpinv_sanitize_amount($fee['recurring_fee']); |
|
648 | + $this->fees[$fee['name']] = $fee; |
|
649 | 649 | |
650 | 650 | } |
651 | 651 | |
@@ -654,13 +654,13 @@ discard block |
||
654 | 654 | * |
655 | 655 | * @since 1.0.19 |
656 | 656 | */ |
657 | - public function remove_fee( $name ) { |
|
657 | + public function remove_fee($name) { |
|
658 | 658 | |
659 | - if ( isset( $this->fees[ $name ] ) ) { |
|
660 | - $fee = $this->fees[ $name ]; |
|
659 | + if (isset($this->fees[$name])) { |
|
660 | + $fee = $this->fees[$name]; |
|
661 | 661 | $this->total_fees_amount -= $fee['initial_fee']; |
662 | 662 | $this->total_recurring_fees_amount -= $fee['recurring_fee']; |
663 | - unset( $this->fees[ $name ] ); |
|
663 | + unset($this->fees[$name]); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | } |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | */ |
702 | 702 | public function get_total() { |
703 | 703 | $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
704 | - $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this ); |
|
705 | - return wpinv_sanitize_amount( $total ); |
|
704 | + $total = apply_filters('getpaid_get_submission_total_amount', $total, $this); |
|
705 | + return wpinv_sanitize_amount($total); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -713,11 +713,11 @@ discard block |
||
713 | 713 | public function get_payment_details() { |
714 | 714 | $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
715 | 715 | |
716 | - if ( $this->has_recurring ) { |
|
716 | + if ($this->has_recurring) { |
|
717 | 717 | $collect = true; |
718 | 718 | } |
719 | 719 | |
720 | - $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this ); |
|
720 | + $collect = apply_filters('getpaid_submission_collect_payment_details', $collect, $this); |
|
721 | 721 | return $collect; |
722 | 722 | } |
723 | 723 | |
@@ -727,8 +727,8 @@ discard block |
||
727 | 727 | * @since 1.0.19 |
728 | 728 | */ |
729 | 729 | public function get_billing_email() { |
730 | - $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email']; |
|
731 | - return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this ); |
|
730 | + $billing_email = empty($this->data['billing_email']) ? '' : $this->data['billing_email']; |
|
731 | + return apply_filters('getpaid_get_submission_billing_email', $billing_email, $this); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | */ |
739 | 739 | public function has_billing_email() { |
740 | 740 | $billing_email = $this->get_billing_email(); |
741 | - return ! empty( $billing_email ); |
|
741 | + return !empty($billing_email); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | } |