Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions api/subscriptions/get_subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
This API Endpoint accepts both POST and GET requests.
It receives the following parameters:
- member: comma-separated IDs of the members to filter (integer) default null.
- member_email: the email of a user to filter subscriptions (string) default null. Admin only (userId == 1).
- category: the ID of the category to filter (integer) default null.
- payment_method: the ID of the payment method to filter (integer) default null.
- state: the state of the subscription to filter (boolean) default null [0 - active, 1 - inactive].
- disabled_to_bottom: whether to sort the inactive subscriptions to the bottom (boolean) default false.
- sort: the sorting method (string) default next_payment ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive', 'alphanumeric'].
- convert_currency: whether to convert to the main currency (boolean) default false.
- api_key: the API key of the user.
- image_base64: when set to 1, return logo as a base64 data URI (boolean) default false.

It returns a JSON object with the following properties:
- success: whether the request was successful (boolean).
Expand Down Expand Up @@ -142,6 +144,43 @@ function getPriceConverted($price, $currency, $database)
$userId = $user['id'];
$userCurrencyId = $user['main_currency'];

// -------------------------------------------------------------------------
// Handle member_email parameter (admin only)
// -------------------------------------------------------------------------
$targetUserId = $userId; // By default, filter on the calling user

Comment thread
ellite marked this conversation as resolved.
if (isset($_REQUEST['member_email']) && $_REQUEST['member_email'] !== '') {
// Only admin (userId == 1) is allowed to use this parameter
if ($userId != 1) {
$response = [
"success" => false,
"title" => "Denied. Only admin can filter by member_email"
];
echo json_encode($response);
exit;
}

$memberEmail = $_REQUEST['member_email'];

$sql = "SELECT id FROM user WHERE email = :email LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->bindValue(':email', $memberEmail);
$result = $stmt->execute();
$targetUser = $result->fetchArray(SQLITE3_ASSOC);
Comment thread
ellite marked this conversation as resolved.

if (!$targetUser) {
$response = [
"success" => false,
"title" => "No user found with the provided email"
];
echo json_encode($response);
exit;
}

$targetUserId = $targetUser['id'];
}
// -------------------------------------------------------------------------

$allUserSubscription = isset($_REQUEST['all-user-subscription']) ? $_REQUEST['all-user-subscription'] : null;
if ($allUserSubscription == 1 && $userId != 1) {
$response = [
Expand Down Expand Up @@ -217,10 +256,12 @@ function getPriceConverted($price, $currency, $database)
// Construction of the main SQL Query
$params = [];
if ($allUserSubscription == 1 && $userId == 1) {
// all-user-subscription: return all subscriptions regardless of user
$sql = "SELECT * FROM subscriptions";
} else {
// Filter by targetUserId (either the caller, or the user resolved from member_email)
$sql = "SELECT * FROM subscriptions WHERE user_id = :userId";
$params[':userId'] = $userId;
$params[':userId'] = $targetUserId;
}
Comment thread
ellite marked this conversation as resolved.

if (isset($_REQUEST['member'])) {
Expand Down Expand Up @@ -292,13 +333,25 @@ function getPriceConverted($price, $currency, $database)
}
}
$subscriptionsToReturn = array();
$imageBase64 = isset($_REQUEST['image_base64']) && $_REQUEST['image_base64'] == 1;
foreach ($subscriptions as $subscription) {
$subscriptionToReturn = $subscription;
if (isset($_REQUEST['convert_currency']) && $_REQUEST['convert_currency'] === 'true' && $canConvertCurrency && $subscription['currency_id'] != $userCurrencyId) {
$subscriptionToReturn['price'] = getPriceConverted($subscription['price'], $subscription['currency_id'], $db);
} else {
$subscriptionToReturn['price'] = $subscription['price'];
}
if ($imageBase64 && !empty($subscription['logo'])) {
$logoPath = __DIR__ . '/../../images/uploads/logos/' . $subscription['logo'];
if (is_file($logoPath)) {
$logoContents = file_get_contents($logoPath);
if ($logoContents !== false) {
$extension = strtolower(pathinfo($logoPath, PATHINFO_EXTENSION));
$mime = ($extension === 'svg') ? 'image/svg+xml' : 'image/' . ($extension ?: 'png');
$subscriptionToReturn['logo'] = 'data:' . $mime . ';base64,' . base64_encode($logoContents);
}
}
}
$subscriptionToReturn['category_name'] = isset($categories[$subscription['category_id']]) ? $categories[$subscription['category_id']] : 'No category';
$subscriptionToReturn['payer_user_name'] = isset($members[$subscription['payer_user_id']]) ? $members[$subscription['payer_user_id']] : 'Unknown member';
$subscriptionToReturn['payment_method_name'] = isset($paymentMethods[$subscription['payment_method_id']]) ? $paymentMethods[$subscription['payment_method_id']] : 'Unknown payment method';
Expand All @@ -307,7 +360,7 @@ function getPriceConverted($price, $currency, $database)

$response = [
"success" => true,
"title" => "subscriptions",
"title" => "subscriptions3",
Copy link
Copy Markdown
Owner

@ellite ellite Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3?

"subscriptions" => $subscriptionsToReturn,
"notes" => []
];
Expand Down
2 changes: 2 additions & 0 deletions local-dev/.gitignore
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
images/
db/
15 changes: 15 additions & 0 deletions local-dev/docker-compose-dev.yaml
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
wallos:
container_name: wallos-dev
image: wallos-local:latest
build:
context: ../
ports:
- "8282:80/tcp"
environment:
TZ: 'Europe/Paris'
# Volumes store your data between container upgrades
volumes:
- './db:/var/www/html/db'
- './images/uploads/logos:/var/www/html/images/uploads/logos'
restart: unless-stopped
Loading