Add WooCommerce integration: sync orders to invoices/people with webhook, cron, and settings UI.

This commit is contained in:
2026-09-26 17:59:16 +03:30
parent 1b160c8cd3
commit 26085b54a9
15 changed files with 1571 additions and 2 deletions
@@ -0,0 +1,63 @@
-- CreateTable
CREATE TABLE "WooCommerceConnection" (
"id" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"label" TEXT NOT NULL,
"storeUrl" TEXT NOT NULL,
"consumerKeyCiphertext" TEXT NOT NULL,
"consumerKeyIv" TEXT NOT NULL,
"consumerKeyTag" TEXT NOT NULL,
"consumerKeyLast4" TEXT NOT NULL DEFAULT '',
"consumerSecretCiphertext" TEXT NOT NULL,
"consumerSecretIv" TEXT NOT NULL,
"consumerSecretTag" TEXT NOT NULL,
"webhookSecretCiphertext" TEXT,
"webhookSecretIv" TEXT,
"webhookSecretTag" TEXT,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"lastSyncAt" TIMESTAMP(3),
"lastHealthAt" TIMESTAMP(3),
"lastHealthOk" BOOLEAN,
"lastError" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "WooCommerceConnection_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "WooCommerceOrderLink" (
"id" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"connectionId" TEXT NOT NULL,
"wooOrderId" TEXT NOT NULL,
"wooOrderNumber" TEXT,
"invoiceId" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT '',
"total" DECIMAL(18,2) NOT NULL DEFAULT 0,
"currency" TEXT NOT NULL DEFAULT 'IRR',
"rawPayload" JSONB,
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "WooCommerceOrderLink_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "WooCommerceConnection_organizationId_enabled_idx" ON "WooCommerceConnection"("organizationId", "enabled");
-- CreateIndex
CREATE INDEX "WooCommerceOrderLink_organizationId_syncedAt_idx" ON "WooCommerceOrderLink"("organizationId", "syncedAt");
-- CreateIndex
CREATE INDEX "WooCommerceOrderLink_invoiceId_idx" ON "WooCommerceOrderLink"("invoiceId");
-- CreateIndex
CREATE UNIQUE INDEX "WooCommerceOrderLink_connectionId_wooOrderId_key" ON "WooCommerceOrderLink"("connectionId", "wooOrderId");
-- AddForeignKey
ALTER TABLE "WooCommerceConnection" ADD CONSTRAINT "WooCommerceConnection_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "WooCommerceOrderLink" ADD CONSTRAINT "WooCommerceOrderLink_connectionId_fkey" FOREIGN KEY ("connectionId") REFERENCES "WooCommerceConnection"("id") ON DELETE CASCADE ON UPDATE CASCADE;