diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-customer.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-customer.php index 87533b3..487e8b8 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-customer.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-customer.php @@ -22,8 +22,8 @@ class Wiaas_REST_Customer_API { 'permission_callback' => 'is_user_logged_in' ) ); - register_rest_route( self::$namespace, 'customer/(?P\d+)/profile-addresses', array( - 'methods' => 'POST', + register_rest_route( self::$namespace, 'customer/(?P\d+)/profile-addresses/(?P\d+)', array( + 'methods' => 'DELETE', 'callback' => array(__CLASS__, 'delete_customer_profile_address'), 'permission_callback' => 'is_user_logged_in' ) ); @@ -34,8 +34,8 @@ class Wiaas_REST_Customer_API { 'permission_callback' => 'is_user_logged_in' ) ); - register_rest_route( self::$namespace, 'customer/(?P\d+)/billing-addresses', array( - 'methods' => 'POST', + register_rest_route( self::$namespace, 'customer/(?P\d+)/billing-addresses/(?P\d+)', array( + 'methods' => 'DELETE', 'callback' => array(__CLASS__, 'delete_customer_billing_addresses'), 'permission_callback' => 'is_user_logged_in' ) ); @@ -70,8 +70,7 @@ class Wiaas_REST_Customer_API { public static function delete_customer_profile_address(WP_REST_Request $request){ $customer_id = $request['id']; - $params = $request->get_body_params(); - $address_id = $params['address_id']; + $address_id = $request['address_id']; if (!Wiaas_Customer::delete_customer_profile_address($customer_id, $address_id)){ return self::generate_wiaas_response('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id)); @@ -95,8 +94,7 @@ class Wiaas_REST_Customer_API { public static function delete_customer_billing_addresses(WP_REST_Request $request){ $customer_id = $request['id']; - $params = $request->get_body_params(); - $address_id = json_decode($params['address_id']); + $address_id = $request['address_id']; if (!Wiaas_Customer::delete_customer_billing_address($customer_id, $address_id)){ return self::generate_wiaas_response('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id)); diff --git a/frontend/src/actions/profileSettings/addressActions.js b/frontend/src/actions/profileSettings/addressActions.js index 83cd000..3db8807 100644 --- a/frontend/src/actions/profileSettings/addressActions.js +++ b/frontend/src/actions/profileSettings/addressActions.js @@ -52,11 +52,8 @@ export const removeProfileAddress = (idUser, idProfileAddress) => { return dispatch => { dispatch(requestRemoveAddress()); return client.fetch({ - url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`, - method: 'post', - data: { - 'address_id':idProfileAddress - } + url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses/${idProfileAddress}`, + method: 'delete' }) .then(response => { if(response.data){ @@ -105,11 +102,8 @@ export const removeBillingAddress = (idUser, idBillingAddress) => { return dispatch => { dispatch(requestRemoveBillingAddress()); return client.fetch({ - url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`, - method: 'POST', - data: { - 'address_id':idBillingAddress - } + url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses/${idBillingAddress}`, + method: 'delete' }) .then(response => { if(response.data){