PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 1.9.12 1.9.11 1.9.10 1.9.9 All 158 releases
woocommerce-pos / includes / Sync / Order_Document.php

Order_Document.php in WCPOS – Point of Sale (POS) plugin for WooCommerce trunk, at includes/Sync/Order_Document.php

75 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WCPOS sync read surface.
4 *
5 * @package WCPOS\WooCommercePOS\Sync
6 */
7
8 namespace WCPOS\WooCommercePOS\Sync;
9
10 // phpcs:disable Squiz.Commenting, Generic.Commenting -- Ported lab documentation is preserved verbatim.
11 // phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- The uuid-stop fail-closed message carries only a numeric order id, not rendered output.
12
13 /**
14 * THE complete-order-document builder (#424): the envelope the order read
15 * surface ships — the batch custom pull — assembled in exactly one place, keyed
16 * by the order's stable uuid (P0-1), with the uuid guard's single fail-closed
17 * reaction (Order_Uuid_Exception).
18 *
19 * The re-key (ADR 0021 trap): `id` is the record's _woocommerce_pos_uuid — the
20 * SAME identity the client stores under — never woo-order:<id>. A numeric-keyed
21 * document would duplicate the uuid-keyed row client-side.
22 */
23 final class Order_Document {
24 /**
25 * Read the order's stable uuid from a payload's meta, failing closed.
26 * The IDENTITY payload must be the full serialized payload (the serializer
27 * stamped it via the woocommerce_pos_sync_serialized_order filter).
28 *
29 * @param array $identity_payload The FULL serialized payload (uuid source of truth).
30 * @param int $order_id The numeric Woo order id (for the error message).
31 *
32 * @throws Order_Uuid_Exception when the payload carries no valid uuid.
33 */
34 public static function require_uuid( array $identity_payload, int $order_id ): string {
35 $uuid = Pos_Uuid::read_valid_uuid_from_meta( $identity_payload['meta_data'] ?? array() );
36 if ( '' === $uuid ) {
37 throw Order_Uuid_Exception::for_order( $order_id );
38 }
39 return $uuid;
40 }
41
42 /**
43 * Build the complete order document envelope.
44 *
45 * @param array $identity_payload The FULL serialized payload (uuid source of truth).
46 * @param array $client_payload The payload actually shipped.
47 * @param int $order_id The numeric Woo order id (for the uuid guard's error message).
48 * @param string $revision The document revision (index row's, or the canonical fallback).
49 * @param array $checkpoint The per-document checkpoint (updatedAtGmt/orderId/revision/sequence).
50 * @param bool $partial Whether $client_payload is a partial fieldset.
51 * @param string $source 'custom-pull' | 'skeleton' | 'snapshot'.
52 *
53 * @throws Order_Uuid_Exception when the identity payload carries no valid uuid.
54 */
55 public static function build( array $identity_payload, array $client_payload, int $order_id, string $revision, array $checkpoint, bool $partial, string $source ): array {
56 return array(
57 // ADR 0029 decision 6: no per-document wooOrderId key — the client derives
58 // remote identity from payload.id at its ingest edge. The deletes channel
59 // (a SEPARATE response key) still speaks numeric order ids.
60 'id' => self::require_uuid( $identity_payload, $order_id ),
61 'payload' => $client_payload,
62 'sync' => array(
63 'revision' => $revision,
64 'checkpoint' => $checkpoint,
65 'partial' => $partial,
66 'source' => $source,
67 ),
68 'local' => array(
69 'dirty' => false,
70 'pendingMutationIds' => array(),
71 ),
72 );
73 }
74 }
75