feat: add client self-service purchases and integration kit
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
5
backend/migrations/000016_client_purchases.down.sql
Normal file
5
backend/migrations/000016_client_purchases.down.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
DROP TABLE client_purchases;
|
||||
ALTER TABLE payment_orders DROP FOREIGN KEY fk_payment_plan_version, DROP COLUMN plan_version, DROP COLUMN plan_id;
|
||||
DROP TABLE purchase_credentials;
|
||||
DROP TABLE payment_plan_versions;
|
||||
DROP TABLE payment_plans;
|
||||
57
backend/migrations/000016_client_purchases.up.sql
Normal file
57
backend/migrations/000016_client_purchases.up.sql
Normal file
@@ -0,0 +1,57 @@
|
||||
-- Operator-applied only. Fixed days start at successful payment issuance (UTC, 24 hours/day).
|
||||
CREATE TABLE payment_plans (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
product_id BIGINT UNSIGNED NOT NULL,
|
||||
code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
name VARCHAR(190) NOT NULL,
|
||||
amount_cents BIGINT UNSIGNED NOT NULL,
|
||||
currency CHAR(3) NOT NULL DEFAULT 'CNY',
|
||||
license_days INT UNSIGNED NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
version BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
||||
UNIQUE KEY uq_plan_code(product_id,code),
|
||||
FOREIGN KEY(product_id) REFERENCES products(id)
|
||||
) ENGINE=InnoDB;
|
||||
CREATE TABLE payment_plan_versions (
|
||||
plan_id BIGINT UNSIGNED NOT NULL,
|
||||
version BIGINT UNSIGNED NOT NULL,
|
||||
product_id BIGINT UNSIGNED NOT NULL,
|
||||
code VARCHAR(64) NOT NULL,
|
||||
name VARCHAR(190) NOT NULL,
|
||||
amount_cents BIGINT UNSIGNED NOT NULL,
|
||||
currency CHAR(3) NOT NULL,
|
||||
license_days INT UNSIGNED NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
created_by BIGINT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY(plan_id,version),
|
||||
FOREIGN KEY(plan_id) REFERENCES payment_plans(id),
|
||||
FOREIGN KEY(created_by) REFERENCES admins(id)
|
||||
) ENGINE=InnoDB;
|
||||
CREATE TABLE purchase_credentials (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
token_hash BINARY(32) NOT NULL UNIQUE,
|
||||
customer_id BIGINT UNSIGNED NOT NULL,
|
||||
product_id BIGINT UNSIGNED NOT NULL,
|
||||
label VARCHAR(190) NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_by BIGINT UNSIGNED NOT NULL,
|
||||
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
FOREIGN KEY(customer_id) REFERENCES customers(id),
|
||||
FOREIGN KEY(product_id) REFERENCES products(id),
|
||||
FOREIGN KEY(created_by) REFERENCES admins(id)
|
||||
) ENGINE=InnoDB;
|
||||
ALTER TABLE payment_orders
|
||||
ADD COLUMN plan_id BIGINT UNSIGNED NULL,
|
||||
ADD COLUMN plan_version BIGINT UNSIGNED NULL,
|
||||
ADD CONSTRAINT fk_payment_plan_version FOREIGN KEY(plan_id,plan_version) REFERENCES payment_plan_versions(plan_id,version);
|
||||
CREATE TABLE client_purchases (
|
||||
order_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
credential_id BIGINT UNSIGNED NOT NULL,
|
||||
installation_id VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
request_fingerprint BINARY(32) NOT NULL,
|
||||
instance_id CHAR(36) NULL,
|
||||
UNIQUE KEY uq_client_purchase_key(credential_id,idempotency_key),
|
||||
FOREIGN KEY(order_id) REFERENCES offline_orders(id),
|
||||
FOREIGN KEY(credential_id) REFERENCES purchase_credentials(id)
|
||||
) ENGINE=InnoDB;
|
||||
Reference in New Issue
Block a user