Question:
From backend Velo code (a .jsw
module), I want to retrieve and inspect any “ACTIVE” subscription orders tied to a given memberId
so that I can conditionally enable site features for paying subscribers.
Product:
Wix Studio Editor / Velo
What are you trying to achieve:
I need to programmatically determine, from backend Velo code, whether a given site member has an active Pricing Plan subscription so that I can enable or restrict features (e.g., the “Connect” button) based on their subscription status.
What have you already tried:
- Installed and published the Paid Plans (Pricing Plans) app in Wix Studio.
- Created a backend file (
backend/userUtils.jsw
) and attempted multiple imports: import { orders } from "wix-pricing-plans-backend"
→orders
undefined /listOrders
not found.import { orders } from "wix-pricing-plans-v2"
→ module not found.import { orders } from "wix-pricing-plans.v2"
→orders
undefined /managementListOrders
not found.- Followed documentation examples (using
filter: [{ field:"memberId",… }]
,orderStatuses: ["Active"]
, and{ suppressAuth: true }
), but every call either threw “undefined” errors or returned an empty array despite an active subscription existing in the Dashboard.
// backend/userUtils.jsw
import wixData from “wix-data”;
// ← Import the V2 Pricing Plans package:
import wixPricingPlansV2 from “wix-pricing-plans.v2”;
/**
- Given a member’s email, returns an object:
- {
-
found: Boolean, // true if that email is a registered member
-
memberId: String|null, // the Wix Member ID (or null if not found)
-
hasActivePlan: Boolean // true if ≥1 ACTIVE subscription order exists
- }
*/
export async function getMemberWithActivePlanByEmail(email) {
console.log(“Looking up member by email:”, email);
// 1) Find the member record by loginEmail
let memberResult;
try {
memberResult = await wixData
.query(“Members/PrivateMembersData”)
.eq(“loginEmail”, email) // “loginEmail” is the correct field
.limit(1)
.find({
suppressAuth: true, // run as site owner
suppressHooks: true
});
} catch (err) {
console.error(“ Error querying Members/PrivateMembersData:”, err);
throw new Error(“Failed to query member by email”);
}
if (!memberResult.items.length) {
// No member with that email
console.log(“ No member found for:”, email);
return {
found: false,
memberId: null,
hasActivePlan: false
};
}
const member = memberResult.items[0];
const memberId = member._id;
console.log(“ Found member ID:”, memberId);
// 2) Use V2’s managementListOrders() to fetch Active subscription orders
let activeOrders = ;
try {
// The V2 call lives under wixPricingPlansV2.orders.managementListOrders
const listResult = await wixPricingPlansV2.orders.managementListOrders(
{
filter: [
{ field: “memberId”, operator: “eq”, value: memberId }
],
orderStatuses: [“Active”] // only active subscriptions
},
null, // no custom sort
null, // no custom pagination
{ suppressAuth: true } // run as site owner
);
// listResult.items is an array of matching orders
activeOrders = Array.isArray(listResult.items)
? listResult.items
: ;
console.log(“ Retrieved ACTIVE orders:”, activeOrders);
} catch (err) {
console.error(“ Error calling managementListOrders:”, err);
// If the Pricing Plans API fails, assume no active plan
return {
found: true,
memberId,
hasActivePlan: false
};
}
// 3) If activeOrders is non‐empty, the user has an ACTIVE subscription
const hasActivePlan = activeOrders.length > 0;
console.log(“ hasActivePlan =”, hasActivePlan, “for memberId:”, memberId);
return {
found: true,
memberId,
hasActivePlan
};
}
Additional information:
I got the error : Error calling managementListOrders: Cannot read properties of undefined (reading ‘orders’)