*/ final class OrganizationPushHandler implements PushEndpointHandlerInterface { /** * Field the shared apply relies on to derive the billing state; a payload * missing it carries no applicable organization change and is rejected before * the apply runs. `country` is intentionally not required — the shared apply * only updates `organization-country` when a code is present. * * @since 4.3.0 * @var string[] */ const REQUIRED_FIELDS = array( 'hasBilling' ); /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function endpoint() { return 'organization'; } /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function event_type() { return 'wordpress.organization.updated'; // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Actirise API event-type identifier. } /** * {@inheritDoc} * * @since 4.3.0 * @return int[] */ public function supported_versions() { return array( 1 ); } /** * Apply an organization-info update. * * The payload must be an object carrying at least the field the shared apply * relies on ({@see self::REQUIRED_FIELDS}); anything else is a schema error * rejected with a 400 by the controller. Rejecting an incomplete payload also * guards the reused writer: an empty argument makes check_organization_fields() * fetch from the API (the page-load GET this story removes), so a push must * never reach it empty. * * @since 4.3.0 * @param mixed $data The organization resource payload (contract §5.5). * @return bool True when the update was applied. */ public function apply( $data ) { if ( ! is_array( $data ) ) { return false; } foreach ( self::REQUIRED_FIELDS as $field ) { if ( ! isset( $data[ $field ] ) ) { return false; } } /** @var array $data The verified organization resource (contract §5.5). */ AdminCore::check_organization_fields( $data ); return true; } }