feat: add client self-service purchases and integration kit
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-15 17:33:52 +08:00
parent 68a2b4d892
commit cfcc9b386b
33 changed files with 2598 additions and 44 deletions

View File

@@ -2,8 +2,8 @@
"openapi": "3.0.3",
"info": {
"title": "License Platform Client API",
"version": "1.1.0",
"description": "Client-facing instance APIs. Update checks return signed update-v1 metadata; admin sessions are never client credentials. See protocol.md for canonical signature and trust-root rules."
"version": "1.2.0",
"description": "Client-facing instance APIs. Update checks return signed update-v1 metadata; admin sessions are never client credentials. See protocol.md for canonical signature and trust-root rules. Restricted Bearer purchase flow is documented in purchase.md."
},
"servers": [
{
@@ -395,6 +395,187 @@
}
}
}
},
"/api/v1/client/plans": {
"post": {
"operationId": "listClientPlans",
"summary": "List enabled fixed-day plans for bound product",
"security": [
{
"PurchaseBearer": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PurchaseInstallation"
}
}
}
},
"responses": {
"200": {
"description": "data envelope; consult purchase.md for recovery and trust rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"$ref": "#/components/schemas/ClientPlans"
}
}
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/api/v1/client/purchases": {
"post": {
"operationId": "createClientPurchase",
"summary": "Create or recover an idempotent purchase",
"security": [
{
"PurchaseBearer": []
}
],
"parameters": [
{
"$ref": "#/components/parameters/IdempotencyKey"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PurchaseRequest"
}
}
}
},
"responses": {
"200": {
"description": "data envelope; consult purchase.md for recovery and trust rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"$ref": "#/components/schemas/PurchaseOrder"
}
}
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/api/v1/client/purchases/status": {
"post": {
"operationId": "clientPurchaseStatus",
"summary": "Recover by order_no or idempotency_key for same installation",
"security": [
{
"PurchaseBearer": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PurchaseLookup"
}
}
}
},
"responses": {
"200": {
"description": "data envelope; consult purchase.md for recovery and trust rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"$ref": "#/components/schemas/PurchaseOrder"
}
}
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/api/v1/client/purchases/claim": {
"post": {
"operationId": "claimClientPurchase",
"summary": "Claim same issued instance credentials idempotently",
"security": [
{
"PurchaseBearer": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PurchaseClaim"
}
}
}
},
"responses": {
"200": {
"description": "data envelope; consult purchase.md for recovery and trust rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"$ref": "#/components/schemas/PurchaseCredentials"
}
}
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
}
}
}
},
"components": {
@@ -772,6 +953,273 @@
"type": "string"
}
}
},
"PurchaseInstallation": {
"type": "object",
"required": [
"installation_id"
],
"properties": {
"installation_id": {
"type": "string"
}
}
},
"PaymentPlan": {
"type": "object",
"required": [
"id",
"product_id",
"code",
"name",
"amount_cents",
"currency",
"license_days",
"enabled",
"version"
],
"properties": {
"id": {
"type": "integer",
"minimum": 1
},
"product_id": {
"type": "integer",
"minimum": 1
},
"code": {
"type": "string"
},
"name": {
"type": "string"
},
"amount_cents": {
"type": "integer",
"minimum": 1
},
"currency": {
"type": "string",
"enum": [
"CNY"
]
},
"license_days": {
"type": "integer",
"minimum": 1
},
"enabled": {
"type": "boolean"
},
"version": {
"type": "integer",
"minimum": 1
}
}
},
"ClientPlans": {
"type": "object",
"required": [
"plans",
"channels",
"license_duration",
"purchase_mode"
],
"properties": {
"plans": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PaymentPlan"
}
},
"channels": {
"type": "array",
"items": {
"type": "string",
"enum": [
"alipay",
"wechat"
]
}
},
"license_duration": {
"type": "string",
"enum": [
"fixed_days_from_payment"
]
},
"purchase_mode": {
"type": "string",
"enum": [
"new_purchase"
]
},
"customer_setup": {
"type": "string"
}
}
},
"PurchaseRequest": {
"type": "object",
"required": [
"plan_id",
"plan_version",
"installation_id",
"channel"
],
"properties": {
"plan_id": {
"type": "integer",
"minimum": 1
},
"plan_version": {
"type": "integer",
"minimum": 1
},
"installation_id": {
"type": "string"
},
"channel": {
"type": "string",
"enum": [
"alipay",
"wechat"
]
}
}
},
"PurchaseLookup": {
"type": "object",
"required": [
"installation_id"
],
"description": "Provide either order_no or original idempotency_key",
"properties": {
"installation_id": {
"type": "string"
},
"order_no": {
"type": "string"
},
"idempotency_key": {
"type": "string"
}
}
},
"PurchaseClaim": {
"type": "object",
"required": [
"installation_id",
"order_no"
],
"properties": {
"installation_id": {
"type": "string"
},
"order_no": {
"type": "string"
}
}
},
"PurchaseOrder": {
"type": "object",
"required": [
"order_no",
"status",
"order_status",
"code_url",
"qr_expired",
"expires_at",
"amount_cents",
"currency",
"license_days",
"channel"
],
"properties": {
"order_no": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"created",
"paid"
]
},
"order_status": {
"type": "string",
"enum": [
"pending_payment",
"paid",
"issued"
]
},
"code_url": {
"type": "string"
},
"qr_expired": {
"type": "boolean",
"description": "QR display expiry only; not proof of channel closure"
},
"expires_at": {
"type": "string",
"format": "date-time"
},
"amount_cents": {
"type": "integer",
"minimum": 1
},
"currency": {
"type": "string",
"enum": [
"CNY"
]
},
"license_days": {
"type": "integer",
"minimum": 1
},
"channel": {
"type": "string",
"enum": [
"alipay",
"wechat"
]
}
}
},
"PurchaseCredentials": {
"type": "object",
"required": [
"instance_id",
"secret",
"license_key",
"license_id"
],
"properties": {
"instance_id": {
"type": "string",
"format": "uuid"
},
"secret": {
"type": "string",
"format": "password"
},
"license_key": {
"type": "string",
"format": "password"
},
"license_id": {
"type": "integer",
"minimum": 1
}
}
}
},
"securitySchemes": {
"PurchaseBearer": {
"type": "http",
"scheme": "bearer",
"description": "Admin-issued 32-random-byte purchase credential, restricted to an existing customer/product; never an admin session"
}
}
}