40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
<?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,
|
|
];
|
|
} |