return $instance->wps_wsp_subscription_permission_check($request);
}
+function listOrderStatus($request) {
+ $args = array(
+ 'limit' => -1,
+ 'customer_id' => $request['id']
+ );
+ $orders = wc_get_orders( $args );
+
+ if ( empty( $orders ) ) {
+ return new WP_Error( 'no_order', 'Aucune commande trouvée pour cet utilisateur', array( 'status' => 404 ) );
+ }
+
+ $array = ['code' => 200,'status' => 'success'];
+ $array['data'] = array_map(function($n) {
+ return [
+ 'order_id' => $n->get_id(),
+ 'customer_id' => $n->get_customer_id(),
+ 'total' => $n->get_total().$n->get_currency(),
+ 'status' => $n->get_status(),
+ ];
+ }, $orders);
+ return new WP_REST_Response($array, 200);
+}
+
add_action( 'rest_api_init', function () {
register_rest_route( 'wsp-route/v1', '/cancel/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'cancelSubscription',
+ 'args' => array(
+ 'id' => array(
+ 'validate_callback' => 'is_numeric'
+ ),
+ ),
) );
} );
'methods' => 'GET',
'callback' => 'listSubscriptionByUserId',
'permission_callback' => 'wps_wsp_subscription_permission_check',
+ 'args' => array(
+ 'id' => array(
+ 'validate_callback' => 'is_numeric'
+ ),
+ ),
+ ) );
+} );
+
+add_action( 'rest_api_init', function () {
+ register_rest_route( 'wsp-route/v1', '/orders-status/(?P<id>\d+)', array(
+ 'methods' => 'GET',
+ 'callback' => 'listOrderStatus',
+ 'args' => array(
+ 'id' => array(
+ 'validate_callback' => 'is_numeric'
+ ),
+ ),
) );
} );