| | |
| | | */ |
| | | protected bool $isOAuthService = true; |
| | | |
| | | protected string $orderPostType = '_sq_order'; |
| | | protected string $orderPostType = '_square_order'; |
| | | protected array $newOrder = []; |
| | | protected array $oauth = [ |
| | | 'authorize' => '', |
| | |
| | | |
| | | public function registerSquarePostTypes():void |
| | | { |
| | | $orders = Registrar::forPost('_sq_orders', 'Square Order', 'Square Orders'); |
| | | $orders = Registrar::forPost($this->orderPostType, 'Square Order', 'Square Orders'); |
| | | $orders->make([ |
| | | 'public' => true |
| | | ]); |
| | |
| | | 'name' => $variation['name'], |
| | | 'pricing_type' => 'FIXED_PRICING', |
| | | 'price_money' => [ |
| | | 'amount' => intval($variation['price'] * 100), // Convert to cents |
| | | 'amount' => intval($variation['_square_price'] * 100), // Convert to cents |
| | | 'currency' => 'USD' |
| | | ] |
| | | ] |
| | |
| | | 'name' => 'Regular', |
| | | 'pricing_type' => 'FIXED_PRICING', |
| | | 'price_money' => [ |
| | | 'amount' => intval(($itemData['price'] ?? 0) * 100), |
| | | 'amount' => intval(($itemData['_square_price'] ?? 0) * 100), |
| | | 'currency' => 'USD' |
| | | ] |
| | | ] |
| | |
| | | |
| | | add_filter('jvbAdditionalActions', [Checkout::class, 'render']); |
| | | |
| | | |
| | | add_filter('jvb_checkout_description', function (string $desc, string $provider) { |
| | | if ($provider === 'square') { |
| | | return 'Securely checkout with your name, email, and payments processed by Square.'; |
| | |
| | | add_filter('jvb_checkout_browse_text', function () { |
| | | return 'browse our menu'; |
| | | }); |
| | | |
| | | // Register queue executor types |
| | | $this->registerQueueTypes(); |
| | | add_action('init', [$this, 'registerQueueTypes'], 10); |
| | | } |
| | | |
| | | /** |
| | |
| | | ]); |
| | | } |
| | | |
| | | protected function registerQueueTypes(): void |
| | | public function registerQueueTypes(): void |
| | | { |
| | | $queue = JVB()->queue(); |
| | | $executor = new IntegrationExecutor(); |
| | |
| | | if (!empty($product_variations) && is_array($product_variations)) { |
| | | foreach ($product_variations as $index => $variation_data) { |
| | | // Skip empty variations |
| | | if (empty($variation_data['name']) && empty($variation_data['sku'])) { |
| | | if (empty($variation_data['name']) && empty($variation_data['_square_sku'])) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | break; |
| | | |
| | | case 'sku': |
| | | $variation['item_variation_data']['sku'] = $variation_data[$wp_field]; |
| | | $variation['item_variation_data']['_square_sku'] = $variation_data[$wp_field]; |
| | | break; |
| | | |
| | | case 'track_inventory': |
| | |
| | | |
| | | $defaults = [ |
| | | 'name' => 'name', |
| | | 'id' => '_square_catalog_id', |
| | | 'sku' => 'sku', |
| | | 'price' => 'price', |
| | | 'track_inventory' => 'track_inventory', |
| | | 'service_duration' => 'service_duration', |
| | | 'available_for_booking' => 'available_for_booking', |
| | | 'gift_card_type' => 'gift_card_type', |
| | | 'ingredients' => 'ingredients', |
| | | 'preparation_time_duration' => 'preparation_time_duration' |
| | | 'id' => '_square_item_id', |
| | | 'sku' => '_square_sku', |
| | | 'price' => '_square_price', |
| | | 'track_inventory' => '_square_track_inventory', |
| | | 'service_duration' => '_square_service_duration', |
| | | 'available_for_booking' => '_square_available_for_booking', |
| | | 'gift_card_type' => '_square_gift_card_type', |
| | | 'ingredients' => '_square_ingredients', |
| | | 'preparation_time_duration' => '_square_preparation_time_duration' |
| | | ]; |
| | | |
| | | $extended = apply_filters( |
| | |
| | | 'description_html' => 'post_content', |
| | | 'abbreviation' => 'abbreviation', |
| | | 'id' => '_square_catalog_id', |
| | | 'sku' => 'sku', |
| | | 'sku' => '_square_sku', |
| | | 'category_id' => 'category', |
| | | 'image_ids' => 'post_thumbnail', |
| | | 'price' => 'price', |
| | | 'price' => '_square_price', |
| | | 'tax_ids' => 'tax_ids', |
| | | // Availability |
| | | 'available_online' => 'available_online', |
| | | 'available_for_pickup' => 'available_for_pickup', |
| | | 'available_electronically' => 'available_electronically', |
| | | 'available_online' => '_square_available_online', |
| | | 'available_for_pickup' => '_square_available_for_pickup', |
| | | 'available_electronically' => '_square_available_electronically', |
| | | // Modifiers |
| | | 'modifier_list_info' => 'modifiers', |
| | | // Item options |
| | |
| | | wp_enqueue_script('jvb-square-checkout'); |
| | | |
| | | wp_localize_script('jvb-square-checkout', 'squareConfig', [ |
| | | //TODO 'isOpen' => jvbIsOpen(), |
| | | 'isOpen' => jvbIsOpen()?'1':'0', |
| | | 'application_id' => $this->credentials['client_id'] ?? '', |
| | | 'location_id' => $this->locationId, |
| | | 'environment' => $this->environment, |
| | |
| | | foreach ($item['item_data']['variations'] as $index => $variation) { |
| | | $var_data = [ |
| | | 'name' => $variation['item_variation_data']['name'] ?? '', |
| | | 'sku' => $variation['item_variation_data']['sku'] ?? '', |
| | | 'sku' => $variation['item_variation_data']['_square_sku'] ?? '', |
| | | ]; |
| | | |
| | | // Extract price |
| | |
| | | if ($content_type && array_key_exists($content_type, $this->contentTypes)){ |
| | | $array = $this->contentTypes[$content_type]; |
| | | return array_combine( |
| | | array_map(fn($k) => 'sq_' . $k, array_keys($array)), |
| | | array_map(fn($k) => '_square_' . $k, array_keys($array)), |
| | | $array |
| | | ); |
| | | } else if ($content_type && !array_key_exists($content_type, $this->contentTypes)) { |
| | |
| | | return []; |
| | | } |
| | | $array = $this->setBaseFields(); |
| | | $return = array_combine( |
| | | array_map(fn($k) => 'sq_' . $k, array_keys($array)), |
| | | return array_combine( |
| | | array_map(fn($k) => '_square_' . $k, array_keys($array)), |
| | | $array |
| | | ); |
| | | |
| | | return $return; |
| | | } |
| | | protected function setBaseFields():array |
| | | { |
| | |
| | | 'label' => 'Variation Name', |
| | | 'description' => 'e.g., "Small", "Large", "Red", etc.' |
| | | ], |
| | | 'sku' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'SKU', |
| | | 'description' => 'Stock keeping unit' |
| | | ], |
| | | 'price' => [ |
| | | 'type' => 'number', |
| | | 'label' => 'Price', |
| | |
| | | 'max' => 99999, |
| | | 'description' => 'Price for this variation' |
| | | ], |
| | | |
| | | 'track_inventory' => [ |
| | | 'type' => 'true_false', |
| | | 'label' => 'Track Inventory', |
| | | ], |
| | | '_square_item_id' => [ |
| | | 'item_id' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'Square Variation ID', |
| | | 'description' => 'Square catalog ID for this variation', |
| | | 'hidden' => true |
| | | ], |
| | | '_square_last_sync' => [ |
| | | 'last_sync' => [ |
| | | 'type' => 'datetime', |
| | | 'label' => 'Last Sync', |
| | | 'hidden' => true |
| | |
| | | ]; |
| | | break; |
| | | } |
| | | return $fields; |
| | | return array_combine( |
| | | array_map(fn($k) => '_square_' . $k, array_keys($fields)), |
| | | $fields |
| | | ); |
| | | } |
| | | protected function setFoodAndBevFields():array |
| | | { |
| | |
| | | // Ad-hoc line item (not recommended - no tax/inventory automation) |
| | | $line_item['name'] = $item['name']; |
| | | $line_item['base_price_money'] = [ |
| | | 'amount' => (int)$item['price'], |
| | | 'amount' => (int)$item['_square_price'], |
| | | 'currency' => $this->getCurrency() |
| | | ]; |
| | | } |
| | |
| | | |
| | | // Create order post |
| | | $order_post_id = wp_insert_post([ |
| | | 'post_type' => BASE . '_sq_orders', |
| | | 'post_type' => BASE . '_square_orders', |
| | | 'post_title' => 'Order #' . $order_data['square_order_id'], |
| | | 'post_status' => 'publish', |
| | | 'post_author' => $user_id // Associate with user if logged in |