2.5.4
Upgraded pro/extra access
This commit is contained in:
+36
-8
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
// ─── SunScope Extra — Restore Access ─────────────────────────────────────────
|
||||
// JSON endpoint for the in-app "Already subscribed? Restore access" modal.
|
||||
// The modal POSTs an email here and reads back {"active": bool, "error": str}.
|
||||
// Paste your Stripe SECRET key below (never the publishable key).
|
||||
// Swap sk_test_... for sk_live_... when you go live.
|
||||
// The modal POSTs an email here and reads back
|
||||
// {"active": bool, "mode": "subscription"|"payment"|null, "customer": string|null, "error": str}.
|
||||
|
||||
define('STRIPE_SECRET_KEY', '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');
|
||||
require __DIR__ . '/secrets.local.php';
|
||||
define('SUNSCOPE_URL', 'https://sunscope.net');
|
||||
|
||||
// Direct visits no longer get a page — the restore flow is an in-app modal
|
||||
@@ -15,8 +14,10 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = '';
|
||||
$isActive = false;
|
||||
$error = '';
|
||||
$isActive = false;
|
||||
$activeMode = null;
|
||||
$activeCust = null;
|
||||
|
||||
$email = trim(strtolower($_POST['email'] ?? ''));
|
||||
|
||||
@@ -44,7 +45,34 @@ if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
curl_close($ch2);
|
||||
|
||||
if (!empty($subs['data'])) {
|
||||
$isActive = true;
|
||||
$isActive = true;
|
||||
$activeMode = 'subscription';
|
||||
$activeCust = $customer['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
// No active subscription - check for a completed one-off payment
|
||||
// (the "pay what you like, once" option has no subscription at all).
|
||||
$ch3 = curl_init('https://api.stripe.com/v1/checkout/sessions?customer=' . $customer['id'] . '&limit=5');
|
||||
curl_setopt_array($ch3, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_USERPWD => STRIPE_SECRET_KEY . ':',
|
||||
]);
|
||||
$sessions = json_decode(curl_exec($ch3), true);
|
||||
curl_close($ch3);
|
||||
|
||||
$paidOneOff = false;
|
||||
foreach ($sessions['data'] ?? [] as $session) {
|
||||
if (($session['mode'] ?? '') === 'payment' && ($session['payment_status'] ?? '') === 'paid') {
|
||||
$paidOneOff = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($paidOneOff) {
|
||||
$isActive = true;
|
||||
$activeMode = 'payment';
|
||||
$activeCust = $customer['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -56,4 +84,4 @@ if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['active' => $isActive, 'error' => $error]);
|
||||
echo json_encode(['active' => $isActive, 'mode' => $activeMode, 'customer' => $activeCust, 'error' => $error]);
|
||||
|
||||
Reference in New Issue
Block a user