Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/preheaders/checkout.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + global $post, $gateway, $wpdb, $besecure, $discount_code, $discount_code_id, $pmpro_level, $pmpro_msg, $pmpro_msgt, $pmpro_review, $skip_account_fields, $pmpro_paypal_token, $pmpro_show_discount_code, $pmpro_error_fields, $pmpro_required_billing_fields, $pmpro_required_user_fields, $wp_version, $current_user, $pmpro_checkout_level_ids;
3 +
4 + // we are on the checkout page
5 + add_filter( 'pmpro_is_checkout', '__return_true' );
6 +
7 + //this var stores fields with errors so we can make them red on the frontend
8 + $pmpro_error_fields = array();
9 +
10 + //blank array for required fields, set below
11 + $pmpro_required_billing_fields = array();
12 + $pmpro_required_user_fields = array();
13 +
14 + /**
15 + * If there is a token order passed in the URL, we are processing the payment for that order.
16 + */
17 + if ( ! empty( $_REQUEST['pmpro_order'] ) ) {
18 + $order_code = sanitize_text_field( $_REQUEST['pmpro_order'] );
19 + $order_obj = new MemberOrder( $order_code );
20 + if ( ! empty( $order_obj->id ) ) {
21 + // $pmpro_review is a legacy variable from the old PayPal Express flow. When set, it was used to
22 + // display a version of the checkout page where the user could review their order before submitting.
23 + // Fields were not editable.
24 + // We are reworking this variable to maintain backwards compatiblity with custom page templates and
25 + // setting it whenever a token order is passed in the URL and requires addtional payment steps.
26 + $pmpro_review = $order_obj;
27 +
28 + // If the order is not for the current user or the order is in error status, redirect to the account page.
29 + if ( $current_user->ID != $pmpro_review->user_id || 'error' === $pmpro_review->status ) {
30 + wp_redirect( pmpro_url( 'account' ) );
31 + exit;
32 + }
33 +
34 + // If the order has already had a payment submitted, redirect to the confirmation page.
35 + if ( in_array( $pmpro_review->status, array( 'success', 'pending' ) ) ) {
36 + wp_redirect( pmpro_url( 'confirmation', '?level=' . $pmpro_review->membership_id ) );
37 + exit;
38 + }
39 +
40 + pmpro_pull_checkout_data_from_order( $pmpro_review );
41 + } else {
42 + // This is an invalid order. Redirect to the account page.
43 + wp_redirect( pmpro_url( 'account' ) );
44 + exit;
45 + }
46 + }
47 +
48 + //was a gateway passed?
49 + if ( ! empty( $pmpro_review ) ) {
50 + $gateway = $pmpro_review->gateway;
51 + } elseif ( ! empty( $_REQUEST['gateway'] ) ) {
52 + $gateway = sanitize_text_field($_REQUEST['gateway']);
53 + } else {
54 + $gateway = get_option( "pmpro_gateway" );
55 + }
56 +
57 + //set valid gateways - the active gateway in the settings and any gateway added through the filter will be allowed
58 + $valid_gateways = apply_filters( "pmpro_valid_gateways", array( get_option( "pmpro_gateway" ) ) );
59 +
60 + //let's add an error now, if an invalid gateway is set
61 + if ( ! in_array( $gateway, $valid_gateways ) ) {
62 + $pmpro_msg = __( "Invalid gateway.", 'paid-memberships-pro' );
63 + $pmpro_msgt = "pmpro_error";
64 + }
65 +
66 + /**
67 + * Action to run extra preheader code before setting checkout level.
68 + *
69 + * @since 2.0.5
70 + */
71 + do_action( 'pmpro_checkout_preheader_before_get_level_at_checkout' );
72 +
73 + //what level are they purchasing? (discount code passed)
74 + $pmpro_level = pmpro_getLevelAtCheckout();
75 +
76 + /**
77 + * Action to run extra preheader code after setting checkout level.
78 + *
79 + * @since 2.0.5
80 + * //TODO update docblock
81 + */
82 + do_action( 'pmpro_checkout_preheader_after_get_level_at_checkout', $pmpro_level );
83 +
84 + if ( empty( $pmpro_level->id ) ) {
85 + wp_redirect( pmpro_url( "levels" ) );
86 + exit( 0 );
87 + }
88 +
89 + //enqueue some scripts
90 + wp_enqueue_script( 'jquery.creditCardValidator', plugins_url( '/js/jquery.creditCardValidator.js', dirname( __FILE__ ) ), array( 'jquery' ), '1.2' );
91 +
92 + global $wpdb, $current_user, $pmpro_requirebilling;
93 + //unless we're submitting a form, let's try to figure out if https should be used
94 +
95 + if ( ! pmpro_isLevelFree( $pmpro_level ) ) {
96 + //require billing and ssl
97 + $pagetitle = __( "Checkout: Payment Information", 'paid-memberships-pro' );
98 + $pmpro_requirebilling = true;
99 + $besecure = get_option( "pmpro_use_ssl" );
100 + } else {
101 + //no payment so we don't need ssl
102 + $pagetitle = __( "Set Up Your Account", 'paid-memberships-pro' );
103 + $pmpro_requirebilling = false;
104 + $besecure = false;
105 + }
106 +
107 + // Allow for filters.
108 + // TODO: docblock.
109 + /**
110 + * @deprecated 3.2
111 + */
112 + $pmpro_requirebilling = apply_filters_deprecated( 'pmpro_require_billing', array( $pmpro_requirebilling, $pmpro_level ), '3.2' );
113 +
114 + //in case a discount code was used or something else made the level free, but we're already over ssl
115 + if ( ! $besecure && ! empty( $_REQUEST['submit-checkout'] ) && is_ssl() ) {
116 + $besecure = true;
117 + } //be secure anyway since we're already checking out
118 +
119 + /**
120 + * Action to run extra code for gateways/etc.
121 + *
122 + * @since 3.4 Added $pmpro_level parameter.
123 + *
124 + * @param object $pmpro_level The level being purchased.
125 + */
126 + do_action( 'pmpro_checkout_preheader', $pmpro_level );
127 +
128 + // We set a global var for add-ons that are expecting it.
129 + $pmpro_show_discount_code = pmpro_show_discount_code();
130 +
131 + /**
132 + * Set whether the account fields should be skipped on the checkout page.
133 + * This filter is useful when you do not want to show the account fields during the initial signup process.
134 + *
135 + * @param bool $skip_account_fields True if the account fields should be skipped.
136 + * @param WP_User|null $current_user The current user object or null if there is no user.
137 + */
138 + $skip_account_fields = apply_filters( "pmpro_skip_account_fields", ! empty( $current_user->ID ), $current_user );
139 +
140 + //load em up (other fields)
141 + global $username, $password, $password2, $bfirstname, $blastname, $baddress1, $baddress2, $bcity, $bstate, $bzipcode, $bcountry, $bphone, $bemail, $bconfirmemail, $CardType, $AccountNumber, $ExpirationMonth, $ExpirationYear;
142 +
143 + if ( isset( $_REQUEST['order_id'] ) ) {
144 + $order_id = intval( $_REQUEST['order_id'] );
145 + } else {
146 + $order_id = "";
147 + }
148 + if ( isset( $_REQUEST['bfirstname'] ) ) {
149 + $bfirstname = stripslashes( sanitize_text_field( $_REQUEST['bfirstname'] ) );
150 + } else {
151 + $bfirstname = "";
152 + }
153 + if ( isset( $_REQUEST['blastname'] ) ) {
154 + $blastname = stripslashes( sanitize_text_field( $_REQUEST['blastname'] ) );
155 + } else {
156 + $blastname = "";
157 + }
158 + if ( isset( $_REQUEST['fullname'] ) ) {
159 + $fullname = sanitize_text_field( $_REQUEST['fullname'] );
160 + } //honeypot for spammers
161 + if ( isset( $_REQUEST['baddress1'] ) ) {
162 + $baddress1 = stripslashes( sanitize_text_field( $_REQUEST['baddress1'] ) );
163 + } else {
164 + $baddress1 = "";
165 + }
166 + if ( isset( $_REQUEST['baddress2'] ) ) {
167 + $baddress2 = stripslashes( sanitize_text_field( $_REQUEST['baddress2'] ) );
168 + } else {
169 + $baddress2 = "";
170 + }
171 + if ( isset( $_REQUEST['bcity'] ) ) {
172 + $bcity = stripslashes( sanitize_text_field( $_REQUEST['bcity'] ) );
173 + } else {
174 + $bcity = "";
175 + }
176 +
177 + if ( isset( $_REQUEST['bstate'] ) ) {
178 + $bstate = stripslashes( sanitize_text_field( $_REQUEST['bstate'] ) );
179 + } else {
180 + $bstate = "";
181 + }
182 +
183 + //convert long state names to abbreviations
184 + if ( ! empty( $bstate ) ) {
185 + global $pmpro_states;
186 + foreach ( $pmpro_states as $abbr => $state ) {
187 + if ( $bstate == $state ) {
188 + $bstate = $abbr;
189 + break;
190 + }
191 + }
192 + }
193 +
194 + if ( isset( $_REQUEST['bzipcode'] ) ) {
195 + $bzipcode = stripslashes( sanitize_text_field( $_REQUEST['bzipcode'] ) );
196 + } else {
197 + $bzipcode = "";
198 + }
199 + if ( isset( $_REQUEST['bcountry'] ) ) {
200 + $bcountry = stripslashes( sanitize_text_field( $_REQUEST['bcountry'] ) );
201 + } else {
202 + $bcountry = "";
203 + }
204 + if ( isset( $_REQUEST['bphone'] ) ) {
205 + $bphone = stripslashes( sanitize_text_field( $_REQUEST['bphone'] ) );
206 + } else {
207 + $bphone = "";
208 + }
209 + if ( isset ( $_REQUEST['bemail'] ) ) {
210 + $bemail = stripslashes( sanitize_email( $_REQUEST['bemail'] ) );
211 + } elseif ( is_user_logged_in() ) {
212 + $bemail = $current_user->user_email;
213 + } else {
214 + $bemail = "";
215 + }
216 + if ( isset( $_REQUEST['bconfirmemail_copy'] ) ) {
217 + $bconfirmemail = $bemail;
218 + } elseif ( isset( $_REQUEST['bconfirmemail'] ) ) {
219 + $bconfirmemail = stripslashes( sanitize_email( $_REQUEST['bconfirmemail'] ) );
220 + } elseif ( is_user_logged_in() ) {
221 + $bconfirmemail = $current_user->user_email;
222 + } else {
223 + $bconfirmemail = "";
224 + }
225 +
226 + if ( isset( $_REQUEST['CardType'] ) && ! empty( $_REQUEST['AccountNumber'] ) ) {
227 + $CardType = sanitize_text_field( $_REQUEST['CardType'] );
228 + } else {
229 + $CardType = "";
230 + }
231 + if ( isset( $_REQUEST['AccountNumber'] ) ) {
232 + $AccountNumber = sanitize_text_field( $_REQUEST['AccountNumber'] );
233 + } else {
234 + $AccountNumber = "";
235 + }
236 +
237 + if ( isset( $_REQUEST['ExpirationMonth'] ) ) {
238 + $ExpirationMonth = sanitize_text_field( $_REQUEST['ExpirationMonth'] );
239 + } else {
240 + $ExpirationMonth = "";
241 + }
242 + if ( isset( $_REQUEST['ExpirationYear'] ) ) {
243 + $ExpirationYear = sanitize_text_field( $_REQUEST['ExpirationYear'] );
244 + } else {
245 + $ExpirationYear = "";
246 + }
247 + if ( isset( $_REQUEST['CVV'] ) ) {
248 + $CVV = sanitize_text_field( $_REQUEST['CVV'] );
249 + } else {
250 + $CVV = "";
251 + }
252 +
253 + if ( ! empty( $pmpro_level->discount_code ) ) {
254 + $discount_code = preg_replace( "/[^A-Za-z0-9\-]/", "", sanitize_text_field( $pmpro_level->discount_code ) );
255 + } else {
256 + $discount_code = "";
257 + }
258 + if ( isset( $_REQUEST['username'] ) ) {
259 + $username = sanitize_user( $_REQUEST['username'] , true);
260 + } else {
261 + $username = "";
262 + }
263 +
264 + // Note: We can't sanitize the passwords. They get hashed when saved.
265 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
266 + if ( isset( $_REQUEST['password'] ) ) {
267 + $password = $_REQUEST['password'];
268 + } else {
269 + $password = "";
270 + }
271 + if ( isset( $_REQUEST['password2_copy'] ) ) {
272 + $password2 = $password;
273 + } elseif ( isset( $_REQUEST['password2'] ) ) {
274 + $password2 = $_REQUEST['password2'];
275 + } else {
276 + $password2 = "";
277 + }
278 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
279 +
280 + $submit = pmpro_was_checkout_form_submitted();
281 +
282 + /**
283 + * Hook to run actions after the parameters are set on the checkout page.
284 + * @since 2.1
285 + */
286 + do_action( 'pmpro_checkout_after_parameters_set' );
287 +
288 + //require fields
289 + $pmpro_required_billing_fields = array(
290 + "bfirstname" => $bfirstname,
291 + "blastname" => $blastname,
292 + "baddress1" => $baddress1,
293 + "bcity" => $bcity,
294 + "bstate" => $bstate,
295 + "bzipcode" => $bzipcode,
296 + "bphone" => $bphone,
297 + "bemail" => $bemail,
298 + "bcountry" => $bcountry,
299 + "CardType" => $CardType,
300 + "AccountNumber" => $AccountNumber,
301 + "ExpirationMonth" => $ExpirationMonth,
302 + "ExpirationYear" => $ExpirationYear,
303 + "CVV" => $CVV
304 + );
305 + $pmpro_required_billing_fields = apply_filters( "pmpro_required_billing_fields", $pmpro_required_billing_fields );
306 + $pmpro_required_user_fields = array(
307 + "username" => $username,
308 + "password" => $password,
309 + "password2" => $password2,
310 + "bemail" => $bemail,
311 + "bconfirmemail" => $bconfirmemail
312 + );
313 + $pmpro_required_user_fields = apply_filters( "pmpro_required_user_fields", $pmpro_required_user_fields );
314 +
315 + //pmpro_confirmed is set to true later if payment goes through
316 + $pmpro_confirmed = false;
317 +
318 + // If there was a checkout submission, make sure that the form submission is valid.
319 + if ( $submit && $pmpro_msgt != "pmpro_error" ) {
320 + // Check the nonce.
321 + if ( empty( $_REQUEST['pmpro_checkout_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['pmpro_checkout_nonce'] ), 'pmpro_checkout_nonce' ) ) {
322 + // Nonce is not valid, but a nonce was only added in the 3.0 checkout template. We only want to show an error if the checkout template is 3.0 or later.
323 + $loaded_path = pmpro_get_template_path_to_load( 'checkout' );
324 + $loaded_version = pmpro_get_version_for_page_template_at_path( $loaded_path );
325 + if ( ! empty( $loaded_version ) && version_compare( $loaded_version, '3.0', '>=' ) ) {
326 + // Nonce is not valid. Show an error.
327 + pmpro_setMessage( __( "Nonce security check failed.", 'paid-memberships-pro' ), 'pmpro_error' );
328 + }
329 + }
330 +
331 + // Make sure javascript is ok.
332 + if ( apply_filters( "pmpro_require_javascript_for_checkout", true ) && ! empty( $_REQUEST['checkjavascript'] ) && empty( $_REQUEST['javascriptok'] ) ) {
333 + pmpro_setMessage( __( "There are JavaScript errors on the page. Please contact the webmaster.", 'paid-memberships-pro' ), "pmpro_error" );
334 + }
335 +
336 + // Make sure honeypot is ok.
337 + if ( ! empty( $fullname ) ) {
338 + pmpro_setMessage( __( "Are you a spammer?", 'paid-memberships-pro' ), "pmpro_error" );
339 + $pmpro_error_fields[] = "fullname";
340 + }
341 + }
342 +
343 + // If there is still a valid checkout submission, allow custom code to halt the checkout.
344 + if ( $submit && $pmpro_msgt != "pmpro_error" ) {
345 + /**
346 + * Filter whether the current checkout should continue.
347 + *
348 + * This filter will be checked every time that a checkout form is submitted regardless of if there is already a user or if $pmpro_review is set.
349 + * It should be used for checks that have to do with the form submisision itself, such as captchas.
350 + *
351 + * @param bool $pmpro_checkout_checks True if the checkout should continue.
352 + */
353 + $pmpro_checkout_checks = apply_filters( "pmpro_checkout_checks", true );
354 + if ( ! $pmpro_checkout_checks ) {
355 + // If this is false, there should have been an error message set by the filter but just in case, set a generic error message.
356 + pmpro_setMessage( __( 'Checkout checks failed.', 'paid-memberships-pro' ), 'pmpro_error' );
357 + }
358 + }
359 +
360 + // If there is still a valid checkout submission and we don't have an order yet, run the the code needed to get to that point in the checkout process.
361 + if ( $submit && $pmpro_msgt != 'pmpro_error' && empty( $pmpro_review ) ) {
362 + // Fill out account fields if we are skipping the account fields and we don't have a user yet.
363 + if ( empty( $current_user->ID ) && $skip_account_fields ) {
364 + // If the first name, last name, and email address are set, use them to generate the username and password.
365 + if ( ! empty( $bfirstname ) && ! empty( $blastname ) && ! empty( $bemail ) ) {
366 + // Generate the username using the first name, last name and/or email address.
367 + $username = pmpro_generateUsername( $bfirstname, $blastname, $bemail );
368 +
369 + // Generate the password.
370 + $password = wp_generate_password();
371 +
372 + // Set the password confirmation to the generated password.
373 + $password2 = $password;
374 + }
375 + }
376 +
377 + // If we don't have a user yet, check the user fields.
378 + if ( empty( $current_user->ID ) ) {
379 + foreach ( $pmpro_required_user_fields as $key => $field ) {
380 + if ( ! $field ) {
381 + $pmpro_error_fields[] = $key;
382 + }
383 + }
384 + if ( ! empty( $pmpro_error_fields ) ) {
385 + pmpro_setMessage( __( "Please complete all required fields.", 'paid-memberships-pro' ), "pmpro_error" );
386 + }
387 + if ( $password != $password2 ) {
388 + pmpro_setMessage( __( "Your passwords do not match. Please try again.", 'paid-memberships-pro' ), "pmpro_error" );
389 + $pmpro_error_fields[] = "password";
390 + $pmpro_error_fields[] = "password2";
391 + }
392 + if ( strcasecmp($bemail, $bconfirmemail) !== 0 ) {
393 + pmpro_setMessage( __( "Your email addresses do not match. Please try again.", 'paid-memberships-pro' ), "pmpro_error" );
394 + $pmpro_error_fields[] = "bemail";
395 + $pmpro_error_fields[] = "bconfirmemail";
396 + }
397 + if ( ! is_email( $bemail ) ) {
398 + pmpro_setMessage( __( "The email address entered is in an invalid format. Please try again.", 'paid-memberships-pro' ), "pmpro_error" );
399 + $pmpro_error_fields[] = "bemail";
400 + $pmpro_error_fields[] = "bconfirmemail";
401 + }
402 + $ouser = get_user_by( 'login', $username );
403 + if ( ! empty( $ouser->user_login ) ) {
404 + pmpro_setMessage( __( "That username is already taken. Please try another.", 'paid-memberships-pro' ), "pmpro_error" );
405 + $pmpro_error_fields[] = "username";
406 + }
407 + $oldem_user = get_user_by( 'email', $bemail );
408 + $oldem_user = apply_filters_deprecated( "pmpro_checkout_oldemail", array( ( false !== $oldem_user ? $oldem_user->user_email : null ) ), '3.2' );
409 + if ( ! empty( $oldem_user ) ) {
410 + pmpro_setMessage( __( "That email address is already in use. Please log in, or use a different email address.", 'paid-memberships-pro' ), "pmpro_error" );
411 + $pmpro_error_fields[] = "bemail";
412 + $pmpro_error_fields[] = "bconfirmemail";
413 + }
414 + }
415 +
416 + // Make sure to mark billing fields as missing if they aren't filled out.
417 + if ( $pmpro_requirebilling ) {
418 + //filter
419 + foreach ( $pmpro_required_billing_fields as $key => $field ) {
420 + if ( ! $field ) {
421 + $pmpro_error_fields[] = $key;
422 + }
423 + }
424 + }
425 +
426 + // If there is still a vaild checkout submission, give custom code the chance to halt all checkouts (to be deprecated).
427 + if ( $pmpro_msgt != "pmpro_error" ) {
428 + /**
429 + * Filter whether the current checkout should continue.
430 + * Note: This will be deprecated in a future version. Use pmpro_checkout_checks, pmpro_checkout_user_creation_checks, or pmpro_checkout_order_creation_checks instead.
431 + *
432 + * @since 3.4 Added $pmpro_level parameter.
433 + *
434 + * @param bool $pmpro_continue_registration True if the checkout should continue.
435 + * @param object $pmpro_level The level being purchased.
436 + */
437 + $pmpro_continue_registration = apply_filters( "pmpro_registration_checks", true, $pmpro_level );
438 + if ( ! $pmpro_continue_registration ) {
439 + // If this is false, there should have been an error message set by the filter but just in case, set a generic error message.
440 + pmpro_setMessage( __( 'Checkout checks failed.', 'paid-memberships-pro' ), 'pmpro_error' );
441 + }
442 + }
443 +
444 + // If there is still a valid checkout submission and we don't have a user yet, give custom code the chance to halt user creation.
445 + if ( $pmpro_msgt != "pmpro_error" && empty( $current_user->ID ) ) {
446 + /**
447 + * Filter whether this checkout should proceed to the user creation step.
448 + *
449 + * @since 3.4 Added $pmpro_level parameter.
450 + *
451 + * @param bool $pmpro_checkout_user_creation_checks True if the checkout should continue.
452 + * @param object $pmpro_level The level being purchased.
453 + */
454 + $pmpro_checkout_user_creation_checks = apply_filters( 'pmpro_checkout_user_creation_checks', true, $pmpro_level );
455 + if ( ! $pmpro_checkout_user_creation_checks ) {
456 + // If this is false, there should have been an error message set by the filter but just in case, set a generic error message.
457 + pmpro_setMessage( __( 'User creation checks failed.', 'paid-memberships-pro' ), 'pmpro_error' );
458 + }
459 + }
460 +
461 + // If there is still a vaild checkout submission but we don't have a user yet, create one.
462 + if ( $pmpro_msgt != "pmpro_error" && empty( $current_user->ID ) ) {
463 + //first name
464 + if ( ! empty( $_REQUEST['first_name'] ) ) {
465 + $first_name = sanitize_text_field( $_REQUEST['first_name'] );
466 + } else {
467 + $first_name = $bfirstname;
468 + }
469 + //last name
470 + if ( ! empty( $_REQUEST['last_name'] ) ) {
471 + $last_name = sanitize_text_field( $_REQUEST['last_name'] );
472 + } else {
473 + $last_name = $blastname;
474 + }
475 +
476 + //insert user
477 + $new_user_array = apply_filters( 'pmpro_checkout_new_user_array', array(
478 + "user_login" => $username,
479 + "user_pass" => $password,
480 + "user_email" => $bemail,
481 + "first_name" => $first_name,
482 + "last_name" => $last_name
483 + )
484 + );
485 +
486 + $user_id = apply_filters_deprecated( 'pmpro_new_user', array( '', $new_user_array ), '3.2' );
487 + if ( empty( $user_id ) ) {
488 + $user_id = wp_insert_user( $new_user_array );
489 + }
490 +
491 + if ( empty( $user_id ) || is_wp_error( $user_id ) ) {
492 + $e_msg = '';
493 +
494 + if ( is_wp_error( $user_id ) ) {
495 + $e_msg = $user_id->get_error_message();
496 + }
497 +
498 + $pmpro_msg = __( "There was an error setting up your account. Please contact us.", 'paid-memberships-pro' ) . sprintf( " %s", $e_msg ); // Dirty 'don't break translation hack.
499 + $pmpro_msgt = "pmpro_error";
500 + } elseif ( apply_filters( 'pmpro_setup_new_user', true, $user_id, $new_user_array, $pmpro_level ) ) {
501 +
502 + pmpro_maybe_send_wp_new_user_notification( $user_id, $pmpro_level->id );
503 +
504 + $wpuser = get_userdata( $user_id );
505 + $wpuser->set_role( get_option( 'default_role', 'subscriber' ) );
506 +
507 + /**
508 + * Allow hooking before the user authentication process when setting up new user.
509 + *
510 + * @since 2.5.10
511 + *
512 + * @param int $user_id The user ID that is being setting up.
513 + */
514 + do_action( 'pmpro_checkout_before_user_auth', $user_id );
515 +
516 +
517 + //okay, log them in to WP
518 + $creds = array();
519 + $creds['user_login'] = $new_user_array['user_login'];
520 + $creds['user_password'] = $new_user_array['user_pass'];
521 + $creds['remember'] = true;
522 + $user = wp_signon( $creds, false );
523 + //setting some cookies
524 + wp_set_current_user( $user_id, $username );
525 + wp_set_auth_cookie( $user_id, true, apply_filters( 'pmpro_checkout_signon_secure', force_ssl_admin() ) );
526 + global $current_user;
527 + if ( ! $current_user->ID && $user->ID ) {
528 + $current_user = $user;
529 + } //in case the user just signed up
530 + pmpro_set_current_user();
531 +
532 + // Update nonce value to be for this new user when we load the checkout page.
533 + add_filter( 'pmpro_update_nonce_at_checkout', '__return_true' );
534 +
535 + // Skip the account fields since we just created an account.
536 + $skip_account_fields = true;
537 + }
538 + }
539 +
540 + // If there is still a valid checkout submission, check the billing fields.
541 + if ( $pmpro_msgt != "pmpro_error" ) {
542 + // We can check the billing fields at this point by checking if $pmpro_error_fields is not empty.
543 + if ( ! empty( $pmpro_error_fields ) ) {
544 + pmpro_setMessage( __( "Please complete all required fields.", 'paid-memberships-pro' ), "pmpro_error" );
545 + }
546 + if ( ! empty( $bemail ) && ! is_email( $bemail ) ) {
547 + pmpro_setMessage( __( "The email address entered is in an invalid format. Please try again.", 'paid-memberships-pro' ), "pmpro_error" );
548 + $pmpro_error_fields[] = "bemail";
549 + $pmpro_error_fields[] = "bconfirmemail";
550 + }
551 + if ( ! in_array( $gateway, $valid_gateways ) ) {
552 + pmpro_setMessage( __( "Invalid gateway.", 'paid-memberships-pro' ), "pmpro_error" );
553 + }
554 + if ( ! empty( $fullname ) ) {
555 + pmpro_setMessage( __( "Are you a spammer?", 'paid-memberships-pro' ), "pmpro_error" );
556 + }
557 + }
558 +
559 + // If there is still a valid checkout submission, give custom code the chance to halt checkout.
560 + if ( $pmpro_msgt != "pmpro_error" ) {
561 + /**
562 + * Filter whether this checkout should proceed to the order creation step.
563 + *
564 + * @since 3.4 Added $pmpro_level parameter.
565 + *
566 + * @param bool $pmpro_checkout_checks True if the checkout should continue.
567 + * @param object $pmpro_level The level being purchased.
568 + */
569 + $pmpro_checkout_order_creation_checks = apply_filters( "pmpro_checkout_order_creation_checks", true, $pmpro_level );
570 + if ( ! $pmpro_checkout_order_creation_checks ) {
571 + // If this is false, there should have been an error message set by the filter but just in case, set a generic error message.
572 + pmpro_setMessage( __( 'Order creation checks failed.', 'paid-memberships-pro' ), 'pmpro_error' );
573 + }
574 + }
575 +
576 + // If there is still a valid checkout submission, create the order.
577 + if ( $pmpro_msgt != "pmpro_error" ) {
578 + $pmpro_review = new MemberOrder();
579 + $pmpro_review->user_id = $current_user->ID;
580 + $pmpro_review->membership_id = $pmpro_level->id;
581 + $pmpro_review->cardtype = $CardType;
582 + $pmpro_review->accountnumber = $AccountNumber;
583 + $pmpro_review->expirationmonth = $ExpirationMonth;
584 + $pmpro_review->expirationyear = $ExpirationYear;
585 + $pmpro_review->gateway = $pmpro_requirebilling ? $gateway : 'free';
586 + $pmpro_review->billing = new stdClass();
587 + $pmpro_review->billing->name = $bfirstname . " " . $blastname;
588 + $pmpro_review->billing->street = trim( $baddress1 );
589 + $pmpro_review->billing->street2 = trim( $baddress2 );
590 + $pmpro_review->billing->city = $bcity;
591 + $pmpro_review->billing->state = $bstate;
592 + $pmpro_review->billing->country = $bcountry;
593 + $pmpro_review->billing->zip = $bzipcode;
594 + $pmpro_review->billing->phone = $bphone;
595 +
596 + // Calculate the order subtotal, tax, and total.
597 + $pmpro_review->subtotal = pmpro_round_price( $pmpro_level->initial_payment );
598 + $pmpro_review->tax = pmpro_round_price( $pmpro_review->getTax( true ) );
599 + $pmpro_review->total = pmpro_round_price( $pmpro_review->subtotal + $pmpro_review->tax );
600 +
601 + // Finish setting up the order.
602 + $pmpro_review->setGateway();
603 + $pmpro_review->getMembershipLevelAtCheckout();
604 +
605 + // Filter for order, since v1.8
606 + if ( $pmpro_requirebilling ) {
607 + $pmpro_review = apply_filters( 'pmpro_checkout_order', $pmpro_review );
608 + } else {
609 + $pmpro_review = apply_filters( 'pmpro_checkout_order_free', $pmpro_review );
610 + }
611 + }
612 + } // End if ( $submit && $pmpro_msgt != 'pmpro_error' && empty( $pmpro_review ) )
613 +
614 + // If there is still a valid checkout submission, process the order.
615 + if ( $submit && $pmpro_msgt != "pmpro_error" && ! empty( $pmpro_review ) ) {
616 + do_action( 'pmpro_checkout_before_processing' );
617 +
618 + // Process the payment.
619 + $pmpro_processed = $pmpro_review->process();
620 + if ( ! empty( $pmpro_processed ) ) {
621 + $pmpro_msg = __( "Payment accepted.", 'paid-memberships-pro' );
622 + $pmpro_msgt = "pmpro_success";
623 + $pmpro_confirmed = true;
624 + } else {
625 + /**
626 + * Allow running code when processing fails.
627 + *
628 + * @since 2.7
629 + * @param MemberOrder $pmpro_review The order object used at checkout.
630 + */
631 + do_action( 'pmpro_checkout_processing_failed', $pmpro_review );
632 +
633 + // Make sure we have an error message.
634 + if( ! empty( $pmpro_review->error ) ) {
635 + $pmpro_msg = $pmpro_review->error;
636 + }
637 +
638 + if ( empty( $pmpro_msg ) ) {
639 + $pmpro_msg = __( "Unknown error generating account. Please contact us to set up your membership.", 'paid-memberships-pro' );
640 + }
641 + if ( ! empty( $pmpro_review->error_type ) ) {
642 + $pmpro_msgt = $pmpro_review->error_type;
643 + } else {
644 + $pmpro_msgt = "pmpro_error";
645 + }
646 + }
647 + }
648 +
649 + // Hook to check payment confirmation or replace it. If we get an array back, pull the values (pmpro_review) out
650 + // All of this is deprecated and will be removed in a future version.
651 + if ( empty( $pmpro_review ) ) {
652 + // make sure we have at least an empty order here to avoid a warning
653 + $pmpro_review = false;
654 + }
655 + $pmpro_confirmed_data = apply_filters_deprecated( 'pmpro_checkout_confirmed', array( $pmpro_confirmed, $pmpro_review ), '3.2' );
656 + if ( is_array( $pmpro_confirmed_data ) ) {
657 + extract( $pmpro_confirmed_data );
658 +
659 + // Our old PPE integration had $morder dynamically set here. We changed that variable name to $pmpro_review. In case other integrations are using this filter, set $pmpro_review to $morder.
660 + if ( ! empty( $morder ) ) {
661 + $pmpro_review = $morder;
662 + }
663 + } else {
664 + $pmpro_confirmed = $pmpro_confirmed_data;
665 + }
666 +
667 + // If the payment was successful, complete the checkout.
668 + if ( ! empty( $pmpro_confirmed ) ) {
669 + if ( pmpro_complete_checkout( $pmpro_review ) ) {
670 + //redirect to confirmation
671 + $rurl = pmpro_url( "confirmation", "?pmpro_level=" . $pmpro_level->id );
672 + $rurl = apply_filters( "pmpro_confirmation_url", $rurl, $current_user->ID, $pmpro_level );
673 + wp_redirect( $rurl );
674 + exit;
675 + } else {
676 +
677 + // Something went wrong with the checkout.
678 + // If we get here, then the call to pmpro_changeMembershipLevel() returned false within pmpro_complete_checkout(). Let's try to cancel the payment.
679 + $test = (array) $pmpro_review;
680 + if ( ! empty( $test ) && $pmpro_review->cancel() ) {
681 + $pmpro_msg = __( "IMPORTANT: Something went wrong while processing your checkout. Your credit card authorized, but we cancelled the order immediately. You should not try to submit this form again. Please contact the site owner to fix this issue.", 'paid-memberships-pro' );
682 + $pmpro_review = null;
683 + } else {
684 + $pmpro_msg = __( "IMPORTANT: Something went wrong while processing your checkout. Your credit card was charged, but we couldn't assign your membership. You should not submit this form again. Please contact the site owner to fix this issue.", 'paid-memberships-pro' );
685 + }
686 + }
687 + } else {
688 + //show message if the payment gateway is not setup yet
689 + if ( $pmpro_requirebilling && ! get_option( "pmpro_gateway" ) ) {
690 +
691 + if ( pmpro_isAdmin() ) {
692 + $pmpro_msg = sprintf( __( 'You must <a href="%s">set up a Payment Gateway</a> before any payments will be processed.', 'paid-memberships-pro' ), admin_url( 'admin.php?page=pmpro-paymentsettings' ) );
693 + } else {
694 + $pmpro_msg = __( "A Payment Gateway must be set up before any payments will be processed.", 'paid-memberships-pro' );
695 + }
696 + $pmpro_msgt = "";
697 + }
698 +
699 + // Default billing address fields from the values stored in user meta.
700 + // Note that this will be removed in a future update as billing addresses are no longer stored in user meta by default.
701 + if ( ! empty( $current_user->ID ) && empty( $submit ) ) {
702 + $bfirstname = get_user_meta( $current_user->ID, "pmpro_bfirstname", true );
703 + $blastname = get_user_meta( $current_user->ID, "pmpro_blastname", true );
704 + $baddress1 = get_user_meta( $current_user->ID, "pmpro_baddress1", true );
705 + $baddress2 = get_user_meta( $current_user->ID, "pmpro_baddress2", true );
706 + $bcity = get_user_meta( $current_user->ID, "pmpro_bcity", true );
707 + $bstate = get_user_meta( $current_user->ID, "pmpro_bstate", true );
708 + $bzipcode = get_user_meta( $current_user->ID, "pmpro_bzipcode", true );
709 + $bcountry = get_user_meta( $current_user->ID, "pmpro_bcountry", true );
710 + $bphone = get_user_meta( $current_user->ID, "pmpro_bphone", true );
711 + $bemail = get_user_meta( $current_user->ID, "pmpro_bemail", true );
712 + $bconfirmemail = $bemail; //as of 1.7.5, just setting to bemail
713 + }
714 + }
715 +
716 + // Preventing conflicts with old checkout templates that depend on the $pmpro_level global being set.
717 + pmpro_getAllLevels();
718 +
719 + /**
720 + * Hook to run actions after the checkout preheader is loaded.
721 + * @since 2.1
722 + */
723 + do_action( 'pmpro_after_checkout_preheader', $pmpro_review );
724 +