API: Orders: Add payment_url

Adds the payment URL to the order response if we request it. This is
helpful for sharing payment links from the apps.

Ref: https://wp.me/p91TBi-7ov
This commit is contained in:
Josh Betz 2022-02-03 14:10:20 -06:00
parent c36d25af71
commit 8a9782986d
1 changed files with 11 additions and 1 deletions

View File

@ -257,7 +257,7 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
* @return array
*/
protected function get_formatted_item_data( $order ) {
$extra_fields = array( 'meta_data', 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines', 'refunds' );
$extra_fields = array( 'meta_data', 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines', 'refunds', 'payment_url' );
$format_decimal = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
$format_date = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
// These fields are dependent on other fields.
@ -317,6 +317,9 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
);
}
break;
case 'payment_url':
$data['payment_url'] = $order->get_checkout_payment_url();
break;
}
}
@ -382,6 +385,7 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
'fee_lines',
'coupon_lines',
'refunds',
'payment_url',
);
$data = array_intersect_key( $data, array_flip( $allowed_fields ) );
@ -1774,6 +1778,12 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
),
),
),
'payment_url' => array(
'description' => __( 'Order payment URL.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'set_paid' => array(
'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ),
'type' => 'boolean',