mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Do not validate WC checkout form when creating PayPal order
This commit is contained in:
parent
0460342b41
commit
9b6b0e2769
1 changed files with 18 additions and 64 deletions
|
@ -187,10 +187,26 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
|
||||
if ( 'checkout' === $data['context'] ) {
|
||||
if ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) {
|
||||
$this->process_checkout_form_when_creating_account( $data['form'], $wc_order );
|
||||
try {
|
||||
$order = $this->create_paypal_order( $wc_order );
|
||||
} catch ( Exception $exception ) {
|
||||
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
||||
throw $exception;
|
||||
}
|
||||
wp_send_json_success( $order->to_array() );
|
||||
}
|
||||
|
||||
$this->process_checkout_form( $data['form'] );
|
||||
try {
|
||||
$order = $this->create_paypal_order();
|
||||
} catch ( Exception $exception ) {
|
||||
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if ( ! $this->early_order_handler->should_create_early_order() ) {
|
||||
wp_send_json_success( $order->to_array() );
|
||||
}
|
||||
$this->early_order_handler->register_for_order( $order );
|
||||
}
|
||||
if ( 'pay-now' === $data['context'] && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) {
|
||||
$this->validate_paynow_form( $data['form'] );
|
||||
|
@ -320,7 +336,6 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
return $payer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the BN Code for the following request.
|
||||
*
|
||||
|
@ -354,32 +369,6 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
return $payment_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the Request parameter and process the checkout form and validate it.
|
||||
*
|
||||
* @param string $form_values The values of the form.
|
||||
*
|
||||
* @throws Exception On Error.
|
||||
*/
|
||||
private function process_checkout_form( string $form_values ) {
|
||||
parse_str( $form_values, $parsed_values );
|
||||
|
||||
$_POST = $parsed_values;
|
||||
$_REQUEST = $parsed_values;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_after_checkout_validation',
|
||||
array(
|
||||
$this,
|
||||
'after_checkout_validation',
|
||||
),
|
||||
10,
|
||||
2
|
||||
);
|
||||
$checkout = \WC()->checkout();
|
||||
$checkout->process_checkout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the terms input field is checked.
|
||||
*
|
||||
|
@ -394,39 +383,4 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes checkout and creates the PayPal order after success form validation.
|
||||
*
|
||||
* @param string $form_values The values of the form.
|
||||
* @param \WC_Order|null $wc_order WC order to get data from.
|
||||
* @throws Exception On Error.
|
||||
*/
|
||||
private function process_checkout_form_when_creating_account( string $form_values, \WC_Order $wc_order = null ) {
|
||||
parse_str( $form_values, $parsed_values );
|
||||
|
||||
$_POST = $parsed_values;
|
||||
$_REQUEST = $parsed_values;
|
||||
|
||||
add_action(
|
||||
'woocommerce_after_checkout_validation',
|
||||
function ( array $data, \WP_Error $errors ) use ( $wc_order ) {
|
||||
if ( ! $errors->errors ) {
|
||||
try {
|
||||
$order = $this->create_paypal_order( $wc_order );
|
||||
} catch ( Exception $exception ) {
|
||||
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
||||
throw $exception;
|
||||
}
|
||||
wp_send_json_success( $order->to_array() );
|
||||
return true;
|
||||
}
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
$checkout = \WC()->checkout();
|
||||
$checkout->process_checkout();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue