[REST API] Include refunds data into orders endpoint

This commit is contained in:
Claudio Sanches 2016-06-02 16:05:08 -03:00
parent 0132f4d5dd
commit d205c2e85f
1 changed files with 36 additions and 0 deletions

View File

@ -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,
),
),
),
),
);