From d205c2e85fdfb0e66431fd9c2ca2a9e0b2f5e6c1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 2 Jun 2016 16:05:08 -0300 Subject: [PATCH] [REST API] Include refunds data into orders endpoint --- .../api/class-wc-rest-orders-controller.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/includes/api/class-wc-rest-orders-controller.php b/includes/api/class-wc-rest-orders-controller.php index b3252423300..b794036131e 100644 --- a/includes/api/class-wc-rest-orders-controller.php +++ b/includes/api/class-wc-rest-orders-controller.php @@ -159,6 +159,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller { 'shipping_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array(), + 'refunds' => array(), ); // Add addresses. @@ -320,6 +321,15 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller { $data['coupon_lines'][] = $coupon_line; } + // Add refunds. + foreach ( $order->get_refunds() as $refund ) { + $data['refunds'][] = array( + 'id' => $refund->id, + 'refund' => $refund->get_refund_reason() ? $refund->get_refund_reason() : '', + 'total' => '-' . wc_format_decimal( $refund->get_refund_amount(), $dp ), + ); + } + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); @@ -1685,6 +1695,32 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller { ), ), ), + 'refunds' => array( + 'description' => __( 'List of refunds.', 'woocommerce' ), + 'type' => 'array', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + 'properties' => array( + 'id' => array( + 'description' => __( 'Refund ID.', 'woocommerce' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), + 'reason' => array( + 'description' => __( 'Refund reason.', 'woocommerce' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), + 'total' => array( + 'description' => __( 'Refund total.', 'woocommerce' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), + ), + ), ), );