Search.../

listPlans( )

Retrieves a list of pricing plans.

Description

The listPlans() function returns a Promise that resolves to a list of up to 100 pricing plans. This includes public, hidden, and archived plans.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listPlans(options: ListPlansOptions): Promise<ListPlansResponse>

listPlans Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListPlansOptions

Options for filtering and paging the list of plans.

Returns

Fulfilled - List of plans that match the given criteria.

Return Type:

Promise<
ListPlansResponse
>
NAME
TYPE
DESCRIPTION
pagingMetadata
PagingMetadataV2

Details on the paged set of pricing plans returned.

plans
Array<
Plan
>

List of all public and hidden pricing plans.

Was this helpful?

List plans

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4export async function myListPlansFunction() {
5 try {
6 const elevatedListPlans = elevate(plans.listPlans);
7 const plansList = await elevatedListPlans();
8
9 return plansList;
10 } catch (error) {
11 console.error(error);
12 // Handle the error
13 }
14}
15
16/* Promise resolves to:
17 * {
18 * "pagingMetadata": {
19 * "count": 4,
20 * "offset": 0,
21 * "total": 4
22 * },
23 * "plans": [
24 * {
25 * "_createdDate": "2024-01-08T14:33:12.209Z",
26 * "_id": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990",
27 * "_updatedDate": "2024-01-08T14:33:12.209Z",
28 * "allowFutureStartDate": false,
29 * "archived": false,
30 * "buyerCanCancel": true,
31 * "description": "The value plan",
32 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
33 * "hasOrders": false,
34 * "maxPurchasesPerBuyer": 1,
35 * "name": "Silver Membership - Monthly",
36 * "perks": {
37 * "values": [
38 * "Full site access",
39 * "Full video access",
40 * "Consultation booking"
41 * ]
42 * },
43 * "pricing": {
44 * "cycleCount": 0,
45 * "cycleDuration": {
46 * "count": 1,
47 * "unit": "MONTH"
48 * },
49 * "freeTrialDays": 14,
50 * "price": {
51 * "currency": "EUR",
52 * "value": "100"
53 * },
54 * "subscription": {
55 * "cycleCount": 0,
56 * "cycleDuration": {
57 * "count": 1,
58 * "unit": "MONTH"
59 * }
60 * }
61 * },
62 * "primary": false,
63 * "public": true,
64 * "slug": "silver-membership-monthly",
65 * "termsAndConditions": ""
66 * },
67 * {
68 * "_createdDate": "2024-01-07T07:33:59.973Z",
69 * "_id": "b20feb39-a452-453e-96ee-01036adcd04e",
70 * "_updatedDate": "2024-01-09T09:08:05.665Z",
71 * "allowFutureStartDate": false,
72 * "archived": false,
73 * "buyerCanCancel": true,
74 * "description": "Full feature enablement - lifetime plan",
75 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
76 * "hasOrders": false,
77 * "maxPurchasesPerBuyer": 0,
78 * "name": "Premium Plan - Lifetime Membership",
79 * "perks": {
80 * "values": [
81 * "Cloud drive and file upload services",
82 * "Unlimited video content access"
83 * ]
84 * },
85 * "pricing": {
86 * "price": {
87 * "currency": "EUR",
88 * "value": "1000"
89 * },
90 * "singlePaymentUnlimited": true
91 * },
92 * "primary": false,
93 * "public": true,
94 * "slug": "premium-plan-lifetime-membership",
95 * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement."
96 * },
97 * {
98 * "_createdDate": "2024-01-04T12:51:42.249Z",
99 * "_id": "025a0d1f-7076-4e27-9696-4a67075dc2aa",
100 * "_updatedDate": "2024-01-07T12:53:53.562Z",
101 * "allowFutureStartDate": true,
102 * "archived": false,
103 * "buyerCanCancel": true,
104 * "description": "Bronze membership to the MyGame World of Online Gaming",
105 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
106 * "hasOrders": false,
107 * "maxPurchasesPerBuyer": 1,
108 * "name": "Bronze Plan",
109 * "perks": {
110 * "values": [
111 * "Multiplayer",
112 * "Multiple devices",
113 * "No ads",
114 * "Unlimited access"
115 * ]
116 * },
117 * "pricing": {
118 * "price": {
119 * "currency": "USD",
120 * "value": "10.00"
121 * },
122 * "singlePaymentUnlimited": true
123 * },
124 * "primary": false,
125 * "public": false,
126 * "slug": "bronze-plan-1",
127 * "termsAndConditions": "No sharing access with others!"
128 * }
129 * ]
130 * }
131 */
List plans with options

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample options value:
5 * {
6 * public: 'HIDDEN',
7 * archived: 'ARCHIVED_AND_ACTIVE'
8 * }
9 */
10
11export async function myListPlansFunction(options) {
12 try {
13 const elevatedListPlans = elevate(plans.listPlans);
14 const plansList = await elevatedListPlans(options);
15
16 return plansList;
17 } catch (error) {
18 console.error(error);
19 // Handle the error
20 }
21}
22
23/* Promise resolves to:
24 * {
25 * "pagingMetadata": {
26 * "count": 4,
27 * "offset": 0,
28 * "total": 4
29 * },
30 * "plans": [
31 * {
32 * "_createdDate": "2023-12-31T11:23:01.664Z",
33 * "_id": "1421abaa-44c7-42ae-8a75-960fe7a8aa55",
34 * "_updatedDate": "2024-01-08T11:24:18.561Z",
35 * "allowFutureStartDate": false,
36 * "archived": true,
37 * "buyerCanCancel": true,
38 * "description": "Free Plan",
39 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
40 * "hasOrders": false,
41 * "maxPurchasesPerBuyer": 0,
42 * "name": "Basic",
43 * "perks": {
44 * "values": []
45 * },
46 * "pricing": {
47 * "price": {
48 * "currency": "EUR",
49 * "value": "0"
50 * },
51 * "singlePaymentForDuration": {
52 * "count": 3,
53 * "unit": "MONTH"
54 * }
55 * },
56 * "primary": false,
57 * "public": false,
58 * "slug": "basic",
59 * "termsAndConditions": "After 90 day free trial ends, your plan will end and you will need to purchase a paid plan."
60 * },
61 * {
62 * "_createdDate": "2024-01-04T12:28:21.004Z",
63 * "_id": "97033d3e-b0ad-47d7-932c-197371aab9ec",
64 * "_updatedDate": "2024-01-04T14:11:39.860Z",
65 * "allowFutureStartDate": true,
66 * "archived": true,
67 * "buyerCanCancel": true,
68 * "description": "Gold membership to the MyGame World of Online Gaming",
69 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
70 * "hasOrders": false,
71 * "maxPurchasesPerBuyer": 1,
72 * "name": "Gold",
73 * "perks": {
74 * "values": [
75 * "Multiplayer",
76 * "Multiple devices",
77 * "No ads",
78 * "Unlimited access"
79 * ]
80 * },
81 * "pricing": {
82 * "price": {
83 * "currency": "USD",
84 * "value": "10.00"
85 * },
86 * "singlePaymentUnlimited": true
87 * },
88 * "primary": false,
89 * "public": false,
90 * "slug": "gold",
91 * "termsAndConditions": "No sharing access with others!"
92 * },
93 * {
94 * "_createdDate": "2024-01-04T12:51:42.249Z",
95 * "_id": "025a0d1f-7076-4e27-9696-4a67075dc2aa",
96 * "_updatedDate": "2024-01-07T12:53:53.562Z",
97 * "allowFutureStartDate": true,
98 * "archived": false,
99 * "buyerCanCancel": true,
100 * "description": "Bronze membership to the MyGame World of Online Gaming",
101 * "hasOrders": false,
102 * "maxPurchasesPerBuyer": 1,
103 * "name": "Bronze Plan",
104 * "perks": {
105 * "values": [
106 * "Multiplayer",
107 * "Multiple devices",
108 * "No ads",
109 * "Unlimited access"
110 * ]
111 * },
112 * "pricing": {
113 * "price": {
114 * "currency": "USD",
115 * "value": "10.00"
116 * },
117 * "singlePaymentUnlimited": true
118 * },
119 * "primary": false,
120 * "public": false,
121 * "slug": "bronze-plan-1",
122 * "termsAndConditions": "No sharing access with others!"
123 * },
124 * {
125 * "_createdDate": "2024-01-07T07:13:04.076Z",
126 * "_id": "0b9a1993-c1ff-4952-9575-915b48d1a5e0",
127 * "_updatedDate": "2024-01-09T12:32:26.807Z",
128 * "allowFutureStartDate": false,
129 * "archived": true,
130 * "buyerCanCancel": true,
131 * "description": "For new users just getting the feel of the product",
132 * "hasOrders": false,
133 * "maxPurchasesPerBuyer": 0,
134 * "name": "Simple Plan",
135 * "perks": {
136 * "values": [
137 * "Login member access",
138 * "Access to real-time articles",
139 * "Included in mailing list"
140 * ]
141 * },
142 * "pricing": {
143 * "price": {
144 * "currency": "USD",
145 * "value": "3"
146 * },
147 * "singlePaymentForDuration": {
148 * "count": 12,
149 * "unit": "MONTH"
150 * }
151 * },
152 * "primary": false,
153 * "public": false,
154 * "slug": "simple-plan",
155 * "termsAndConditions": "I agree to refrain from sharing any of the exclusive content with non-members"
156 * }
157 * ]
158 * }
159 */
Duplicate a plan

The populatePlansDropdown function retrieves all plans and then populates them into the #plansDropdown. The #plansDropdown and #clonePlanBtn are set to disabled by default.

Copy Code
1/*************************************
2 * Backend code - plan-functions.jsw *
3 *************************************/
4
5import { plans } from 'wix-pricing-plans.v2';
6import { elevate } from 'wix-auth';
7
8const elevatedListPlans = elevate(plans.listPlans);
9const elevatedGetPlan = elevate(plans.getPlan);
10const elevatedCreatePlan = elevate(plans.createPlan);
11
12export async function listPlans() {
13 try {
14 const response = await elevatedListPlans();
15 const allPlans = response.plans;
16
17 return allPlans;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22}
23
24export async function getPlan(planId) {
25 try {
26 const selectedPlan = await elevatedGetPlan(planId);
27
28 return selectedPlan;
29 } catch (error) {
30 console.error(error);
31 // Handle the error
32 }
33}
34
35export async function createPlan(plan) {
36 try {
37 const newPlan = await elevatedCreatePlan(plan);
38
39 return newPlan;
40 } catch (error) {
41 console.error(error);
42 // Handle the error
43 }
44}
45
46
47/*************
48 * Page code *
49 *************/
50
51import { listPlans, getPlan, createPlan } from 'backend/plan-functions';
52$w.onReady(async function () {
53 $w('#plansDropdown').disable();
54 $w('#clonePlanBtn').disable();
55 populatePlansDropdown();
56
57 let selectedPlan;
58
59 $w('#plansDropdown').onChange(async () => {
60 const planId = $w('#plansDropdown').value;
61 selectedPlan = await getPlan(planId);
62
63 // Set default value for the new plan name
64 $w('#planName').value = `${selectedPlan.name}-duplicate`
65 $w('#clonePlanBtn').enable();
66 });
67
68 $w('#clonePlanBtn').onClick(async () => {
69 const newPlan = selectedPlan;
70 // Use inputs to set the new plan name and price
71 newPlan.name = $w('#planName').value;
72 newPlan.pricing.price.value = $w('#price').value;
73
74 await createPlan(newPlan);
75 });
76});
77
78async function populatePlansDropdown() {
79 const plans = await listPlans();
80 $w('#plansDropdown').options = plans.map((plan) => {
81 return {
82 label: plan.name,
83 value: plan._id
84 }
85 });
86 $w('#plansDropdown').enable();
87}