@@ -12,168 +12,168 @@ 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 | - // Get the items and 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( $invoice ); |
|
43 | - |
|
44 | - // Save the invoice. |
|
45 | - $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 | + // Get the items and 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( $invoice ); |
|
43 | + |
|
44 | + // Save the invoice. |
|
45 | + $invoice->recalculate_total(); |
|
46 | 46 | $invoice->save(); |
47 | 47 | |
48 | - // Send to the gateway. |
|
49 | - $this->post_process_submission( $invoice, $prepared ); |
|
50 | - } |
|
48 | + // Send to the gateway. |
|
49 | + $this->post_process_submission( $invoice, $prepared ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Validates the submission. |
|
54 | - * |
|
55 | - */ |
|
56 | - protected function validate_submission() { |
|
52 | + /** |
|
53 | + * Validates the submission. |
|
54 | + * |
|
55 | + */ |
|
56 | + protected function validate_submission() { |
|
57 | 57 | |
58 | - $submission = $this->payment_form_submission; |
|
59 | - $data = $submission->get_data(); |
|
58 | + $submission = $this->payment_form_submission; |
|
59 | + $data = $submission->get_data(); |
|
60 | 60 | |
61 | - // Do we have an error? |
|
61 | + // Do we have an error? |
|
62 | 62 | if ( ! empty( $submission->last_error ) ) { |
63 | - wp_send_json_error( $submission->last_error ); |
|
63 | + wp_send_json_error( $submission->last_error ); |
|
64 | 64 | } |
65 | 65 | |
66 | - // We need a billing email. |
|
66 | + // We need a billing email. |
|
67 | 67 | if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) { |
68 | 68 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | - if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
74 | - } |
|
71 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | + if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
74 | + } |
|
75 | 75 | |
76 | - // Ensure the gateway is active. |
|
77 | - if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | - } |
|
76 | + // Ensure the gateway is active. |
|
77 | + if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | + } |
|
80 | 80 | |
81 | - // Clear any existing errors. |
|
82 | - wpinv_clear_errors(); |
|
81 | + // Clear any existing errors. |
|
82 | + wpinv_clear_errors(); |
|
83 | 83 | |
84 | - // Allow themes and plugins to hook to errors |
|
85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
84 | + // Allow themes and plugins to hook to errors |
|
85 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
86 | 86 | |
87 | - // Do we have any errors? |
|
87 | + // Do we have any errors? |
|
88 | 88 | if ( wpinv_get_errors() ) { |
89 | 89 | wp_send_json_error( getpaid_get_errors_html() ); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves submission items. |
|
96 | - * |
|
97 | - * @return GetPaid_Form_Item[] |
|
98 | - */ |
|
99 | - protected function get_submission_items() { |
|
94 | + /** |
|
95 | + * Retrieves submission items. |
|
96 | + * |
|
97 | + * @return GetPaid_Form_Item[] |
|
98 | + */ |
|
99 | + protected function get_submission_items() { |
|
100 | 100 | |
101 | - $items = $this->payment_form_submission->get_items(); |
|
101 | + $items = $this->payment_form_submission->get_items(); |
|
102 | 102 | |
103 | 103 | // Ensure that we have items. |
104 | 104 | if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) { |
105 | 105 | wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) ); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - return $items; |
|
109 | - } |
|
108 | + return $items; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Retrieves submission invoice. |
|
113 | - * |
|
114 | - * @return WPInv_Invoice |
|
115 | - */ |
|
116 | - protected function get_submission_invoice() { |
|
117 | - $submission = $this->payment_form_submission; |
|
111 | + /** |
|
112 | + * Retrieves submission invoice. |
|
113 | + * |
|
114 | + * @return WPInv_Invoice |
|
115 | + */ |
|
116 | + protected function get_submission_invoice() { |
|
117 | + $submission = $this->payment_form_submission; |
|
118 | 118 | |
119 | - if ( ! $submission->has_invoice() ) { |
|
120 | - return new WPInv_Invoice(); |
|
119 | + if ( ! $submission->has_invoice() ) { |
|
120 | + return new WPInv_Invoice(); |
|
121 | 121 | } |
122 | 122 | |
123 | - $invoice = $submission->get_invoice(); |
|
123 | + $invoice = $submission->get_invoice(); |
|
124 | 124 | |
125 | - // Make sure that it is neither paid or refunded. |
|
126 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
127 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
128 | - } |
|
125 | + // Make sure that it is neither paid or refunded. |
|
126 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
127 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
128 | + } |
|
129 | 129 | |
130 | - return $invoice; |
|
131 | - } |
|
130 | + return $invoice; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Processes the submission invoice. |
|
135 | - * |
|
136 | - * @param WPInv_Invoice $invoice |
|
137 | - * @param GetPaid_Form_Item[] $items |
|
138 | - * @return WPInv_Invoice |
|
139 | - */ |
|
140 | - protected function process_submission_invoice( $invoice, $items ) { |
|
133 | + /** |
|
134 | + * Processes the submission invoice. |
|
135 | + * |
|
136 | + * @param WPInv_Invoice $invoice |
|
137 | + * @param GetPaid_Form_Item[] $items |
|
138 | + * @return WPInv_Invoice |
|
139 | + */ |
|
140 | + protected function process_submission_invoice( $invoice, $items ) { |
|
141 | 141 | |
142 | - $submission = $this->payment_form_submission; |
|
143 | - $data = $submission->get_data(); |
|
142 | + $submission = $this->payment_form_submission; |
|
143 | + $data = $submission->get_data(); |
|
144 | 144 | |
145 | - // Set-up the invoice details. |
|
146 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
147 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
148 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
145 | + // Set-up the invoice details. |
|
146 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
147 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
148 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
149 | 149 | $invoice->set_items( $items ); |
150 | 150 | $invoice->set_fees( $submission->get_fees() ); |
151 | 151 | $invoice->set_taxes( $submission->get_taxes() ); |
152 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
153 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
152 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
153 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
154 | 154 | |
155 | - if ( $submission->has_discount_code() ) { |
|
155 | + if ( $submission->has_discount_code() ) { |
|
156 | 156 | $invoice->set_discount_code( $submission->get_discount_code() ); |
157 | - } |
|
158 | - |
|
159 | - getpaid_maybe_add_default_address( $invoice ); |
|
160 | - return $invoice; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Retrieves the submission's customer. |
|
165 | - * |
|
166 | - * @return int The customer id. |
|
167 | - */ |
|
168 | - protected function get_submission_customer() { |
|
169 | - $submission = $this->payment_form_submission; |
|
170 | - |
|
171 | - // If this is an existing invoice... |
|
172 | - if ( $submission->has_invoice() ) { |
|
173 | - return $submission->get_invoice()->get_user_id(); |
|
174 | - } |
|
175 | - |
|
176 | - // (Maybe) create the user. |
|
157 | + } |
|
158 | + |
|
159 | + getpaid_maybe_add_default_address( $invoice ); |
|
160 | + return $invoice; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Retrieves the submission's customer. |
|
165 | + * |
|
166 | + * @return int The customer id. |
|
167 | + */ |
|
168 | + protected function get_submission_customer() { |
|
169 | + $submission = $this->payment_form_submission; |
|
170 | + |
|
171 | + // If this is an existing invoice... |
|
172 | + if ( $submission->has_invoice() ) { |
|
173 | + return $submission->get_invoice()->get_user_id(); |
|
174 | + } |
|
175 | + |
|
176 | + // (Maybe) create the user. |
|
177 | 177 | $user = get_current_user_id(); |
178 | 178 | |
179 | 179 | if ( empty( $user ) ) { |
@@ -190,31 +190,31 @@ discard block |
||
190 | 190 | |
191 | 191 | if ( is_numeric( $user ) ) { |
192 | 192 | return $user; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - return $user->ID; |
|
195 | + return $user->ID; |
|
196 | 196 | |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
199 | + /** |
|
200 | 200 | * Prepares submission data for saving to the database. |
201 | 201 | * |
202 | - * @param WPInv_Invoice $invoice |
|
202 | + * @param WPInv_Invoice $invoice |
|
203 | 203 | */ |
204 | 204 | public function prepare_submission_data_for_saving( &$invoice ) { |
205 | 205 | |
206 | - $submission = $this->payment_form_submission; |
|
206 | + $submission = $this->payment_form_submission; |
|
207 | 207 | |
208 | - // Prepared submission details. |
|
208 | + // Prepared submission details. |
|
209 | 209 | $prepared = array(); |
210 | 210 | |
211 | 211 | // Raw submission details. |
212 | - $data = $submission->get_data(); |
|
212 | + $data = $submission->get_data(); |
|
213 | 213 | |
214 | - // Loop throught the submitted details. |
|
214 | + // Loop throught the submitted details. |
|
215 | 215 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
216 | 216 | |
217 | - // Skip premade fields. |
|
217 | + // Skip premade fields. |
|
218 | 218 | if ( ! empty( $field['premade'] ) ) { |
219 | 219 | continue; |
220 | 220 | } |
@@ -257,26 +257,26 @@ discard block |
||
257 | 257 | $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
258 | 258 | } |
259 | 259 | |
260 | - } |
|
260 | + } |
|
261 | 261 | |
262 | - return $prepared; |
|
262 | + return $prepared; |
|
263 | 263 | |
264 | - } |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Confirms the submission is valid and send users to the gateway. |
|
268 | - * |
|
269 | - * @param WPInv_Invoice $invoice |
|
270 | - * @param array $prepared_payment_form_data |
|
271 | - */ |
|
272 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
266 | + /** |
|
267 | + * Confirms the submission is valid and send users to the gateway. |
|
268 | + * |
|
269 | + * @param WPInv_Invoice $invoice |
|
270 | + * @param array $prepared_payment_form_data |
|
271 | + */ |
|
272 | + protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
273 | 273 | |
274 | - // Ensure the invoice exists. |
|
274 | + // Ensure the invoice exists. |
|
275 | 275 | if ( $invoice->get_id() == 0 ) { |
276 | 276 | wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
277 | 277 | } |
278 | 278 | |
279 | - // Was this invoice created via the payment form? |
|
279 | + // Was this invoice created via the payment form? |
|
280 | 280 | if ( ! $this->payment_form_submission->has_invoice() ) { |
281 | 281 | update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' ); |
282 | 282 | } |
@@ -284,65 +284,65 @@ discard block |
||
284 | 284 | // Save payment form data. |
285 | 285 | if ( ! empty( $prepared_payment_form_data ) ) { |
286 | 286 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
287 | - } |
|
287 | + } |
|
288 | 288 | |
289 | - // Backwards compatibility. |
|
289 | + // Backwards compatibility. |
|
290 | 290 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
291 | 291 | |
292 | - $this->process_payment( $invoice ); |
|
292 | + $this->process_payment( $invoice ); |
|
293 | 293 | |
294 | 294 | // If we are here, there was an error. |
295 | - $this->checkout_error(); |
|
295 | + $this->checkout_error(); |
|
296 | 296 | |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Processes the actual payment. |
|
301 | - * |
|
302 | - * @param WPInv_Invoice $invoice |
|
303 | - */ |
|
304 | - protected function process_payment( $invoice ) { |
|
299 | + /** |
|
300 | + * Processes the actual payment. |
|
301 | + * |
|
302 | + * @param WPInv_Invoice $invoice |
|
303 | + */ |
|
304 | + protected function process_payment( $invoice ) { |
|
305 | 305 | |
306 | - $submission = $this->payment_form_submission; |
|
306 | + $submission = $this->payment_form_submission; |
|
307 | 307 | |
308 | - // No need to send free invoices to the gateway. |
|
309 | - if ( $invoice->is_free() ) { |
|
310 | - $invoice->set_gateway( 'none' ); |
|
311 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
312 | - $invoice->mark_paid(); |
|
313 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
314 | - } |
|
308 | + // No need to send free invoices to the gateway. |
|
309 | + if ( $invoice->is_free() ) { |
|
310 | + $invoice->set_gateway( 'none' ); |
|
311 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
312 | + $invoice->mark_paid(); |
|
313 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
314 | + } |
|
315 | 315 | |
316 | - // Clear any checkout errors. |
|
317 | - wpinv_clear_errors(); |
|
316 | + // Clear any checkout errors. |
|
317 | + wpinv_clear_errors(); |
|
318 | 318 | |
319 | - // Fires before sending to the gateway. |
|
320 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
319 | + // Fires before sending to the gateway. |
|
320 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
321 | 321 | |
322 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
323 | - $submission_data = $submission->get_data(); |
|
324 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
325 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
322 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
323 | + $submission_data = $submission->get_data(); |
|
324 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
325 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
326 | 326 | |
327 | - // Validate the currency. |
|
328 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
329 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
330 | - } |
|
327 | + // Validate the currency. |
|
328 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
329 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
330 | + } |
|
331 | 331 | |
332 | - // Check to see if we have any errors. |
|
333 | - if ( wpinv_get_errors() ) { |
|
334 | - wpinv_send_back_to_checkout(); |
|
335 | - } |
|
332 | + // Check to see if we have any errors. |
|
333 | + if ( wpinv_get_errors() ) { |
|
334 | + wpinv_send_back_to_checkout(); |
|
335 | + } |
|
336 | 336 | |
337 | - // Send info to the gateway for payment processing |
|
338 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
337 | + // Send info to the gateway for payment processing |
|
338 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
339 | 339 | |
340 | - // Backwards compatibility. |
|
341 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
340 | + // Backwards compatibility. |
|
341 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
345 | + /** |
|
346 | 346 | * Sends a redrect response to payment details. |
347 | 347 | * |
348 | 348 | */ |
@@ -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,15 +38,15 @@ discard block |
||
38 | 38 | // Get the items and invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving($invoice); |
|
43 | 43 | |
44 | 44 | // Save the invoice. |
45 | 45 | $invoice->recalculate_total(); |
46 | 46 | $invoice->save(); |
47 | 47 | |
48 | 48 | // Send to the gateway. |
49 | - $this->post_process_submission( $invoice, $prepared ); |
|
49 | + $this->post_process_submission($invoice, $prepared); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,34 +59,34 @@ discard block |
||
59 | 59 | $data = $submission->get_data(); |
60 | 60 | |
61 | 61 | // Do we have an error? |
62 | - if ( ! empty( $submission->last_error ) ) { |
|
63 | - wp_send_json_error( $submission->last_error ); |
|
62 | + if (!empty($submission->last_error)) { |
|
63 | + wp_send_json_error($submission->last_error); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // We need a billing email. |
67 | - if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) { |
|
68 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
67 | + if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) { |
|
68 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Non-recurring gateways should not be allowed to process recurring invoices. |
72 | - if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
72 | + if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
73 | + wp_send_json_error(__('The selected payment gateway does not support subscription payment.', 'invoicing')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Ensure the gateway is active. |
77 | - if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
77 | + if (!wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
78 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | // Clear any existing errors. |
82 | 82 | wpinv_clear_errors(); |
83 | 83 | |
84 | 84 | // Allow themes and plugins to hook to errors |
85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
85 | + do_action('getpaid_checkout_error_checks', $submission); |
|
86 | 86 | |
87 | 87 | // Do we have any errors? |
88 | - if ( wpinv_get_errors() ) { |
|
89 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
88 | + if (wpinv_get_errors()) { |
|
89 | + wp_send_json_error(getpaid_get_errors_html()); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | $items = $this->payment_form_submission->get_items(); |
102 | 102 | |
103 | 103 | // Ensure that we have items. |
104 | - if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) { |
|
105 | - wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) ); |
|
104 | + if (empty($items) && 0 == count($this->payment_form_submission->get_fees())) { |
|
105 | + wp_send_json_error(__('Please select at least one item.', 'invoicing')); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $items; |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | protected function get_submission_invoice() { |
117 | 117 | $submission = $this->payment_form_submission; |
118 | 118 | |
119 | - if ( ! $submission->has_invoice() ) { |
|
119 | + if (!$submission->has_invoice()) { |
|
120 | 120 | return new WPInv_Invoice(); |
121 | 121 | } |
122 | 122 | |
123 | 123 | $invoice = $submission->get_invoice(); |
124 | 124 | |
125 | 125 | // Make sure that it is neither paid or refunded. |
126 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
127 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
126 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
127 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $invoice; |
@@ -137,26 +137,26 @@ discard block |
||
137 | 137 | * @param GetPaid_Form_Item[] $items |
138 | 138 | * @return WPInv_Invoice |
139 | 139 | */ |
140 | - protected function process_submission_invoice( $invoice, $items ) { |
|
140 | + protected function process_submission_invoice($invoice, $items) { |
|
141 | 141 | |
142 | 142 | $submission = $this->payment_form_submission; |
143 | 143 | $data = $submission->get_data(); |
144 | 144 | |
145 | 145 | // Set-up the invoice details. |
146 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
147 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
148 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
149 | - $invoice->set_items( $items ); |
|
150 | - $invoice->set_fees( $submission->get_fees() ); |
|
151 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
152 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
153 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
154 | - |
|
155 | - if ( $submission->has_discount_code() ) { |
|
156 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
146 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
147 | + $invoice->set_user_id($this->get_submission_customer()); |
|
148 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
149 | + $invoice->set_items($items); |
|
150 | + $invoice->set_fees($submission->get_fees()); |
|
151 | + $invoice->set_taxes($submission->get_taxes()); |
|
152 | + $invoice->set_discounts($submission->get_discounts()); |
|
153 | + $invoice->set_gateway($data['wpi-gateway']); |
|
154 | + |
|
155 | + if ($submission->has_discount_code()) { |
|
156 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
157 | 157 | } |
158 | 158 | |
159 | - getpaid_maybe_add_default_address( $invoice ); |
|
159 | + getpaid_maybe_add_default_address($invoice); |
|
160 | 160 | return $invoice; |
161 | 161 | } |
162 | 162 | |
@@ -169,26 +169,26 @@ discard block |
||
169 | 169 | $submission = $this->payment_form_submission; |
170 | 170 | |
171 | 171 | // If this is an existing invoice... |
172 | - if ( $submission->has_invoice() ) { |
|
172 | + if ($submission->has_invoice()) { |
|
173 | 173 | return $submission->get_invoice()->get_user_id(); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // (Maybe) create the user. |
177 | 177 | $user = get_current_user_id(); |
178 | 178 | |
179 | - if ( empty( $user ) ) { |
|
180 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
179 | + if (empty($user)) { |
|
180 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( empty( $user ) ) { |
|
184 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
183 | + if (empty($user)) { |
|
184 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
185 | 185 | } |
186 | 186 | |
187 | - if ( is_wp_error( $user ) ) { |
|
188 | - wp_send_json_error( $user->get_error_message() ); |
|
187 | + if (is_wp_error($user)) { |
|
188 | + wp_send_json_error($user->get_error_message()); |
|
189 | 189 | } |
190 | 190 | |
191 | - if ( is_numeric( $user ) ) { |
|
191 | + if (is_numeric($user)) { |
|
192 | 192 | return $user; |
193 | 193 | } |
194 | 194 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @param WPInv_Invoice $invoice |
203 | 203 | */ |
204 | - public function prepare_submission_data_for_saving( &$invoice ) { |
|
204 | + public function prepare_submission_data_for_saving(&$invoice) { |
|
205 | 205 | |
206 | 206 | $submission = $this->payment_form_submission; |
207 | 207 | |
@@ -212,49 +212,49 @@ discard block |
||
212 | 212 | $data = $submission->get_data(); |
213 | 213 | |
214 | 214 | // Loop throught the submitted details. |
215 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
215 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
216 | 216 | |
217 | 217 | // Skip premade fields. |
218 | - if ( ! empty( $field['premade'] ) ) { |
|
218 | + if (!empty($field['premade'])) { |
|
219 | 219 | continue; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // If it is required and not set, abort. |
223 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
224 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
223 | + if (!$submission->is_required_field_set($field)) { |
|
224 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // Handle address fields. |
228 | - if ( $field['type'] == 'address' ) { |
|
228 | + if ($field['type'] == 'address') { |
|
229 | 229 | |
230 | - foreach ( $field['fields'] as $address_field ) { |
|
230 | + foreach ($field['fields'] as $address_field) { |
|
231 | 231 | |
232 | 232 | // skip if it is not visible. |
233 | - if ( empty( $address_field['visible'] ) ) { |
|
233 | + if (empty($address_field['visible'])) { |
|
234 | 234 | continue; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // If it is required and not set, abort |
238 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
239 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
238 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
239 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
240 | 240 | } |
241 | 241 | |
242 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
243 | - $name = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
242 | + if (isset($data[$address_field['name']])) { |
|
243 | + $name = str_replace('wpinv_', '', $address_field['name']); |
|
244 | 244 | $method = "set_$name"; |
245 | - $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) ); |
|
245 | + $invoice->$method(wpinv_clean($data[$address_field['name']])); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | } |
249 | 249 | |
250 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
250 | + } else if (isset($data[$field['id']])) { |
|
251 | 251 | $label = $field['id']; |
252 | 252 | |
253 | - if ( isset( $field['label'] ) ) { |
|
253 | + if (isset($field['label'])) { |
|
254 | 254 | $label = $field['label']; |
255 | 255 | } |
256 | 256 | |
257 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
257 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | } |
@@ -269,27 +269,27 @@ discard block |
||
269 | 269 | * @param WPInv_Invoice $invoice |
270 | 270 | * @param array $prepared_payment_form_data |
271 | 271 | */ |
272 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
272 | + protected function post_process_submission($invoice, $prepared_payment_form_data) { |
|
273 | 273 | |
274 | 274 | // Ensure the invoice exists. |
275 | - if ( $invoice->get_id() == 0 ) { |
|
276 | - wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
|
275 | + if ($invoice->get_id() == 0) { |
|
276 | + wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing')); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | // Was this invoice created via the payment form? |
280 | - if ( ! $this->payment_form_submission->has_invoice() ) { |
|
281 | - update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' ); |
|
280 | + if (!$this->payment_form_submission->has_invoice()) { |
|
281 | + update_post_meta($invoice->get_id(), 'wpinv_created_via', 'payment_form'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // Save payment form data. |
285 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
286 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
285 | + if (!empty($prepared_payment_form_data)) { |
|
286 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Backwards compatibility. |
290 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
290 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
291 | 291 | |
292 | - $this->process_payment( $invoice ); |
|
292 | + $this->process_payment($invoice); |
|
293 | 293 | |
294 | 294 | // If we are here, there was an error. |
295 | 295 | $this->checkout_error(); |
@@ -301,44 +301,44 @@ discard block |
||
301 | 301 | * |
302 | 302 | * @param WPInv_Invoice $invoice |
303 | 303 | */ |
304 | - protected function process_payment( $invoice ) { |
|
304 | + protected function process_payment($invoice) { |
|
305 | 305 | |
306 | 306 | $submission = $this->payment_form_submission; |
307 | 307 | |
308 | 308 | // No need to send free invoices to the gateway. |
309 | - if ( $invoice->is_free() ) { |
|
310 | - $invoice->set_gateway( 'none' ); |
|
311 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
309 | + if ($invoice->is_free()) { |
|
310 | + $invoice->set_gateway('none'); |
|
311 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
312 | 312 | $invoice->mark_paid(); |
313 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
313 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | // Clear any checkout errors. |
317 | 317 | wpinv_clear_errors(); |
318 | 318 | |
319 | 319 | // Fires before sending to the gateway. |
320 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
320 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
321 | 321 | |
322 | 322 | // Allow the sumission data to be modified before it is sent to the gateway. |
323 | 323 | $submission_data = $submission->get_data(); |
324 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
325 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
324 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
325 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
326 | 326 | |
327 | 327 | // Validate the currency. |
328 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
329 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
328 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
329 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Check to see if we have any errors. |
333 | - if ( wpinv_get_errors() ) { |
|
333 | + if (wpinv_get_errors()) { |
|
334 | 334 | wpinv_send_back_to_checkout(); |
335 | 335 | } |
336 | 336 | |
337 | 337 | // Send info to the gateway for payment processing |
338 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
338 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
339 | 339 | |
340 | 340 | // Backwards compatibility. |
341 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
341 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
342 | 342 | |
343 | 343 | } |
344 | 344 | |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * Sends a redrect response to payment details. |
347 | 347 | * |
348 | 348 | */ |
349 | - public function send_redirect_response( $url ) { |
|
350 | - $url = urlencode( $url ); |
|
351 | - wp_send_json_success( $url ); |
|
349 | + public function send_redirect_response($url) { |
|
350 | + $url = urlencode($url); |
|
351 | + wp_send_json_success($url); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | } |
@@ -229,7 +229,7 @@ |
||
229 | 229 | */ |
230 | 230 | function wpinv_send_back_to_checkout() { |
231 | 231 | |
232 | - // Do we have any errors? |
|
232 | + // Do we have any errors? |
|
233 | 233 | if ( wpinv_get_errors() ) { |
234 | 234 | wp_send_json_error( getpaid_get_errors_html() ); |
235 | 235 | } |
@@ -1,155 +1,155 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
3 | - if ( empty( $invoice ) ) { |
|
2 | +function wpinv_is_subscription_payment($invoice = '') { |
|
3 | + if (empty($invoice)) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
7 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
7 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
8 | + $invoice = wpinv_get_invoice($invoice); |
|
9 | 9 | } |
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
11 | + if (empty($invoice)) { |
|
12 | 12 | return false; |
13 | 13 | } |
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
15 | + if ($invoice->is_renewal()) { |
|
16 | 16 | return true; |
17 | 17 | } |
18 | 18 | |
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
23 | - if ( empty( $invoice ) ) { |
|
22 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
23 | + if (empty($invoice)) { |
|
24 | 24 | return false; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
27 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
28 | + $invoice = wpinv_get_invoice($invoice); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
31 | + if (empty($invoice)) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
36 | 36 | } |
37 | 37 | |
38 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
38 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
39 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
40 | 40 | |
41 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
41 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
42 | + $amount = __('Free', 'invoicing'); |
|
43 | 43 | $interval = $trial_interval; |
44 | 44 | $period = $trial_period; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $description = ''; |
48 | - switch ( $period ) { |
|
48 | + switch ($period) { |
|
49 | 49 | case 'D' : |
50 | 50 | case 'day' : |
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
51 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
52 | 52 | break; |
53 | 53 | case 'W' : |
54 | 54 | case 'week' : |
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
55 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
56 | 56 | break; |
57 | 57 | case 'M' : |
58 | 58 | case 'month' : |
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
59 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
60 | 60 | break; |
61 | 61 | case 'Y' : |
62 | 62 | case 'year' : |
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
63 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
64 | 64 | break; |
65 | 65 | } |
66 | 66 | |
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
67 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
70 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
71 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
72 | + $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0; |
|
73 | 73 | |
74 | 74 | $description = ''; |
75 | - switch ( $period ) { |
|
75 | + switch ($period) { |
|
76 | 76 | case 'D' : |
77 | 77 | case 'day' : |
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
78 | + if ((int) $bill_times > 0) { |
|
79 | + if ($interval > 1) { |
|
80 | + if ($bill_times > 1) { |
|
81 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
82 | 82 | } else { |
83 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
83 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
84 | 84 | } |
85 | 85 | } else { |
86 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
86 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
87 | 87 | } |
88 | 88 | } else { |
89 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
89 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
90 | 90 | } |
91 | 91 | break; |
92 | 92 | case 'W' : |
93 | 93 | case 'week' : |
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
94 | + if ((int) $bill_times > 0) { |
|
95 | + if ($interval > 1) { |
|
96 | + if ($bill_times > 1) { |
|
97 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
98 | 98 | } else { |
99 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
99 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
100 | 100 | } |
101 | 101 | } else { |
102 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
102 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
105 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
106 | 106 | } |
107 | 107 | break; |
108 | 108 | case 'M' : |
109 | 109 | case 'month' : |
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
110 | + if ((int) $bill_times > 0) { |
|
111 | + if ($interval > 1) { |
|
112 | + if ($bill_times > 1) { |
|
113 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
114 | 114 | } else { |
115 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
115 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
118 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
121 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | case 'Y' : |
125 | 125 | case 'year' : |
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
126 | + if ((int) $bill_times > 0) { |
|
127 | + if ($interval > 1) { |
|
128 | + if ($bill_times > 1) { |
|
129 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
130 | 130 | } else { |
131 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
131 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
134 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
135 | 135 | } |
136 | 136 | } else { |
137 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
137 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
138 | 138 | } |
139 | 139 | break; |
140 | 140 | } |
141 | 141 | |
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
142 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
146 | - if ( empty( $invoice ) ) { |
|
145 | +function wpinv_subscription_payment_desc($invoice) { |
|
146 | + if (empty($invoice)) { |
|
147 | 147 | return NULL; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $description = ''; |
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
152 | + if ($item->has_free_trial()) { |
|
153 | 153 | $trial_period = $item->get_trial_period(); |
154 | 154 | $trial_interval = $item->get_trial_interval(); |
155 | 155 | } else { |
@@ -157,40 +157,40 @@ discard block |
||
157 | 157 | $trial_interval = 0; |
158 | 158 | } |
159 | 159 | |
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
160 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
163 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
164 | 164 | } |
165 | 165 | |
166 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
166 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
167 | + $initial_total = wpinv_round_amount($initial); |
|
168 | + $recurring_total = wpinv_round_amount($recurring); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
170 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
171 | 171 | // Free trial |
172 | 172 | } else { |
173 | - if ( $bill_times == 1 ) { |
|
173 | + if ($bill_times == 1) { |
|
174 | 174 | $recurring_total = $initial_total; |
175 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
175 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
176 | 176 | $bill_times--; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
181 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
180 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
181 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ($initial_total != $recurring_total) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
188 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
189 | 189 | } else { |
190 | 190 | $description = $recurring; |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * @param string $card_number Card number. |
201 | 201 | * @return string |
202 | 202 | */ |
203 | -function getpaid_get_card_name( $card_number ) { |
|
203 | +function getpaid_get_card_name($card_number) { |
|
204 | 204 | |
205 | 205 | // Known regexes. |
206 | 206 | $regexes = array( |
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
207 | + '/^4/' => __('Visa', 'invoicing'), |
|
208 | + '/^5[1-5]/' => __('Mastercard', 'invoicing'), |
|
209 | + '/^3[47]/' => __('Amex', 'invoicing'), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __('Diners Club', 'invoicing'), |
|
211 | + '/^6(?:011|5)/' => __('Discover', 'invoicing'), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'), |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | // Confirm if one matches. |
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match ( $regex, $card_number ) >= 1 ) { |
|
216 | + foreach ($regexes as $regex => $card) { |
|
217 | + if (preg_match($regex, $card_number) >= 1) { |
|
218 | 218 | return $card; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | // None matched. |
223 | - return __( 'Card', 'invoicing' ); |
|
223 | + return __('Card', 'invoicing'); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | function wpinv_send_back_to_checkout() { |
231 | 231 | |
232 | 232 | // Do we have any errors? |
233 | - if ( wpinv_get_errors() ) { |
|
234 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
233 | + if (wpinv_get_errors()) { |
|
234 | + wp_send_json_error(getpaid_get_errors_html()); |
|
235 | 235 | } |
236 | 236 | |
237 | - wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) ); |
|
237 | + wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing')); |
|
238 | 238 | } |
@@ -31,36 +31,36 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
34 | + $can_checkout = true; // Always true for now |
|
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | + $page_id = absint( $page_id ); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | function wpinv_get_history_page_uri() { |
47 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | - $page_id = absint( $page_id ); |
|
47 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | + $page_id = absint( $page_id ); |
|
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function wpinv_is_success_page() { |
54 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
54 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
56 | 56 | |
57 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function wpinv_is_invoice_history_page() { |
61 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | - $ret = $ret ? is_page( $ret ) : false; |
|
63 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
61 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | + $ret = $ret ? is_page( $ret ) : false; |
|
63 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_subscriptions_history_page() { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | function wpinv_send_to_failed_page( $args = null ) { |
86 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
86 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
87 | 87 | |
88 | 88 | if ( !empty( $args ) ) { |
89 | 89 | // Check for backward compatibility |
@@ -103,55 +103,55 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | function wpinv_get_checkout_uri( $args = array() ) { |
106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
106 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
108 | 108 | |
109 | - if ( !empty( $args ) ) { |
|
110 | - // Check for backward compatibility |
|
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
109 | + if ( !empty( $args ) ) { |
|
110 | + // Check for backward compatibility |
|
111 | + if ( is_string( $args ) ) |
|
112 | + $args = str_replace( '?', '', $args ); |
|
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args( $args ); |
|
115 | 115 | |
116 | - $uri = add_query_arg( $args, $uri ); |
|
117 | - } |
|
116 | + $uri = add_query_arg( $args, $uri ); |
|
117 | + } |
|
118 | 118 | |
119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
119 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
120 | 120 | |
121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
121 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
122 | 122 | |
123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
125 | - } |
|
123 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
125 | + } |
|
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
127 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | function wpinv_get_success_page_url( $query_string = null ) { |
131 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
132 | - $success_page = get_permalink( $success_page ); |
|
131 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
132 | + $success_page = get_permalink( $success_page ); |
|
133 | 133 | |
134 | - if ( $query_string ) |
|
135 | - $success_page .= $query_string; |
|
134 | + if ( $query_string ) |
|
135 | + $success_page .= $query_string; |
|
136 | 136 | |
137 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
137 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
141 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
142 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
141 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
142 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
143 | 143 | |
144 | - if ( $extras ) |
|
145 | - $uri .= $extras; |
|
144 | + if ( $extras ) |
|
145 | + $uri .= $extras; |
|
146 | 146 | |
147 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
147 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | function wpinv_is_failed_transaction_page() { |
151 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
152 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
151 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
152 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
153 | 153 | |
154 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
154 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -226,36 +226,36 @@ discard block |
||
226 | 226 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
227 | 227 | |
228 | 228 | if ( $require_billing_details ) { |
229 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
230 | - $required_fields['first_name'] = array( |
|
231 | - 'error_id' => 'invalid_first_name', |
|
232 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
233 | - ); |
|
234 | - } |
|
235 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
236 | - $required_fields['address'] = array( |
|
237 | - 'error_id' => 'invalid_address', |
|
238 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
239 | - ); |
|
240 | - } |
|
241 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
242 | - $required_fields['city'] = array( |
|
243 | - 'error_id' => 'invalid_city', |
|
244 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
245 | - ); |
|
246 | - } |
|
247 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
248 | - $required_fields['state'] = array( |
|
249 | - 'error_id' => 'invalid_state', |
|
250 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
254 | - $required_fields['country'] = array( |
|
255 | - 'error_id' => 'invalid_country', |
|
256 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
257 | - ); |
|
258 | - } |
|
229 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
230 | + $required_fields['first_name'] = array( |
|
231 | + 'error_id' => 'invalid_first_name', |
|
232 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
233 | + ); |
|
234 | + } |
|
235 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
236 | + $required_fields['address'] = array( |
|
237 | + 'error_id' => 'invalid_address', |
|
238 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
239 | + ); |
|
240 | + } |
|
241 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
242 | + $required_fields['city'] = array( |
|
243 | + 'error_id' => 'invalid_city', |
|
244 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
245 | + ); |
|
246 | + } |
|
247 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
248 | + $required_fields['state'] = array( |
|
249 | + 'error_id' => 'invalid_state', |
|
250 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
254 | + $required_fields['country'] = array( |
|
255 | + 'error_id' => 'invalid_country', |
|
256 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
257 | + ); |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -7,172 +7,172 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( !$is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( !$is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | function wpinv_get_history_page_uri() { |
47 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | - $page_id = absint( $page_id ); |
|
47 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
48 | + $page_id = absint($page_id); |
|
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function wpinv_is_success_page() { |
54 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
54 | + $is_success_page = wpinv_get_option('success_page', false); |
|
55 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
56 | 56 | |
57 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function wpinv_is_invoice_history_page() { |
61 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | - $ret = $ret ? is_page( $ret ) : false; |
|
63 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
61 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
62 | + $ret = $ret ? is_page($ret) : false; |
|
63 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_subscriptions_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Redirects a user the success page. |
74 | 74 | */ |
75 | -function wpinv_send_to_success_page( $args = array() ) { |
|
75 | +function wpinv_send_to_success_page($args = array()) { |
|
76 | 76 | $redirect = add_query_arg( |
77 | - wp_parse_args( $args ), |
|
77 | + wp_parse_args($args), |
|
78 | 78 | wpinv_get_success_page_uri() |
79 | 79 | ); |
80 | 80 | |
81 | - wp_redirect( $redirect ); |
|
81 | + wp_redirect($redirect); |
|
82 | 82 | exit; |
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_send_to_failed_page( $args = null ) { |
|
85 | +function wpinv_send_to_failed_page($args = null) { |
|
86 | 86 | $redirect = wpinv_get_failed_transaction_uri(); |
87 | 87 | |
88 | - if ( !empty( $args ) ) { |
|
88 | + if (!empty($args)) { |
|
89 | 89 | // Check for backward compatibility |
90 | - if ( is_string( $args ) ) |
|
91 | - $args = str_replace( '?', '', $args ); |
|
90 | + if (is_string($args)) |
|
91 | + $args = str_replace('?', '', $args); |
|
92 | 92 | |
93 | - $args = wp_parse_args( $args ); |
|
93 | + $args = wp_parse_args($args); |
|
94 | 94 | |
95 | - $redirect = add_query_arg( $args, $redirect ); |
|
95 | + $redirect = add_query_arg($args, $redirect); |
|
96 | 96 | } |
97 | 97 | |
98 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
98 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
99 | 99 | |
100 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
101 | - wp_redirect( $redirect ); |
|
100 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
101 | + wp_redirect($redirect); |
|
102 | 102 | exit; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
105 | +function wpinv_get_checkout_uri($args = array()) { |
|
106 | + $uri = wpinv_get_option('checkout_page', false); |
|
107 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
108 | 108 | |
109 | - if ( !empty( $args ) ) { |
|
109 | + if (!empty($args)) { |
|
110 | 110 | // Check for backward compatibility |
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
111 | + if (is_string($args)) |
|
112 | + $args = str_replace('?', '', $args); |
|
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args($args); |
|
115 | 115 | |
116 | - $uri = add_query_arg( $args, $uri ); |
|
116 | + $uri = add_query_arg($args, $uri); |
|
117 | 117 | } |
118 | 118 | |
119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
119 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
120 | 120 | |
121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
121 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
122 | 122 | |
123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
123 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
124 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
125 | 125 | } |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
127 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
131 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
132 | - $success_page = get_permalink( $success_page ); |
|
130 | +function wpinv_get_success_page_url($query_string = null) { |
|
131 | + $success_page = wpinv_get_option('success_page', 0); |
|
132 | + $success_page = get_permalink($success_page); |
|
133 | 133 | |
134 | - if ( $query_string ) |
|
134 | + if ($query_string) |
|
135 | 135 | $success_page .= $query_string; |
136 | 136 | |
137 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
137 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
141 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
142 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
140 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
141 | + $uri = wpinv_get_option('failure_page', ''); |
|
142 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
143 | 143 | |
144 | - if ( $extras ) |
|
144 | + if ($extras) |
|
145 | 145 | $uri .= $extras; |
146 | 146 | |
147 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
147 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | function wpinv_is_failed_transaction_page() { |
151 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
152 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
151 | + $ret = wpinv_get_option('failure_page', false); |
|
152 | + $ret = isset($ret) ? is_page($ret) : false; |
|
153 | 153 | |
154 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
154 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
155 | 155 | } |
156 | 156 | |
157 | -function wpinv_transaction_query( $type = 'start' ) { |
|
157 | +function wpinv_transaction_query($type = 'start') { |
|
158 | 158 | global $wpdb; |
159 | 159 | |
160 | 160 | $wpdb->hide_errors(); |
161 | 161 | |
162 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
163 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
162 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
163 | + define('WPINV_USE_TRANSACTIONS', true); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
167 | - switch ( $type ) { |
|
166 | + if (WPINV_USE_TRANSACTIONS) { |
|
167 | + switch ($type) { |
|
168 | 168 | case 'commit' : |
169 | - $wpdb->query( 'COMMIT' ); |
|
169 | + $wpdb->query('COMMIT'); |
|
170 | 170 | break; |
171 | 171 | case 'rollback' : |
172 | - $wpdb->query( 'ROLLBACK' ); |
|
172 | + $wpdb->query('ROLLBACK'); |
|
173 | 173 | break; |
174 | 174 | default : |
175 | - $wpdb->query( 'START TRANSACTION' ); |
|
175 | + $wpdb->query('START TRANSACTION'); |
|
176 | 176 | break; |
177 | 177 | } |
178 | 178 | } |
@@ -181,141 +181,141 @@ discard block |
||
181 | 181 | function wpinv_get_prefix() { |
182 | 182 | $invoice_prefix = 'INV-'; |
183 | 183 | |
184 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
184 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | function wpinv_get_business_logo() { |
188 | - $business_logo = wpinv_get_option( 'logo' ); |
|
189 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
188 | + $business_logo = wpinv_get_option('logo'); |
|
189 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_get_business_name() { |
193 | 193 | $business_name = wpinv_get_option('store_name'); |
194 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
194 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | function wpinv_get_blogname() { |
198 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
198 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | function wpinv_get_admin_email() { |
202 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
203 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
202 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
203 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function wpinv_get_business_website() { |
207 | - $business_website = home_url( '/' ); |
|
208 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
207 | + $business_website = home_url('/'); |
|
208 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
209 | 209 | } |
210 | 210 | |
211 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
211 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
212 | 212 | $terms_text = ''; |
213 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
213 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | function wpinv_get_business_footer() { |
217 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
218 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
219 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
217 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
218 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
219 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_checkout_required_fields() { |
223 | 223 | $required_fields = array(); |
224 | 224 | |
225 | 225 | // Let payment gateways and other extensions determine if address fields should be required |
226 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
226 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
227 | 227 | |
228 | - if ( $require_billing_details ) { |
|
229 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
228 | + if ($require_billing_details) { |
|
229 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
230 | 230 | $required_fields['first_name'] = array( |
231 | 231 | 'error_id' => 'invalid_first_name', |
232 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
232 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
233 | 233 | ); |
234 | 234 | } |
235 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
235 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
236 | 236 | $required_fields['address'] = array( |
237 | 237 | 'error_id' => 'invalid_address', |
238 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
238 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
239 | 239 | ); |
240 | 240 | } |
241 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
241 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
242 | 242 | $required_fields['city'] = array( |
243 | 243 | 'error_id' => 'invalid_city', |
244 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
244 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
245 | 245 | ); |
246 | 246 | } |
247 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
247 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
248 | 248 | $required_fields['state'] = array( |
249 | 249 | 'error_id' => 'invalid_state', |
250 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
250 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
251 | 251 | ); |
252 | 252 | } |
253 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
253 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
254 | 254 | $required_fields['country'] = array( |
255 | 255 | 'error_id' => 'invalid_country', |
256 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
256 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
257 | 257 | ); |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
261 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | function wpinv_is_ssl_enforced() { |
265 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
266 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
265 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
266 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | function wpinv_schedule_event_twicedaily() { |
270 | 270 | wpinv_email_payment_reminders(); |
271 | 271 | } |
272 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
272 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
273 | 273 | |
274 | 274 | function wpinv_require_login_to_checkout() { |
275 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
276 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
275 | + $return = wpinv_get_option('login_to_checkout', false); |
|
276 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
277 | 277 | } |
278 | 278 | |
279 | -function wpinv_sequential_number_active( $type = '' ) { |
|
280 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
281 | - if ( null !== $check ) { |
|
279 | +function wpinv_sequential_number_active($type = '') { |
|
280 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
281 | + if (null !== $check) { |
|
282 | 282 | return $check; |
283 | 283 | } |
284 | 284 | |
285 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
285 | + return wpinv_get_option('sequential_invoice_number'); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
288 | +function wpinv_switch_to_locale($locale = NULL) { |
|
289 | 289 | global $invoicing, $wpi_switch_locale; |
290 | 290 | |
291 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
292 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
291 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
292 | + $locale = empty($locale) ? get_locale() : $locale; |
|
293 | 293 | |
294 | - switch_to_locale( $locale ); |
|
294 | + switch_to_locale($locale); |
|
295 | 295 | |
296 | 296 | $wpi_switch_locale = $locale; |
297 | 297 | |
298 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
298 | + add_filter('plugin_locale', 'get_locale'); |
|
299 | 299 | |
300 | 300 | $invoicing->load_textdomain(); |
301 | 301 | |
302 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
302 | + do_action('wpinv_switch_to_locale', $locale); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | 306 | function wpinv_restore_locale() { |
307 | 307 | global $invoicing, $wpi_switch_locale; |
308 | 308 | |
309 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
309 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
310 | 310 | restore_previous_locale(); |
311 | 311 | |
312 | 312 | $wpi_switch_locale = NULL; |
313 | 313 | |
314 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
314 | + remove_filter('plugin_locale', 'get_locale'); |
|
315 | 315 | |
316 | 316 | $invoicing->load_textdomain(); |
317 | 317 | |
318 | - do_action( 'wpinv_restore_locale' ); |
|
318 | + do_action('wpinv_restore_locale'); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,22 +323,22 @@ discard block |
||
323 | 323 | * Returns the default form's id. |
324 | 324 | */ |
325 | 325 | function wpinv_get_default_payment_form() { |
326 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
326 | + $form = get_option('wpinv_default_payment_form'); |
|
327 | 327 | |
328 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
328 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
329 | 329 | $form = wp_insert_post( |
330 | 330 | array( |
331 | 331 | 'post_type' => 'wpi_payment_form', |
332 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
332 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
333 | 333 | 'post_status' => 'publish', |
334 | 334 | 'meta_input' => array( |
335 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
335 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
336 | 336 | 'wpinv_form_items' => array(), |
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
340 | 340 | |
341 | - update_option( 'wpinv_default_payment_form', $form ); |
|
341 | + update_option('wpinv_default_payment_form', $form); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $form; |
@@ -87,8 +87,9 @@ discard block |
||
87 | 87 | |
88 | 88 | if ( !empty( $args ) ) { |
89 | 89 | // Check for backward compatibility |
90 | - if ( is_string( $args ) ) |
|
91 | - $args = str_replace( '?', '', $args ); |
|
90 | + if ( is_string( $args ) ) { |
|
91 | + $args = str_replace( '?', '', $args ); |
|
92 | + } |
|
92 | 93 | |
93 | 94 | $args = wp_parse_args( $args ); |
94 | 95 | |
@@ -108,8 +109,9 @@ discard block |
||
108 | 109 | |
109 | 110 | if ( !empty( $args ) ) { |
110 | 111 | // Check for backward compatibility |
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
112 | + if ( is_string( $args ) ) { |
|
113 | + $args = str_replace( '?', '', $args ); |
|
114 | + } |
|
113 | 115 | |
114 | 116 | $args = wp_parse_args( $args ); |
115 | 117 | |
@@ -131,8 +133,9 @@ discard block |
||
131 | 133 | $success_page = wpinv_get_option( 'success_page', 0 ); |
132 | 134 | $success_page = get_permalink( $success_page ); |
133 | 135 | |
134 | - if ( $query_string ) |
|
135 | - $success_page .= $query_string; |
|
136 | + if ( $query_string ) { |
|
137 | + $success_page .= $query_string; |
|
138 | + } |
|
136 | 139 | |
137 | 140 | return apply_filters( 'wpinv_success_page_url', $success_page ); |
138 | 141 | } |
@@ -141,8 +144,9 @@ discard block |
||
141 | 144 | $uri = wpinv_get_option( 'failure_page', '' ); |
142 | 145 | $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
143 | 146 | |
144 | - if ( $extras ) |
|
145 | - $uri .= $extras; |
|
147 | + if ( $extras ) { |
|
148 | + $uri .= $extras; |
|
149 | + } |
|
146 | 150 | |
147 | 151 | return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
148 | 152 | } |