Search.../

makePlanPrimary( )

Marks a pricing plan as the primary pricing plan.

Description

The makePlanPrimary() function returns a Promise that resolves to the now primary pricing plan.

Only a single plan can be marked as a primary plan at any given time. If there is an existing plan marked as primary, calling makePlanPrimary() causes the existing primary plan to lose its primary status.

When viewing pricing plans on the site, the primary plan is highlighted with a customizable ribbon.

Admin Method

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

Syntax

function makePlanPrimary(_id: string): Promise<MakePlanPrimaryResponse>

makePlanPrimary Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the pricing plan to set as the primary plan.

Returns

Fulfilled - The primary plan.

Return Type:

Promise<
MakePlanPrimaryResponse
>
NAME
TYPE
DESCRIPTION
plan
Plan

Primary plan info.

Was this helpful?

Make a plan a primary plan (dashboard page code)

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2
3/* Sample _id value: '0b9a1993-c1ff-4952-9575-915b48d1a5e0' */
4
5export async function myMakePlanPrimaryFunction(_id) {
6 try {
7 const primaryPlan = await plans.makePlanPrimary(_id);
8
9 return primaryPlan;
10 } catch(error) {
11 console.error(error);
12 // Handle the error
13 }
14}
15
16/* Promise resolves to:
17 * {
18 * "_id": "b20feb39-a452-453e-96ee-01036adcd04e",
19 * "_createdDate": "2024-01-07T07:33:59.973Z",
20 * "_updatedDate": "2024-01-07T13:32:11.263Z",
21 * "allowFutureStartDate": false,
22 * "archived": false,
23 * "buyerCanCancel": true,
24 * "description": "Full feature enablement - lifetime plan",
25 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
26 * "hasOrders": false,
27 * "maxPurchasesPerBuyer": 0,
28 * "name": "Premium Plan - Lifetime Membership",
29 * "perks": {
30 * "values": [
31 * "Cloud drive and file upload services",
32 * "Unlimited video content access"
33 * ]
34 * },
35 * "pricing": {
36 * "price": {
37 * "currency": "EUR",
38 * "value": "1000"
39 * },
40 * "singlePaymentUnlimited": true
41 * },
42 * "primary": true,
43 * "public": true,
44 * "slug": "premium-plan-lifetime-membership",
45 * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement."
46 * }
47 */
Make a plan a primary plan (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample _id value: '0b9a1993-c1ff-4952-9575-915b48d1a5e0' */
6
7export const myMakePlanPrimaryFunction = webMethod(Permissions.Anyone, async (_id) => {
8 try {
9 const elevatedMakePlanPrimary = elevate(plans.makePlanPrimary);
10 const primaryPlan = await elevatedMakePlanPrimary(_id);
11
12 return primaryPlan;
13 } catch(error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Promise resolves to:
20 * {
21 * "_id": "b20feb39-a452-453e-96ee-01036adcd04e",
22 * "_createdDate": "2024-01-07T07:33:59.973Z",
23 * "_updatedDate": "2024-01-07T13:32:11.263Z",
24 * "allowFutureStartDate": false,
25 * "archived": false,
26 * "buyerCanCancel": true,
27 * "description": "Full feature enablement - lifetime plan",
28 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
29 * "hasOrders": false,
30 * "maxPurchasesPerBuyer": 0,
31 * "name": "Premium Plan - Lifetime Membership",
32 * "perks": {
33 * "values": [
34 * "Cloud drive and file upload services",
35 * "Unlimited video content access"
36 * ]
37 * },
38 * "pricing": {
39 * "price": {
40 * "currency": "EUR",
41 * "value": "1000"
42 * },
43 * "singlePaymentUnlimited": true
44 * },
45 * "primary": true,
46 * "public": true,
47 * "slug": "premium-plan-lifetime-membership",
48 * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement."
49 * }
50 */
51
Make a plan primary

Select a public plan from the dropdown to make it appear as a primary plan on the business site.

Copy Code
1/*************************************
2 * Backend code - plan-functions.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { plans } from 'wix-pricing-plans.v2';
7import { elevate } from 'wix-auth';
8
9const elevatedListPublicPlans = elevate(plans.listPublicPlans);
10const elevatedMakePlanPrimary = elevate(plans.makePlanPrimary);
11
12export const listPublicPlans = webMethod(Permissions.Anyone, async () => {
13 try {
14 const response = await elevatedListPublicPlans();
15 const plansList = response.plans;
16
17 return plansList;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22});
23
24export const makePlanPrimaryFunction = webMethod(Permissions.Anyone, async (_id) => {
25 try {
26 const primaryPlan = await elevatedMakePlanPrimary(_id);
27
28 return primaryPlan;
29 } catch (error) {
30 console.error(error);
31 // Handle the error
32 }
33});
34
35/*************
36 * Page code *
37 *************/
38
39import { listPublicPlans, makePlanPrimaryFunction } from 'backend/plan-functions.web';
40
41$w.onReady(function () {
42 populateDropdown();
43 $w('#plansList').onChange(async () => {
44 await makePlanPrimaryFunction(
45 $w('#plansList').value
46 )
47 });
48});
49
50async function populateDropdown() {
51 const plans = await listPublicPlans();
52 $w('#plansList').options = plans.map(item => ({
53 label: item.name,
54 value: item._id
55 })
56 )
57}