@@ -12,58 +12,58 @@ |
||
12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | if ( ! empty( $required ) ) { |
15 | - $label .= "<span class='text-danger'> *</span>"; |
|
15 | + $label .= "<span class='text-danger'> *</span>"; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | 20 | if ( ! empty( $disabled_dates ) ) { |
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim( $disabled_date ); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | - $disable_dates[] = $disabled_date; |
|
31 | - continue; |
|
32 | - } |
|
29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | + $disable_dates[] = $disabled_date; |
|
31 | + continue; |
|
32 | + } |
|
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
35 | - $disable_dates[] = array( |
|
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
38 | - ); |
|
34 | + $disabled_date = explode( '|', $disabled_date ); |
|
35 | + $disable_dates[] = array( |
|
36 | + 'from' => trim( $disabled_date[0] ), |
|
37 | + 'to' => trim( $disabled_date[1] ), |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | $options = array( |
45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | - 'data-date-format' => 'Y-m-d', |
|
51 | - 'data-alt-input' => 'true', |
|
52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
45 | + 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | + 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | + 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | + 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | + 'data-date-format' => 'Y-m-d', |
|
51 | + 'data-alt-input' => 'true', |
|
52 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | echo aui()->input( |
57 | - array( |
|
58 | - 'name' => esc_attr( $id ), |
|
59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | - 'required' => ! empty( $required ), |
|
62 | - 'label' => $label, |
|
63 | - 'label_type' => 'vertical', |
|
64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | - 'type' => 'datepicker', |
|
66 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | - ) |
|
57 | + array( |
|
58 | + 'name' => esc_attr( $id ), |
|
59 | + 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | + 'required' => ! empty( $required ), |
|
62 | + 'label' => $label, |
|
63 | + 'label_type' => 'vertical', |
|
64 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | + 'type' => 'datepicker', |
|
66 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | + ) |
|
69 | 69 | ); |
@@ -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,203 +10,203 @@ 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; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - 'shipping' => array( |
|
54 | - 'initial' => 0, |
|
55 | - 'recurring' => 0, |
|
56 | - ), |
|
57 | - |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets the associated payment form. |
|
62 | - * |
|
63 | - * @var GetPaid_Payment_Form |
|
64 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + 'shipping' => array( |
|
54 | + 'initial' => 0, |
|
55 | + 'recurring' => 0, |
|
56 | + ), |
|
57 | + |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets the associated payment form. |
|
62 | + * |
|
63 | + * @var GetPaid_Payment_Form |
|
64 | + */ |
|
65 | 65 | protected $payment_form = null; |
66 | 66 | |
67 | 67 | /** |
68 | - * The country for the submission. |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $country = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * The state for the submission. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - public $state = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * The invoice associated with the submission. |
|
84 | - * |
|
85 | - * @var WPInv_Invoice |
|
86 | - */ |
|
87 | - protected $invoice = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The recurring item for the submission. |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - public $has_recurring = 0; |
|
95 | - |
|
96 | - /** |
|
97 | - * An array of fees for the submission. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - protected $fees = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of discounts for the submission. |
|
105 | - * |
|
106 | - * @var array |
|
107 | - */ |
|
108 | - protected $discounts = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * An array of taxes for the submission. |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $taxes = array(); |
|
116 | - |
|
117 | - /** |
|
118 | - * An array of items for the submission. |
|
119 | - * |
|
120 | - * @var GetPaid_Form_Item[] |
|
121 | - */ |
|
122 | - protected $items = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * The last error. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $last_error = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * The last error code. |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $last_error_code = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * Class constructor. |
|
140 | - * |
|
141 | - */ |
|
142 | - public function __construct() { |
|
143 | - |
|
144 | - // Set the state and country to the default state and country. |
|
145 | - $this->country = wpinv_default_billing_country(); |
|
146 | - $this->state = wpinv_get_default_state(); |
|
147 | - |
|
148 | - // Do we have an actual submission? |
|
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( $_POST ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Remove slashes from the submitted data... |
|
163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | - |
|
165 | - // Allow plugins to filter the data. |
|
166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | - |
|
168 | - // Cache it... |
|
169 | - $this->data = $data; |
|
170 | - |
|
171 | - // Then generate a unique id from the data. |
|
172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
173 | - |
|
174 | - // Finally, process the submission. |
|
175 | - try { |
|
176 | - |
|
177 | - // Each process is passed an instance of the class (with reference) |
|
178 | - // and should throw an Exception whenever it encounters one. |
|
179 | - $processors = apply_filters( |
|
180 | - 'getpaid_payment_form_submission_processors', |
|
181 | - array( |
|
182 | - array( $this, 'process_payment_form' ), |
|
183 | - array( $this, 'process_invoice' ), |
|
184 | - array( $this, 'process_fees' ), |
|
185 | - array( $this, 'process_items' ), |
|
186 | - array( $this, 'process_discount' ), |
|
187 | - array( $this, 'process_taxes' ), |
|
188 | - ), |
|
189 | - $this |
|
190 | - ); |
|
191 | - |
|
192 | - foreach ( $processors as $processor ) { |
|
193 | - call_user_func_array( $processor, array( &$this ) ); |
|
194 | - } |
|
195 | - |
|
196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
197 | - $this->last_error = $e->getMessage(); |
|
198 | - $this->last_error_code = $e->getErrorCode(); |
|
199 | - } catch ( Exception $e ) { |
|
200 | - $this->last_error = $e->getMessage(); |
|
201 | - $this->last_error_code = $e->getCode(); |
|
202 | - } |
|
203 | - |
|
204 | - // Fired when we are done processing a submission. |
|
205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /* |
|
68 | + * The country for the submission. |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $country = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * The state for the submission. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + public $state = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * The invoice associated with the submission. |
|
84 | + * |
|
85 | + * @var WPInv_Invoice |
|
86 | + */ |
|
87 | + protected $invoice = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The recurring item for the submission. |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + public $has_recurring = 0; |
|
95 | + |
|
96 | + /** |
|
97 | + * An array of fees for the submission. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + protected $fees = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of discounts for the submission. |
|
105 | + * |
|
106 | + * @var array |
|
107 | + */ |
|
108 | + protected $discounts = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * An array of taxes for the submission. |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $taxes = array(); |
|
116 | + |
|
117 | + /** |
|
118 | + * An array of items for the submission. |
|
119 | + * |
|
120 | + * @var GetPaid_Form_Item[] |
|
121 | + */ |
|
122 | + protected $items = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * The last error. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $last_error = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * The last error code. |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $last_error_code = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * Class constructor. |
|
140 | + * |
|
141 | + */ |
|
142 | + public function __construct() { |
|
143 | + |
|
144 | + // Set the state and country to the default state and country. |
|
145 | + $this->country = wpinv_default_billing_country(); |
|
146 | + $this->state = wpinv_get_default_state(); |
|
147 | + |
|
148 | + // Do we have an actual submission? |
|
149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | + $this->load_data( $_POST ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Remove slashes from the submitted data... |
|
163 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | + |
|
165 | + // Allow plugins to filter the data. |
|
166 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | + |
|
168 | + // Cache it... |
|
169 | + $this->data = $data; |
|
170 | + |
|
171 | + // Then generate a unique id from the data. |
|
172 | + $this->id = md5( wp_json_encode( $data ) ); |
|
173 | + |
|
174 | + // Finally, process the submission. |
|
175 | + try { |
|
176 | + |
|
177 | + // Each process is passed an instance of the class (with reference) |
|
178 | + // and should throw an Exception whenever it encounters one. |
|
179 | + $processors = apply_filters( |
|
180 | + 'getpaid_payment_form_submission_processors', |
|
181 | + array( |
|
182 | + array( $this, 'process_payment_form' ), |
|
183 | + array( $this, 'process_invoice' ), |
|
184 | + array( $this, 'process_fees' ), |
|
185 | + array( $this, 'process_items' ), |
|
186 | + array( $this, 'process_discount' ), |
|
187 | + array( $this, 'process_taxes' ), |
|
188 | + ), |
|
189 | + $this |
|
190 | + ); |
|
191 | + |
|
192 | + foreach ( $processors as $processor ) { |
|
193 | + call_user_func_array( $processor, array( &$this ) ); |
|
194 | + } |
|
195 | + |
|
196 | + } catch( GetPaid_Payment_Exception $e ) { |
|
197 | + $this->last_error = $e->getMessage(); |
|
198 | + $this->last_error_code = $e->getErrorCode(); |
|
199 | + } catch ( Exception $e ) { |
|
200 | + $this->last_error = $e->getMessage(); |
|
201 | + $this->last_error_code = $e->getCode(); |
|
202 | + } |
|
203 | + |
|
204 | + // Fired when we are done processing a submission. |
|
205 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /* |
|
210 | 210 | |-------------------------------------------------------------------------- |
211 | 211 | | Payment Forms. |
212 | 212 | |-------------------------------------------------------------------------- |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | | submission has an active payment form etc. |
216 | 216 | */ |
217 | 217 | |
218 | - /** |
|
219 | - * Prepares the submission's payment form. |
|
220 | - * |
|
221 | - * @since 1.0.19 |
|
222 | - */ |
|
223 | - public function process_payment_form() { |
|
218 | + /** |
|
219 | + * Prepares the submission's payment form. |
|
220 | + * |
|
221 | + * @since 1.0.19 |
|
222 | + */ |
|
223 | + public function process_payment_form() { |
|
224 | 224 | |
225 | - // Every submission needs an active payment form. |
|
226 | - if ( empty( $this->data['form_id'] ) ) { |
|
227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | - } |
|
225 | + // Every submission needs an active payment form. |
|
226 | + if ( empty( $this->data['form_id'] ) ) { |
|
227 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | + } |
|
229 | 229 | |
230 | - // Fetch the payment form. |
|
231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
230 | + // Fetch the payment form. |
|
231 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
232 | 232 | |
233 | - if ( ! $this->payment_form->is_active() ) { |
|
234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | - } |
|
233 | + if ( ! $this->payment_form->is_active() ) { |
|
234 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | + } |
|
236 | 236 | |
237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | - } |
|
237 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | + } |
|
239 | 239 | |
240 | 240 | /** |
241 | - * Returns the payment form. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @return GetPaid_Payment_Form |
|
245 | - */ |
|
246 | - public function get_payment_form() { |
|
247 | - return $this->payment_form; |
|
248 | - } |
|
241 | + * Returns the payment form. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @return GetPaid_Payment_Form |
|
245 | + */ |
|
246 | + public function get_payment_form() { |
|
247 | + return $this->payment_form; |
|
248 | + } |
|
249 | 249 | |
250 | - /* |
|
250 | + /* |
|
251 | 251 | |-------------------------------------------------------------------------- |
252 | 252 | | Invoices. |
253 | 253 | |-------------------------------------------------------------------------- |
@@ -256,84 +256,84 @@ discard block |
||
256 | 256 | | might be for an existing invoice. |
257 | 257 | */ |
258 | 258 | |
259 | - /** |
|
260 | - * Prepares the submission's invoice. |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - */ |
|
264 | - public function process_invoice() { |
|
259 | + /** |
|
260 | + * Prepares the submission's invoice. |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + */ |
|
264 | + public function process_invoice() { |
|
265 | 265 | |
266 | - // Abort if there is no invoice. |
|
267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | - return; |
|
269 | - } |
|
266 | + // Abort if there is no invoice. |
|
267 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | 270 | |
271 | - // If the submission is for an existing invoice, ensure that it exists |
|
272 | - // and that it is not paid for. |
|
273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
271 | + // If the submission is for an existing invoice, ensure that it exists |
|
272 | + // and that it is not paid for. |
|
273 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
274 | 274 | |
275 | 275 | if ( empty( $invoice ) ) { |
276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | - } |
|
276 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | + } |
|
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | - } |
|
279 | + if ( $invoice->is_paid() ) { |
|
280 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | + } |
|
282 | 282 | |
283 | - $this->payment_form->invoice = $invoice; |
|
284 | - if ( ! $this->payment_form->is_default() ) { |
|
283 | + $this->payment_form->invoice = $invoice; |
|
284 | + if ( ! $this->payment_form->is_default() ) { |
|
285 | 285 | |
286 | - $items = array(); |
|
287 | - $item_ids = array(); |
|
286 | + $items = array(); |
|
287 | + $item_ids = array(); |
|
288 | 288 | |
289 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | - $item_ids[] = $item->get_id(); |
|
292 | - $items[] = $item; |
|
293 | - } |
|
294 | - } |
|
289 | + foreach ( $invoice->get_items() as $item ) { |
|
290 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | + $item_ids[] = $item->get_id(); |
|
292 | + $items[] = $item; |
|
293 | + } |
|
294 | + } |
|
295 | 295 | |
296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | - $item_ids[] = $item->get_id(); |
|
299 | - $items[] = $item; |
|
300 | - } |
|
301 | - } |
|
296 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | + $item_ids[] = $item->get_id(); |
|
299 | + $items[] = $item; |
|
300 | + } |
|
301 | + } |
|
302 | 302 | |
303 | - $this->payment_form->set_items( $items ); |
|
303 | + $this->payment_form->set_items( $items ); |
|
304 | 304 | |
305 | - } else { |
|
306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | - } |
|
308 | - |
|
309 | - $this->country = $invoice->get_country(); |
|
310 | - $this->state = $invoice->get_state(); |
|
311 | - $this->invoice = $invoice; |
|
312 | - |
|
313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the associated invoice. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @return WPInv_Invoice |
|
321 | - */ |
|
322 | - public function get_invoice() { |
|
323 | - return $this->invoice; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Checks whether there is an invoice associated with this submission. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function has_invoice() { |
|
333 | - return ! empty( $this->invoice ); |
|
334 | - } |
|
335 | - |
|
336 | - /* |
|
305 | + } else { |
|
306 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | + } |
|
308 | + |
|
309 | + $this->country = $invoice->get_country(); |
|
310 | + $this->state = $invoice->get_state(); |
|
311 | + $this->invoice = $invoice; |
|
312 | + |
|
313 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the associated invoice. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @return WPInv_Invoice |
|
321 | + */ |
|
322 | + public function get_invoice() { |
|
323 | + return $this->invoice; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Checks whether there is an invoice associated with this submission. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function has_invoice() { |
|
333 | + return ! empty( $this->invoice ); |
|
334 | + } |
|
335 | + |
|
336 | + /* |
|
337 | 337 | |-------------------------------------------------------------------------- |
338 | 338 | | Items. |
339 | 339 | |-------------------------------------------------------------------------- |
@@ -342,129 +342,129 @@ discard block |
||
342 | 342 | | recurring item. But can have an unlimited number of non-recurring items. |
343 | 343 | */ |
344 | 344 | |
345 | - /** |
|
346 | - * Prepares the submission's items. |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
349 | - */ |
|
350 | - public function process_items() { |
|
351 | - |
|
352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | - |
|
354 | - foreach ( $processor->items as $item ) { |
|
355 | - $this->add_item( $item ); |
|
356 | - } |
|
357 | - |
|
358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Adds an item to the submission. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param GetPaid_Form_Item $item |
|
366 | - */ |
|
367 | - public function add_item( $item ) { |
|
368 | - |
|
369 | - // Make sure that it is available for purchase. |
|
370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - // Each submission can only contain one recurring item. |
|
375 | - if ( $item->is_recurring() ) { |
|
376 | - $this->has_recurring = $item->get_id(); |
|
377 | - } |
|
378 | - |
|
379 | - // Update the items and totals. |
|
380 | - $this->items[ $item->get_id() ] = $item; |
|
381 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Removes a specific item. |
|
388 | - * |
|
389 | - * You should not call this method after the discounts and taxes |
|
390 | - * have been calculated. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function remove_item( $item_id ) { |
|
395 | - |
|
396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | - |
|
400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | - $this->has_recurring = 0; |
|
402 | - } |
|
403 | - |
|
404 | - unset( $this->items[ $item_id ] ); |
|
405 | - } |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns the subtotal. |
|
411 | - * |
|
412 | - * @since 1.0.19 |
|
413 | - */ |
|
414 | - public function get_subtotal() { |
|
415 | - |
|
416 | - if ( wpinv_prices_include_tax() ) { |
|
417 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | - } |
|
419 | - |
|
420 | - return $this->totals['subtotal']['initial']; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Returns the recurring subtotal. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function get_recurring_subtotal() { |
|
429 | - |
|
430 | - if ( wpinv_prices_include_tax() ) { |
|
431 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | - } |
|
433 | - |
|
434 | - return $this->totals['subtotal']['recurring']; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Returns all items. |
|
439 | - * |
|
440 | - * @since 1.0.19 |
|
441 | - * @return GetPaid_Form_Item[] |
|
442 | - */ |
|
443 | - public function get_items() { |
|
444 | - return $this->items; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Checks if there's a single subscription group in the submission. |
|
449 | - * |
|
450 | - * @since 2.3.0 |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - public function has_subscription_group() { |
|
454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Checks if there are multipe subscription groups in the submission. |
|
459 | - * |
|
460 | - * @since 2.3.0 |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function has_multiple_subscription_groups() { |
|
464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | - } |
|
466 | - |
|
467 | - /* |
|
345 | + /** |
|
346 | + * Prepares the submission's items. |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | + */ |
|
350 | + public function process_items() { |
|
351 | + |
|
352 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | + |
|
354 | + foreach ( $processor->items as $item ) { |
|
355 | + $this->add_item( $item ); |
|
356 | + } |
|
357 | + |
|
358 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Adds an item to the submission. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param GetPaid_Form_Item $item |
|
366 | + */ |
|
367 | + public function add_item( $item ) { |
|
368 | + |
|
369 | + // Make sure that it is available for purchase. |
|
370 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + // Each submission can only contain one recurring item. |
|
375 | + if ( $item->is_recurring() ) { |
|
376 | + $this->has_recurring = $item->get_id(); |
|
377 | + } |
|
378 | + |
|
379 | + // Update the items and totals. |
|
380 | + $this->items[ $item->get_id() ] = $item; |
|
381 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Removes a specific item. |
|
388 | + * |
|
389 | + * You should not call this method after the discounts and taxes |
|
390 | + * have been calculated. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function remove_item( $item_id ) { |
|
395 | + |
|
396 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | + |
|
400 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | + $this->has_recurring = 0; |
|
402 | + } |
|
403 | + |
|
404 | + unset( $this->items[ $item_id ] ); |
|
405 | + } |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns the subtotal. |
|
411 | + * |
|
412 | + * @since 1.0.19 |
|
413 | + */ |
|
414 | + public function get_subtotal() { |
|
415 | + |
|
416 | + if ( wpinv_prices_include_tax() ) { |
|
417 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | + } |
|
419 | + |
|
420 | + return $this->totals['subtotal']['initial']; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Returns the recurring subtotal. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function get_recurring_subtotal() { |
|
429 | + |
|
430 | + if ( wpinv_prices_include_tax() ) { |
|
431 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | + } |
|
433 | + |
|
434 | + return $this->totals['subtotal']['recurring']; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Returns all items. |
|
439 | + * |
|
440 | + * @since 1.0.19 |
|
441 | + * @return GetPaid_Form_Item[] |
|
442 | + */ |
|
443 | + public function get_items() { |
|
444 | + return $this->items; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Checks if there's a single subscription group in the submission. |
|
449 | + * |
|
450 | + * @since 2.3.0 |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + public function has_subscription_group() { |
|
454 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Checks if there are multipe subscription groups in the submission. |
|
459 | + * |
|
460 | + * @since 2.3.0 |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function has_multiple_subscription_groups() { |
|
464 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | + } |
|
466 | + |
|
467 | + /* |
|
468 | 468 | |-------------------------------------------------------------------------- |
469 | 469 | | Taxes |
470 | 470 | |-------------------------------------------------------------------------- |
@@ -473,128 +473,128 @@ discard block |
||
473 | 473 | | or only one-time. |
474 | 474 | */ |
475 | 475 | |
476 | - /** |
|
477 | - * Prepares the submission's taxes. |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - */ |
|
481 | - public function process_taxes() { |
|
482 | - |
|
483 | - // Abort if we're not using taxes. |
|
484 | - if ( ! $this->use_taxes() ) { |
|
485 | - return; |
|
486 | - } |
|
487 | - |
|
488 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | - if ( ! empty( $country ) ) { |
|
491 | - $this->country = $country; |
|
492 | - } |
|
493 | - |
|
494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | - if ( ! empty( $state ) ) { |
|
496 | - $this->state = $state; |
|
497 | - } |
|
498 | - |
|
499 | - // Confirm if the provided country and the ip country are similar. |
|
500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
503 | - } |
|
504 | - |
|
505 | - // Abort if the country is not taxable. |
|
506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | - return; |
|
508 | - } |
|
509 | - |
|
510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | - |
|
512 | - foreach ( $processor->taxes as $tax ) { |
|
513 | - $this->add_tax( $tax ); |
|
514 | - } |
|
515 | - |
|
516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Adds a tax to the submission. |
|
521 | - * |
|
522 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | - * @since 1.0.19 |
|
524 | - */ |
|
525 | - public function add_tax( $tax ) { |
|
526 | - |
|
527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | - } |
|
531 | - |
|
532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | - |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Removes a specific tax. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - */ |
|
543 | - public function remove_tax( $tax_name ) { |
|
544 | - |
|
545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | - unset( $this->taxes[ $tax_name ] ); |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Whether or not we'll use taxes for the submission. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function use_taxes() { |
|
559 | - |
|
560 | - $use_taxes = wpinv_use_taxes(); |
|
561 | - |
|
562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | - $use_taxes = false; |
|
564 | - } |
|
565 | - |
|
566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | - |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Returns the tax. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - */ |
|
575 | - public function get_tax() { |
|
576 | - return $this->totals['taxes']['initial']; |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Returns the recurring tax. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - */ |
|
584 | - public function get_recurring_tax() { |
|
585 | - return $this->totals['taxes']['recurring']; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns all taxes. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - */ |
|
593 | - public function get_taxes() { |
|
594 | - return $this->taxes; |
|
595 | - } |
|
596 | - |
|
597 | - /* |
|
476 | + /** |
|
477 | + * Prepares the submission's taxes. |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + */ |
|
481 | + public function process_taxes() { |
|
482 | + |
|
483 | + // Abort if we're not using taxes. |
|
484 | + if ( ! $this->use_taxes() ) { |
|
485 | + return; |
|
486 | + } |
|
487 | + |
|
488 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | + if ( ! empty( $country ) ) { |
|
491 | + $this->country = $country; |
|
492 | + } |
|
493 | + |
|
494 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | + if ( ! empty( $state ) ) { |
|
496 | + $this->state = $state; |
|
497 | + } |
|
498 | + |
|
499 | + // Confirm if the provided country and the ip country are similar. |
|
500 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
503 | + } |
|
504 | + |
|
505 | + // Abort if the country is not taxable. |
|
506 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | + return; |
|
508 | + } |
|
509 | + |
|
510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | + |
|
512 | + foreach ( $processor->taxes as $tax ) { |
|
513 | + $this->add_tax( $tax ); |
|
514 | + } |
|
515 | + |
|
516 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Adds a tax to the submission. |
|
521 | + * |
|
522 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | + * @since 1.0.19 |
|
524 | + */ |
|
525 | + public function add_tax( $tax ) { |
|
526 | + |
|
527 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | + } |
|
531 | + |
|
532 | + $this->taxes[ $tax['name'] ] = $tax; |
|
533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | + |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Removes a specific tax. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + */ |
|
543 | + public function remove_tax( $tax_name ) { |
|
544 | + |
|
545 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | + unset( $this->taxes[ $tax_name ] ); |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Whether or not we'll use taxes for the submission. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function use_taxes() { |
|
559 | + |
|
560 | + $use_taxes = wpinv_use_taxes(); |
|
561 | + |
|
562 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | + $use_taxes = false; |
|
564 | + } |
|
565 | + |
|
566 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | + |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Returns the tax. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + */ |
|
575 | + public function get_tax() { |
|
576 | + return $this->totals['taxes']['initial']; |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Returns the recurring tax. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + */ |
|
584 | + public function get_recurring_tax() { |
|
585 | + return $this->totals['taxes']['recurring']; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns all taxes. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + */ |
|
593 | + public function get_taxes() { |
|
594 | + return $this->taxes; |
|
595 | + } |
|
596 | + |
|
597 | + /* |
|
598 | 598 | |-------------------------------------------------------------------------- |
599 | 599 | | Discounts |
600 | 600 | |-------------------------------------------------------------------------- |
@@ -603,99 +603,99 @@ discard block |
||
603 | 603 | | or only one-time. They also do not have to come from a discount code. |
604 | 604 | */ |
605 | 605 | |
606 | - /** |
|
607 | - * Prepares the submission's discount. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - */ |
|
611 | - public function process_discount() { |
|
612 | - |
|
613 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | - |
|
617 | - foreach ( $processor->discounts as $discount ) { |
|
618 | - $this->add_discount( $discount ); |
|
619 | - } |
|
620 | - |
|
621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Adds a discount to the submission. |
|
626 | - * |
|
627 | - * @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. |
|
628 | - * @since 1.0.19 |
|
629 | - */ |
|
630 | - public function add_discount( $discount ) { |
|
631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Removes a discount from the submission. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function remove_discount( $name ) { |
|
642 | - |
|
643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | - unset( $this->discounts[ $name ] ); |
|
647 | - } |
|
648 | - |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Checks whether there is a discount code associated with this submission. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @return bool |
|
656 | - */ |
|
657 | - public function has_discount_code() { |
|
658 | - return ! empty( $this->discounts['discount_code'] ); |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Returns the discount code. |
|
663 | - * |
|
664 | - * @since 1.0.19 |
|
665 | - * @return string |
|
666 | - */ |
|
667 | - public function get_discount_code() { |
|
668 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Returns the discount. |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - */ |
|
676 | - public function get_discount() { |
|
677 | - return $this->totals['discount']['initial']; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Returns the recurring discount. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - */ |
|
685 | - public function get_recurring_discount() { |
|
686 | - return $this->totals['discount']['recurring']; |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Returns all discounts. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - */ |
|
694 | - public function get_discounts() { |
|
695 | - return $this->discounts; |
|
696 | - } |
|
697 | - |
|
698 | - /* |
|
606 | + /** |
|
607 | + * Prepares the submission's discount. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + */ |
|
611 | + public function process_discount() { |
|
612 | + |
|
613 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | + |
|
617 | + foreach ( $processor->discounts as $discount ) { |
|
618 | + $this->add_discount( $discount ); |
|
619 | + } |
|
620 | + |
|
621 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Adds a discount to the submission. |
|
626 | + * |
|
627 | + * @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. |
|
628 | + * @since 1.0.19 |
|
629 | + */ |
|
630 | + public function add_discount( $discount ) { |
|
631 | + $this->discounts[ $discount['name'] ] = $discount; |
|
632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Removes a discount from the submission. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function remove_discount( $name ) { |
|
642 | + |
|
643 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | + unset( $this->discounts[ $name ] ); |
|
647 | + } |
|
648 | + |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Checks whether there is a discount code associated with this submission. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @return bool |
|
656 | + */ |
|
657 | + public function has_discount_code() { |
|
658 | + return ! empty( $this->discounts['discount_code'] ); |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Returns the discount code. |
|
663 | + * |
|
664 | + * @since 1.0.19 |
|
665 | + * @return string |
|
666 | + */ |
|
667 | + public function get_discount_code() { |
|
668 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Returns the discount. |
|
673 | + * |
|
674 | + * @since 1.0.19 |
|
675 | + */ |
|
676 | + public function get_discount() { |
|
677 | + return $this->totals['discount']['initial']; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Returns the recurring discount. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + */ |
|
685 | + public function get_recurring_discount() { |
|
686 | + return $this->totals['discount']['recurring']; |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Returns all discounts. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + */ |
|
694 | + public function get_discounts() { |
|
695 | + return $this->discounts; |
|
696 | + } |
|
697 | + |
|
698 | + /* |
|
699 | 699 | |-------------------------------------------------------------------------- |
700 | 700 | | Fees |
701 | 701 | |-------------------------------------------------------------------------- |
@@ -705,100 +705,100 @@ discard block |
||
705 | 705 | | fees. |
706 | 706 | */ |
707 | 707 | |
708 | - /** |
|
709 | - * Prepares the submission's fees. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - */ |
|
713 | - public function process_fees() { |
|
714 | - |
|
715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | - |
|
717 | - foreach ( $fees_processor->fees as $fee ) { |
|
718 | - $this->add_fee( $fee ); |
|
719 | - } |
|
720 | - |
|
721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Adds a fee to the submission. |
|
726 | - * |
|
727 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | - * @since 1.0.19 |
|
729 | - */ |
|
730 | - public function add_fee( $fee ) { |
|
731 | - |
|
732 | - if ( $fee['name'] == 'shipping' ) { |
|
733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | - return; |
|
736 | - } |
|
737 | - |
|
738 | - $this->fees[ $fee['name'] ] = $fee; |
|
739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | - |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Removes a fee from the submission. |
|
746 | - * |
|
747 | - * @since 1.0.19 |
|
748 | - */ |
|
749 | - public function remove_fee( $name ) { |
|
750 | - |
|
751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | - unset( $this->fees[ $name ] ); |
|
755 | - } |
|
756 | - |
|
757 | - if ( 'shipping' == $name ) { |
|
758 | - $this->totals['shipping']['initial'] = 0; |
|
759 | - $this->totals['shipping']['recurring'] = 0; |
|
760 | - } |
|
761 | - |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Returns the fees. |
|
766 | - * |
|
767 | - * @since 1.0.19 |
|
768 | - */ |
|
769 | - public function get_fee() { |
|
770 | - return $this->totals['fees']['initial']; |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Returns the recurring fees. |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - */ |
|
778 | - public function get_recurring_fee() { |
|
779 | - return $this->totals['fees']['recurring']; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Returns all fees. |
|
784 | - * |
|
785 | - * @since 1.0.19 |
|
786 | - */ |
|
787 | - public function get_fees() { |
|
788 | - return $this->fees; |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Checks if there are any fees for the form. |
|
793 | - * |
|
794 | - * @return bool |
|
795 | - * @since 1.0.19 |
|
796 | - */ |
|
797 | - public function has_fees() { |
|
798 | - return count( $this->fees ) !== 0; |
|
799 | - } |
|
800 | - |
|
801 | - /* |
|
708 | + /** |
|
709 | + * Prepares the submission's fees. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + */ |
|
713 | + public function process_fees() { |
|
714 | + |
|
715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | + |
|
717 | + foreach ( $fees_processor->fees as $fee ) { |
|
718 | + $this->add_fee( $fee ); |
|
719 | + } |
|
720 | + |
|
721 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Adds a fee to the submission. |
|
726 | + * |
|
727 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | + * @since 1.0.19 |
|
729 | + */ |
|
730 | + public function add_fee( $fee ) { |
|
731 | + |
|
732 | + if ( $fee['name'] == 'shipping' ) { |
|
733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | + return; |
|
736 | + } |
|
737 | + |
|
738 | + $this->fees[ $fee['name'] ] = $fee; |
|
739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | + |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Removes a fee from the submission. |
|
746 | + * |
|
747 | + * @since 1.0.19 |
|
748 | + */ |
|
749 | + public function remove_fee( $name ) { |
|
750 | + |
|
751 | + if ( isset( $this->fees[ $name ] ) ) { |
|
752 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | + unset( $this->fees[ $name ] ); |
|
755 | + } |
|
756 | + |
|
757 | + if ( 'shipping' == $name ) { |
|
758 | + $this->totals['shipping']['initial'] = 0; |
|
759 | + $this->totals['shipping']['recurring'] = 0; |
|
760 | + } |
|
761 | + |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Returns the fees. |
|
766 | + * |
|
767 | + * @since 1.0.19 |
|
768 | + */ |
|
769 | + public function get_fee() { |
|
770 | + return $this->totals['fees']['initial']; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Returns the recurring fees. |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + */ |
|
778 | + public function get_recurring_fee() { |
|
779 | + return $this->totals['fees']['recurring']; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Returns all fees. |
|
784 | + * |
|
785 | + * @since 1.0.19 |
|
786 | + */ |
|
787 | + public function get_fees() { |
|
788 | + return $this->fees; |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Checks if there are any fees for the form. |
|
793 | + * |
|
794 | + * @return bool |
|
795 | + * @since 1.0.19 |
|
796 | + */ |
|
797 | + public function has_fees() { |
|
798 | + return count( $this->fees ) !== 0; |
|
799 | + } |
|
800 | + |
|
801 | + /* |
|
802 | 802 | |-------------------------------------------------------------------------- |
803 | 803 | | MISC |
804 | 804 | |-------------------------------------------------------------------------- |
@@ -806,147 +806,147 @@ discard block |
||
806 | 806 | | Extra submission functions. |
807 | 807 | */ |
808 | 808 | |
809 | - /** |
|
810 | - * Returns the shipping amount. |
|
811 | - * |
|
812 | - * @since 1.0.19 |
|
813 | - */ |
|
814 | - public function get_shipping() { |
|
815 | - return $this->totals['shipping']['initial']; |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Returns the recurring shipping. |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - */ |
|
823 | - public function get_recurring_shipping() { |
|
824 | - return $this->totals['shipping']['recurring']; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * Checks if there are any shipping fees for the form. |
|
829 | - * |
|
830 | - * @return bool |
|
831 | - * @since 1.0.19 |
|
832 | - */ |
|
833 | - public function has_shipping() { |
|
834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Checks if this is the initial fetch. |
|
839 | - * |
|
840 | - * @return bool |
|
841 | - * @since 1.0.19 |
|
842 | - */ |
|
843 | - public function is_initial_fetch() { |
|
844 | - return empty( $this->data['initial_state'] ); |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Returns the total amount to collect for this submission. |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function get_total() { |
|
853 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | - return max( $total, 0 ); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the recurring total amount to collect for this submission. |
|
859 | - * |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function get_recurring_total() { |
|
863 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | - return max( $total, 0 ); |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * Whether payment details should be collected for this submission. |
|
869 | - * |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function should_collect_payment_details() { |
|
873 | - $initial = $this->get_total(); |
|
874 | - $recurring = $this->get_recurring_total(); |
|
875 | - |
|
876 | - if ( $this->has_recurring == 0 ) { |
|
877 | - $recurring = 0; |
|
878 | - } |
|
879 | - |
|
880 | - $collect = $initial > 0 || $recurring > 0; |
|
881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Returns the billing email of the user. |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - */ |
|
889 | - public function get_billing_email() { |
|
890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Checks if the submitter has a billing email. |
|
895 | - * |
|
896 | - * @since 1.0.19 |
|
897 | - */ |
|
898 | - public function has_billing_email() { |
|
899 | - $billing_email = $this->get_billing_email(); |
|
900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * Returns the appropriate currency for the submission. |
|
905 | - * |
|
906 | - * @since 1.0.19 |
|
907 | - * @return string |
|
908 | - */ |
|
909 | - public function get_currency() { |
|
910 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * Returns the raw submission data. |
|
915 | - * |
|
916 | - * @since 1.0.19 |
|
917 | - * @return array |
|
918 | - */ |
|
919 | - public function get_data() { |
|
920 | - return $this->data; |
|
921 | - } |
|
922 | - |
|
923 | - /** |
|
924 | - * Returns a field from the submission data |
|
925 | - * |
|
926 | - * @param string $field |
|
927 | - * @since 1.0.19 |
|
928 | - * @return mixed|null |
|
929 | - */ |
|
930 | - public function get_field( $field, $sub_array_key = null ) { |
|
931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Checks if a required field is set. |
|
936 | - * |
|
937 | - * @since 1.0.19 |
|
938 | - */ |
|
939 | - public function is_required_field_set( $field ) { |
|
940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Formats an amount |
|
945 | - * |
|
946 | - * @since 1.0.19 |
|
947 | - */ |
|
948 | - public function format_amount( $amount ) { |
|
949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
950 | - } |
|
809 | + /** |
|
810 | + * Returns the shipping amount. |
|
811 | + * |
|
812 | + * @since 1.0.19 |
|
813 | + */ |
|
814 | + public function get_shipping() { |
|
815 | + return $this->totals['shipping']['initial']; |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * Returns the recurring shipping. |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + */ |
|
823 | + public function get_recurring_shipping() { |
|
824 | + return $this->totals['shipping']['recurring']; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * Checks if there are any shipping fees for the form. |
|
829 | + * |
|
830 | + * @return bool |
|
831 | + * @since 1.0.19 |
|
832 | + */ |
|
833 | + public function has_shipping() { |
|
834 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Checks if this is the initial fetch. |
|
839 | + * |
|
840 | + * @return bool |
|
841 | + * @since 1.0.19 |
|
842 | + */ |
|
843 | + public function is_initial_fetch() { |
|
844 | + return empty( $this->data['initial_state'] ); |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Returns the total amount to collect for this submission. |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function get_total() { |
|
853 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | + return max( $total, 0 ); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the recurring total amount to collect for this submission. |
|
859 | + * |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function get_recurring_total() { |
|
863 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | + return max( $total, 0 ); |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * Whether payment details should be collected for this submission. |
|
869 | + * |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function should_collect_payment_details() { |
|
873 | + $initial = $this->get_total(); |
|
874 | + $recurring = $this->get_recurring_total(); |
|
875 | + |
|
876 | + if ( $this->has_recurring == 0 ) { |
|
877 | + $recurring = 0; |
|
878 | + } |
|
879 | + |
|
880 | + $collect = $initial > 0 || $recurring > 0; |
|
881 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Returns the billing email of the user. |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + */ |
|
889 | + public function get_billing_email() { |
|
890 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Checks if the submitter has a billing email. |
|
895 | + * |
|
896 | + * @since 1.0.19 |
|
897 | + */ |
|
898 | + public function has_billing_email() { |
|
899 | + $billing_email = $this->get_billing_email(); |
|
900 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * Returns the appropriate currency for the submission. |
|
905 | + * |
|
906 | + * @since 1.0.19 |
|
907 | + * @return string |
|
908 | + */ |
|
909 | + public function get_currency() { |
|
910 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * Returns the raw submission data. |
|
915 | + * |
|
916 | + * @since 1.0.19 |
|
917 | + * @return array |
|
918 | + */ |
|
919 | + public function get_data() { |
|
920 | + return $this->data; |
|
921 | + } |
|
922 | + |
|
923 | + /** |
|
924 | + * Returns a field from the submission data |
|
925 | + * |
|
926 | + * @param string $field |
|
927 | + * @since 1.0.19 |
|
928 | + * @return mixed|null |
|
929 | + */ |
|
930 | + public function get_field( $field, $sub_array_key = null ) { |
|
931 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Checks if a required field is set. |
|
936 | + * |
|
937 | + * @since 1.0.19 |
|
938 | + */ |
|
939 | + public function is_required_field_set( $field ) { |
|
940 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Formats an amount |
|
945 | + * |
|
946 | + * @since 1.0.19 |
|
947 | + */ |
|
948 | + public function format_amount( $amount ) { |
|
949 | + return wpinv_price( $amount, $this->get_currency() ); |
|
950 | + } |
|
951 | 951 | |
952 | 952 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,544 +15,544 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - '_wpinv_phone', |
|
34 | - '_wpinv_company_id', |
|
35 | - 'wpinv_shipping', |
|
36 | - 'wpinv_email_cc', |
|
37 | - 'wpinv_template', |
|
38 | - 'wpinv_created_via' |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * A map of meta keys to data props. |
|
43 | - * |
|
44 | - * @since 1.0.19 |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $meta_key_to_props = array( |
|
49 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | - '_wpinv_subscription_id' => 'subscription_id', |
|
51 | - '_wpinv_taxes' => 'taxes', |
|
52 | - '_wpinv_fees' => 'fees', |
|
53 | - '_wpinv_discounts' => 'discounts', |
|
54 | - '_wpinv_submission_id' => 'submission_id', |
|
55 | - '_wpinv_payment_form' => 'payment_form', |
|
56 | - '_wpinv_is_viewed' => 'is_viewed', |
|
57 | - 'wpinv_email_cc' => 'email_cc', |
|
58 | - 'wpinv_template' => 'template', |
|
59 | - 'wpinv_created_via' => 'created_via', |
|
60 | - '_wpinv_phone' => 'phone', |
|
61 | - '_wpinv_company_id' => 'company_id', |
|
62 | - 'wpinv_shipping' => 'shipping', |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * A map of database fields to data props. |
|
67 | - * |
|
68 | - * @since 1.0.19 |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $database_fields_to_props = array( |
|
73 | - 'post_id' => 'id', |
|
74 | - 'number' => 'number', |
|
75 | - 'currency' => 'currency', |
|
76 | - 'key' => 'key', |
|
77 | - 'type' => 'type', |
|
78 | - 'mode' => 'mode', |
|
79 | - 'user_ip' => 'user_ip', |
|
80 | - 'first_name' => 'first_name', |
|
81 | - 'last_name' => 'last_name', |
|
82 | - 'address' => 'address', |
|
83 | - 'city' => 'city', |
|
84 | - 'state' => 'state', |
|
85 | - 'country' => 'country', |
|
86 | - 'zip' => 'zip', |
|
87 | - 'zip' => 'zip', |
|
88 | - 'adddress_confirmed' => 'address_confirmed', |
|
89 | - 'gateway' => 'gateway', |
|
90 | - 'transaction_id' => 'transaction_id', |
|
91 | - 'currency' => 'currency', |
|
92 | - 'subtotal' => 'subtotal', |
|
93 | - 'tax' => 'total_tax', |
|
94 | - 'fees_total' => 'total_fees', |
|
95 | - 'discount' => 'total_discount', |
|
96 | - 'total' => 'total', |
|
97 | - 'discount_code' => 'discount_code', |
|
98 | - 'disable_taxes' => 'disable_taxes', |
|
99 | - 'due_date' => 'due_date', |
|
100 | - 'completed_date' => 'completed_date', |
|
101 | - 'company' => 'company', |
|
102 | - 'vat_number' => 'vat_number', |
|
103 | - 'vat_rate' => 'vat_rate', |
|
104 | - ); |
|
105 | - |
|
106 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + '_wpinv_phone', |
|
34 | + '_wpinv_company_id', |
|
35 | + 'wpinv_shipping', |
|
36 | + 'wpinv_email_cc', |
|
37 | + 'wpinv_template', |
|
38 | + 'wpinv_created_via' |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * A map of meta keys to data props. |
|
43 | + * |
|
44 | + * @since 1.0.19 |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $meta_key_to_props = array( |
|
49 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | + '_wpinv_subscription_id' => 'subscription_id', |
|
51 | + '_wpinv_taxes' => 'taxes', |
|
52 | + '_wpinv_fees' => 'fees', |
|
53 | + '_wpinv_discounts' => 'discounts', |
|
54 | + '_wpinv_submission_id' => 'submission_id', |
|
55 | + '_wpinv_payment_form' => 'payment_form', |
|
56 | + '_wpinv_is_viewed' => 'is_viewed', |
|
57 | + 'wpinv_email_cc' => 'email_cc', |
|
58 | + 'wpinv_template' => 'template', |
|
59 | + 'wpinv_created_via' => 'created_via', |
|
60 | + '_wpinv_phone' => 'phone', |
|
61 | + '_wpinv_company_id' => 'company_id', |
|
62 | + 'wpinv_shipping' => 'shipping', |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * A map of database fields to data props. |
|
67 | + * |
|
68 | + * @since 1.0.19 |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $database_fields_to_props = array( |
|
73 | + 'post_id' => 'id', |
|
74 | + 'number' => 'number', |
|
75 | + 'currency' => 'currency', |
|
76 | + 'key' => 'key', |
|
77 | + 'type' => 'type', |
|
78 | + 'mode' => 'mode', |
|
79 | + 'user_ip' => 'user_ip', |
|
80 | + 'first_name' => 'first_name', |
|
81 | + 'last_name' => 'last_name', |
|
82 | + 'address' => 'address', |
|
83 | + 'city' => 'city', |
|
84 | + 'state' => 'state', |
|
85 | + 'country' => 'country', |
|
86 | + 'zip' => 'zip', |
|
87 | + 'zip' => 'zip', |
|
88 | + 'adddress_confirmed' => 'address_confirmed', |
|
89 | + 'gateway' => 'gateway', |
|
90 | + 'transaction_id' => 'transaction_id', |
|
91 | + 'currency' => 'currency', |
|
92 | + 'subtotal' => 'subtotal', |
|
93 | + 'tax' => 'total_tax', |
|
94 | + 'fees_total' => 'total_fees', |
|
95 | + 'discount' => 'total_discount', |
|
96 | + 'total' => 'total', |
|
97 | + 'discount_code' => 'discount_code', |
|
98 | + 'disable_taxes' => 'disable_taxes', |
|
99 | + 'due_date' => 'due_date', |
|
100 | + 'completed_date' => 'completed_date', |
|
101 | + 'company' => 'company', |
|
102 | + 'vat_number' => 'vat_number', |
|
103 | + 'vat_rate' => 'vat_rate', |
|
104 | + ); |
|
105 | + |
|
106 | + /* |
|
107 | 107 | |-------------------------------------------------------------------------- |
108 | 108 | | CRUD Methods |
109 | 109 | |-------------------------------------------------------------------------- |
110 | 110 | */ |
111 | 111 | |
112 | - /** |
|
113 | - * Method to create a new invoice in the database. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice Invoice object. |
|
116 | - */ |
|
117 | - public function create( &$invoice ) { |
|
118 | - $invoice->set_version( WPINV_VERSION ); |
|
119 | - $invoice->set_date_created( current_time('mysql') ); |
|
120 | - |
|
121 | - // Create a new post. |
|
122 | - $id = wp_insert_post( |
|
123 | - apply_filters( |
|
124 | - 'getpaid_new_invoice_data', |
|
125 | - array( |
|
126 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
127 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
128 | - 'post_status' => $this->get_post_status( $invoice ), |
|
129 | - 'ping_status' => 'closed', |
|
130 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
131 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
132 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
133 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
134 | - ) |
|
135 | - ), |
|
136 | - true |
|
137 | - ); |
|
138 | - |
|
139 | - if ( $id && ! is_wp_error( $id ) ) { |
|
140 | - |
|
141 | - // Update the new id and regenerate a title. |
|
142 | - $invoice->set_id( $id ); |
|
143 | - |
|
144 | - $invoice->maybe_set_number(); |
|
145 | - |
|
146 | - wp_update_post( |
|
147 | - array( |
|
148 | - 'ID' => $invoice->get_id(), |
|
149 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
150 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
151 | - ) |
|
152 | - ); |
|
153 | - |
|
154 | - // Save special fields and items. |
|
155 | - $this->save_special_fields( $invoice ); |
|
156 | - $this->save_items( $invoice ); |
|
157 | - |
|
158 | - // Update meta data. |
|
159 | - $this->update_post_meta( $invoice ); |
|
160 | - $invoice->save_meta_data(); |
|
161 | - |
|
162 | - // Apply changes. |
|
163 | - $invoice->apply_changes(); |
|
164 | - $this->clear_caches( $invoice ); |
|
165 | - |
|
166 | - // Fires after a new invoice is created. |
|
167 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
168 | - return true; |
|
169 | - } |
|
170 | - |
|
171 | - if ( is_wp_error( $id ) ) { |
|
172 | - $invoice->last_error = $id->get_error_message(); |
|
173 | - } |
|
174 | - |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Method to read an invoice from the database. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * |
|
183 | - */ |
|
184 | - public function read( &$invoice ) { |
|
185 | - |
|
186 | - $invoice->set_defaults(); |
|
187 | - $invoice_object = get_post( $invoice->get_id() ); |
|
188 | - |
|
189 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
190 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
191 | - $invoice->set_id( 0 ); |
|
192 | - return false; |
|
193 | - } |
|
194 | - |
|
195 | - $invoice->set_props( |
|
196 | - array( |
|
197 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
198 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
199 | - 'status' => $invoice_object->post_status, |
|
200 | - 'author' => $invoice_object->post_author, |
|
201 | - 'description' => $invoice_object->post_excerpt, |
|
202 | - 'parent_id' => $invoice_object->post_parent, |
|
203 | - 'name' => $invoice_object->post_title, |
|
204 | - 'path' => $invoice_object->post_name, |
|
205 | - 'post_type' => $invoice_object->post_type, |
|
206 | - ) |
|
207 | - ); |
|
208 | - |
|
209 | - $invoice->set_type( $invoice_object->post_type ); |
|
210 | - |
|
211 | - $this->read_object_data( $invoice, $invoice_object ); |
|
212 | - $this->add_special_fields( $invoice ); |
|
213 | - $this->add_items( $invoice ); |
|
214 | - $invoice->read_meta_data(); |
|
215 | - $invoice->set_object_read( true ); |
|
216 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
217 | - |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Method to update an invoice in the database. |
|
222 | - * |
|
223 | - * @param WPInv_Invoice $invoice Invoice object. |
|
224 | - */ |
|
225 | - public function update( &$invoice ) { |
|
226 | - $invoice->save_meta_data(); |
|
227 | - $invoice->set_version( WPINV_VERSION ); |
|
228 | - |
|
229 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
230 | - $invoice->set_date_created( current_time('mysql') ); |
|
231 | - } |
|
232 | - |
|
233 | - // Ensure both the key and number are set. |
|
234 | - $invoice->get_path(); |
|
235 | - |
|
236 | - // Grab the current status so we can compare. |
|
237 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
238 | - |
|
239 | - $changes = $invoice->get_changes(); |
|
240 | - |
|
241 | - // Only update the post when the post data changes. |
|
242 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
243 | - $post_data = array( |
|
244 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
245 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
246 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
247 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
248 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
249 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
250 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
251 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
252 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
253 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
254 | - ); |
|
255 | - |
|
256 | - /** |
|
257 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
258 | - * to update data, since wp_update_post spawns more calls to the |
|
259 | - * save_post action. |
|
260 | - * |
|
261 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
262 | - * or an update purely from CRUD. |
|
263 | - */ |
|
264 | - if ( doing_action( 'save_post' ) ) { |
|
265 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
266 | - clean_post_cache( $invoice->get_id() ); |
|
267 | - } else { |
|
268 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
269 | - } |
|
270 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
271 | - } |
|
272 | - |
|
273 | - // Update meta data. |
|
274 | - $this->update_post_meta( $invoice ); |
|
275 | - |
|
276 | - // Save special fields and items. |
|
277 | - $this->save_special_fields( $invoice ); |
|
278 | - $this->save_items( $invoice ); |
|
279 | - |
|
280 | - // Apply the changes. |
|
281 | - $invoice->apply_changes(); |
|
282 | - |
|
283 | - // Clear caches. |
|
284 | - $this->clear_caches( $invoice ); |
|
285 | - |
|
286 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
287 | - $new_status = $invoice->get_status( 'edit' ); |
|
288 | - |
|
289 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
290 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
291 | - } else { |
|
292 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
293 | - } |
|
294 | - |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
112 | + /** |
|
113 | + * Method to create a new invoice in the database. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice Invoice object. |
|
116 | + */ |
|
117 | + public function create( &$invoice ) { |
|
118 | + $invoice->set_version( WPINV_VERSION ); |
|
119 | + $invoice->set_date_created( current_time('mysql') ); |
|
120 | + |
|
121 | + // Create a new post. |
|
122 | + $id = wp_insert_post( |
|
123 | + apply_filters( |
|
124 | + 'getpaid_new_invoice_data', |
|
125 | + array( |
|
126 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
127 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
128 | + 'post_status' => $this->get_post_status( $invoice ), |
|
129 | + 'ping_status' => 'closed', |
|
130 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
131 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
132 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
133 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
134 | + ) |
|
135 | + ), |
|
136 | + true |
|
137 | + ); |
|
138 | + |
|
139 | + if ( $id && ! is_wp_error( $id ) ) { |
|
140 | + |
|
141 | + // Update the new id and regenerate a title. |
|
142 | + $invoice->set_id( $id ); |
|
143 | + |
|
144 | + $invoice->maybe_set_number(); |
|
145 | + |
|
146 | + wp_update_post( |
|
147 | + array( |
|
148 | + 'ID' => $invoice->get_id(), |
|
149 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
150 | + 'post_name' => $invoice->get_path( 'edit' ) |
|
151 | + ) |
|
152 | + ); |
|
153 | + |
|
154 | + // Save special fields and items. |
|
155 | + $this->save_special_fields( $invoice ); |
|
156 | + $this->save_items( $invoice ); |
|
157 | + |
|
158 | + // Update meta data. |
|
159 | + $this->update_post_meta( $invoice ); |
|
160 | + $invoice->save_meta_data(); |
|
161 | + |
|
162 | + // Apply changes. |
|
163 | + $invoice->apply_changes(); |
|
164 | + $this->clear_caches( $invoice ); |
|
165 | + |
|
166 | + // Fires after a new invoice is created. |
|
167 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
168 | + return true; |
|
169 | + } |
|
170 | + |
|
171 | + if ( is_wp_error( $id ) ) { |
|
172 | + $invoice->last_error = $id->get_error_message(); |
|
173 | + } |
|
174 | + |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Method to read an invoice from the database. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * |
|
183 | + */ |
|
184 | + public function read( &$invoice ) { |
|
185 | + |
|
186 | + $invoice->set_defaults(); |
|
187 | + $invoice_object = get_post( $invoice->get_id() ); |
|
188 | + |
|
189 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
190 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
191 | + $invoice->set_id( 0 ); |
|
192 | + return false; |
|
193 | + } |
|
194 | + |
|
195 | + $invoice->set_props( |
|
196 | + array( |
|
197 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
198 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
199 | + 'status' => $invoice_object->post_status, |
|
200 | + 'author' => $invoice_object->post_author, |
|
201 | + 'description' => $invoice_object->post_excerpt, |
|
202 | + 'parent_id' => $invoice_object->post_parent, |
|
203 | + 'name' => $invoice_object->post_title, |
|
204 | + 'path' => $invoice_object->post_name, |
|
205 | + 'post_type' => $invoice_object->post_type, |
|
206 | + ) |
|
207 | + ); |
|
208 | + |
|
209 | + $invoice->set_type( $invoice_object->post_type ); |
|
210 | + |
|
211 | + $this->read_object_data( $invoice, $invoice_object ); |
|
212 | + $this->add_special_fields( $invoice ); |
|
213 | + $this->add_items( $invoice ); |
|
214 | + $invoice->read_meta_data(); |
|
215 | + $invoice->set_object_read( true ); |
|
216 | + do_action( 'getpaid_read_invoice', $invoice ); |
|
217 | + |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Method to update an invoice in the database. |
|
222 | + * |
|
223 | + * @param WPInv_Invoice $invoice Invoice object. |
|
224 | + */ |
|
225 | + public function update( &$invoice ) { |
|
226 | + $invoice->save_meta_data(); |
|
227 | + $invoice->set_version( WPINV_VERSION ); |
|
228 | + |
|
229 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
230 | + $invoice->set_date_created( current_time('mysql') ); |
|
231 | + } |
|
232 | + |
|
233 | + // Ensure both the key and number are set. |
|
234 | + $invoice->get_path(); |
|
235 | + |
|
236 | + // Grab the current status so we can compare. |
|
237 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
238 | + |
|
239 | + $changes = $invoice->get_changes(); |
|
240 | + |
|
241 | + // Only update the post when the post data changes. |
|
242 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
243 | + $post_data = array( |
|
244 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
245 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
246 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
247 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
248 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
249 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
250 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
251 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
252 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
253 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
254 | + ); |
|
255 | + |
|
256 | + /** |
|
257 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
258 | + * to update data, since wp_update_post spawns more calls to the |
|
259 | + * save_post action. |
|
260 | + * |
|
261 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
262 | + * or an update purely from CRUD. |
|
263 | + */ |
|
264 | + if ( doing_action( 'save_post' ) ) { |
|
265 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
266 | + clean_post_cache( $invoice->get_id() ); |
|
267 | + } else { |
|
268 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
269 | + } |
|
270 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
271 | + } |
|
272 | + |
|
273 | + // Update meta data. |
|
274 | + $this->update_post_meta( $invoice ); |
|
275 | + |
|
276 | + // Save special fields and items. |
|
277 | + $this->save_special_fields( $invoice ); |
|
278 | + $this->save_items( $invoice ); |
|
279 | + |
|
280 | + // Apply the changes. |
|
281 | + $invoice->apply_changes(); |
|
282 | + |
|
283 | + // Clear caches. |
|
284 | + $this->clear_caches( $invoice ); |
|
285 | + |
|
286 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
287 | + $new_status = $invoice->get_status( 'edit' ); |
|
288 | + |
|
289 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
290 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
291 | + } else { |
|
292 | + do_action( 'getpaid_update_invoice', $invoice ); |
|
293 | + } |
|
294 | + |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Additional Methods |
300 | 300 | |-------------------------------------------------------------------------- |
301 | 301 | */ |
302 | 302 | |
303 | - /** |
|
303 | + /** |
|
304 | 304 | * Retrieves special fields and adds to the invoice. |
305 | - * |
|
306 | - * @param WPInv_Invoice $invoice Invoice object. |
|
305 | + * |
|
306 | + * @param WPInv_Invoice $invoice Invoice object. |
|
307 | 307 | */ |
308 | 308 | public function add_special_fields( &$invoice ) { |
309 | - global $wpdb; |
|
309 | + global $wpdb; |
|
310 | 310 | |
311 | - // Maybe retrieve from the cache. |
|
312 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
311 | + // Maybe retrieve from the cache. |
|
312 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
313 | 313 | |
314 | - // If not found, retrieve from the db. |
|
315 | - if ( false === $data ) { |
|
316 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
314 | + // If not found, retrieve from the db. |
|
315 | + if ( false === $data ) { |
|
316 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
317 | 317 | |
318 | - $data = $wpdb->get_row( |
|
319 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
320 | - ARRAY_A |
|
321 | - ); |
|
318 | + $data = $wpdb->get_row( |
|
319 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
320 | + ARRAY_A |
|
321 | + ); |
|
322 | 322 | |
323 | - // Update the cache with our data |
|
324 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
323 | + // Update the cache with our data |
|
324 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
325 | 325 | |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | - // Abort if the data does not exist. |
|
329 | - if ( empty( $data ) ) { |
|
330 | - $invoice->set_object_read( true ); |
|
331 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
332 | - return; |
|
333 | - } |
|
328 | + // Abort if the data does not exist. |
|
329 | + if ( empty( $data ) ) { |
|
330 | + $invoice->set_object_read( true ); |
|
331 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
332 | + return; |
|
333 | + } |
|
334 | 334 | |
335 | - $props = array(); |
|
335 | + $props = array(); |
|
336 | 336 | |
337 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
337 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
338 | 338 | |
339 | - if ( $db_field == 'post_id' ) { |
|
340 | - continue; |
|
341 | - } |
|
342 | - |
|
343 | - $props[ $prop ] = $data[ $db_field ]; |
|
344 | - } |
|
345 | - |
|
346 | - $invoice->set_props( $props ); |
|
347 | - |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Gets a list of special fields that need updated based on change state |
|
352 | - * or if they are present in the database or not. |
|
353 | - * |
|
354 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
355 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
356 | - */ |
|
357 | - protected function get_special_fields_to_update( $invoice ) { |
|
358 | - $fields_to_update = array(); |
|
359 | - $changed_props = $invoice->get_changes(); |
|
360 | - |
|
361 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
362 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
363 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
364 | - $fields_to_update[ $database_field ] = $prop; |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - return $fields_to_update; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
373 | - * |
|
374 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
375 | - * @since 1.0.19 |
|
376 | - */ |
|
377 | - protected function update_special_fields( &$invoice ) { |
|
378 | - global $wpdb; |
|
379 | - |
|
380 | - $updated_props = array(); |
|
381 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
382 | - |
|
383 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
384 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
385 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
386 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
387 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
388 | - } |
|
389 | - |
|
390 | - if ( ! empty( $updated_props ) ) { |
|
391 | - |
|
392 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
393 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
394 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
395 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
396 | - |
|
397 | - } |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Helper method that inserts special fields to the database. |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
405 | - * @since 1.0.19 |
|
406 | - */ |
|
407 | - protected function insert_special_fields( &$invoice ) { |
|
408 | - global $wpdb; |
|
409 | - |
|
410 | - $updated_props = array(); |
|
411 | - |
|
412 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
413 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
414 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
415 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
416 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
417 | - } |
|
418 | - |
|
419 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
420 | - $wpdb->insert( $table, $updated_props ); |
|
421 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
422 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
423 | - |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
339 | + if ( $db_field == 'post_id' ) { |
|
340 | + continue; |
|
341 | + } |
|
342 | + |
|
343 | + $props[ $prop ] = $data[ $db_field ]; |
|
344 | + } |
|
345 | + |
|
346 | + $invoice->set_props( $props ); |
|
347 | + |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Gets a list of special fields that need updated based on change state |
|
352 | + * or if they are present in the database or not. |
|
353 | + * |
|
354 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
355 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
356 | + */ |
|
357 | + protected function get_special_fields_to_update( $invoice ) { |
|
358 | + $fields_to_update = array(); |
|
359 | + $changed_props = $invoice->get_changes(); |
|
360 | + |
|
361 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
362 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
363 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
364 | + $fields_to_update[ $database_field ] = $prop; |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + return $fields_to_update; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
373 | + * |
|
374 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
375 | + * @since 1.0.19 |
|
376 | + */ |
|
377 | + protected function update_special_fields( &$invoice ) { |
|
378 | + global $wpdb; |
|
379 | + |
|
380 | + $updated_props = array(); |
|
381 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
382 | + |
|
383 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
384 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
385 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
386 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
387 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
388 | + } |
|
389 | + |
|
390 | + if ( ! empty( $updated_props ) ) { |
|
391 | + |
|
392 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
393 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
394 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
395 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
396 | + |
|
397 | + } |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Helper method that inserts special fields to the database. |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
405 | + * @since 1.0.19 |
|
406 | + */ |
|
407 | + protected function insert_special_fields( &$invoice ) { |
|
408 | + global $wpdb; |
|
409 | + |
|
410 | + $updated_props = array(); |
|
411 | + |
|
412 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
413 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
414 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
415 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
416 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
417 | + } |
|
418 | + |
|
419 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
420 | + $wpdb->insert( $table, $updated_props ); |
|
421 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
422 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
423 | + |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | 427 | * Saves all special fields. |
428 | - * |
|
429 | - * @param WPInv_Invoice $invoice Invoice object. |
|
428 | + * |
|
429 | + * @param WPInv_Invoice $invoice Invoice object. |
|
430 | 430 | */ |
431 | 431 | public function save_special_fields( & $invoice ) { |
432 | - global $wpdb; |
|
432 | + global $wpdb; |
|
433 | 433 | |
434 | - // The invoices table. |
|
435 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
436 | - $id = (int) $invoice->get_id(); |
|
437 | - $invoice->maybe_set_key(); |
|
434 | + // The invoices table. |
|
435 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
436 | + $id = (int) $invoice->get_id(); |
|
437 | + $invoice->maybe_set_key(); |
|
438 | 438 | |
439 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
439 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
440 | 440 | |
441 | - $this->update_special_fields( $invoice ); |
|
441 | + $this->update_special_fields( $invoice ); |
|
442 | 442 | |
443 | - } else { |
|
443 | + } else { |
|
444 | 444 | |
445 | - $this->insert_special_fields( $invoice ); |
|
445 | + $this->insert_special_fields( $invoice ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - } |
|
449 | + } |
|
450 | 450 | |
451 | - /** |
|
451 | + /** |
|
452 | 452 | * Set's up cart details. |
453 | - * |
|
454 | - * @param WPInv_Invoice $invoice Invoice object. |
|
453 | + * |
|
454 | + * @param WPInv_Invoice $invoice Invoice object. |
|
455 | 455 | */ |
456 | 456 | public function add_items( &$invoice ) { |
457 | - global $wpdb; |
|
457 | + global $wpdb; |
|
458 | 458 | |
459 | - // Maybe retrieve from the cache. |
|
460 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
459 | + // Maybe retrieve from the cache. |
|
460 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
461 | 461 | |
462 | - // If not found, retrieve from the db. |
|
463 | - if ( false === $items ) { |
|
464 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
462 | + // If not found, retrieve from the db. |
|
463 | + if ( false === $items ) { |
|
464 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
465 | 465 | |
466 | - $items = $wpdb->get_results( |
|
467 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
468 | - ); |
|
466 | + $items = $wpdb->get_results( |
|
467 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
468 | + ); |
|
469 | 469 | |
470 | - // Update the cache with our data |
|
471 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
470 | + // Update the cache with our data |
|
471 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
472 | 472 | |
473 | - } |
|
473 | + } |
|
474 | 474 | |
475 | - // Abort if no items found. |
|
475 | + // Abort if no items found. |
|
476 | 476 | if ( empty( $items ) ) { |
477 | 477 | return; |
478 | - } |
|
479 | - |
|
480 | - $_items = array(); |
|
481 | - foreach ( $items as $item_data ) { |
|
482 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
483 | - |
|
484 | - // Set item data. |
|
485 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
486 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
487 | - $item->set_name( $item_data->item_name ); |
|
488 | - $item->set_description( $item_data->item_description ); |
|
489 | - $item->set_price( $item_data->item_price ); |
|
490 | - $item->set_quantity( $item_data->quantity ); |
|
491 | - $item->set_item_meta( $item_data->meta ); |
|
492 | - $_items[] = $item; |
|
493 | - } |
|
494 | - |
|
495 | - $invoice->set_items( $_items ); |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
478 | + } |
|
479 | + |
|
480 | + $_items = array(); |
|
481 | + foreach ( $items as $item_data ) { |
|
482 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
483 | + |
|
484 | + // Set item data. |
|
485 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
486 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
487 | + $item->set_name( $item_data->item_name ); |
|
488 | + $item->set_description( $item_data->item_description ); |
|
489 | + $item->set_price( $item_data->item_price ); |
|
490 | + $item->set_quantity( $item_data->quantity ); |
|
491 | + $item->set_item_meta( $item_data->meta ); |
|
492 | + $_items[] = $item; |
|
493 | + } |
|
494 | + |
|
495 | + $invoice->set_items( $_items ); |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | 499 | * Saves cart details. |
500 | - * |
|
501 | - * @param WPInv_Invoice $invoice Invoice object. |
|
500 | + * |
|
501 | + * @param WPInv_Invoice $invoice Invoice object. |
|
502 | 502 | */ |
503 | 503 | public function save_items( $invoice ) { |
504 | 504 | |
505 | - // Delete previously existing items. |
|
506 | - $this->delete_items( $invoice ); |
|
505 | + // Delete previously existing items. |
|
506 | + $this->delete_items( $invoice ); |
|
507 | 507 | |
508 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
508 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
509 | 509 | |
510 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
511 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
512 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
513 | - } |
|
510 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
511 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
512 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
513 | + } |
|
514 | 514 | |
515 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
516 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
515 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
516 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
517 | 517 | |
518 | - } |
|
518 | + } |
|
519 | 519 | |
520 | - /** |
|
520 | + /** |
|
521 | 521 | * Deletes an invoice's cart details from the database. |
522 | - * |
|
523 | - * @param WPInv_Invoice $invoice Invoice object. |
|
522 | + * |
|
523 | + * @param WPInv_Invoice $invoice Invoice object. |
|
524 | 524 | */ |
525 | 525 | public function delete_items( $invoice ) { |
526 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
527 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
528 | - } |
|
526 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
527 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
528 | + } |
|
529 | 529 | |
530 | - /** |
|
530 | + /** |
|
531 | 531 | * Deletes an invoice's special fields from the database. |
532 | - * |
|
533 | - * @param WPInv_Invoice $invoice Invoice object. |
|
532 | + * |
|
533 | + * @param WPInv_Invoice $invoice Invoice object. |
|
534 | 534 | */ |
535 | 535 | public function delete_special_fields( $invoice ) { |
536 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
537 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
538 | - } |
|
536 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
537 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
538 | + } |
|
539 | 539 | |
540 | - /** |
|
541 | - * Get the status to save to the post object. |
|
542 | - * |
|
543 | - * |
|
544 | - * @since 1.0.19 |
|
545 | - * @param WPInv_Invoice $object GetPaid_Data object. |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - protected function get_post_status( $object ) { |
|
549 | - $object_status = $object->get_status( 'edit' ); |
|
550 | - |
|
551 | - if ( ! $object_status ) { |
|
552 | - $object_status = $object->get_default_status(); |
|
553 | - } |
|
554 | - |
|
555 | - return $object_status; |
|
556 | - } |
|
540 | + /** |
|
541 | + * Get the status to save to the post object. |
|
542 | + * |
|
543 | + * |
|
544 | + * @since 1.0.19 |
|
545 | + * @param WPInv_Invoice $object GetPaid_Data object. |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + protected function get_post_status( $object ) { |
|
549 | + $object_status = $object->get_status( 'edit' ); |
|
550 | + |
|
551 | + if ( ! $object_status ) { |
|
552 | + $object_status = $object->get_default_status(); |
|
553 | + } |
|
554 | + |
|
555 | + return $object_status; |
|
556 | + } |
|
557 | 557 | |
558 | 558 | } |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
125 | + |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
131 | + |
|
132 | + $invoice = $submission->get_invoice(); |
|
133 | 133 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
138 | 138 | |
139 | - return $invoice; |
|
140 | - } |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | 150 | |
151 | - $submission = $this->payment_form_submission; |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | 152 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | if ( empty( $user ) ) { |
200 | 200 | $user = wpinv_create_user( $submission->get_billing_email() ); |
201 | 201 | |
202 | - // (Maybe) send new user notification. |
|
203 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | - wp_send_new_user_notifications( $user, 'user' ); |
|
206 | - } |
|
202 | + // (Maybe) send new user notification. |
|
203 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | + wp_send_new_user_notifications( $user, 'user' ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -213,49 +213,49 @@ discard block |
||
213 | 213 | |
214 | 214 | if ( is_numeric( $user ) ) { |
215 | 215 | return $user; |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - return $user->ID; |
|
218 | + return $user->ID; |
|
219 | 219 | |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
222 | + /** |
|
223 | 223 | * Prepares submission data for saving to the database. |
224 | 224 | * |
225 | - * @return array |
|
225 | + * @return array |
|
226 | 226 | */ |
227 | 227 | public function prepare_submission_data_for_saving() { |
228 | 228 | |
229 | - $submission = $this->payment_form_submission; |
|
229 | + $submission = $this->payment_form_submission; |
|
230 | 230 | |
231 | - // Prepared submission details. |
|
231 | + // Prepared submission details. |
|
232 | 232 | $prepared = array( |
233 | - 'all' => array(), |
|
234 | - 'meta' => array(), |
|
235 | - ); |
|
233 | + 'all' => array(), |
|
234 | + 'meta' => array(), |
|
235 | + ); |
|
236 | 236 | |
237 | 237 | // Raw submission details. |
238 | - $data = $submission->get_data(); |
|
238 | + $data = $submission->get_data(); |
|
239 | 239 | |
240 | - // Loop through the submitted details. |
|
240 | + // Loop through the submitted details. |
|
241 | 241 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
242 | 242 | |
243 | - // Skip premade fields. |
|
243 | + // Skip premade fields. |
|
244 | 244 | if ( ! empty( $field['premade'] ) ) { |
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | - // Ensure address is provided. |
|
249 | - if ( $field['type'] == 'address' ) { |
|
248 | + // Ensure address is provided. |
|
249 | + if ( $field['type'] == 'address' ) { |
|
250 | 250 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
251 | 251 | |
252 | - foreach ( $field['fields'] as $address_field ) { |
|
252 | + foreach ( $field['fields'] as $address_field ) { |
|
253 | 253 | |
254 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | 260 | } |
261 | 261 | |
@@ -267,31 +267,31 @@ discard block |
||
267 | 267 | // Handle misc fields. |
268 | 268 | if ( isset( $data[ $field['id'] ] ) ) { |
269 | 269 | |
270 | - // Uploads. |
|
271 | - if ( $field['type'] == 'file_upload' ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + // Uploads. |
|
271 | + if ( $field['type'] == 'file_upload' ) { |
|
272 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | - } |
|
274 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | + } |
|
277 | 277 | |
278 | - $value = array(); |
|
278 | + $value = array(); |
|
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | - $value[] = sprintf( |
|
282 | - '<a href="%s" target="_blank">%s</a>', |
|
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
285 | - ); |
|
286 | - } |
|
280 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | + $value[] = sprintf( |
|
282 | + '<a href="%s" target="_blank">%s</a>', |
|
283 | + esc_url_raw( $url ), |
|
284 | + esc_html( $name ) |
|
285 | + ); |
|
286 | + } |
|
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode( ' | ', $value ); |
|
289 | 289 | |
290 | - } else if ( $field['type'] == 'checkbox' ) { |
|
291 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | - } else { |
|
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | - } |
|
290 | + } else if ( $field['type'] == 'checkbox' ) { |
|
291 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | + } else { |
|
293 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | + } |
|
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
@@ -299,190 +299,190 @@ discard block |
||
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | - } |
|
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if ( ! empty( $field['add_meta'] ) ) { |
|
303 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + } |
|
305 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - return $prepared; |
|
311 | + return $prepared; |
|
312 | 312 | |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
315 | + /** |
|
316 | 316 | * Retrieves address details. |
317 | 317 | * |
318 | - * @return array |
|
319 | - * @param WPInv_Invoice $invoice |
|
320 | - * @param string $type |
|
318 | + * @return array |
|
319 | + * @param WPInv_Invoice $invoice |
|
320 | + * @param string $type |
|
321 | 321 | */ |
322 | 322 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
323 | 323 | |
324 | - $data = $this->payment_form_submission->get_data(); |
|
325 | - $type = sanitize_key( $type ); |
|
326 | - $address = array(); |
|
327 | - $prepared = array(); |
|
324 | + $data = $this->payment_form_submission->get_data(); |
|
325 | + $type = sanitize_key( $type ); |
|
326 | + $address = array(); |
|
327 | + $prepared = array(); |
|
328 | 328 | |
329 | - if ( ! empty( $data[ $type ] ) ) { |
|
330 | - $address = $data[ $type ]; |
|
331 | - } |
|
329 | + if ( ! empty( $data[ $type ] ) ) { |
|
330 | + $address = $data[ $type ]; |
|
331 | + } |
|
332 | 332 | |
333 | - // Clean address details. |
|
334 | - foreach ( $address as $key => $value ) { |
|
335 | - $key = sanitize_key( $key ); |
|
336 | - $key = str_replace( 'wpinv_', '', $key ); |
|
337 | - $value = wpinv_clean( $value ); |
|
338 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
339 | - } |
|
333 | + // Clean address details. |
|
334 | + foreach ( $address as $key => $value ) { |
|
335 | + $key = sanitize_key( $key ); |
|
336 | + $key = str_replace( 'wpinv_', '', $key ); |
|
337 | + $value = wpinv_clean( $value ); |
|
338 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
339 | + } |
|
340 | 340 | |
341 | - // Filter address details. |
|
342 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | + // Filter address details. |
|
342 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
343 | 343 | |
344 | - // Remove non-whitelisted values. |
|
345 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | + // Remove non-whitelisted values. |
|
345 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
346 | 346 | |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
349 | + /** |
|
350 | 350 | * Prepares the billing details. |
351 | 351 | * |
352 | - * @return array |
|
353 | - * @param WPInv_Invoice $invoice |
|
352 | + * @return array |
|
353 | + * @param WPInv_Invoice $invoice |
|
354 | 354 | */ |
355 | 355 | protected function prepare_billing_info( &$invoice ) { |
356 | 356 | |
357 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
357 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
358 | 358 | |
359 | - // Update the invoice with the billing details. |
|
360 | - $invoice->set_props( $billing_address ); |
|
359 | + // Update the invoice with the billing details. |
|
360 | + $invoice->set_props( $billing_address ); |
|
361 | 361 | |
362 | - } |
|
362 | + } |
|
363 | 363 | |
364 | - /** |
|
364 | + /** |
|
365 | 365 | * Prepares the shipping details. |
366 | 366 | * |
367 | - * @return array |
|
368 | - * @param WPInv_Invoice $invoice |
|
367 | + * @return array |
|
368 | + * @param WPInv_Invoice $invoice |
|
369 | 369 | */ |
370 | 370 | protected function prepare_shipping_info( $invoice ) { |
371 | 371 | |
372 | - $data = $this->payment_form_submission->get_data(); |
|
372 | + $data = $this->payment_form_submission->get_data(); |
|
373 | 373 | |
374 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
376 | - } |
|
374 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
376 | + } |
|
377 | 377 | |
378 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
378 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
379 | 379 | |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Confirms the submission is valid and send users to the gateway. |
|
384 | - * |
|
385 | - * @param WPInv_Invoice $invoice |
|
386 | - * @param array $prepared_payment_form_data |
|
387 | - * @param array $shipping |
|
388 | - */ |
|
389 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
382 | + /** |
|
383 | + * Confirms the submission is valid and send users to the gateway. |
|
384 | + * |
|
385 | + * @param WPInv_Invoice $invoice |
|
386 | + * @param array $prepared_payment_form_data |
|
387 | + * @param array $shipping |
|
388 | + */ |
|
389 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
390 | 390 | |
391 | - // Ensure the invoice exists. |
|
391 | + // Ensure the invoice exists. |
|
392 | 392 | if ( ! $invoice->exists() ) { |
393 | 393 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
394 | 394 | } |
395 | 395 | |
396 | - // Save payment form data. |
|
397 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | + // Save payment form data. |
|
397 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
398 | 398 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
399 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
401 | 401 | |
402 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
404 | - } |
|
402 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
404 | + } |
|
405 | 405 | |
406 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
408 | - } |
|
406 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
408 | + } |
|
409 | 409 | |
410 | - } |
|
410 | + } |
|
411 | 411 | |
412 | - // Save payment form data. |
|
413 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
412 | + // Save payment form data. |
|
413 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
414 | 414 | if ( ! empty( $shipping ) ) { |
415 | 415 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
416 | - } |
|
416 | + } |
|
417 | 417 | |
418 | - // Backwards compatibility. |
|
418 | + // Backwards compatibility. |
|
419 | 419 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
420 | 420 | |
421 | - $this->process_payment( $invoice ); |
|
421 | + $this->process_payment( $invoice ); |
|
422 | 422 | |
423 | 423 | // If we are here, there was an error. |
424 | - wpinv_send_back_to_checkout( $invoice ); |
|
424 | + wpinv_send_back_to_checkout( $invoice ); |
|
425 | 425 | |
426 | - } |
|
426 | + } |
|
427 | 427 | |
428 | - /** |
|
429 | - * Processes the actual payment. |
|
430 | - * |
|
431 | - * @param WPInv_Invoice $invoice |
|
432 | - */ |
|
433 | - protected function process_payment( $invoice ) { |
|
428 | + /** |
|
429 | + * Processes the actual payment. |
|
430 | + * |
|
431 | + * @param WPInv_Invoice $invoice |
|
432 | + */ |
|
433 | + protected function process_payment( $invoice ) { |
|
434 | 434 | |
435 | - // Clear any checkout errors. |
|
436 | - wpinv_clear_errors(); |
|
435 | + // Clear any checkout errors. |
|
436 | + wpinv_clear_errors(); |
|
437 | 437 | |
438 | - // No need to send free invoices to the gateway. |
|
439 | - if ( $invoice->is_free() ) { |
|
440 | - $this->process_free_payment( $invoice ); |
|
441 | - } |
|
438 | + // No need to send free invoices to the gateway. |
|
439 | + if ( $invoice->is_free() ) { |
|
440 | + $this->process_free_payment( $invoice ); |
|
441 | + } |
|
442 | 442 | |
443 | - $submission = $this->payment_form_submission; |
|
443 | + $submission = $this->payment_form_submission; |
|
444 | 444 | |
445 | - // Fires before sending to the gateway. |
|
446 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
445 | + // Fires before sending to the gateway. |
|
446 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
447 | 447 | |
448 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
449 | - $submission_data = $submission->get_data(); |
|
450 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
448 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
449 | + $submission_data = $submission->get_data(); |
|
450 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
452 | 452 | |
453 | - // Validate the currency. |
|
454 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
456 | - } |
|
453 | + // Validate the currency. |
|
454 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
456 | + } |
|
457 | 457 | |
458 | - // Check to see if we have any errors. |
|
459 | - if ( wpinv_get_errors() ) { |
|
460 | - wpinv_send_back_to_checkout( $invoice ); |
|
461 | - } |
|
458 | + // Check to see if we have any errors. |
|
459 | + if ( wpinv_get_errors() ) { |
|
460 | + wpinv_send_back_to_checkout( $invoice ); |
|
461 | + } |
|
462 | 462 | |
463 | - // Send info to the gateway for payment processing |
|
464 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
463 | + // Send info to the gateway for payment processing |
|
464 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
465 | 465 | |
466 | - // Backwards compatibility. |
|
467 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
466 | + // Backwards compatibility. |
|
467 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Marks the invoice as paid in case the checkout is free. |
|
473 | - * |
|
474 | - * @param WPInv_Invoice $invoice |
|
475 | - */ |
|
476 | - protected function process_free_payment( $invoice ) { |
|
471 | + /** |
|
472 | + * Marks the invoice as paid in case the checkout is free. |
|
473 | + * |
|
474 | + * @param WPInv_Invoice $invoice |
|
475 | + */ |
|
476 | + protected function process_free_payment( $invoice ) { |
|
477 | 477 | |
478 | - $invoice->set_gateway( 'none' ); |
|
479 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
480 | - $invoice->mark_paid(); |
|
481 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + $invoice->set_gateway( 'none' ); |
|
479 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
480 | + $invoice->mark_paid(); |
|
481 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
482 | 482 | |
483 | - } |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
485 | + /** |
|
486 | 486 | * Sends a redrect response to payment details. |
487 | 487 | * |
488 | 488 | */ |
@@ -12,474 +12,474 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | 216 | |
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | 223 | |
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
231 | 231 | |
232 | - // Process a refund. |
|
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + // Process a refund. |
|
233 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | - } |
|
237 | + if ( ! $invoice->is_refunded() ) { |
|
238 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | + } |
|
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | - } |
|
241 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | + } |
|
243 | 243 | |
244 | - // Process payments. |
|
245 | - if ( $payment_status == 'completed' ) { |
|
244 | + // Process payments. |
|
245 | + if ( $payment_status == 'completed' ) { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | - } |
|
247 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | + } |
|
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
252 | 252 | |
253 | - $note = ''; |
|
253 | + $note = ''; |
|
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | - } |
|
255 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | + } |
|
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | - } |
|
259 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | + } |
|
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - // Pending payments. |
|
269 | - if ( $payment_status == 'pending' ) { |
|
268 | + // Pending payments. |
|
269 | + if ( $payment_status == 'pending' ) { |
|
270 | 270 | |
271 | - /* translators: %s: pending reason. */ |
|
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + /* translators: %s: pending reason. */ |
|
272 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | - } |
|
274 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | + } |
|
276 | 276 | |
277 | - /* translators: %s: payment status. */ |
|
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + /* translators: %s: payment status. */ |
|
278 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Handles one time payments. |
|
284 | - * |
|
285 | - * @param WPInv_Invoice $invoice Invoice object. |
|
286 | - * @param array $posted Posted data. |
|
287 | - */ |
|
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | - } |
|
282 | + /** |
|
283 | + * Handles one time payments. |
|
284 | + * |
|
285 | + * @param WPInv_Invoice $invoice Invoice object. |
|
286 | + * @param array $posted Posted data. |
|
287 | + */ |
|
288 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Handles subscription sign ups. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice Invoice object. |
|
296 | - * @param array $posted Posted data. |
|
297 | - */ |
|
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
292 | + /** |
|
293 | + * Handles subscription sign ups. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice Invoice object. |
|
296 | + * @param array $posted Posted data. |
|
297 | + */ |
|
298 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
301 | 301 | |
302 | - // Make sure the invoice has a subscription. |
|
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + // Make sure the invoice has a subscription. |
|
303 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | - } |
|
305 | + if ( empty( $subscription ) ) { |
|
306 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | + } |
|
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
310 | 310 | |
311 | - // Validate the IPN. |
|
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + // Validate the IPN. |
|
312 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
315 | 315 | |
316 | - // Activate the subscription. |
|
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | - $subscription->activate(); |
|
316 | + // Activate the subscription. |
|
317 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | + $subscription->activate(); |
|
322 | 322 | |
323 | - // Set the transaction id. |
|
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | - } |
|
323 | + // Set the transaction id. |
|
324 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | + } |
|
328 | 328 | |
329 | - // Update the payment status. |
|
330 | - $invoice->mark_paid(); |
|
329 | + // Update the payment status. |
|
330 | + $invoice->mark_paid(); |
|
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
335 | - } |
|
334 | + wpinv_error_log( 'Subscription started.', false ); |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Handles subscription renewals. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice Invoice object. |
|
341 | - * @param array $posted Posted data. |
|
342 | - */ |
|
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
337 | + /** |
|
338 | + * Handles subscription renewals. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice Invoice object. |
|
341 | + * @param array $posted Posted data. |
|
342 | + */ |
|
343 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
344 | 344 | |
345 | - // Make sure the invoice has a subscription. |
|
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + // Make sure the invoice has a subscription. |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | - } |
|
348 | + if ( empty( $subscription ) ) { |
|
349 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | + } |
|
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
353 | 353 | |
354 | - // PayPal sends a subscr_payment for the first payment too. |
|
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + // PayPal sends a subscr_payment for the first payment too. |
|
355 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach( $dates as $date ) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | - continue; |
|
366 | - } |
|
364 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | + continue; |
|
366 | + } |
|
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | - } |
|
368 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | + } |
|
372 | 372 | |
373 | - return $invoice->mark_paid(); |
|
374 | - |
|
375 | - } |
|
373 | + return $invoice->mark_paid(); |
|
374 | + |
|
375 | + } |
|
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | - |
|
379 | - // Abort if the payment is already recorded. |
|
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | - } |
|
383 | - |
|
384 | - $args = array( |
|
385 | - 'transaction_id' => $posted['txn_id'], |
|
386 | - 'gateway' => $this->id, |
|
387 | - ); |
|
388 | - |
|
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
377 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | + |
|
379 | + // Abort if the payment is already recorded. |
|
380 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | + } |
|
383 | + |
|
384 | + $args = array( |
|
385 | + 'transaction_id' => $posted['txn_id'], |
|
386 | + 'gateway' => $this->id, |
|
387 | + ); |
|
388 | + |
|
389 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
392 | - return; |
|
393 | - } |
|
391 | + if ( empty( $invoice ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
397 | 397 | |
398 | - $subscription->renew(); |
|
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + $subscription->renew(); |
|
399 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
400 | 400 | |
401 | - } |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * Handles subscription cancelations. |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice Invoice object. |
|
407 | - */ |
|
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
403 | + /** |
|
404 | + * Handles subscription cancelations. |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice Invoice object. |
|
407 | + */ |
|
408 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
409 | 409 | |
410 | - // Make sure the invoice has a subscription. |
|
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | - |
|
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | - } |
|
416 | - |
|
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | - $subscription->cancel(); |
|
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
410 | + // Make sure the invoice has a subscription. |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | + |
|
413 | + if ( empty( $subscription ) ) { |
|
414 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | + } |
|
416 | + |
|
417 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | + $subscription->cancel(); |
|
419 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * Handles subscription completions. |
|
425 | - * |
|
426 | - * @param WPInv_Invoice $invoice Invoice object. |
|
427 | - * @param array $posted Posted data. |
|
428 | - */ |
|
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
423 | + /** |
|
424 | + * Handles subscription completions. |
|
425 | + * |
|
426 | + * @param WPInv_Invoice $invoice Invoice object. |
|
427 | + * @param array $posted Posted data. |
|
428 | + */ |
|
429 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
430 | 430 | |
431 | - // Make sure the invoice has a subscription. |
|
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + // Make sure the invoice has a subscription. |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | - } |
|
434 | + if ( empty( $subscription ) ) { |
|
435 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | + } |
|
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | - $subscription->complete(); |
|
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
438 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | + $subscription->complete(); |
|
440 | + wpinv_error_log( 'Subscription completed.', false ); |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * Handles subscription fails. |
|
446 | - * |
|
447 | - * @param WPInv_Invoice $invoice Invoice object. |
|
448 | - * @param array $posted Posted data. |
|
449 | - */ |
|
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
444 | + /** |
|
445 | + * Handles subscription fails. |
|
446 | + * |
|
447 | + * @param WPInv_Invoice $invoice Invoice object. |
|
448 | + * @param array $posted Posted data. |
|
449 | + */ |
|
450 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
451 | 451 | |
452 | - // Make sure the invoice has a subscription. |
|
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + // Make sure the invoice has a subscription. |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | - } |
|
455 | + if ( empty( $subscription ) ) { |
|
456 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | + } |
|
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | - $subscription->failing(); |
|
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
459 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | + $subscription->failing(); |
|
461 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
462 | 462 | |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | - /** |
|
466 | - * Handles subscription suspensions. |
|
467 | - * |
|
468 | - * @param WPInv_Invoice $invoice Invoice object. |
|
469 | - * @param array $posted Posted data. |
|
470 | - */ |
|
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
465 | + /** |
|
466 | + * Handles subscription suspensions. |
|
467 | + * |
|
468 | + * @param WPInv_Invoice $invoice Invoice object. |
|
469 | + * @param array $posted Posted data. |
|
470 | + */ |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
472 | 472 | |
473 | - // Make sure the invoice has a subscription. |
|
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + // Make sure the invoice has a subscription. |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | - } |
|
479 | - |
|
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | - $subscription->cancel(); |
|
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | - } |
|
476 | + if ( empty( $subscription ) ) { |
|
477 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | + } |
|
479 | + |
|
480 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | + $subscription->cancel(); |
|
482 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | + } |
|
484 | 484 | |
485 | 485 | } |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Export { |
14 | 14 | |
15 | - /** |
|
16 | - * Displays the reports tab. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function display() { |
|
20 | - |
|
21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
24 | - } |
|
25 | - $this->display_subscription_export(); |
|
26 | - echo "</div>"; |
|
27 | - |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the download url. |
|
32 | - * |
|
33 | - */ |
|
34 | - public function get_download_url( $post_type ) { |
|
35 | - |
|
36 | - return wp_nonce_url( |
|
37 | - add_query_arg( |
|
38 | - array( |
|
39 | - 'getpaid-admin-action' => 'export_invoices', |
|
40 | - 'post_type' => urlencode( $post_type ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'getpaid-nonce', |
|
44 | - 'getpaid-nonce' |
|
45 | - ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Displays a single post type export card. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display_post_type_export( $post_type ) { |
|
54 | - |
|
55 | - ?> |
|
15 | + /** |
|
16 | + * Displays the reports tab. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function display() { |
|
20 | + |
|
21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | + $this->display_post_type_export( $post_type ); |
|
24 | + } |
|
25 | + $this->display_subscription_export(); |
|
26 | + echo "</div>"; |
|
27 | + |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the download url. |
|
32 | + * |
|
33 | + */ |
|
34 | + public function get_download_url( $post_type ) { |
|
35 | + |
|
36 | + return wp_nonce_url( |
|
37 | + add_query_arg( |
|
38 | + array( |
|
39 | + 'getpaid-admin-action' => 'export_invoices', |
|
40 | + 'post_type' => urlencode( $post_type ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'getpaid-nonce', |
|
44 | + 'getpaid-nonce' |
|
45 | + ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Displays a single post type export card. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display_post_type_export( $post_type ) { |
|
54 | + |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <div class="col-12 col-md-6"> |
58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | <div class="card-header"> |
61 | 61 | <strong> |
62 | 62 | <?php |
63 | - printf( |
|
64 | - __( 'Export %s', 'invoicing' ), |
|
65 | - sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
66 | - ); |
|
67 | - ?> |
|
63 | + printf( |
|
64 | + __( 'Export %s', 'invoicing' ), |
|
65 | + sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
66 | + ); |
|
67 | + ?> |
|
68 | 68 | </strong> |
69 | 69 | </div> |
70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | - ?> |
|
76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | + ?> |
|
82 | 82 | |
83 | 83 | </form> |
84 | 84 | |
@@ -89,122 +89,122 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generates the from date input field. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function generate_from_date( $post_type ) { |
|
99 | - |
|
100 | - return aui()->input( |
|
101 | - array( |
|
102 | - 'name' => 'from_date', |
|
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | - 'placeholder'=> 'yy-mm-dd', |
|
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
106 | - 'label_type' => 'vertical', |
|
107 | - 'label_class' => 'd-block', |
|
108 | - 'type' => 'datepicker', |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Generates the to date input field. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function generate_to_date( $post_type ) { |
|
119 | - |
|
120 | - return aui()->input( |
|
121 | - array( |
|
122 | - 'name' => 'to_date', |
|
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | - 'placeholder'=> 'yy-mm-dd', |
|
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
126 | - 'label_type' => 'vertical', |
|
127 | - 'label_class' => 'd-block', |
|
128 | - 'type' => 'datepicker', |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Generates the to post status select field. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function generate_post_status_select( $post_type ) { |
|
139 | - |
|
140 | - if ( 'subscriptions' === $post_type ) { |
|
141 | - $options = getpaid_get_subscription_statuses(); |
|
142 | - } else { |
|
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | - } |
|
145 | - |
|
146 | - return aui()->select( |
|
147 | - array( |
|
148 | - 'name' => 'status', |
|
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
152 | - 'label_type' => 'vertical', |
|
153 | - 'label_class' => 'd-block', |
|
154 | - 'options' => $options, |
|
155 | - ) |
|
156 | - ); |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Generates the to file type select field. |
|
162 | - * |
|
163 | - */ |
|
164 | - public function generate_file_type_select( $post_type ) { |
|
165 | - |
|
166 | - return aui()->select( |
|
167 | - array( |
|
168 | - 'name' => 'file_type', |
|
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
172 | - 'label_type' => 'vertical', |
|
173 | - 'label_class' => 'd-block', |
|
174 | - 'options' => array( |
|
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
178 | - ), |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Displays a field's markup. |
|
186 | - * |
|
187 | - */ |
|
188 | - public function display_markup( $markup ) { |
|
189 | - |
|
190 | - echo str_replace( |
|
191 | - array( |
|
192 | - 'form-control', |
|
193 | - 'custom-select' |
|
194 | - ), |
|
195 | - 'regular-text', |
|
196 | - $markup |
|
197 | - ); |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Displays a subscription export card. |
|
203 | - * |
|
204 | - */ |
|
205 | - public function display_subscription_export() { |
|
206 | - |
|
207 | - ?> |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generates the from date input field. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function generate_from_date( $post_type ) { |
|
99 | + |
|
100 | + return aui()->input( |
|
101 | + array( |
|
102 | + 'name' => 'from_date', |
|
103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | + 'placeholder'=> 'yy-mm-dd', |
|
105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
106 | + 'label_type' => 'vertical', |
|
107 | + 'label_class' => 'd-block', |
|
108 | + 'type' => 'datepicker', |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Generates the to date input field. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function generate_to_date( $post_type ) { |
|
119 | + |
|
120 | + return aui()->input( |
|
121 | + array( |
|
122 | + 'name' => 'to_date', |
|
123 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | + 'placeholder'=> 'yy-mm-dd', |
|
125 | + 'label' => __( 'To Date', 'invoicing' ), |
|
126 | + 'label_type' => 'vertical', |
|
127 | + 'label_class' => 'd-block', |
|
128 | + 'type' => 'datepicker', |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Generates the to post status select field. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function generate_post_status_select( $post_type ) { |
|
139 | + |
|
140 | + if ( 'subscriptions' === $post_type ) { |
|
141 | + $options = getpaid_get_subscription_statuses(); |
|
142 | + } else { |
|
143 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | + } |
|
145 | + |
|
146 | + return aui()->select( |
|
147 | + array( |
|
148 | + 'name' => 'status', |
|
149 | + 'id' => esc_attr( "$post_type-status" ), |
|
150 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | + 'label' => __( 'Status', 'invoicing' ), |
|
152 | + 'label_type' => 'vertical', |
|
153 | + 'label_class' => 'd-block', |
|
154 | + 'options' => $options, |
|
155 | + ) |
|
156 | + ); |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Generates the to file type select field. |
|
162 | + * |
|
163 | + */ |
|
164 | + public function generate_file_type_select( $post_type ) { |
|
165 | + |
|
166 | + return aui()->select( |
|
167 | + array( |
|
168 | + 'name' => 'file_type', |
|
169 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | + 'label' => __( 'Export File', 'invoicing' ), |
|
172 | + 'label_type' => 'vertical', |
|
173 | + 'label_class' => 'd-block', |
|
174 | + 'options' => array( |
|
175 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | + 'xml' => __( 'XML', 'invoicing' ), |
|
177 | + 'json' => __( 'JSON', 'invoicing' ), |
|
178 | + ), |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Displays a field's markup. |
|
186 | + * |
|
187 | + */ |
|
188 | + public function display_markup( $markup ) { |
|
189 | + |
|
190 | + echo str_replace( |
|
191 | + array( |
|
192 | + 'form-control', |
|
193 | + 'custom-select' |
|
194 | + ), |
|
195 | + 'regular-text', |
|
196 | + $markup |
|
197 | + ); |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Displays a subscription export card. |
|
203 | + * |
|
204 | + */ |
|
205 | + public function display_subscription_export() { |
|
206 | + |
|
207 | + ?> |
|
208 | 208 | |
209 | 209 | <div class="col-12 col-md-6"> |
210 | 210 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
221 | 221 | |
222 | 222 | <?php |
223 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
224 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
225 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
226 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
227 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
228 | - ?> |
|
223 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
224 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
225 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
226 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
227 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
228 | + ?> |
|
229 | 229 | |
230 | 230 | </form> |
231 | 231 | |
@@ -236,6 +236,6 @@ discard block |
||
236 | 236 | |
237 | 237 | <?php |
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -12,177 +12,177 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves subscription query args. |
|
17 | - * |
|
18 | - * @param array $args Args to search for. |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function get_subscription_query_args( $args ) { |
|
22 | - |
|
23 | - $query_args = array( |
|
24 | - 'status' => 'all', |
|
25 | - 'number' => -1, |
|
26 | - 'count_total' => false, |
|
27 | - 'fields' => 'all', |
|
28 | - ); |
|
29 | - |
|
30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | - } |
|
33 | - |
|
34 | - $date_query = array(); |
|
35 | - if ( ! empty( $args['to_date'] ) ) { |
|
36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | - } |
|
38 | - |
|
39 | - if ( ! empty( $args['from_date'] ) ) { |
|
40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | - } |
|
42 | - |
|
43 | - if ( ! empty( $date_query ) ) { |
|
44 | - $date_query['inclusive'] = true; |
|
45 | - $query_args['date_created_query'] = array( $date_query ); |
|
46 | - } |
|
47 | - |
|
48 | - return $query_args; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves subscriptions. |
|
53 | - * |
|
54 | - * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | - * @return WPInv_Subscription[] |
|
56 | - */ |
|
57 | - public function get_subscriptions( $query_args ) { |
|
58 | - |
|
59 | - // Get subscriptions. |
|
60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | - |
|
62 | - // Prepare the results. |
|
63 | - return $subscriptions->get_results(); |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Handles the actual download. |
|
69 | - * |
|
70 | - */ |
|
71 | - public function export( $post_type, $args ) { |
|
72 | - |
|
73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | - $stream = $this->prepare_output(); |
|
75 | - $headers = $this->get_export_fields(); |
|
76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | - |
|
78 | - if ( 'csv' == $file_type ) { |
|
79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | - } else if( 'xml' == $file_type ) { |
|
81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | - } else { |
|
83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | - } |
|
85 | - |
|
86 | - fclose( $stream ); |
|
87 | - exit; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Prepares a single subscription for download. |
|
92 | - * |
|
93 | - * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | - * @param array $fields The fields to stream. |
|
95 | - * @since 1.0.19 |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function prepare_row( $subscription, $fields ) { |
|
99 | - |
|
100 | - $prepared = array(); |
|
101 | - $amount_fields = $this->get_amount_fields(); |
|
102 | - $invoice = $subscription->get_parent_payment(); |
|
103 | - |
|
104 | - foreach ( $fields as $field ) { |
|
105 | - |
|
106 | - $value = ''; |
|
107 | - $method = "get_$field"; |
|
108 | - |
|
109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } |
|
114 | - |
|
115 | - } else if ( method_exists( $subscription, $method ) ) { |
|
116 | - $value = $subscription->$method(); |
|
117 | - } |
|
118 | - |
|
119 | - if ( in_array( $field, $amount_fields ) ) { |
|
120 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
121 | - } |
|
122 | - |
|
123 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - return $prepared; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves export fields. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function get_export_fields() { |
|
137 | - |
|
138 | - $fields = array( |
|
139 | - 'id', |
|
140 | - 'currency', |
|
141 | - 'initial_amount', |
|
142 | - 'recurring_amount', |
|
143 | - 'trial_period', |
|
144 | - 'frequency', |
|
145 | - 'period', |
|
146 | - 'bill_times', |
|
147 | - 'parent_payment_id', |
|
148 | - 'profile_id', |
|
149 | - 'product_id', |
|
150 | - 'status', |
|
151 | - 'date_created', |
|
152 | - 'date_expires', |
|
153 | - |
|
154 | - 'customer_id', |
|
155 | - 'customer_first_name', |
|
156 | - 'customer_last_name', |
|
157 | - 'customer_phone', |
|
158 | - 'customer_email', |
|
159 | - 'customer_country', |
|
160 | - 'customer_city', |
|
161 | - 'customer_state', |
|
162 | - 'customer_zip', |
|
163 | - 'customer_company', |
|
164 | - 'customer_vat_number', |
|
165 | - 'customer_address', |
|
166 | - |
|
167 | - ); |
|
168 | - |
|
169 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Retrieves amount fields. |
|
174 | - * |
|
175 | - * @since 1.0.19 |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function get_amount_fields() { |
|
179 | - |
|
180 | - $fields = array( |
|
181 | - 'initial_amount', |
|
182 | - 'recurring_amount' |
|
183 | - ); |
|
184 | - |
|
185 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
186 | - } |
|
15 | + /** |
|
16 | + * Retrieves subscription query args. |
|
17 | + * |
|
18 | + * @param array $args Args to search for. |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function get_subscription_query_args( $args ) { |
|
22 | + |
|
23 | + $query_args = array( |
|
24 | + 'status' => 'all', |
|
25 | + 'number' => -1, |
|
26 | + 'count_total' => false, |
|
27 | + 'fields' => 'all', |
|
28 | + ); |
|
29 | + |
|
30 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | + $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | + } |
|
33 | + |
|
34 | + $date_query = array(); |
|
35 | + if ( ! empty( $args['to_date'] ) ) { |
|
36 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | + } |
|
38 | + |
|
39 | + if ( ! empty( $args['from_date'] ) ) { |
|
40 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | + } |
|
42 | + |
|
43 | + if ( ! empty( $date_query ) ) { |
|
44 | + $date_query['inclusive'] = true; |
|
45 | + $query_args['date_created_query'] = array( $date_query ); |
|
46 | + } |
|
47 | + |
|
48 | + return $query_args; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves subscriptions. |
|
53 | + * |
|
54 | + * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | + * @return WPInv_Subscription[] |
|
56 | + */ |
|
57 | + public function get_subscriptions( $query_args ) { |
|
58 | + |
|
59 | + // Get subscriptions. |
|
60 | + $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | + |
|
62 | + // Prepare the results. |
|
63 | + return $subscriptions->get_results(); |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Handles the actual download. |
|
69 | + * |
|
70 | + */ |
|
71 | + public function export( $post_type, $args ) { |
|
72 | + |
|
73 | + $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | + $stream = $this->prepare_output(); |
|
75 | + $headers = $this->get_export_fields(); |
|
76 | + $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | + |
|
78 | + if ( 'csv' == $file_type ) { |
|
79 | + $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | + } else if( 'xml' == $file_type ) { |
|
81 | + $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | + } else { |
|
83 | + $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | + } |
|
85 | + |
|
86 | + fclose( $stream ); |
|
87 | + exit; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Prepares a single subscription for download. |
|
92 | + * |
|
93 | + * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | + * @param array $fields The fields to stream. |
|
95 | + * @since 1.0.19 |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function prepare_row( $subscription, $fields ) { |
|
99 | + |
|
100 | + $prepared = array(); |
|
101 | + $amount_fields = $this->get_amount_fields(); |
|
102 | + $invoice = $subscription->get_parent_payment(); |
|
103 | + |
|
104 | + foreach ( $fields as $field ) { |
|
105 | + |
|
106 | + $value = ''; |
|
107 | + $method = "get_$field"; |
|
108 | + |
|
109 | + if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } |
|
114 | + |
|
115 | + } else if ( method_exists( $subscription, $method ) ) { |
|
116 | + $value = $subscription->$method(); |
|
117 | + } |
|
118 | + |
|
119 | + if ( in_array( $field, $amount_fields ) ) { |
|
120 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
121 | + } |
|
122 | + |
|
123 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + return $prepared; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves export fields. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function get_export_fields() { |
|
137 | + |
|
138 | + $fields = array( |
|
139 | + 'id', |
|
140 | + 'currency', |
|
141 | + 'initial_amount', |
|
142 | + 'recurring_amount', |
|
143 | + 'trial_period', |
|
144 | + 'frequency', |
|
145 | + 'period', |
|
146 | + 'bill_times', |
|
147 | + 'parent_payment_id', |
|
148 | + 'profile_id', |
|
149 | + 'product_id', |
|
150 | + 'status', |
|
151 | + 'date_created', |
|
152 | + 'date_expires', |
|
153 | + |
|
154 | + 'customer_id', |
|
155 | + 'customer_first_name', |
|
156 | + 'customer_last_name', |
|
157 | + 'customer_phone', |
|
158 | + 'customer_email', |
|
159 | + 'customer_country', |
|
160 | + 'customer_city', |
|
161 | + 'customer_state', |
|
162 | + 'customer_zip', |
|
163 | + 'customer_company', |
|
164 | + 'customer_vat_number', |
|
165 | + 'customer_address', |
|
166 | + |
|
167 | + ); |
|
168 | + |
|
169 | + return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Retrieves amount fields. |
|
174 | + * |
|
175 | + * @since 1.0.19 |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function get_amount_fields() { |
|
179 | + |
|
180 | + $fields = array( |
|
181 | + 'initial_amount', |
|
182 | + 'recurring_amount' |
|
183 | + ); |
|
184 | + |
|
185 | + return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | } |
@@ -12,49 +12,49 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Registers the reports page. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function register_reports_page() { |
|
33 | - |
|
34 | - add_submenu_page( |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Registers the reports page. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function register_reports_page() { |
|
33 | + |
|
34 | + add_submenu_page( |
|
35 | 35 | 'wpinv', |
36 | 36 | __( 'Reports', 'invoicing' ), |
37 | 37 | __( 'Reports', 'invoicing' ), |
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | 40 | array( $this, 'display_reports_page' ) |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Displays the reports page. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function display_reports_page() { |
|
45 | + /** |
|
46 | + * Displays the reports page. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function display_reports_page() { |
|
50 | 50 | |
51 | - // Prepare variables. |
|
52 | - $tabs = $this->get_tabs(); |
|
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + // Prepare variables. |
|
52 | + $tabs = $this->get_tabs(); |
|
53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | - // Display the current tab. |
|
57 | - ?> |
|
56 | + // Display the current tab. |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach( $tabs as $key => $label ) { |
|
66 | + foreach( $tabs as $key => $label ) { |
|
67 | 67 | |
68 | - $key = sanitize_text_field( $key ); |
|
69 | - $label = sanitize_text_field( $label ); |
|
70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | - $url = esc_url( |
|
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | - ); |
|
68 | + $key = sanitize_text_field( $key ); |
|
69 | + $label = sanitize_text_field( $label ); |
|
70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | + $url = esc_url( |
|
72 | + add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | + ); |
|
74 | 74 | |
75 | - echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
75 | + echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
76 | 76 | |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
@@ -86,83 +86,83 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
90 | + wp_deregister_style( 'chart-js' ); |
|
91 | + wp_deregister_script( 'chart-js' ); |
|
92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | + wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
94 | 94 | |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Retrieves reports page tabs. |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function get_tabs() { |
|
97 | + /** |
|
98 | + * Retrieves reports page tabs. |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function get_tabs() { |
|
103 | 103 | |
104 | - $tabs = array( |
|
105 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | - 'export' => __( 'Export', 'invoicing' ), |
|
107 | - ); |
|
104 | + $tabs = array( |
|
105 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | + 'export' => __( 'Export', 'invoicing' ), |
|
107 | + ); |
|
108 | 108 | |
109 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | - } |
|
109 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Displays the reports tab. |
|
114 | - * |
|
115 | - */ |
|
116 | - public function display_reports_tab() { |
|
112 | + /** |
|
113 | + * Displays the reports tab. |
|
114 | + * |
|
115 | + */ |
|
116 | + public function display_reports_tab() { |
|
117 | 117 | |
118 | - $reports = new GetPaid_Reports_Report(); |
|
119 | - $reports->display(); |
|
118 | + $reports = new GetPaid_Reports_Report(); |
|
119 | + $reports->display(); |
|
120 | 120 | |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Displays the exports tab. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function display_exports_tab() { |
|
123 | + /** |
|
124 | + * Displays the exports tab. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function display_exports_tab() { |
|
128 | 128 | |
129 | - $exports = new GetPaid_Reports_Export(); |
|
130 | - $exports->display(); |
|
129 | + $exports = new GetPaid_Reports_Export(); |
|
130 | + $exports->display(); |
|
131 | 131 | |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Donwnloads a graph. |
|
136 | - * |
|
137 | - * @param array $args |
|
138 | - */ |
|
139 | - public function download_graph( $args ) { |
|
134 | + /** |
|
135 | + * Donwnloads a graph. |
|
136 | + * |
|
137 | + * @param array $args |
|
138 | + */ |
|
139 | + public function download_graph( $args ) { |
|
140 | 140 | |
141 | - if ( ! empty( $args['graph'] ) ) { |
|
142 | - $downloader = new GetPaid_Graph_Downloader(); |
|
143 | - $downloader->download( $args['graph'] ); |
|
144 | - } |
|
141 | + if ( ! empty( $args['graph'] ) ) { |
|
142 | + $downloader = new GetPaid_Graph_Downloader(); |
|
143 | + $downloader->download( $args['graph'] ); |
|
144 | + } |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Exports invoices. |
|
150 | - * |
|
151 | - * @param array $args |
|
152 | - */ |
|
153 | - public function export_invoices( $args ) { |
|
148 | + /** |
|
149 | + * Exports invoices. |
|
150 | + * |
|
151 | + * @param array $args |
|
152 | + */ |
|
153 | + public function export_invoices( $args ) { |
|
154 | 154 | |
155 | - if ( ! empty( $args['post_type'] ) ) { |
|
155 | + if ( ! empty( $args['post_type'] ) ) { |
|
156 | 156 | |
157 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
158 | - $downloader = new GetPaid_Subscription_Exporter(); |
|
159 | - } else { |
|
160 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
161 | - } |
|
157 | + if ( 'subscriptions' === $args['post_type'] ) { |
|
158 | + $downloader = new GetPaid_Subscription_Exporter(); |
|
159 | + } else { |
|
160 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
161 | + } |
|
162 | 162 | |
163 | - $downloader->export( $args['post_type'], $args ); |
|
164 | - } |
|
163 | + $downloader->export( $args['post_type'], $args ); |
|
164 | + } |
|
165 | 165 | |
166 | - } |
|
166 | + } |
|
167 | 167 | |
168 | 168 | } |
@@ -12,265 +12,265 @@ |
||
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
15 | - array( |
|
16 | - 'country' => 'AT', // Austria |
|
17 | - 'state' => '', |
|
18 | - 'global' => true, |
|
19 | - 'rate' => 20, |
|
20 | - 'reduced_rate' => 13, |
|
21 | - 'name' => __( 'VAT', 'invoicing' ), |
|
22 | - ), |
|
23 | - |
|
24 | - array( |
|
25 | - 'country' => 'BE', // Belgium |
|
26 | - 'state' => '', |
|
27 | - 'global' => true, |
|
28 | - 'rate' => 21, |
|
29 | - 'reduced_rate' => 12, |
|
30 | - 'name' => __( 'VAT', 'invoicing' ), |
|
31 | - ), |
|
32 | - |
|
33 | - array( |
|
34 | - 'country' => 'BG', // Bulgaria |
|
35 | - 'state' => '', |
|
36 | - 'global' => true, |
|
37 | - 'rate' => 20, |
|
38 | - 'reduced_rate' => 9, |
|
39 | - 'name' => __( 'VAT', 'invoicing' ), |
|
40 | - ), |
|
41 | - |
|
42 | - array( |
|
43 | - 'country' => 'HR', // Croatia |
|
44 | - 'state' => '', |
|
45 | - 'global' => true, |
|
46 | - 'rate' => 25, |
|
47 | - 'reduced_rate' => 13, |
|
48 | - 'name' => __( 'VAT', 'invoicing' ), |
|
49 | - ), |
|
50 | - |
|
51 | - array( |
|
52 | - 'country' => 'CY', // Cyprus |
|
53 | - 'state' => '', |
|
54 | - 'global' => true, |
|
55 | - 'rate' => 19, |
|
56 | - 'reduced_rate' => 9, |
|
57 | - 'name' => __( 'VAT', 'invoicing' ), |
|
58 | - ), |
|
59 | - |
|
60 | - array( |
|
61 | - 'country' => 'CZ', // Czech Republic |
|
62 | - 'state' => '', |
|
63 | - 'global' => true, |
|
64 | - 'rate' => 21, |
|
65 | - 'reduced_rate' => 15, |
|
66 | - 'name' => __( 'VAT', 'invoicing' ), |
|
67 | - ), |
|
68 | - |
|
69 | - array( |
|
70 | - 'country' => 'DK', // Denmark |
|
71 | - 'state' => '', |
|
72 | - 'global' => true, |
|
73 | - 'rate' => 25, |
|
74 | - 'reduced_rate' => 0, |
|
75 | - 'name' => __( 'VAT', 'invoicing' ), |
|
76 | - ), |
|
77 | - |
|
78 | - array( |
|
79 | - 'country' => 'EE', // Estonia |
|
80 | - 'state' => '', |
|
81 | - 'global' => true, |
|
82 | - 'rate' => 20, |
|
83 | - 'reduced_rate' => 9, |
|
84 | - 'name' => __( 'VAT', 'invoicing' ), |
|
85 | - ), |
|
86 | - |
|
87 | - array( |
|
88 | - 'country' => 'FI', // Finland |
|
89 | - 'state' => '', |
|
90 | - 'global' => true, |
|
91 | - 'rate' => 24, |
|
92 | - 'reduced_rate' => 14, |
|
93 | - 'name' => __( 'VAT', 'invoicing' ), |
|
94 | - ), |
|
95 | - |
|
96 | - array( |
|
97 | - 'country' => 'FR', // France |
|
98 | - 'state' => '', |
|
99 | - 'global' => true, |
|
100 | - 'rate' => 20, |
|
101 | - 'reduced_rate' => 5.5, |
|
102 | - 'name' => __( 'VAT', 'invoicing' ), |
|
103 | - ), |
|
104 | - |
|
105 | - array( |
|
106 | - 'country' => 'DE', // Germany |
|
107 | - 'state' => '', |
|
108 | - 'global' => true, |
|
109 | - 'rate' => 19, |
|
110 | - 'reduced_rate' => 7, |
|
111 | - 'name' => __( 'VAT', 'invoicing' ), |
|
112 | - ), |
|
113 | - |
|
114 | - array( |
|
115 | - 'country' => 'GR', // Greece |
|
116 | - 'state' => '', |
|
117 | - 'global' => true, |
|
118 | - 'rate' => 24, |
|
119 | - 'reduced_rate' => 13, |
|
120 | - 'name' => __( 'VAT', 'invoicing' ), |
|
121 | - ), |
|
122 | - |
|
123 | - array( |
|
124 | - 'country' => 'HU', // Hungary |
|
125 | - 'state' => '', |
|
126 | - 'global' => true, |
|
127 | - 'rate' => 27, |
|
128 | - 'reduced_rate' => 18, |
|
129 | - 'name' => __( 'VAT', 'invoicing' ), |
|
130 | - ), |
|
131 | - |
|
132 | - array( |
|
133 | - 'country' => 'IE', // Ireland |
|
134 | - 'state' => '', |
|
135 | - 'global' => true, |
|
136 | - 'rate' => 23, |
|
137 | - 'reduced_rate' => 13.5, |
|
138 | - 'name' => __( 'VAT', 'invoicing' ), |
|
139 | - ), |
|
140 | - |
|
141 | - array( |
|
142 | - 'country' => 'IT', // Italy |
|
143 | - 'state' => '', |
|
144 | - 'global' => true, |
|
145 | - 'rate' => 22, |
|
146 | - 'reduced_rate' => 10, |
|
147 | - 'name' => __( 'VAT', 'invoicing' ), |
|
148 | - ), |
|
149 | - |
|
150 | - array( |
|
151 | - 'country' => 'LV', // Latvia |
|
152 | - 'state' => '', |
|
153 | - 'global' => true, |
|
154 | - 'rate' => 21, |
|
155 | - 'reduced_rate' => 12, |
|
156 | - 'name' => __( 'VAT', 'invoicing' ), |
|
157 | - ), |
|
158 | - |
|
159 | - array( |
|
160 | - 'country' => 'LT', // Lithuania |
|
161 | - 'state' => '', |
|
162 | - 'global' => true, |
|
163 | - 'rate' => 21, |
|
164 | - 'reduced_rate' => 9, |
|
165 | - 'name' => __( 'VAT', 'invoicing' ), |
|
166 | - ), |
|
167 | - |
|
168 | - array( |
|
169 | - 'country' => 'LU', // Luxembourg |
|
170 | - 'state' => '', |
|
171 | - 'global' => true, |
|
172 | - 'rate' => 17, |
|
173 | - 'reduced_rate' => 14, |
|
174 | - 'name' => __( 'VAT', 'invoicing' ), |
|
175 | - ), |
|
176 | - |
|
177 | - array( |
|
178 | - 'country' => 'MT', // Malta |
|
179 | - 'state' => '', |
|
180 | - 'global' => true, |
|
181 | - 'rate' => 18, |
|
182 | - 'reduced_rate' => 7, |
|
183 | - 'name' => __( 'VAT', 'invoicing' ), |
|
184 | - ), |
|
185 | - |
|
186 | - array( |
|
187 | - 'country' => 'MC', // Monaco |
|
188 | - 'state' => '', |
|
189 | - 'global' => true, |
|
190 | - 'rate' => 20, |
|
191 | - 'reduced_rate' => 10, |
|
192 | - 'name' => __( 'VAT', 'invoicing' ), |
|
193 | - ), |
|
194 | - |
|
195 | - array( |
|
196 | - 'country' => 'NL', // Netherlands |
|
197 | - 'state' => '', |
|
198 | - 'global' => true, |
|
199 | - 'rate' => 21, |
|
200 | - 'reduced_rate' => 9, |
|
201 | - 'name' => __( 'VAT', 'invoicing' ), |
|
202 | - ), |
|
203 | - |
|
204 | - array( |
|
205 | - 'country' => 'PL', // Poland |
|
206 | - 'state' => '', |
|
207 | - 'global' => true, |
|
208 | - 'rate' => 23, |
|
209 | - 'reduced_rate' => 8, |
|
210 | - 'name' => __( 'VAT', 'invoicing' ), |
|
211 | - ), |
|
212 | - |
|
213 | - array( |
|
214 | - 'country' => 'PT', // Portugal |
|
215 | - 'state' => '', |
|
216 | - 'global' => true, |
|
217 | - 'rate' => 23, |
|
218 | - 'reduced_rate' => 13, |
|
219 | - 'name' => __( 'VAT', 'invoicing' ), |
|
220 | - ), |
|
221 | - |
|
222 | - array( |
|
223 | - 'country' => 'RO', // Romania |
|
224 | - 'state' => '', |
|
225 | - 'global' => true, |
|
226 | - 'rate' => 19, |
|
227 | - 'reduced_rate' => 9, |
|
228 | - 'name' => __( 'VAT', 'invoicing' ), |
|
229 | - ), |
|
230 | - |
|
231 | - array( |
|
232 | - 'country' => 'SK', // Slovakia |
|
233 | - 'state' => '', |
|
234 | - 'global' => true, |
|
235 | - 'rate' => 20, |
|
236 | - 'reduced_rate' => 10, |
|
237 | - 'name' => __( 'VAT', 'invoicing' ), |
|
238 | - ), |
|
239 | - |
|
240 | - array( |
|
241 | - 'country' => 'SI', // Slovenia |
|
242 | - 'state' => '', |
|
243 | - 'global' => true, |
|
244 | - 'rate' => 22, |
|
245 | - 'reduced_rate' => 9.5, |
|
246 | - 'name' => __( 'VAT', 'invoicing' ), |
|
247 | - ), |
|
248 | - |
|
249 | - array( |
|
250 | - 'country' => 'ES', // Spain |
|
251 | - 'state' => '', |
|
252 | - 'global' => true, |
|
253 | - 'rate' => 21, |
|
254 | - 'reduced_rate' => 10, |
|
255 | - 'name' => __( 'VAT', 'invoicing' ), |
|
256 | - ), |
|
257 | - |
|
258 | - array( |
|
259 | - 'country' => 'SE', // Sweden |
|
260 | - 'state' => '', |
|
261 | - 'global' => true, |
|
262 | - 'rate' => 25, |
|
263 | - 'reduced_rate' => 12, |
|
264 | - 'name' => __( 'VAT', 'invoicing' ), |
|
265 | - ), |
|
266 | - |
|
267 | - array( |
|
268 | - 'country' => 'GB', // UK |
|
269 | - 'state' => '', |
|
270 | - 'global' => true, |
|
271 | - 'rate' => 20, |
|
272 | - 'reduced_rate' => 5, |
|
273 | - 'name' => __( 'VAT', 'invoicing' ), |
|
274 | - ) |
|
15 | + array( |
|
16 | + 'country' => 'AT', // Austria |
|
17 | + 'state' => '', |
|
18 | + 'global' => true, |
|
19 | + 'rate' => 20, |
|
20 | + 'reduced_rate' => 13, |
|
21 | + 'name' => __( 'VAT', 'invoicing' ), |
|
22 | + ), |
|
23 | + |
|
24 | + array( |
|
25 | + 'country' => 'BE', // Belgium |
|
26 | + 'state' => '', |
|
27 | + 'global' => true, |
|
28 | + 'rate' => 21, |
|
29 | + 'reduced_rate' => 12, |
|
30 | + 'name' => __( 'VAT', 'invoicing' ), |
|
31 | + ), |
|
32 | + |
|
33 | + array( |
|
34 | + 'country' => 'BG', // Bulgaria |
|
35 | + 'state' => '', |
|
36 | + 'global' => true, |
|
37 | + 'rate' => 20, |
|
38 | + 'reduced_rate' => 9, |
|
39 | + 'name' => __( 'VAT', 'invoicing' ), |
|
40 | + ), |
|
41 | + |
|
42 | + array( |
|
43 | + 'country' => 'HR', // Croatia |
|
44 | + 'state' => '', |
|
45 | + 'global' => true, |
|
46 | + 'rate' => 25, |
|
47 | + 'reduced_rate' => 13, |
|
48 | + 'name' => __( 'VAT', 'invoicing' ), |
|
49 | + ), |
|
50 | + |
|
51 | + array( |
|
52 | + 'country' => 'CY', // Cyprus |
|
53 | + 'state' => '', |
|
54 | + 'global' => true, |
|
55 | + 'rate' => 19, |
|
56 | + 'reduced_rate' => 9, |
|
57 | + 'name' => __( 'VAT', 'invoicing' ), |
|
58 | + ), |
|
59 | + |
|
60 | + array( |
|
61 | + 'country' => 'CZ', // Czech Republic |
|
62 | + 'state' => '', |
|
63 | + 'global' => true, |
|
64 | + 'rate' => 21, |
|
65 | + 'reduced_rate' => 15, |
|
66 | + 'name' => __( 'VAT', 'invoicing' ), |
|
67 | + ), |
|
68 | + |
|
69 | + array( |
|
70 | + 'country' => 'DK', // Denmark |
|
71 | + 'state' => '', |
|
72 | + 'global' => true, |
|
73 | + 'rate' => 25, |
|
74 | + 'reduced_rate' => 0, |
|
75 | + 'name' => __( 'VAT', 'invoicing' ), |
|
76 | + ), |
|
77 | + |
|
78 | + array( |
|
79 | + 'country' => 'EE', // Estonia |
|
80 | + 'state' => '', |
|
81 | + 'global' => true, |
|
82 | + 'rate' => 20, |
|
83 | + 'reduced_rate' => 9, |
|
84 | + 'name' => __( 'VAT', 'invoicing' ), |
|
85 | + ), |
|
86 | + |
|
87 | + array( |
|
88 | + 'country' => 'FI', // Finland |
|
89 | + 'state' => '', |
|
90 | + 'global' => true, |
|
91 | + 'rate' => 24, |
|
92 | + 'reduced_rate' => 14, |
|
93 | + 'name' => __( 'VAT', 'invoicing' ), |
|
94 | + ), |
|
95 | + |
|
96 | + array( |
|
97 | + 'country' => 'FR', // France |
|
98 | + 'state' => '', |
|
99 | + 'global' => true, |
|
100 | + 'rate' => 20, |
|
101 | + 'reduced_rate' => 5.5, |
|
102 | + 'name' => __( 'VAT', 'invoicing' ), |
|
103 | + ), |
|
104 | + |
|
105 | + array( |
|
106 | + 'country' => 'DE', // Germany |
|
107 | + 'state' => '', |
|
108 | + 'global' => true, |
|
109 | + 'rate' => 19, |
|
110 | + 'reduced_rate' => 7, |
|
111 | + 'name' => __( 'VAT', 'invoicing' ), |
|
112 | + ), |
|
113 | + |
|
114 | + array( |
|
115 | + 'country' => 'GR', // Greece |
|
116 | + 'state' => '', |
|
117 | + 'global' => true, |
|
118 | + 'rate' => 24, |
|
119 | + 'reduced_rate' => 13, |
|
120 | + 'name' => __( 'VAT', 'invoicing' ), |
|
121 | + ), |
|
122 | + |
|
123 | + array( |
|
124 | + 'country' => 'HU', // Hungary |
|
125 | + 'state' => '', |
|
126 | + 'global' => true, |
|
127 | + 'rate' => 27, |
|
128 | + 'reduced_rate' => 18, |
|
129 | + 'name' => __( 'VAT', 'invoicing' ), |
|
130 | + ), |
|
131 | + |
|
132 | + array( |
|
133 | + 'country' => 'IE', // Ireland |
|
134 | + 'state' => '', |
|
135 | + 'global' => true, |
|
136 | + 'rate' => 23, |
|
137 | + 'reduced_rate' => 13.5, |
|
138 | + 'name' => __( 'VAT', 'invoicing' ), |
|
139 | + ), |
|
140 | + |
|
141 | + array( |
|
142 | + 'country' => 'IT', // Italy |
|
143 | + 'state' => '', |
|
144 | + 'global' => true, |
|
145 | + 'rate' => 22, |
|
146 | + 'reduced_rate' => 10, |
|
147 | + 'name' => __( 'VAT', 'invoicing' ), |
|
148 | + ), |
|
149 | + |
|
150 | + array( |
|
151 | + 'country' => 'LV', // Latvia |
|
152 | + 'state' => '', |
|
153 | + 'global' => true, |
|
154 | + 'rate' => 21, |
|
155 | + 'reduced_rate' => 12, |
|
156 | + 'name' => __( 'VAT', 'invoicing' ), |
|
157 | + ), |
|
158 | + |
|
159 | + array( |
|
160 | + 'country' => 'LT', // Lithuania |
|
161 | + 'state' => '', |
|
162 | + 'global' => true, |
|
163 | + 'rate' => 21, |
|
164 | + 'reduced_rate' => 9, |
|
165 | + 'name' => __( 'VAT', 'invoicing' ), |
|
166 | + ), |
|
167 | + |
|
168 | + array( |
|
169 | + 'country' => 'LU', // Luxembourg |
|
170 | + 'state' => '', |
|
171 | + 'global' => true, |
|
172 | + 'rate' => 17, |
|
173 | + 'reduced_rate' => 14, |
|
174 | + 'name' => __( 'VAT', 'invoicing' ), |
|
175 | + ), |
|
176 | + |
|
177 | + array( |
|
178 | + 'country' => 'MT', // Malta |
|
179 | + 'state' => '', |
|
180 | + 'global' => true, |
|
181 | + 'rate' => 18, |
|
182 | + 'reduced_rate' => 7, |
|
183 | + 'name' => __( 'VAT', 'invoicing' ), |
|
184 | + ), |
|
185 | + |
|
186 | + array( |
|
187 | + 'country' => 'MC', // Monaco |
|
188 | + 'state' => '', |
|
189 | + 'global' => true, |
|
190 | + 'rate' => 20, |
|
191 | + 'reduced_rate' => 10, |
|
192 | + 'name' => __( 'VAT', 'invoicing' ), |
|
193 | + ), |
|
194 | + |
|
195 | + array( |
|
196 | + 'country' => 'NL', // Netherlands |
|
197 | + 'state' => '', |
|
198 | + 'global' => true, |
|
199 | + 'rate' => 21, |
|
200 | + 'reduced_rate' => 9, |
|
201 | + 'name' => __( 'VAT', 'invoicing' ), |
|
202 | + ), |
|
203 | + |
|
204 | + array( |
|
205 | + 'country' => 'PL', // Poland |
|
206 | + 'state' => '', |
|
207 | + 'global' => true, |
|
208 | + 'rate' => 23, |
|
209 | + 'reduced_rate' => 8, |
|
210 | + 'name' => __( 'VAT', 'invoicing' ), |
|
211 | + ), |
|
212 | + |
|
213 | + array( |
|
214 | + 'country' => 'PT', // Portugal |
|
215 | + 'state' => '', |
|
216 | + 'global' => true, |
|
217 | + 'rate' => 23, |
|
218 | + 'reduced_rate' => 13, |
|
219 | + 'name' => __( 'VAT', 'invoicing' ), |
|
220 | + ), |
|
221 | + |
|
222 | + array( |
|
223 | + 'country' => 'RO', // Romania |
|
224 | + 'state' => '', |
|
225 | + 'global' => true, |
|
226 | + 'rate' => 19, |
|
227 | + 'reduced_rate' => 9, |
|
228 | + 'name' => __( 'VAT', 'invoicing' ), |
|
229 | + ), |
|
230 | + |
|
231 | + array( |
|
232 | + 'country' => 'SK', // Slovakia |
|
233 | + 'state' => '', |
|
234 | + 'global' => true, |
|
235 | + 'rate' => 20, |
|
236 | + 'reduced_rate' => 10, |
|
237 | + 'name' => __( 'VAT', 'invoicing' ), |
|
238 | + ), |
|
239 | + |
|
240 | + array( |
|
241 | + 'country' => 'SI', // Slovenia |
|
242 | + 'state' => '', |
|
243 | + 'global' => true, |
|
244 | + 'rate' => 22, |
|
245 | + 'reduced_rate' => 9.5, |
|
246 | + 'name' => __( 'VAT', 'invoicing' ), |
|
247 | + ), |
|
248 | + |
|
249 | + array( |
|
250 | + 'country' => 'ES', // Spain |
|
251 | + 'state' => '', |
|
252 | + 'global' => true, |
|
253 | + 'rate' => 21, |
|
254 | + 'reduced_rate' => 10, |
|
255 | + 'name' => __( 'VAT', 'invoicing' ), |
|
256 | + ), |
|
257 | + |
|
258 | + array( |
|
259 | + 'country' => 'SE', // Sweden |
|
260 | + 'state' => '', |
|
261 | + 'global' => true, |
|
262 | + 'rate' => 25, |
|
263 | + 'reduced_rate' => 12, |
|
264 | + 'name' => __( 'VAT', 'invoicing' ), |
|
265 | + ), |
|
266 | + |
|
267 | + array( |
|
268 | + 'country' => 'GB', // UK |
|
269 | + 'state' => '', |
|
270 | + 'global' => true, |
|
271 | + 'rate' => 20, |
|
272 | + 'reduced_rate' => 5, |
|
273 | + 'name' => __( 'VAT', 'invoicing' ), |
|
274 | + ) |
|
275 | 275 | |
276 | 276 | ); |