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.
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 of the pricing plan to set as the primary plan.
Returns
Fulfilled - The primary plan.
Return Type:
NAME
TYPE
DESCRIPTION
Primary plan info.
Was this helpful?
1import { plans } from 'wix-pricing-plans.v2';23/* Sample _id value: '0b9a1993-c1ff-4952-9575-915b48d1a5e0' */45export async function myMakePlanPrimaryFunction(_id) {6 try {7 const primaryPlan = await plans.makePlanPrimary(_id);89 return primaryPlan;10 } catch(error) {11 console.error(error);12 // Handle the error13 }14}1516/* 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": true41 * },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 */
1import { Permissions, webMethod } from 'wix-web-module';2import { plans } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '0b9a1993-c1ff-4952-9575-915b48d1a5e0' */67export const myMakePlanPrimaryFunction = webMethod(Permissions.Anyone, async (_id) => {8 try {9 const elevatedMakePlanPrimary = elevate(plans.makePlanPrimary);10 const primaryPlan = await elevatedMakePlanPrimary(_id);1112 return primaryPlan;13 } catch(error) {14 console.error(error);15 // Handle the error16 }17});1819/* 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": true44 * },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
Select a public plan from the dropdown to make it appear as a primary plan on the business site.
1/*************************************2 * Backend code - plan-functions.web.js *3 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { plans } from 'wix-pricing-plans.v2';7import { elevate } from 'wix-auth';89const elevatedListPublicPlans = elevate(plans.listPublicPlans);10const elevatedMakePlanPrimary = elevate(plans.makePlanPrimary);1112export const listPublicPlans = webMethod(Permissions.Anyone, async () => {13 try {14 const response = await elevatedListPublicPlans();15 const plansList = response.plans;1617 return plansList;18 } catch (error) {19 console.error(error);20 // Handle the error21 }22});2324export const makePlanPrimaryFunction = webMethod(Permissions.Anyone, async (_id) => {25 try {26 const primaryPlan = await elevatedMakePlanPrimary(_id);2728 return primaryPlan;29 } catch (error) {30 console.error(error);31 // Handle the error32 }33});3435/*************36 * Page code *37 *************/3839import { listPublicPlans, makePlanPrimaryFunction } from 'backend/plan-functions.web';4041$w.onReady(function () {42 populateDropdown();43 $w('#plansList').onChange(async () => {44 await makePlanPrimaryFunction(45 $w('#plansList').value46 )47 });48});4950async function populateDropdown() {51 const plans = await listPublicPlans();52 $w('#plansList').options = plans.map(item => ({53 label: item.name,54 value: item._id55 })56 )57}