@@ -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,392 +10,392 @@ 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 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Returns the payment form. |
|
287 | - * |
|
288 | - * @since 1.0.19 |
|
289 | - * @return GetPaid_Payment_Form |
|
290 | - */ |
|
291 | - public function get_payment_form() { |
|
292 | - return $this->payment_form; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Returns the associated invoice. |
|
297 | - * |
|
298 | - * @since 1.0.19 |
|
299 | - * @return WPInv_Invoice |
|
300 | - */ |
|
301 | - public function get_invoice() { |
|
302 | - return $this->invoice; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Checks whether there is an invoice associated with this submission. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @return bool |
|
310 | - */ |
|
311 | - public function has_invoice() { |
|
312 | - return ! empty( $this->invoice ); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Returns the appropriate currency for the submission. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - public function get_currency() { |
|
322 | - if ( $this->has_invoice() ) { |
|
323 | - return $this->invoice->get_currency(); |
|
324 | - } |
|
325 | - return wpinv_get_currency(); |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the raw submission data. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @return array |
|
333 | - */ |
|
334 | - public function get_data() { |
|
335 | - return $this->data; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Checks if a required field is set. |
|
340 | - * |
|
341 | - * @since 1.0.19 |
|
342 | - */ |
|
343 | - public function is_required_field_set( $field ) { |
|
344 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
345 | - } |
|
346 | - |
|
347 | - ///////// Items ////////////// |
|
348 | - |
|
349 | - /** |
|
350 | - * Adds an item to the submission. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param GetPaid_Form_Item $item |
|
354 | - */ |
|
355 | - public function add_item( $item ) { |
|
356 | - |
|
357 | - // Make sure that it is available for purchase. |
|
358 | - if ( ! $item->can_purchase() ) { |
|
359 | - return; |
|
360 | - } |
|
361 | - |
|
362 | - // Do we have a recurring item? |
|
363 | - if ( $item->is_recurring() ) { |
|
364 | - |
|
365 | - if ( $this->has_recurring ) { |
|
366 | - $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' ); |
|
367 | - } |
|
368 | - |
|
369 | - $this->has_recurring = true; |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - $this->items[ $item->get_id() ] = $item; |
|
374 | - |
|
375 | - $this->subtotal_amount += $item->get_sub_total(); |
|
376 | - |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Retrieves a specific item. |
|
381 | - * |
|
382 | - * @since 1.0.19 |
|
383 | - */ |
|
384 | - public function get_item( $item_id ) { |
|
385 | - return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Returns all items. |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @return GetPaid_Form_Item[] |
|
393 | - */ |
|
394 | - public function get_items() { |
|
395 | - return $this->items; |
|
396 | - } |
|
397 | - |
|
398 | - /* |
|
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 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Returns the payment form. |
|
287 | + * |
|
288 | + * @since 1.0.19 |
|
289 | + * @return GetPaid_Payment_Form |
|
290 | + */ |
|
291 | + public function get_payment_form() { |
|
292 | + return $this->payment_form; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Returns the associated invoice. |
|
297 | + * |
|
298 | + * @since 1.0.19 |
|
299 | + * @return WPInv_Invoice |
|
300 | + */ |
|
301 | + public function get_invoice() { |
|
302 | + return $this->invoice; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Checks whether there is an invoice associated with this submission. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @return bool |
|
310 | + */ |
|
311 | + public function has_invoice() { |
|
312 | + return ! empty( $this->invoice ); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Returns the appropriate currency for the submission. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + public function get_currency() { |
|
322 | + if ( $this->has_invoice() ) { |
|
323 | + return $this->invoice->get_currency(); |
|
324 | + } |
|
325 | + return wpinv_get_currency(); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the raw submission data. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @return array |
|
333 | + */ |
|
334 | + public function get_data() { |
|
335 | + return $this->data; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Checks if a required field is set. |
|
340 | + * |
|
341 | + * @since 1.0.19 |
|
342 | + */ |
|
343 | + public function is_required_field_set( $field ) { |
|
344 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
345 | + } |
|
346 | + |
|
347 | + ///////// Items ////////////// |
|
348 | + |
|
349 | + /** |
|
350 | + * Adds an item to the submission. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param GetPaid_Form_Item $item |
|
354 | + */ |
|
355 | + public function add_item( $item ) { |
|
356 | + |
|
357 | + // Make sure that it is available for purchase. |
|
358 | + if ( ! $item->can_purchase() ) { |
|
359 | + return; |
|
360 | + } |
|
361 | + |
|
362 | + // Do we have a recurring item? |
|
363 | + if ( $item->is_recurring() ) { |
|
364 | + |
|
365 | + if ( $this->has_recurring ) { |
|
366 | + $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' ); |
|
367 | + } |
|
368 | + |
|
369 | + $this->has_recurring = true; |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + $this->items[ $item->get_id() ] = $item; |
|
374 | + |
|
375 | + $this->subtotal_amount += $item->get_sub_total(); |
|
376 | + |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Retrieves a specific item. |
|
381 | + * |
|
382 | + * @since 1.0.19 |
|
383 | + */ |
|
384 | + public function get_item( $item_id ) { |
|
385 | + return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Returns all items. |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @return GetPaid_Form_Item[] |
|
393 | + */ |
|
394 | + public function get_items() { |
|
395 | + return $this->items; |
|
396 | + } |
|
397 | + |
|
398 | + /* |
|
399 | 399 | |-------------------------------------------------------------------------- |
400 | 400 | | Taxes |
401 | 401 | |-------------------------------------------------------------------------- |
@@ -404,86 +404,86 @@ discard block |
||
404 | 404 | | or only one-time. |
405 | 405 | */ |
406 | 406 | |
407 | - /** |
|
408 | - * Prepares the submission's taxes. |
|
409 | - * |
|
410 | - * @since 1.0.19 |
|
411 | - */ |
|
412 | - public function process_taxes() { |
|
413 | - |
|
414 | - $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
415 | - |
|
416 | - if ( ! empty( $tax_processor->tax_error) ) { |
|
417 | - $this->last_error = $tax_processor->tax_error; |
|
418 | - return; |
|
419 | - } |
|
420 | - |
|
421 | - foreach ( $tax_processor->taxes as $tax ) { |
|
422 | - $this->add_tax( $tax ); |
|
423 | - } |
|
424 | - |
|
425 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Adds a tax to the submission. |
|
430 | - * |
|
431 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
432 | - * @since 1.0.19 |
|
433 | - */ |
|
434 | - public function add_tax( $tax ) { |
|
435 | - |
|
436 | - $this->total_tax_amount += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
437 | - $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
438 | - $this->taxes[ $tax['name'] ] = $tax; |
|
439 | - |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Whether or not we'll use taxes for the submission. |
|
444 | - * |
|
445 | - * @since 1.0.19 |
|
446 | - */ |
|
447 | - public function use_taxes() { |
|
448 | - |
|
449 | - $use_taxes = wpinv_use_taxes(); |
|
450 | - |
|
451 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
452 | - $use_taxes = false; |
|
453 | - } |
|
454 | - |
|
455 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
456 | - |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Returns the total tax amount. |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - */ |
|
464 | - public function get_total_tax() { |
|
465 | - return $this->total_tax_amount; |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Returns the total recurring tax amount. |
|
470 | - * |
|
471 | - * @since 1.0.19 |
|
472 | - */ |
|
473 | - public function get_total_recurring_tax() { |
|
474 | - return $this->total_recurring_tax_amount; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Returns all taxes. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - */ |
|
482 | - public function get_taxes() { |
|
483 | - return $this->taxes; |
|
484 | - } |
|
485 | - |
|
486 | - /* |
|
407 | + /** |
|
408 | + * Prepares the submission's taxes. |
|
409 | + * |
|
410 | + * @since 1.0.19 |
|
411 | + */ |
|
412 | + public function process_taxes() { |
|
413 | + |
|
414 | + $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
415 | + |
|
416 | + if ( ! empty( $tax_processor->tax_error) ) { |
|
417 | + $this->last_error = $tax_processor->tax_error; |
|
418 | + return; |
|
419 | + } |
|
420 | + |
|
421 | + foreach ( $tax_processor->taxes as $tax ) { |
|
422 | + $this->add_tax( $tax ); |
|
423 | + } |
|
424 | + |
|
425 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Adds a tax to the submission. |
|
430 | + * |
|
431 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
432 | + * @since 1.0.19 |
|
433 | + */ |
|
434 | + public function add_tax( $tax ) { |
|
435 | + |
|
436 | + $this->total_tax_amount += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
437 | + $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
438 | + $this->taxes[ $tax['name'] ] = $tax; |
|
439 | + |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Whether or not we'll use taxes for the submission. |
|
444 | + * |
|
445 | + * @since 1.0.19 |
|
446 | + */ |
|
447 | + public function use_taxes() { |
|
448 | + |
|
449 | + $use_taxes = wpinv_use_taxes(); |
|
450 | + |
|
451 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
452 | + $use_taxes = false; |
|
453 | + } |
|
454 | + |
|
455 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
456 | + |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Returns the total tax amount. |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + */ |
|
464 | + public function get_total_tax() { |
|
465 | + return $this->total_tax_amount; |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Returns the total recurring tax amount. |
|
470 | + * |
|
471 | + * @since 1.0.19 |
|
472 | + */ |
|
473 | + public function get_total_recurring_tax() { |
|
474 | + return $this->total_recurring_tax_amount; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Returns all taxes. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + */ |
|
482 | + public function get_taxes() { |
|
483 | + return $this->taxes; |
|
484 | + } |
|
485 | + |
|
486 | + /* |
|
487 | 487 | |-------------------------------------------------------------------------- |
488 | 488 | | Discounts |
489 | 489 | |-------------------------------------------------------------------------- |
@@ -492,116 +492,116 @@ discard block |
||
492 | 492 | | or only one-time. They also do not have to come from a discount code. |
493 | 493 | */ |
494 | 494 | |
495 | - /** |
|
496 | - * Prepares the submission's discount. |
|
497 | - * |
|
498 | - * @since 1.0.19 |
|
499 | - */ |
|
500 | - public function process_discount() { |
|
501 | - |
|
502 | - $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax(); |
|
503 | - $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total ); |
|
504 | - |
|
505 | - if ( ! $discount_handler->is_discount_valid ) { |
|
506 | - $this->last_error = $discount_handler->discount_error; |
|
507 | - return; |
|
508 | - } |
|
509 | - |
|
510 | - // Process any existing invoice discounts. |
|
511 | - if ( $this->has_invoice() ) { |
|
512 | - $discounts = $this->get_invoice()->get_discounts(); |
|
513 | - |
|
514 | - foreach ( $discounts as $discount ) { |
|
515 | - $this->add_discount( $discount ); |
|
516 | - } |
|
517 | - |
|
518 | - } |
|
519 | - |
|
520 | - if ( $discount_handler->has_discount ) { |
|
521 | - $this->add_discount( $discount_handler->calculate_discount( $this ) ); |
|
522 | - } |
|
523 | - |
|
524 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Adds a discount to the submission. |
|
529 | - * |
|
530 | - * @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. |
|
531 | - * @since 1.0.19 |
|
532 | - */ |
|
533 | - public function add_discount( $discount ) { |
|
534 | - |
|
535 | - $this->total_discount_amount += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
536 | - $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
537 | - $this->discounts[ $discount['name'] ] = $discount; |
|
538 | - |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Removes a discount from the submission. |
|
543 | - * |
|
544 | - * @since 1.0.19 |
|
545 | - */ |
|
546 | - public function remove_discount( $name ) { |
|
547 | - |
|
548 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
549 | - $discount = $this->discounts[ $name ]; |
|
550 | - $this->total_discount_amount -= $discount['initial_discount']; |
|
551 | - $this->total_recurring_discount_amount -= $discount['recurring_discount']; |
|
552 | - unset( $this->discounts[ $name ] ); |
|
553 | - } |
|
554 | - |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Checks whether there is a discount code associated with this submission. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @return bool |
|
562 | - */ |
|
563 | - public function has_discount_code() { |
|
564 | - return ! empty( $this->discounts['discount_code'] ); |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Returns the discount code. |
|
569 | - * |
|
570 | - * @since 1.0.19 |
|
571 | - * @return string |
|
572 | - */ |
|
573 | - public function get_discount_code() { |
|
574 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Returns the total discount amount. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - */ |
|
582 | - public function get_total_discount() { |
|
583 | - return $this->total_discount_amount; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Returns the total recurring discount amount. |
|
588 | - * |
|
589 | - * @since 1.0.19 |
|
590 | - */ |
|
591 | - public function get_total_recurring_discount() { |
|
592 | - return $this->total_recurring_discount_amount; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Returns all discounts. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - public function get_discounts() { |
|
601 | - return $this->discounts; |
|
602 | - } |
|
603 | - |
|
604 | - /* |
|
495 | + /** |
|
496 | + * Prepares the submission's discount. |
|
497 | + * |
|
498 | + * @since 1.0.19 |
|
499 | + */ |
|
500 | + public function process_discount() { |
|
501 | + |
|
502 | + $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax(); |
|
503 | + $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total ); |
|
504 | + |
|
505 | + if ( ! $discount_handler->is_discount_valid ) { |
|
506 | + $this->last_error = $discount_handler->discount_error; |
|
507 | + return; |
|
508 | + } |
|
509 | + |
|
510 | + // Process any existing invoice discounts. |
|
511 | + if ( $this->has_invoice() ) { |
|
512 | + $discounts = $this->get_invoice()->get_discounts(); |
|
513 | + |
|
514 | + foreach ( $discounts as $discount ) { |
|
515 | + $this->add_discount( $discount ); |
|
516 | + } |
|
517 | + |
|
518 | + } |
|
519 | + |
|
520 | + if ( $discount_handler->has_discount ) { |
|
521 | + $this->add_discount( $discount_handler->calculate_discount( $this ) ); |
|
522 | + } |
|
523 | + |
|
524 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Adds a discount to the submission. |
|
529 | + * |
|
530 | + * @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. |
|
531 | + * @since 1.0.19 |
|
532 | + */ |
|
533 | + public function add_discount( $discount ) { |
|
534 | + |
|
535 | + $this->total_discount_amount += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
536 | + $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
537 | + $this->discounts[ $discount['name'] ] = $discount; |
|
538 | + |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Removes a discount from the submission. |
|
543 | + * |
|
544 | + * @since 1.0.19 |
|
545 | + */ |
|
546 | + public function remove_discount( $name ) { |
|
547 | + |
|
548 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
549 | + $discount = $this->discounts[ $name ]; |
|
550 | + $this->total_discount_amount -= $discount['initial_discount']; |
|
551 | + $this->total_recurring_discount_amount -= $discount['recurring_discount']; |
|
552 | + unset( $this->discounts[ $name ] ); |
|
553 | + } |
|
554 | + |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Checks whether there is a discount code associated with this submission. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @return bool |
|
562 | + */ |
|
563 | + public function has_discount_code() { |
|
564 | + return ! empty( $this->discounts['discount_code'] ); |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Returns the discount code. |
|
569 | + * |
|
570 | + * @since 1.0.19 |
|
571 | + * @return string |
|
572 | + */ |
|
573 | + public function get_discount_code() { |
|
574 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Returns the total discount amount. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + */ |
|
582 | + public function get_total_discount() { |
|
583 | + return $this->total_discount_amount; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Returns the total recurring discount amount. |
|
588 | + * |
|
589 | + * @since 1.0.19 |
|
590 | + */ |
|
591 | + public function get_total_recurring_discount() { |
|
592 | + return $this->total_recurring_discount_amount; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Returns all discounts. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + public function get_discounts() { |
|
601 | + return $this->discounts; |
|
602 | + } |
|
603 | + |
|
604 | + /* |
|
605 | 605 | |-------------------------------------------------------------------------- |
606 | 606 | | Fees |
607 | 607 | |-------------------------------------------------------------------------- |
@@ -611,131 +611,131 @@ discard block |
||
611 | 611 | | fees. |
612 | 612 | */ |
613 | 613 | |
614 | - /** |
|
615 | - * Prepares the submission's fees. |
|
616 | - * |
|
617 | - * @since 1.0.19 |
|
618 | - */ |
|
619 | - public function process_fees() { |
|
620 | - |
|
621 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
622 | - |
|
623 | - if ( ! empty( $fees_processor->fee_error) ) { |
|
624 | - $this->last_error = $fees_processor->fee_error; |
|
625 | - return; |
|
626 | - } |
|
627 | - |
|
628 | - foreach ( $fees_processor->fees as $fee ) { |
|
629 | - $this->add_fee( $fee ); |
|
630 | - } |
|
631 | - |
|
632 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Adds a fee to the submission. |
|
637 | - * |
|
638 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function add_fee( $fee ) { |
|
642 | - |
|
643 | - $this->total_fees_amount += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
644 | - $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
645 | - $this->fees[ $fee['name'] ] = $fee; |
|
646 | - |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Removes a fee from the submission. |
|
651 | - * |
|
652 | - * @since 1.0.19 |
|
653 | - */ |
|
654 | - public function remove_fee( $name ) { |
|
655 | - |
|
656 | - if ( isset( $this->fees[ $name ] ) ) { |
|
657 | - $fee = $this->fees[ $name ]; |
|
658 | - $this->total_fees_amount -= $fee['initial_fee']; |
|
659 | - $this->total_recurring_fees_amount -= $fee['recurring_fee']; |
|
660 | - unset( $this->fees[ $name ] ); |
|
661 | - } |
|
662 | - |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Returns the total fees amount. |
|
667 | - * |
|
668 | - * @since 1.0.19 |
|
669 | - */ |
|
670 | - public function get_total_fees() { |
|
671 | - return $this->total_fees_amount; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Returns the total recurring fees amount. |
|
676 | - * |
|
677 | - * @since 1.0.19 |
|
678 | - */ |
|
679 | - public function get_total_recurring_fees() { |
|
680 | - return $this->total_recurring_fees_amount; |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Returns all fees. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - */ |
|
688 | - public function get_fees() { |
|
689 | - return $this->fees; |
|
690 | - } |
|
691 | - |
|
692 | - // MISC // |
|
693 | - |
|
694 | - /** |
|
695 | - * Returns the total amount to collect for this submission. |
|
696 | - * |
|
697 | - * @since 1.0.19 |
|
698 | - */ |
|
699 | - public function get_total() { |
|
700 | - $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
701 | - $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this ); |
|
702 | - return wpinv_sanitize_amount( $total ); |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * Whether payment details should be collected for this submission. |
|
707 | - * |
|
708 | - * @since 1.0.19 |
|
709 | - */ |
|
710 | - public function get_payment_details() { |
|
711 | - $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
712 | - |
|
713 | - if ( $this->has_recurring ) { |
|
714 | - $collect = true; |
|
715 | - } |
|
716 | - |
|
717 | - $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this ); |
|
718 | - return $collect; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * Returns the billing email of the user. |
|
723 | - * |
|
724 | - * @since 1.0.19 |
|
725 | - */ |
|
726 | - public function get_billing_email() { |
|
727 | - $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email']; |
|
728 | - return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this ); |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Checks if the submitter has a billing email. |
|
733 | - * |
|
734 | - * @since 1.0.19 |
|
735 | - */ |
|
736 | - public function has_billing_email() { |
|
737 | - $billing_email = $this->get_billing_email(); |
|
738 | - return ! empty( $billing_email ); |
|
739 | - } |
|
614 | + /** |
|
615 | + * Prepares the submission's fees. |
|
616 | + * |
|
617 | + * @since 1.0.19 |
|
618 | + */ |
|
619 | + public function process_fees() { |
|
620 | + |
|
621 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
622 | + |
|
623 | + if ( ! empty( $fees_processor->fee_error) ) { |
|
624 | + $this->last_error = $fees_processor->fee_error; |
|
625 | + return; |
|
626 | + } |
|
627 | + |
|
628 | + foreach ( $fees_processor->fees as $fee ) { |
|
629 | + $this->add_fee( $fee ); |
|
630 | + } |
|
631 | + |
|
632 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Adds a fee to the submission. |
|
637 | + * |
|
638 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function add_fee( $fee ) { |
|
642 | + |
|
643 | + $this->total_fees_amount += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
644 | + $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
645 | + $this->fees[ $fee['name'] ] = $fee; |
|
646 | + |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Removes a fee from the submission. |
|
651 | + * |
|
652 | + * @since 1.0.19 |
|
653 | + */ |
|
654 | + public function remove_fee( $name ) { |
|
655 | + |
|
656 | + if ( isset( $this->fees[ $name ] ) ) { |
|
657 | + $fee = $this->fees[ $name ]; |
|
658 | + $this->total_fees_amount -= $fee['initial_fee']; |
|
659 | + $this->total_recurring_fees_amount -= $fee['recurring_fee']; |
|
660 | + unset( $this->fees[ $name ] ); |
|
661 | + } |
|
662 | + |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Returns the total fees amount. |
|
667 | + * |
|
668 | + * @since 1.0.19 |
|
669 | + */ |
|
670 | + public function get_total_fees() { |
|
671 | + return $this->total_fees_amount; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Returns the total recurring fees amount. |
|
676 | + * |
|
677 | + * @since 1.0.19 |
|
678 | + */ |
|
679 | + public function get_total_recurring_fees() { |
|
680 | + return $this->total_recurring_fees_amount; |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Returns all fees. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + */ |
|
688 | + public function get_fees() { |
|
689 | + return $this->fees; |
|
690 | + } |
|
691 | + |
|
692 | + // MISC // |
|
693 | + |
|
694 | + /** |
|
695 | + * Returns the total amount to collect for this submission. |
|
696 | + * |
|
697 | + * @since 1.0.19 |
|
698 | + */ |
|
699 | + public function get_total() { |
|
700 | + $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
701 | + $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this ); |
|
702 | + return wpinv_sanitize_amount( $total ); |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * Whether payment details should be collected for this submission. |
|
707 | + * |
|
708 | + * @since 1.0.19 |
|
709 | + */ |
|
710 | + public function get_payment_details() { |
|
711 | + $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax(); |
|
712 | + |
|
713 | + if ( $this->has_recurring ) { |
|
714 | + $collect = true; |
|
715 | + } |
|
716 | + |
|
717 | + $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this ); |
|
718 | + return $collect; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Returns the billing email of the user. |
|
723 | + * |
|
724 | + * @since 1.0.19 |
|
725 | + */ |
|
726 | + public function get_billing_email() { |
|
727 | + $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email']; |
|
728 | + return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this ); |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Checks if the submitter has a billing email. |
|
733 | + * |
|
734 | + * @since 1.0.19 |
|
735 | + */ |
|
736 | + public function has_billing_email() { |
|
737 | + $billing_email = $this->get_billing_email(); |
|
738 | + return ! empty( $billing_email ); |
|
739 | + } |
|
740 | 740 | |
741 | 741 | } |