WC_REST_Webhook_Deliveries_Controller

REST API Webhook Deliveries controller class.

Defined (1)

The class is defined in the following location(s).

/includes/api/class-wc-rest-webhook-deliveries.php  
  1. class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Webhook_Deliveries_V1_Controller { 
  2.  
  3. /** 
  4. * Endpoint namespace. 
  5. * @var string 
  6. */ 
  7. protected $namespace = 'wc/v2'; 
  8.  
  9. /** 
  10. * Prepare a single webhook delivery output for response. 
  11. * @param stdClass $log Delivery log object. 
  12. * @param WP_REST_Request $request Request object. 
  13. * @return WP_REST_Response $response Response data. 
  14. */ 
  15. public function prepare_item_for_response( $log, $request ) { 
  16. $data = (array) $log; 
  17.  
  18. // Add timestamp. 
  19. $data['date_created'] = wc_rest_prepare_date_response( $log->comment->comment_date ); 
  20. $data['date_created_gmt'] = wc_rest_prepare_date_response( $log->comment->comment_date_gmt ); 
  21.  
  22. // Remove comment object. 
  23. unset( $data['comment'] ); 
  24.  
  25. $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 
  26. $data = $this->add_additional_fields_to_object( $data, $request ); 
  27. $data = $this->filter_response_by_context( $data, $context ); 
  28.  
  29. // Wrap the data in a response object. 
  30. $response = rest_ensure_response( $data ); 
  31.  
  32. $response->add_links( $this->prepare_links( $log ) ); 
  33.  
  34. /** 
  35. * Filter webhook delivery object returned from the REST API. 
  36. * @param WP_REST_Response $response The response object. 
  37. * @param stdClass $log Delivery log object used to create response. 
  38. * @param WP_REST_Request $request Request object. 
  39. */ 
  40. return apply_filters( 'woocommerce_rest_prepare_webhook_delivery', $response, $log, $request ); 
  41.  
  42. /** 
  43. * Get the Webhook's schema, conforming to JSON Schema. 
  44. * @return array 
  45. */ 
  46. public function get_item_schema() { 
  47. $schema = array( 
  48. '$schema' => 'http://json-schema.org/draft-04/schema#',  
  49. 'title' => 'webhook_delivery',  
  50. 'type' => 'object',  
  51. 'properties' => array( 
  52. 'id' => array( 
  53. 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),  
  54. 'type' => 'integer',  
  55. 'context' => array( 'view' ),  
  56. 'readonly' => true,  
  57. ),  
  58. 'duration' => array( 
  59. 'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ),  
  60. 'type' => 'string',  
  61. 'context' => array( 'view' ),  
  62. 'readonly' => true,  
  63. ),  
  64. 'summary' => array( 
  65. 'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ),  
  66. 'type' => 'string',  
  67. 'context' => array( 'view' ),  
  68. 'readonly' => true,  
  69. ),  
  70. 'request_url' => array( 
  71. 'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ),  
  72. 'type' => 'string',  
  73. 'format' => 'uri',  
  74. 'context' => array( 'view' ),  
  75. 'readonly' => true,  
  76. ),  
  77. 'request_headers' => array( 
  78. 'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ),  
  79. 'type' => 'string',  
  80. 'format' => 'uri',  
  81. 'context' => array( 'view' ),  
  82. 'readonly' => true,  
  83. ),  
  84. 'request_headers' => array( 
  85. 'description' => __( 'Request headers.', 'woocommerce' ),  
  86. 'type' => 'array',  
  87. 'context' => array( 'view' ),  
  88. 'readonly' => true,  
  89. 'items' => array( 
  90. 'type' => 'string',  
  91. ),  
  92. ),  
  93. 'request_body' => array( 
  94. 'description' => __( 'Request body.', 'woocommerce' ),  
  95. 'type' => 'string',  
  96. 'context' => array( 'view' ),  
  97. 'readonly' => true,  
  98. ),  
  99. 'response_code' => array( 
  100. 'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ),  
  101. 'type' => 'string',  
  102. 'context' => array( 'view' ),  
  103. 'readonly' => true,  
  104. ),  
  105. 'response_message' => array( 
  106. 'description' => __( 'The HTTP response message from the receiving server.', 'woocommerce' ),  
  107. 'type' => 'string',  
  108. 'context' => array( 'view' ),  
  109. 'readonly' => true,  
  110. ),  
  111. 'response_headers' => array( 
  112. 'description' => __( 'Array of the response headers from the receiving server.', 'woocommerce' ),  
  113. 'type' => 'array',  
  114. 'context' => array( 'view' ),  
  115. 'readonly' => true,  
  116. 'items' => array( 
  117. 'type' => 'string',  
  118. ),  
  119. ),  
  120. 'response_body' => array( 
  121. 'description' => __( 'The response body from the receiving server.', 'woocommerce' ),  
  122. 'type' => 'string',  
  123. 'context' => array( 'view' ),  
  124. 'readonly' => true,  
  125. ),  
  126. 'date_created' => array( 
  127. 'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ),  
  128. 'type' => 'date-time',  
  129. 'context' => array( 'view', 'edit' ),  
  130. 'readonly' => true,  
  131. ),  
  132. 'date_created_gmt' => array( 
  133. 'description' => __( 'The date the webhook delivery was logged, as GMT.', 'woocommerce' ),  
  134. 'type' => 'date-time',  
  135. 'context' => array( 'view', 'edit' ),  
  136. 'readonly' => true,  
  137. ),  
  138. ),  
  139. ); 
  140.  
  141. return $this->add_additional_fields_schema( $schema );