AbstractSquareAbility.php
1 month ago
GetConnectionStatus.php
1 month ago
GetLocations.php
1 month ago
GetOrderPaymentStatus.php
1 month ago
GetPendingJobs.php
1 month ago
GetProductSyncState.php
1 month ago
GetSyncRecords.php
1 month ago
GetSyncStatus.php
1 month ago
GetConnectionStatus.php
87 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Get connection status ability definition. |
| 4 | * |
| 5 | * @package WooCommerce\Square |
| 6 | */ |
| 7 | |
| 8 | // @phan-file-suppress PhanUndeclaredClassMethod, PhanUndeclaredFunction @phan-suppress-current-line UnusedSuppression -- Abilities API + AbilityDefinition added in WC 10.9; suppression covers older-WC compat runs where this class never loads. |
| 9 | |
| 10 | namespace WooCommerce\Square\Internal\Abilities\Domain; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Automattic\WooCommerce\Abilities\AbilityDefinition; |
| 15 | use WooCommerce\Square\Internal\Abilities\Abilities_Registrar; |
| 16 | |
| 17 | /** |
| 18 | * Registers the woocommerce-square/get-connection-status ability. |
| 19 | * |
| 20 | * Lean alternative to the kitchen-sink general settings read. Answers |
| 21 | * "is this store connected to Square, against which environment, and |
| 22 | * which location ID is configured?" with five focused fields — and |
| 23 | * deliberately excludes access_tokens, connection/disconnection URLs, |
| 24 | * and the locations list. The locations list is available as a |
| 25 | * separate ability (woocommerce-square/get-locations). |
| 26 | * |
| 27 | * @internal Only loaded when WooCommerce 10.9+ is active. |
| 28 | */ |
| 29 | class GetConnectionStatus extends AbstractSquareAbility implements AbilityDefinition { |
| 30 | |
| 31 | public static function get_name(): string { |
| 32 | return 'woocommerce-square/get-connection-status'; |
| 33 | } |
| 34 | |
| 35 | public static function get_registration_args(): array { |
| 36 | return array( |
| 37 | 'label' => __( 'Get Square connection status', 'woocommerce-square' ), |
| 38 | 'description' => __( 'Return the Square OAuth connection state: connected (bool), configured (bool), environment (sandbox or production), the configured location id, and whether the sandbox toggle is on. Deliberately excludes tokens, connection URLs, and the locations list.', 'woocommerce-square' ), |
| 39 | 'category' => self::CATEGORY_SLUG, |
| 40 | 'input_schema' => array( |
| 41 | 'type' => 'object', |
| 42 | 'default' => (object) array(), |
| 43 | 'properties' => array(), |
| 44 | 'additionalProperties' => false, |
| 45 | ), |
| 46 | 'execute_callback' => array( self::class, 'execute' ), |
| 47 | 'permission_callback' => array( Abilities_Registrar::class, 'can_manage_woocommerce_square' ), |
| 48 | 'meta' => array( |
| 49 | 'annotations' => array( |
| 50 | 'readonly' => true, |
| 51 | 'destructive' => false, |
| 52 | 'idempotent' => true, |
| 53 | ), |
| 54 | 'show_in_rest' => true, |
| 55 | 'mcp' => array( |
| 56 | 'public' => true, |
| 57 | ), |
| 58 | ), |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Execute callback. |
| 64 | * |
| 65 | * @param mixed $input Ignored. |
| 66 | * @return array|\WP_Error |
| 67 | */ |
| 68 | public static function execute( $input = null ) { |
| 69 | unset( $input ); |
| 70 | |
| 71 | $settings = self::get_settings_handler_or_error(); |
| 72 | if ( is_wp_error( $settings ) ) { |
| 73 | return $settings; |
| 74 | } |
| 75 | |
| 76 | $location_id = $settings->get_location_id(); |
| 77 | |
| 78 | return array( |
| 79 | 'is_connected' => (bool) $settings->is_connected(), |
| 80 | 'is_configured' => (bool) $settings->is_configured(), |
| 81 | 'is_sandbox' => (bool) $settings->is_sandbox(), |
| 82 | 'environment' => (string) $settings->get_environment(), |
| 83 | 'location_id' => ! empty( $location_id ) ? (string) $location_id : null, |
| 84 | ); |
| 85 | } |
| 86 | } |
| 87 |