@@ -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; |
|
133 | 125 | |
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 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
138 | 131 | |
139 | - return $invoice; |
|
140 | - } |
|
132 | + $invoice = $submission->get_invoice(); |
|
141 | 133 | |
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 ) { |
|
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 | + } |
|
150 | 138 | |
151 | - $submission = $this->payment_form_submission; |
|
139 | + return $invoice; |
|
140 | + } |
|
152 | 141 | |
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() ) ); |
|
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 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
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() ) ); |
|
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 ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( 'address' === $field['type'] ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( 'address' === $field['type'] ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( 'file_upload' === $field['type'] ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( 'file_upload' === $field['type'] ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,192 +298,192 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
407 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | + } |
|
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - try { |
|
419 | - $this->process_payment( $invoice ); |
|
420 | - } catch ( Exception $e ) { |
|
421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | - } |
|
418 | + try { |
|
419 | + $this->process_payment( $invoice ); |
|
420 | + } catch ( Exception $e ) { |
|
421 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | + } |
|
423 | 423 | |
424 | 424 | // If we are here, there was an error. |
425 | - wpinv_send_back_to_checkout( $invoice ); |
|
425 | + wpinv_send_back_to_checkout( $invoice ); |
|
426 | 426 | |
427 | - } |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * Processes the actual payment. |
|
431 | - * |
|
432 | - * @param WPInv_Invoice $invoice |
|
433 | - */ |
|
434 | - protected function process_payment( $invoice ) { |
|
429 | + /** |
|
430 | + * Processes the actual payment. |
|
431 | + * |
|
432 | + * @param WPInv_Invoice $invoice |
|
433 | + */ |
|
434 | + protected function process_payment( $invoice ) { |
|
435 | 435 | |
436 | - // Clear any checkout errors. |
|
437 | - wpinv_clear_errors(); |
|
436 | + // Clear any checkout errors. |
|
437 | + wpinv_clear_errors(); |
|
438 | 438 | |
439 | - // No need to send free invoices to the gateway. |
|
440 | - if ( $invoice->is_free() ) { |
|
441 | - $this->process_free_payment( $invoice ); |
|
442 | - } |
|
439 | + // No need to send free invoices to the gateway. |
|
440 | + if ( $invoice->is_free() ) { |
|
441 | + $this->process_free_payment( $invoice ); |
|
442 | + } |
|
443 | 443 | |
444 | - $submission = $this->payment_form_submission; |
|
444 | + $submission = $this->payment_form_submission; |
|
445 | 445 | |
446 | - // Fires before sending to the gateway. |
|
447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
446 | + // Fires before sending to the gateway. |
|
447 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
448 | 448 | |
449 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | - $submission_data = $submission->get_data(); |
|
451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | + $submission_data = $submission->get_data(); |
|
451 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
453 | 453 | |
454 | - // Validate the currency. |
|
455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | - wpinv_set_error( 'invalid_currency' ); |
|
457 | - } |
|
454 | + // Validate the currency. |
|
455 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | + wpinv_set_error( 'invalid_currency' ); |
|
457 | + } |
|
458 | 458 | |
459 | - // Check to see if we have any errors. |
|
460 | - if ( wpinv_get_errors() ) { |
|
461 | - wpinv_send_back_to_checkout( $invoice ); |
|
462 | - } |
|
459 | + // Check to see if we have any errors. |
|
460 | + if ( wpinv_get_errors() ) { |
|
461 | + wpinv_send_back_to_checkout( $invoice ); |
|
462 | + } |
|
463 | 463 | |
464 | - // Send info to the gateway for payment processing |
|
465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
464 | + // Send info to the gateway for payment processing |
|
465 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
466 | 466 | |
467 | - // Backwards compatibility. |
|
468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
467 | + // Backwards compatibility. |
|
468 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Marks the invoice as paid in case the checkout is free. |
|
474 | - * |
|
475 | - * @param WPInv_Invoice $invoice |
|
476 | - */ |
|
477 | - protected function process_free_payment( $invoice ) { |
|
472 | + /** |
|
473 | + * Marks the invoice as paid in case the checkout is free. |
|
474 | + * |
|
475 | + * @param WPInv_Invoice $invoice |
|
476 | + */ |
|
477 | + protected function process_free_payment( $invoice ) { |
|
478 | 478 | |
479 | - $invoice->set_gateway( 'none' ); |
|
480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | - $invoice->mark_paid(); |
|
482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | + $invoice->set_gateway( 'none' ); |
|
480 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | + $invoice->mark_paid(); |
|
482 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
483 | 483 | |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - /** |
|
486 | + /** |
|
487 | 487 | * Sends a redrect response to payment details. |
488 | 488 | * |
489 | 489 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 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 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 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' ) ); |
|
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 | 81 | } |
82 | 82 | |
83 | 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' ) ); |
|
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 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 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' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 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 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
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() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
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 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
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()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 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() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
199 | + if (empty($user)) { |
|
200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
201 | + $name = implode('', array_filter($name)); |
|
202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
203 | 203 | |
204 | 204 | // (Maybe) send new user notification. |
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
207 | + wp_send_new_user_notifications($user, 'user'); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_wp_error( $user ) ) { |
|
212 | - wp_send_json_error( $user->get_error_message() ); |
|
211 | + if (is_wp_error($user)) { |
|
212 | + wp_send_json_error($user->get_error_message()); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( is_numeric( $user ) ) { |
|
215 | + if (is_numeric($user)) { |
|
216 | 216 | return $user; |
217 | 217 | } |
218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | 241 | // Loop through the submitted details. |
242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
243 | 243 | |
244 | 244 | // Skip premade fields. |
245 | - if ( ! empty( $field['premade'] ) ) { |
|
245 | + if (!empty($field['premade'])) { |
|
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | 249 | // Ensure address is provided. |
250 | - if ( 'address' === $field['type'] ) { |
|
251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
250 | + if ('address' === $field['type']) { |
|
251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ($field['fields'] as $address_field) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
262 | + if (!$submission->is_required_field_set($field)) { |
|
263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Handle misc fields. |
267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
267 | + if (isset($data[$field['id']])) { |
|
268 | 268 | |
269 | 269 | // Uploads. |
270 | - if ( 'file_upload' === $field['type'] ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + if ('file_upload' === $field['type']) { |
|
271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $value = array(); |
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
279 | + foreach ($data[$field['id']] as $url => $name) { |
|
280 | 280 | $value[] = sprintf( |
281 | 281 | '<a href="%s" target="_blank">%s</a>', |
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
282 | + esc_url_raw($url), |
|
283 | + esc_html($name) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode(' | ', $value); |
|
288 | 288 | |
289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
289 | + } elseif ('checkbox' === $field['type']) { |
|
290 | + $value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
291 | 291 | } else { |
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
292 | + $value = wp_kses_post($data[$field['id']]); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
297 | - if ( isset( $field['label'] ) ) { |
|
297 | + if (isset($field['label'])) { |
|
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if (!empty($field['add_meta'])) { |
|
302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
303 | 303 | } |
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | * @param string $type |
319 | 319 | */ |
320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
321 | 321 | |
322 | 322 | $data = $this->payment_form_submission->get_data(); |
323 | - $type = sanitize_key( $type ); |
|
323 | + $type = sanitize_key($type); |
|
324 | 324 | $address = array(); |
325 | 325 | $prepared = array(); |
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
327 | + if (!empty($data[$type])) { |
|
328 | + $address = $data[$type]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Clean address details. |
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
332 | + foreach ($address as $key => $value) { |
|
333 | + $key = sanitize_key($key); |
|
334 | + $key = str_replace('wpinv_', '', $key); |
|
335 | + $value = wpinv_clean($value); |
|
336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Filter address details. |
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
341 | 341 | |
342 | 342 | // Remove non-whitelisted values. |
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | * @param WPInv_Invoice $invoice |
352 | 352 | */ |
353 | - protected function prepare_billing_info( &$invoice ) { |
|
353 | + protected function prepare_billing_info(&$invoice) { |
|
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
356 | 356 | |
357 | 357 | // Update the invoice with the billing details. |
358 | - $invoice->set_props( $billing_address ); |
|
358 | + $invoice->set_props($billing_address); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return array |
366 | 366 | * @param WPInv_Invoice $invoice |
367 | 367 | */ |
368 | - protected function prepare_shipping_info( $invoice ) { |
|
368 | + protected function prepare_shipping_info($invoice) { |
|
369 | 369 | |
370 | 370 | $data = $this->payment_form_submission->get_data(); |
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
372 | + if (empty($data['same-shipping-address'])) { |
|
373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
374 | 374 | } |
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -384,45 +384,45 @@ discard block |
||
384 | 384 | * @param array $prepared_payment_form_data |
385 | 385 | * @param array $shipping |
386 | 386 | */ |
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
388 | 388 | |
389 | 389 | // Ensure the invoice exists. |
390 | - if ( ! $invoice->exists() ) { |
|
391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
390 | + if (!$invoice->exists()) { |
|
391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Save payment form data. |
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
398 | + if (!empty($prepared_payment_form_data)) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Save payment form data. |
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | - if ( ! empty( $shipping ) ) { |
|
412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
411 | + if (!empty($shipping)) { |
|
412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Backwards compatibility. |
416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
417 | 417 | |
418 | 418 | try { |
419 | - $this->process_payment( $invoice ); |
|
420 | - } catch ( Exception $e ) { |
|
421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
419 | + $this->process_payment($invoice); |
|
420 | + } catch (Exception $e) { |
|
421 | + wpinv_set_error('payment_error', $e->getMessage()); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | // If we are here, there was an error. |
425 | - wpinv_send_back_to_checkout( $invoice ); |
|
425 | + wpinv_send_back_to_checkout($invoice); |
|
426 | 426 | |
427 | 427 | } |
428 | 428 | |
@@ -431,41 +431,41 @@ discard block |
||
431 | 431 | * |
432 | 432 | * @param WPInv_Invoice $invoice |
433 | 433 | */ |
434 | - protected function process_payment( $invoice ) { |
|
434 | + protected function process_payment($invoice) { |
|
435 | 435 | |
436 | 436 | // Clear any checkout errors. |
437 | 437 | wpinv_clear_errors(); |
438 | 438 | |
439 | 439 | // No need to send free invoices to the gateway. |
440 | - if ( $invoice->is_free() ) { |
|
441 | - $this->process_free_payment( $invoice ); |
|
440 | + if ($invoice->is_free()) { |
|
441 | + $this->process_free_payment($invoice); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | $submission = $this->payment_form_submission; |
445 | 445 | |
446 | 446 | // Fires before sending to the gateway. |
447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
447 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
448 | 448 | |
449 | 449 | // Allow the sumission data to be modified before it is sent to the gateway. |
450 | 450 | $submission_data = $submission->get_data(); |
451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
451 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
452 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
453 | 453 | |
454 | 454 | // Validate the currency. |
455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | - wpinv_set_error( 'invalid_currency' ); |
|
455 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
456 | + wpinv_set_error('invalid_currency'); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | // Check to see if we have any errors. |
460 | - if ( wpinv_get_errors() ) { |
|
461 | - wpinv_send_back_to_checkout( $invoice ); |
|
460 | + if (wpinv_get_errors()) { |
|
461 | + wpinv_send_back_to_checkout($invoice); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | // Send info to the gateway for payment processing |
465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
465 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
466 | 466 | |
467 | 467 | // Backwards compatibility. |
468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
468 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
469 | 469 | |
470 | 470 | } |
471 | 471 | |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @param WPInv_Invoice $invoice |
476 | 476 | */ |
477 | - protected function process_free_payment( $invoice ) { |
|
477 | + protected function process_free_payment($invoice) { |
|
478 | 478 | |
479 | - $invoice->set_gateway( 'none' ); |
|
480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
479 | + $invoice->set_gateway('none'); |
|
480 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
481 | 481 | $invoice->mark_paid(); |
482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
482 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -487,9 +487,9 @@ discard block |
||
487 | 487 | * Sends a redrect response to payment details. |
488 | 488 | * |
489 | 489 | */ |
490 | - public function send_redirect_response( $url ) { |
|
491 | - $url = rawurlencode( $url ); |
|
492 | - wp_send_json_success( $url ); |
|
490 | + public function send_redirect_response($url) { |
|
491 | + $url = rawurlencode($url); |
|
492 | + wp_send_json_success($url); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( ! empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax()) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,44 +165,44 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - $customer = getpaid_get_customer_by_user_id( $invoice->get_user_id() ); |
|
178 | + $customer = getpaid_get_customer_by_user_id($invoice->get_user_id()); |
|
179 | 179 | |
180 | - if ( empty( $customer ) ) { |
|
181 | - $customer = new GetPaid_Customer( 0 ); |
|
182 | - $customer->clone_user( $invoice->get_user_id() ); |
|
180 | + if (empty($customer)) { |
|
181 | + $customer = new GetPaid_Customer(0); |
|
182 | + $customer->clone_user($invoice->get_user_id()); |
|
183 | 183 | } |
184 | 184 | |
185 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
185 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
186 | 186 | |
187 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
188 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
187 | + if (is_callable(array($invoice, "get_$field"))) { |
|
188 | + $value = call_user_func(array($invoice, "get_$field")); |
|
189 | 189 | |
190 | 190 | // Only save if it is not empty. |
191 | - if ( ! empty( $value ) ) { |
|
192 | - $customer->set( $field, sanitize_text_field( $value ) ); |
|
191 | + if (!empty($value)) { |
|
192 | + $customer->set($field, sanitize_text_field($value)); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | $customer->save(); |
198 | 198 | |
199 | - if ( ! $invoice->get_customer_id() ) { |
|
200 | - $invoice->set_customer_id( $customer->get_id() ); |
|
199 | + if (!$invoice->get_customer_id()) { |
|
200 | + $invoice->set_customer_id($customer->get_id()); |
|
201 | 201 | $invoice->save(); |
202 | 202 | } |
203 | 203 | } |
204 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
205 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
204 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
205 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Retrieves a saved user address. |
@@ -210,36 +210,36 @@ discard block |
||
210 | 210 | * @param int $user_id The user id whose address we should get. Defaults to the current user id. |
211 | 211 | * @return array |
212 | 212 | */ |
213 | -function wpinv_get_user_address( $user_id = 0 ) { |
|
213 | +function wpinv_get_user_address($user_id = 0) { |
|
214 | 214 | |
215 | 215 | // Prepare the user id. |
216 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
217 | - $user_info = get_userdata( $user_id ); |
|
216 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
217 | + $user_info = get_userdata($user_id); |
|
218 | 218 | |
219 | 219 | // Abort if non exists. |
220 | - if ( empty( $user_info ) ) { |
|
220 | + if (empty($user_info)) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
224 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
225 | 225 | |
226 | - if ( empty( $customer ) ) { |
|
227 | - $customer = new GetPaid_Customer( 0 ); |
|
228 | - $customer->clone_user( $user_id ); |
|
226 | + if (empty($customer)) { |
|
227 | + $customer = new GetPaid_Customer(0); |
|
228 | + $customer->clone_user($user_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Prepare the address. |
232 | 232 | $address = array( |
233 | 233 | 'user_id' => $user_id, |
234 | - 'email' => $customer->get( 'email' ), |
|
234 | + 'email' => $customer->get('email'), |
|
235 | 235 | 'display_name' => $user_info->display_name, |
236 | 236 | ); |
237 | 237 | |
238 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
239 | - $address[ $field ] = $customer->get( $field ); |
|
238 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
239 | + $address[$field] = $customer->get($field); |
|
240 | 240 | } |
241 | 241 | |
242 | - $address = array_filter( $address ); |
|
242 | + $address = array_filter($address); |
|
243 | 243 | |
244 | 244 | $defaults = array( |
245 | 245 | 'first_name' => $user_info->first_name, |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'country' => wpinv_get_default_country(), |
249 | 249 | ); |
250 | 250 | |
251 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
251 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
252 | 252 | |
253 | 253 | } |
254 | 254 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @return string|null |
261 | 261 | * @deprecated |
262 | 262 | */ |
263 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
263 | +function getpaid_get_user_address_field($user_id, $field) { |
|
264 | 264 | |
265 | 265 | $prefixes = array( |
266 | 266 | '_wpinv_', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | '', |
269 | 269 | ); |
270 | 270 | |
271 | - foreach ( $prefixes as $prefix ) { |
|
271 | + foreach ($prefixes as $prefix) { |
|
272 | 272 | |
273 | 273 | // Meta table. |
274 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
274 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
275 | 275 | |
276 | 276 | // UWP table. |
277 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
277 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
278 | 278 | |
279 | - if ( ! empty( $value ) ) { |
|
279 | + if (!empty($value)) { |
|
280 | 280 | return $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param string $return What to return. |
293 | 293 | * @return array |
294 | 294 | */ |
295 | -function wpinv_get_continents( $return = 'all' ) { |
|
295 | +function wpinv_get_continents($return = 'all') { |
|
296 | 296 | |
297 | - $continents = wpinv_get_data( 'continents' ); |
|
297 | + $continents = wpinv_get_data('continents'); |
|
298 | 298 | |
299 | - switch ( $return ) { |
|
299 | + switch ($return) { |
|
300 | 300 | case 'name': |
301 | - return wp_list_pluck( $continents, 'name' ); |
|
301 | + return wp_list_pluck($continents, 'name'); |
|
302 | 302 | break; |
303 | 303 | case 'countries': |
304 | - return wp_list_pluck( $continents, 'countries' ); |
|
304 | + return wp_list_pluck($continents, 'countries'); |
|
305 | 305 | break; |
306 | 306 | default: |
307 | 307 | return $continents; |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * @param string $country Country code. If no code is specified, defaults to the default country. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
320 | +function wpinv_get_continent_code_for_country($country = false) { |
|
321 | 321 | |
322 | - $country = wpinv_sanitize_country( $country ); |
|
322 | + $country = wpinv_sanitize_country($country); |
|
323 | 323 | |
324 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
325 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
324 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
325 | + if (false !== array_search($country, $countries, true)) { |
|
326 | 326 | return $continent_code; |
327 | 327 | } |
328 | 328 | } |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @param string $country Country code. If no code is specified, defaults to the default country. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | -function wpinv_get_country_calling_code( $country = null ) { |
|
341 | +function wpinv_get_country_calling_code($country = null) { |
|
342 | 342 | |
343 | - $country = wpinv_sanitize_country( $country ); |
|
344 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
345 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
343 | + $country = wpinv_sanitize_country($country); |
|
344 | + $codes = wpinv_get_data('phone-codes'); |
|
345 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
346 | 346 | |
347 | - if ( is_array( $code ) ) { |
|
347 | + if (is_array($code)) { |
|
348 | 348 | return $code[0]; |
349 | 349 | } |
350 | 350 | return $code; |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param bool $first_empty Whether or not the first item in the list should be empty |
358 | 358 | * @return array |
359 | 359 | */ |
360 | -function wpinv_get_country_list( $first_empty = false ) { |
|
361 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
360 | +function wpinv_get_country_list($first_empty = false) { |
|
361 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,22 +368,22 @@ discard block |
||
368 | 368 | * @param bool $first_empty Whether or not the first item in the list should be empty |
369 | 369 | * @return array |
370 | 370 | */ |
371 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
371 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
372 | 372 | |
373 | 373 | // Prepare the country. |
374 | - $country = wpinv_sanitize_country( $country ); |
|
374 | + $country = wpinv_sanitize_country($country); |
|
375 | 375 | |
376 | 376 | // Fetch all states. |
377 | - $all_states = wpinv_get_data( 'states' ); |
|
377 | + $all_states = wpinv_get_data('states'); |
|
378 | 378 | |
379 | 379 | // Fetch the specified country's states. |
380 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
381 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
382 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
380 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
381 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
382 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
383 | 383 | |
384 | - asort( $states ); |
|
384 | + asort($states); |
|
385 | 385 | |
386 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
386 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | function wpinv_get_us_states_list() { |
396 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
396 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return array |
404 | 404 | */ |
405 | 405 | function wpinv_get_canada_states_list() { |
406 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
406 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return array |
414 | 414 | */ |
415 | 415 | function wpinv_get_australia_states_list() { |
416 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
416 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @return array |
424 | 424 | */ |
425 | 425 | function wpinv_get_bangladesh_states_list() { |
426 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
426 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @return array |
434 | 434 | */ |
435 | 435 | function wpinv_get_brazil_states_list() { |
436 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
436 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * @return array |
444 | 444 | */ |
445 | 445 | function wpinv_get_bulgaria_states_list() { |
446 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
446 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * @return array |
454 | 454 | */ |
455 | 455 | function wpinv_get_hong_kong_states_list() { |
456 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
456 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @return array |
464 | 464 | */ |
465 | 465 | function wpinv_get_hungary_states_list() { |
466 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
466 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @return array |
474 | 474 | */ |
475 | 475 | function wpinv_get_japan_states_list() { |
476 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
476 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @return array |
484 | 484 | */ |
485 | 485 | function wpinv_get_china_states_list() { |
486 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
486 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @return array |
494 | 494 | */ |
495 | 495 | function wpinv_get_new_zealand_states_list() { |
496 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
496 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @return array |
504 | 504 | */ |
505 | 505 | function wpinv_get_peru_states_list() { |
506 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
506 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @return array |
514 | 514 | */ |
515 | 515 | function wpinv_get_indonesia_states_list() { |
516 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
516 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @return array |
524 | 524 | */ |
525 | 525 | function wpinv_get_india_states_list() { |
526 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
526 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return array |
534 | 534 | */ |
535 | 535 | function wpinv_get_iran_states_list() { |
536 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
536 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @return array |
544 | 544 | */ |
545 | 545 | function wpinv_get_italy_states_list() { |
546 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
546 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return array |
554 | 554 | */ |
555 | 555 | function wpinv_get_malaysia_states_list() { |
556 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
556 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return array |
564 | 564 | */ |
565 | 565 | function wpinv_get_mexico_states_list() { |
566 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
566 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @return array |
574 | 574 | */ |
575 | 575 | function wpinv_get_nepal_states_list() { |
576 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
576 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * @return array |
584 | 584 | */ |
585 | 585 | function wpinv_get_south_africa_states_list() { |
586 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
586 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return array |
594 | 594 | */ |
595 | 595 | function wpinv_get_thailand_states_list() { |
596 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
596 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | function wpinv_get_turkey_states_list() { |
606 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
606 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -613,31 +613,31 @@ discard block |
||
613 | 613 | * @return array |
614 | 614 | */ |
615 | 615 | function wpinv_get_spain_states_list() { |
616 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
616 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | function wpinv_get_states_field() { |
620 | - if ( empty( $_POST['country'] ) ) { |
|
620 | + if (empty($_POST['country'])) { |
|
621 | 621 | $_POST['country'] = wpinv_get_default_country(); |
622 | 622 | } |
623 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
623 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
624 | 624 | |
625 | - if ( ! empty( $states ) ) { |
|
626 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
625 | + if (!empty($states)) { |
|
626 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
627 | 627 | |
628 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
628 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
629 | 629 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
630 | 630 | |
631 | - $args = array( |
|
631 | + $args = array( |
|
632 | 632 | 'name' => $sanitized_field_name, |
633 | 633 | 'id' => $sanitized_field_name, |
634 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
635 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
634 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
635 | + 'options' => array_merge(array('' => ''), $states), |
|
636 | 636 | 'show_option_all' => false, |
637 | 637 | 'show_option_none' => false, |
638 | 638 | ); |
639 | 639 | |
640 | - wpinv_html_select( $args ); |
|
640 | + wpinv_html_select($args); |
|
641 | 641 | |
642 | 642 | } else { |
643 | 643 | echo 'nostates'; |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
649 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
648 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
649 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
650 | 650 | |
651 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
651 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | * @see `wpinv_get_invoice_address_replacements` |
711 | 711 | * @return string |
712 | 712 | */ |
713 | -function wpinv_get_full_address_format( $country = false ) { |
|
713 | +function wpinv_get_full_address_format($country = false) { |
|
714 | 714 | |
715 | - if ( empty( $country ) ) { |
|
715 | + if (empty($country)) { |
|
716 | 716 | $country = wpinv_get_default_country(); |
717 | 717 | } |
718 | 718 | |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | $formats = wpinv_get_address_formats(); |
721 | 721 | |
722 | 722 | // Get format for the specified country. |
723 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
723 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Filters the address format to use on Invoices. |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @param string $format The address format to use. |
733 | 733 | * @param string $country The country who's address format is being retrieved. |
734 | 734 | */ |
735 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
735 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @param array $billing_details customer's billing details |
744 | 744 | * @return array |
745 | 745 | */ |
746 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
746 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
747 | 747 | |
748 | 748 | $default_args = array( |
749 | 749 | 'address' => '', |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | 'company' => '', |
757 | 757 | ); |
758 | 758 | |
759 | - $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
|
759 | + $args = map_deep(wp_parse_args(array_filter($billing_details), $default_args), 'trim'); |
|
760 | 760 | $state = $args['state']; |
761 | 761 | $country = $args['country']; |
762 | 762 | |
763 | 763 | // Handle full country name. |
764 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
764 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
765 | 765 | |
766 | 766 | // Handle full state name. |
767 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
767 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
768 | 768 | |
769 | 769 | $args['postcode'] = $args['zip']; |
770 | 770 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -782,14 +782,14 @@ discard block |
||
782 | 782 | * @param array $replacements The address replacements to use. |
783 | 783 | * @param array $billing_details The billing details to use. |
784 | 784 | */ |
785 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
785 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
786 | 786 | |
787 | 787 | $return = array(); |
788 | 788 | |
789 | - foreach ( $replacements as $key => $value ) { |
|
790 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
791 | - $return[ '{{' . $key . '}}' ] = $value; |
|
792 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
789 | + foreach ($replacements as $key => $value) { |
|
790 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
791 | + $return['{{' . $key . '}}'] = $value; |
|
792 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | return $return; |
@@ -803,6 +803,6 @@ discard block |
||
803 | 803 | * @since 1.0.14 |
804 | 804 | * @return string |
805 | 805 | */ |
806 | -function wpinv_trim_formatted_address_line( $line ) { |
|
807 | - return trim( $line, ', ' ); |
|
806 | +function wpinv_trim_formatted_address_line($line) { |
|
807 | + return trim($line, ', '); |
|
808 | 808 | } |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '2.8.0' ); |
|
26 | + define( 'WPINV_VERSION', '2.8.0' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * @package GetPaid |
16 | 16 | */ |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | // Define constants. |
21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
23 | 23 | } |
24 | 24 | |
25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
26 | - define( 'WPINV_VERSION', '2.8.0' ); |
|
25 | +if (!defined('WPINV_VERSION')) { |
|
26 | + define('WPINV_VERSION', '2.8.0'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function getpaid() { |
41 | 41 | |
42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
42 | + if (empty($GLOBALS['invoicing'])) { |
|
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @since 2.0.8 |
53 | 53 | */ |
54 | 54 | function getpaid_deactivation_hook() { |
55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
55 | + update_option('wpinv_flush_permalinks', 1); |
|
56 | 56 | } |
57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | // Kickstart the plugin. |
67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
67 | +add_action('plugins_loaded', 'getpaid', -100); |