diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php index 3fe07414f..42531cf37 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php @@ -145,5 +145,6 @@ function ec_clear_session_data() { unset(WC()->session->post_data); unset(WC()->session->shiptoname); unset(WC()->session->payeremail); + unset(WC()->session->validate_data); } } diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php index 07f54a7dd..806dce960 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php @@ -574,6 +574,7 @@ public function ec_clear_session_data() { unset(WC()->session->post_data); unset(WC()->session->shiptoname); unset(WC()->session->payeremail); + unset(WC()->session->validate_data); } public function ec_is_checkout() { diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index d1a1ef24c..96731d52f 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -2304,35 +2304,45 @@ public function handle_wc_api() { } else { if ( $order_id > 0 && ( $order = wc_get_order( $order_id ) ) && $order->has_status( array( 'pending', 'failed' ) ) ) { $_POST = WC()->session->get( 'post_data' ); + $_POST['post_data'] = WC()->session->get( 'post_data' ); $this->posted = WC()->session->get( 'post_data' ); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) - foreach ($_POST['shipping_method'] as $i => $value) + foreach ($_POST['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); - WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); - if (WC()->cart->needs_shipping()) { - // Validate Shipping Methods - WC()->shipping->get_shipping_methods(); - $packages = WC()->shipping->get_packages(); - WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods'); - } - if (empty($this->posted)) { - $this->posted = array(); - $paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' ); - if( !empty($paypal_express_checkout['shipping_details']['email'])) { - $this->posted['billing_email'] = $paypal_express_checkout['shipping_details']['email']; } - if( !empty($paypal_express_checkout['shipping_details']['first_name'])) { - $this->posted['billing_first_name'] = $paypal_express_checkout['shipping_details']['first_name']; - } - if( !empty($paypal_express_checkout['shipping_details']['last_name'])) { - $this->posted['billing_last_name'] = $paypal_express_checkout['shipping_details']['last_name']; + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); + if (WC()->cart->needs_shipping()) { + // Validate Shipping Methods + WC()->shipping->get_shipping_methods(); + $packages = WC()->shipping->get_packages(); + WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods'); } - $this->posted['payment_method'] = $this->id; + if (empty($this->posted)) { + $this->posted = array(); + $paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' ); + if( !empty($paypal_express_checkout['shipping_details']['email'])) { + $this->posted['billing_email'] = $paypal_express_checkout['shipping_details']['email']; + } + if( !empty($paypal_express_checkout['shipping_details']['first_name'])) { + $this->posted['billing_first_name'] = $paypal_express_checkout['shipping_details']['first_name']; + } + if( !empty($paypal_express_checkout['shipping_details']['last_name'])) { + $this->posted['billing_last_name'] = $paypal_express_checkout['shipping_details']['last_name']; + } + $this->posted['payment_method'] = $this->id; - } + } + $this->angelleye_check_cart_items(); - $order_id = WC()->checkout()->create_order($this->posted); + + $validate_data = WC()->session->get( 'validate_data' ); + WC()->cart->calculate_totals(); + if( !empty($validate_data) ) { + $order_id = WC()->checkout()->create_order($validate_data); + } else { + $order_id = WC()->checkout()->create_order($this->posted); + } if (is_wp_error($order_id)) { throw new Exception($order_id->get_error_message()); @@ -2347,10 +2357,12 @@ public function handle_wc_api() { do_action('woocommerce_checkout_order_processed', $order_id, $this->posted, $order); } else { $_POST = WC()->session->get( 'post_data' ); + $_POST['post_data'] = WC()->session->get( 'post_data' ); $this->posted = WC()->session->get( 'post_data' ); } if ( $order_id == 0 ) { $_POST = WC()->session->get( 'post_data' ); + $_POST['post_data'] = WC()->session->get( 'post_data' ); $this->posted = WC()->session->get( 'post_data' ); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) @@ -2384,7 +2396,17 @@ public function handle_wc_api() { $this->posted['payment_method'] = $this->id; } $this->angelleye_check_cart_items(); - $order_id = WC()->checkout()->create_order($this->posted); + + $validate_data = WC()->session->get( 'validate_data' ); + + WC()->cart->calculate_totals(); + + if( !empty($validate_data) ) { + $order_id = WC()->checkout()->create_order($validate_data); + } else { + $order_id = WC()->checkout()->create_order($this->posted); + } + if (is_wp_error($order_id)) { throw new Exception($order_id->get_error_message()); } @@ -2853,6 +2875,7 @@ public function angelleye_paypal_express_checkout_redirect_to_paypal($data, $err if (empty($_POST['woocommerce_checkout_update_totals']) && 0 === $notice_count) { try { WC()->session->set('post_data', wp_slash($_POST)); + WC()->session->set('validate_data', $data); if ( isset( $_POST['from_checkout'] ) && 'yes' === $_POST['from_checkout'] ) { if ((isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] == 'true') || ( isset($_GET['ec_save_to_account']) && $_GET['ec_save_to_account'] == true)) { WC()->session->set( 'ec_save_to_account', 'on' );