Jake Vanderwerf
4 days ago 0afb2c0046b55c123eafb4ab9ee77efa68d12463
inc/integrations/Square.php
@@ -4,8 +4,9 @@
use JVBase\meta\Form;
use JVBase\meta\Meta;
use Exception;
use JVBase\registrar\Fields;
use JVBase\registrar\Posts;
use JVBase\registrar\Registrar;
use JVBase\registry\PostTypeRegistrar;
use WP_Error;
use JVBase\ui\Checkout;
use JVBase\managers\queue\TypeConfig;
@@ -217,14 +218,9 @@
   }
   public function getSquarePostConfig(string $post = 'all'):array
   public function getOrderFields():array
   {
      $posts = [
         '_sq_orders' => [
            'singular'  => 'Square Order',
            'plural' => 'Square Orders',
            'public' => false,
            'fields' => [
      return [
               'post_title' => [
                  'type' => 'text',
                  'label' => 'Order Number'
@@ -324,25 +320,23 @@
                  'label' => 'Last Updated',
                  'readonly' => true
               ]
            ]
         ]
      ];
      if ($post === 'all'){
         return $posts;
      }elseif(array_key_exists($post, $posts)) {
         return $posts[$post];
      }
      return [];
            ];
   }
   public function registerSquarePostTypes():void
   {
      $squarePostTypes = $this->getSquarePostConfig();
      foreach ($squarePostTypes as $slug => $config) {
         $registrar = new PostTypeRegistrar($slug, $config);
         $registrar->register();
      $orders = Registrar::forPost('_sq_orders', 'Square Order', 'Square Orders');
      $orders->make([
         'public' => false
         ]
      );
      $orders->setAll(['system']);
      $fields = $orders->fields();
      foreach ($this->getOrderFields() as $fieldName => $config) {
         $fields->addField($fieldName, $config);
      }
   }
   /**
@@ -1385,7 +1379,7 @@
    */
   protected function getVariationMapping(string $post_type): array
   {
      $registrar = Registrar::getInstance($post_type));
      $registrar = Registrar::getInstance($post_type);
      if (!$registrar) {
         return [];
      }
@@ -1459,7 +1453,7 @@
    */
   protected function getFieldMapping(string $post_type): array
   {
      $registrar = Registrar::getInstance($post_type));
      $registrar = Registrar::getInstance($post_type);
      if (!$registrar) {
         return [];
      }
@@ -1660,7 +1654,7 @@
      // Set user role (assuming you have a customer role defined)
      $user = new \WP_User($user_id);
      $user->set_role(BASE.'foodie'); // Or whatever role from JVB_USER
      $user->set_role(BASE.'foodie'); // Or whatever role
      // Generate password reset key
      $reset_key = get_password_reset_key($user);
@@ -1896,7 +1890,6 @@
         }
         $meta->setAll($updates);
         $meta->save();
         // Trigger notification to customer if order is ready
         if ($state === 'PREPARED') {
@@ -2006,7 +1999,7 @@
      wp_enqueue_script('jvb-square-checkout');
      wp_localize_script('jvb-square-checkout', 'squareConfig', [
         'isOpen'         => jvbIsOpen(),
//TODO         'isOpen'         => jvbIsOpen(),
         'application_id' => $this->credentials['client_id'] ?? '',
         'location_id'    => $this->locationId,
         'environment'    => $this->environment,
@@ -2353,7 +2346,6 @@
      // Save all values at once
      $meta->setAll($values_to_save);
      $meta->save();
   }
   /**
@@ -3475,7 +3467,7 @@
      // Save all order meta
      $meta = Meta::forPost($order_post_id);
      $fields = $this->getSquarePostConfig('_sq_orders')['fields'];
      $fields = $this->getOrderFields();
      unset($fields['post_title']);
      $meta->setAll([
@@ -3495,7 +3487,6 @@
         'created_at' => current_time('mysql'),
         'updated_at' => current_time('mysql')
      ]);
      $meta->save();
      // Index by Square order ID for quick webhook lookups
      update_option(BASE . 'square_order_map_' . $order_data['square_order_id'], $order_post_id);