Add monetization spine + Build Your Own Case (Min Sak)
- Stripe: StripeClient.php, checkout/portal/webhook endpoints, idempotent event handling - FreeTier: tier-aware credits (free/light/pro/pro_plus), bonus_balance, hourly caps per tier - pricing.php + billing.php: 4-tier cards, 3 topups, Customer Portal, balance breakdown - Min Sak: CaseStore.php, AzureDocIntelligence.php, AzureSearchAdmin.php — per-user hybrid RAG - api/case/: upload, list, delete, ingest-callback (HMAC-auth'd from n8n) - award-survey-credits: inter-site HMAC endpoint for dobetternorge.no survey bonus - dashboard.php: tier badge, balance breakdown card, Min Sak CTA, survey CTA - KorrespondAgent + all 3 other agents: use_my_case toggle wired to dbnToolsCaseContext() - bootstrap.php: dbnToolsCaseContext(), dbnToolsIntersiteSecret(), dbnToolsCurrentTier() Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../includes/bootstrap.php';
|
||||
require_once __DIR__ . '/../includes/StripeClient.php';
|
||||
require_once __DIR__ . '/../includes/FreeTier.php';
|
||||
|
||||
dbnToolsRequireMethod('POST');
|
||||
dbnToolsRequireAuth();
|
||||
|
||||
$user = dbnToolsAuthenticatedUser();
|
||||
$userId = (int)($user['user_id'] ?? 0);
|
||||
if ($userId <= 0) {
|
||||
dbnToolsError('User session missing user_id.', 401, 'bad_session');
|
||||
}
|
||||
|
||||
$row = FreeTier::row($userId);
|
||||
$customerId = (string)($row['stripe_customer_id'] ?? '');
|
||||
if ($customerId === '') {
|
||||
// No Stripe customer yet — happens if user never checked out.
|
||||
dbnToolsError('No Stripe customer on record. Subscribe first.', 400, 'no_customer');
|
||||
}
|
||||
|
||||
try {
|
||||
$stripe = new StripeClient();
|
||||
$baseUrl = (dbnToolsIsHttps() ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'tools.dobetternorge.no');
|
||||
$session = $stripe->createPortalSession($customerId, $baseUrl . '/billing.php');
|
||||
$url = (string)($session['url'] ?? '');
|
||||
if ($url === '') {
|
||||
dbnToolsError('Stripe did not return a portal URL.', 502, 'stripe_no_url');
|
||||
}
|
||||
dbnToolsRespond(['ok' => true, 'url' => $url]);
|
||||
} catch (Throwable $e) {
|
||||
error_log('[stripe-portal] ' . $e->getMessage());
|
||||
dbnToolsError('Could not open billing portal: ' . $e->getMessage(), 500, 'stripe_failed');
|
||||
}
|
||||
Reference in New Issue
Block a user