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 all plans (dashboard page code)

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

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

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