callback must return an array.' );
}
} catch ( \Throwable $e ) {
$this->throw_exception( $e );
}
$registered_schema[ $namespace ] = $this->format_extensions_properties( $namespace, $schema, $callbacks['schema_type'] );
}
}
return (object) $registered_schema;
}
/**
* Returns the additional payment requirements for the cart which are required to make payments. Values listed here
* are compared against each Payment Gateways "supports" flag.
*
* @param array $requirements list of requirements that should be added to the collected requirements.
* @return array Returns a list of payment requirements.
* @throws \Exception If a registered callback throws an error, or silently logs it.
*/
public function get_payment_requirements( array $requirements = [ 'products' ] ) {
if ( ! empty( $this->payment_requirements ) ) {
foreach ( $this->payment_requirements as $callback ) {
try {
$data = $callback();
if ( ! is_array( $data ) ) {
throw new \Exception( '$data_callback must return an array.' );
}
$requirements = array_unique( array_merge( $requirements, $data ) );
} catch ( \Throwable $e ) {
$this->throw_exception( $e );
}
}
}
return $requirements;
}
/**
* Throws error and/or silently logs it.
*
* @param string|\Throwable $exception_or_error Error message or \Exception.
* @throws \Exception An error to throw if we have debug enabled and user is admin.
*/
private function throw_exception( $exception_or_error ) {
$exception = is_string( $exception_or_error ) ? new \Exception( $exception_or_error ) : $exception_or_error;
wc_caught_exception( $exception );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && current_user_can( 'manage_woocommerce' ) ) {
throw $exception;
}
}
/**
* Format schema for an extension.
*
* @param string $namespace Error message or \Exception.
* @param array $schema An error to throw if we have debug enabled and user is admin.
* @param string $schema_type How should data be shaped.
* @return array Formatted schema.
*/
private function format_extensions_properties( $namespace, $schema, $schema_type ) {
if ( ARRAY_N === $schema_type ) {
return [
/* translators: %s: extension namespace */
'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
'type' => [ 'array', 'null' ],
'context' => [ 'view', 'edit' ],
'items' => $schema,
];
}
return [
/* translators: %s: extension namespace */
'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
'type' => [ 'object', 'null' ],
'context' => [ 'view', 'edit' ],
'properties' => $schema,
];
}
}
Warning: Class "Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema" not found in /home/sanattv/public_html/sanat.international/wp-content/plugins/woocommerce/src/StoreApi/deprecated.php on line 73
callback must return an array.' );
}
} catch ( \Throwable $e ) {
$this->throw_exception( $e );
}
$registered_schema[ $namespace ] = $this->format_extensions_properties( $namespace, $schema, $callbacks['schema_type'] );
}
}
return (object) $registered_schema;
}
/**
* Returns the additional payment requirements for the cart which are required to make payments. Values listed here
* are compared against each Payment Gateways "supports" flag.
*
* @param array $requirements list of requirements that should be added to the collected requirements.
* @return array Returns a list of payment requirements.
* @throws \Exception If a registered callback throws an error, or silently logs it.
*/
public function get_payment_requirements( array $requirements = [ 'products' ] ) {
if ( ! empty( $this->payment_requirements ) ) {
foreach ( $this->payment_requirements as $callback ) {
try {
$data = $callback();
if ( ! is_array( $data ) ) {
throw new \Exception( '$data_callback must return an array.' );
}
$requirements = array_unique( array_merge( $requirements, $data ) );
} catch ( \Throwable $e ) {
$this->throw_exception( $e );
}
}
}
return $requirements;
}
/**
* Throws error and/or silently logs it.
*
* @param string|\Throwable $exception_or_error Error message or \Exception.
* @throws \Exception An error to throw if we have debug enabled and user is admin.
*/
private function throw_exception( $exception_or_error ) {
$exception = is_string( $exception_or_error ) ? new \Exception( $exception_or_error ) : $exception_or_error;
wc_caught_exception( $exception );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && current_user_can( 'manage_woocommerce' ) ) {
throw $exception;
}
}
/**
* Format schema for an extension.
*
* @param string $namespace Error message or \Exception.
* @param array $schema An error to throw if we have debug enabled and user is admin.
* @param string $schema_type How should data be shaped.
* @return array Formatted schema.
*/
private function format_extensions_properties( $namespace, $schema, $schema_type ) {
if ( ARRAY_N === $schema_type ) {
return [
/* translators: %s: extension namespace */
'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
'type' => [ 'array', 'null' ],
'context' => [ 'view', 'edit' ],
'items' => $schema,
];
}
return [
/* translators: %s: extension namespace */
'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
'type' => [ 'object', 'null' ],
'context' => [ 'view', 'edit' ],
'properties' => $schema,
];
}
}