本文整理汇总了PHP中WC_Webhook::get_delivery_log方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Webhook::get_delivery_log方法的具体用法?PHP WC_Webhook::get_delivery_log怎么用?PHP WC_Webhook::get_delivery_log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Webhook
的用法示例。
在下文中一共展示了WC_Webhook::get_delivery_log方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_webhook_delivery
/**
* Get the delivery log for the given webhook ID and delivery ID
*
* @since 2.2
* @param string $webhook_id webhook ID
* @param string $id delivery log ID
* @param string|null $fields fields to limit response to
* @return array
*/
public function get_webhook_delivery($webhook_id, $id, $fields = null)
{
try {
// Validate webhook ID
$webhook_id = $this->validate_request($webhook_id, 'shop_webhook', 'read');
if (is_wp_error($webhook_id)) {
return $webhook_id;
}
$id = absint($id);
if (empty($id)) {
throw new WC_API_Exception('woocommerce_api_invalid_webhook_delivery_id', __('Invalid webhook delivery ID', 'woocommerce'), 404);
}
$webhook = new WC_Webhook($webhook_id);
$log = $webhook->get_delivery_log($id);
if (!$log) {
throw new WC_API_Exception('woocommerce_api_invalid_webhook_delivery_id', __('Invalid webhook delivery', 'woocommerce'), 400);
}
$delivery_log = $log;
// Add timestamp
$delivery_log['created_at'] = $this->server->format_datetime($log['comment']->comment_date_gmt);
// Remove comment object
unset($delivery_log['comment']);
return array('webhook_delivery' => apply_filters('woocommerce_api_webhook_delivery_response', $delivery_log, $id, $fields, $log, $webhook_id, $this));
} catch (WC_API_Exception $e) {
return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
}
}
示例2: get_item
/**
* Get a single webhook delivery.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item($request)
{
$id = (int) $request['id'];
$webhook = new WC_Webhook((int) $request['webhook_id']);
if (empty($webhook->post_data->post_type) || 'shop_webhook' !== $webhook->post_data->post_type) {
return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook id.', 'woocommerce'), array('status' => 404));
}
$log = $webhook->get_delivery_log($id);
if (empty($id) || empty($log)) {
return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 404));
}
$delivery = $this->prepare_item_for_response((object) $log, $request);
$response = rest_ensure_response($delivery);
return $response;
}