namespace = $rest_namespace; $this->rest_base = '/payment'; } /** * Register the API endpoints. * * @return void */ public function register_routes() { $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ ); $data_store_id = array( self::PARAM_STORE_ID => $this->get_arg_string() ); $data_methods = array_merge( $data_store_id, array( self::PARAM_MERCHANT_ID => $this->get_arg_string() ) ); $store_id = $this->url_param_pattern( self::PARAM_STORE_ID ); $merchant_id = $this->url_param_pattern( self::PARAM_MERCHANT_ID ); $this->register_get( "methods/{$store_id}/{$merchant_id}", 'get_methods', $data_methods ); $this->register_get( "methods/{$store_id}", 'get_all_methods', $data_store_id ); } /** * Get payment methods. * * @param WP_REST_Request $request The request. * * @return WP_REST_Response|WP_Error */ public function get_methods( WP_REST_Request $request ) { /** * Response * * @var Response $response */ $response = AdminAPI::get() ->paymentMethods( strval( $request->get_param( self::PARAM_STORE_ID ) ) ) ->getPaymentMethods( new GetPaymentMethodsRequest( strval( $request->get_param( self::PARAM_MERCHANT_ID ) ), true ) ); return $this->build_response( $response ); } /** * Get all payment methods. * * @param WP_REST_Request $request The request. * * @return WP_REST_Response|WP_Error */ public function get_all_methods( WP_REST_Request $request ) { /** * Response * * @var Response $response */ $response = AdminAPI::get() ->paymentMethods( strval( $request->get_param( self::PARAM_STORE_ID ) ) ) ->getAllAvailablePaymentMethods( new GetFormattedPaymentMethodsRequest( true ) ); return $this->build_response( $response ); } }