curl --request POST \
--url https://api.example.com/api/check-expiry \
--header 'Content-Type: application/json' \
--data '
{
"saas_key": "<string>",
"domain": "<string>"
}
'{
"error": "<string>"
}Verify if a user’s subscription is active or expired
curl --request POST \
--url https://api.example.com/api/check-expiry \
--header 'Content-Type: application/json' \
--data '
{
"saas_key": "<string>",
"domain": "<string>"
}
'{
"error": "<string>"
}POST /api/check-expiry
check.expiry middleware.
SAAS_KEYcurl -X POST "https://your-domain.com/api/check-expiry" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"saas_key": "YOUR_SAAS_KEY",
"domain": "customer-domain.com"
}'
YES
| Response | Description |
|---|---|
YES | Subscription is active (end_at is in the future) |
NO | Subscription has expired (end_at is in the past) |
| Status Code | Description |
|---|---|
| 200 | Success - Returns YES or NO |
| 401 | Unauthorized - Invalid or missing saas_key |
Validate SaaS Key
saas_key matches the environment variable SAAS_KEYTrim Domain
trimDomain() helper function to normalize ittrimDomain() functionnow() for accurate timezone handlingsaas_key must match the SAAS_KEY environment variable exactly. Keep this key secure and never expose it in client-side code.<?php
function check_subscription_status($domain) {
$response = wp_remote_post('https://your-domain.com/api/check-expiry', [
'body' => json_encode([
'saas_key' => env('SAAS_KEY'),
'domain' => $domain
]),
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
]);
if (is_wp_error($response)) {
return false;
}
$result = wp_remote_retrieve_body($response);
return $result === 'YES';
}
// Usage
if (check_subscription_status('customer-domain.com')) {
// Allow access to feature
echo "Welcome! Your subscription is active.";
} else {
// Deny access
echo "Your subscription has expired. Please renew.";
}
// Express.js middleware example
async function checkSubscription(req, res, next) {
const domain = req.user.domain;
try {
const response = await fetch('https://your-domain.com/api/check-expiry', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
saas_key: process.env.SAAS_KEY,
domain: domain
})
});
const result = await response.text();
if (result === 'YES') {
next(); // Subscription active, proceed
} else {
res.status(403).json({
error: 'Subscription expired',
message: 'Please renew your subscription to continue'
});
}
} catch (error) {
res.status(500).json({ error: 'Failed to verify subscription' });
}
}
// Use in routes
app.get('/api/protected-resource', checkSubscription, (req, res) => {
res.json({ data: 'Protected resource' });
});
import requests
from datetime import datetime
def check_all_subscriptions(domains):
"""Check expiry status for multiple domains"""
results = []
for domain in domains:
response = requests.post(
'https://your-domain.com/api/check-expiry',
json={
'saas_key': 'YOUR_SAAS_KEY',
'domain': domain
}
)
is_active = response.text == 'YES'
results.append({
'domain': domain,
'active': is_active,
'checked_at': datetime.now().isoformat()
})
return results
# Usage: Check multiple customer subscriptions
domains = ['customer1.com', 'customer2.com', 'customer3.com']
statuses = check_all_subscriptions(domains)
for status in statuses:
print(f"{status['domain']}: {'Active' if status['active'] else 'Expired'}")