Do not send whole order in create order response

This commit is contained in:
Alex P 2023-05-31 16:18:34 +03:00
parent df81e5e411
commit bee2a8d5ba
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 17 additions and 4 deletions

View file

@ -109,7 +109,7 @@ class CheckoutActionHandler {
const input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'ppcp-resume-order');
input.setAttribute('value', data.data.purchase_units[0].custom_id);
input.setAttribute('value', data.data.custom_id);
document.querySelector(formSelector).appendChild(input);
return data.data.id;
});

View file

@ -292,7 +292,7 @@ class CreateOrderEndpoint implements EndpointInterface {
! $this->early_order_handler->should_create_early_order()
|| $this->registration_needed
|| isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) {
wp_send_json_success( $order->to_array() );
wp_send_json_success( $this->make_response( $order ) );
}
$this->early_order_handler->register_for_order( $order );
@ -304,7 +304,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$wc_order->save_meta_data();
}
wp_send_json_success( $order->to_array() );
wp_send_json_success( $this->make_response( $order ) );
return true;
} catch ( ValidationException $error ) {
@ -362,7 +362,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* during the "onApprove"-JS callback or the webhook listener.
*/
if ( ! $this->early_order_handler->should_create_early_order() ) {
wp_send_json_success( $order->to_array() );
wp_send_json_success( $this->make_response( $order ) );
}
$this->early_order_handler->register_for_order( $order );
return $data;
@ -569,4 +569,17 @@ class CreateOrderEndpoint implements EndpointInterface {
);
}
}
/**
* Returns the response data for success response.
*
* @param Order $order The PayPal order.
* @return array
*/
private function make_response( Order $order ): array {
return array(
'id' => $order->id(),
'custom_id' => $order->purchase_units()[0]->custom_id(),
);
}
}