WC_REST_Payment_Gateways_Controller::prepare_item_for_response()publicWC 1.0

Prepare a payment gateway for response.

Method of the class: WC_REST_Payment_Gateways_Controller{}

Return

WP_REST_Response. $response Response data.

Usage

$WC_REST_Payment_Gateways_Controller = new WC_REST_Payment_Gateways_Controller();
$WC_REST_Payment_Gateways_Controller->prepare_item_for_response( $gateway, $request );
$gateway(WC_Payment_Gateway) (required)
Payment gateway object.
$request(WP_REST_Request) (required)
Request object.

WC_REST_Payment_Gateways_Controller::prepare_item_for_response() code WC 8.7.0

public function prepare_item_for_response( $gateway, $request ) {
	$order = (array) get_option( 'woocommerce_gateway_order' );
	$item  = array(
		'id'                 => $gateway->id,
		'title'              => $gateway->title,
		'description'        => $gateway->description,
		'order'              => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '',
		'enabled'            => ( 'yes' === $gateway->enabled ),
		'method_title'       => $gateway->get_method_title(),
		'method_description' => $gateway->get_method_description(),
		'method_supports'    => $gateway->supports,
		'settings'           => $this->get_settings( $gateway ),
	);

	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $item, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	$response = rest_ensure_response( $data );
	$response->add_links( $this->prepare_links( $gateway, $request ) );

	/**
	 * Filter payment gateway objects returned from the REST API.
	 *
	 * @param WP_REST_Response   $response The response object.
	 * @param WC_Payment_Gateway $gateway  Payment gateway object.
	 * @param WP_REST_Request    $request  Request object.
	 */
	return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request );
}