polish the api route, response, health, cache, and metrics
This commit is contained in:
40
app/models/license_store.php
Normal file
40
app/models/license_store.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// app/models/license_store.php
|
||||
require_once __DIR__ . '/../db.php';
|
||||
|
||||
function license_upsert_from_verification(array $norm) {
|
||||
// $norm: [
|
||||
// 'key','source','plan','product_id','valid'=>bool,'expires_at'=>null|iso,'meta'=>array
|
||||
// ]
|
||||
$pdo = getPDO();
|
||||
|
||||
// 1) upsert into licenses
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO licenses
|
||||
(license_key, source, plan, product_id, status, expires_at, meta_json, last_verified_at, created_at, updated_at)
|
||||
VALUES
|
||||
(:k, :src, :plan, :pid, :status, :exp, :meta, NOW(), NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
source=:src, plan=:plan, product_id=:pid, status=:status,
|
||||
expires_at=:exp, meta_json=:meta, last_verified_at=NOW(), updated_at=NOW()
|
||||
");
|
||||
$stmt->execute([
|
||||
':k' => $norm['key'],
|
||||
':src' => $norm['source'],
|
||||
':plan' => $norm['plan'],
|
||||
':pid' => $norm['product_id'] ?? null,
|
||||
':status'=> $norm['valid'] ? 'active' : 'invalid',
|
||||
':exp' => $norm['expires_at'] ?? null,
|
||||
':meta' => json_encode($norm['meta'] ?? [], JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
// 2) Return row snapshot (minimal)
|
||||
return [
|
||||
'key' => $norm['key'],
|
||||
'source' => $norm['source'],
|
||||
'plan' => $norm['plan'],
|
||||
'status' => $norm['valid'] ? 'active' : 'invalid',
|
||||
'product_id' => $norm['product_id'] ?? null,
|
||||
'expires_at' => $norm['expires_at'] ?? null,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user