mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Validate checkout form before creating PayPal order when creating account on checkout
This commit is contained in:
parent
f1555d4db4
commit
076a124ec7
2 changed files with 34 additions and 1 deletions
|
@ -21,6 +21,8 @@ class CheckoutActionHandler {
|
|||
const formSelector = this.config.context === 'checkout' ? 'form.checkout' : 'form#order_review';
|
||||
const formValues = jQuery(formSelector).serialize();
|
||||
|
||||
const createaccount = jQuery('#createaccount').is(":checked") ? true : false;
|
||||
|
||||
return fetch(this.config.ajax.create_order.endpoint, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -29,7 +31,8 @@ class CheckoutActionHandler {
|
|||
bn_code:bnCode,
|
||||
context:this.config.context,
|
||||
order_id:this.config.order_id,
|
||||
form:formValues
|
||||
form:formValues,
|
||||
createaccount: createaccount
|
||||
})
|
||||
}).then(function (res) {
|
||||
return res.json();
|
||||
|
|
|
@ -174,6 +174,36 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
$this->set_bn_code( $data );
|
||||
|
||||
if ( 'checkout' === $data['context'] ) {
|
||||
if ( '1' === $data['createaccount'] ) {
|
||||
$form_values = explode( '&', $data['form'] );
|
||||
$parsed_values = array();
|
||||
foreach ( $form_values as $field ) {
|
||||
$field = explode( '=', $field );
|
||||
|
||||
if ( count( $field ) !== 2 ) {
|
||||
continue;
|
||||
}
|
||||
$parsed_values[ $field[0] ] = $field[1];
|
||||
}
|
||||
$_POST = $parsed_values;
|
||||
$_REQUEST = $parsed_values;
|
||||
|
||||
add_action(
|
||||
'woocommerce_after_checkout_validation',
|
||||
function( array $data, \WP_Error $errors ) use ( $wc_order ) {
|
||||
if ( ! $errors->errors ) {
|
||||
$order = $this->create_paypal_order( $wc_order );
|
||||
wp_send_json_success( $order->to_array() );
|
||||
return true;
|
||||
}
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
$checkout = \WC()->checkout();
|
||||
$checkout->process_checkout();
|
||||
}
|
||||
$this->process_checkout_form( $data['form'] );
|
||||
}
|
||||
if ( 'pay-now' === $data['context'] && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue