| File was renamed from inc/integrations/Square.php |
| | |
| | | <?php |
| | | namespace JVBase\integrations; |
| | | |
| | | namespace JVBase\integrations\services; |
| | | use Exception; |
| | | use JVBase\integrations\Integrations; |
| | | use JVBase\managers\queue\executors\IntegrationExecutor; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Meta; |
| | | use Exception; |
| | | use JVBase\registrar\Fields; |
| | | use JVBase\registrar\Posts; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\ui\Checkout; |
| | | use JVBase\ui\CRUDSkeleton; |
| | | use WP_Error; |
| | | use JVBase\ui\Checkout; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\managers\queue\executors\IntegrationExecutor; |
| | | use WP_Post; |
| | | use WP_Query; |
| | | use WP_User; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | protected string $locationId = ''; |
| | | protected array $locations = []; |
| | | |
| | | protected static array $instances = []; |
| | | protected static Square $instance; |
| | | |
| | | public static function getInstance(?int $userID = null):self |
| | | public static function getInstance():self |
| | | { |
| | | $key = is_null($userID) ? 'base' : $userID; |
| | | |
| | | if (!array_key_exists($key, self::$instances)) { |
| | | self::$instances[$key] = new self($userID); |
| | | if (!isset(self::$instance)) { |
| | | self::$instance = new self(); |
| | | } |
| | | return self::$instances[$key]; |
| | | return self::$instance; |
| | | } |
| | | |
| | | protected function __construct(?int $userID = null) |
| | |
| | | 'delete' => true |
| | | ]; |
| | | $this->supportsWebp = false; |
| | | $this->handleWebhooks = true; |
| | | $this->hasWebhooks = true; |
| | | |
| | | parent::__construct($userID); |
| | | parent::__construct(); |
| | | |
| | | // Add Square-specific actions |
| | | $this->actions = array_merge( |
| | |
| | | protected function registerAdditionalHooks(): void |
| | | { |
| | | if (!$this->isSetUp()) { |
| | | error_log('Square is not setup'); |
| | | return; |
| | | } |
| | | |
| | |
| | | /** |
| | | * Handle post save for Square sync |
| | | */ |
| | | protected function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings): void |
| | | protected function handleTheSavePost(int $postID, WP_Post $post, bool $update, array $settings): void |
| | | { |
| | | error_log('==== [Square]::handleTheSavePost ===='); |
| | | $this->queueOperation(self::$syncTo, [ |
| | |
| | | if (!in_array($post_id, $success)) { |
| | | $found_in_errors = false; |
| | | foreach ($errors as $error) { |
| | | if (strpos($error, "Post $post_id") !== false) { |
| | | if (str_contains($error, "Post $post_id")) { |
| | | $found_in_errors = true; |
| | | break; |
| | | } |
| | |
| | | } |
| | | |
| | | // Set user role (assuming you have a customer role defined) |
| | | $user = new \WP_User($user_id); |
| | | $user = new WP_User($user_id); |
| | | $user->set_role(BASE.'foodie'); |
| | | |
| | | // Generate password reset key |
| | |
| | | /** |
| | | * Send welcome email with password setup |
| | | */ |
| | | private function sendWelcomeEmail(\WP_User $user, string $reset_key): void |
| | | private function sendWelcomeEmail(WP_User $user, string $reset_key): void |
| | | { |
| | | $site_name = get_bloginfo('name'); |
| | | $reset_url = get_home_url(null, "wp-login.php?action=rp&key=$reset_key&login=" . rawurlencode($user->user_login), 'login'); |
| | |
| | | $sanitized[$key] = sanitize_key($value); |
| | | } |
| | | // Handle boolean fields |
| | | elseif ($key === 'use_sandbox' || strpos($key, 'enable_') === 0) { |
| | | elseif ($key === 'use_sandbox' || str_starts_with($key, 'enable_')) { |
| | | $sanitized[$key] = (bool) $value; |
| | | } |
| | | // Handle numeric fields |
| | |
| | | // Fetch from Square |
| | | $response = $this->getRequest('orders/' . $order_id); |
| | | if (!is_wp_error($response)) { |
| | | $state = $response['order']['state'] ?? null; |
| | | return $state; |
| | | return $response['order']['state'] ?? null; |
| | | } |
| | | |
| | | return null; |
| | |
| | | } |
| | | public function renderDashPage():void |
| | | { |
| | | $instance = $this->determineInstance(); |
| | | $this->determineUser(); |
| | | |
| | | $crud = new CRUDSkeleton(); |
| | | $crud->icon('receipt'); |
| | |
| | | |
| | | $crud->render(); |
| | | } |
| | | protected function determineInstance():self |
| | | { |
| | | if (current_user_can('manage_options')) { |
| | | return self::$instances['base']; |
| | | } |
| | | return self::getInstance(get_current_user_id()); |
| | | } |
| | | |
| | | |
| | | public function getOrderPost(string $order_id):int|false |
| | | { |