getPlan( )
Retrieves a pricing plan by the specified ID.
Description
The getPlan()
function returns a Promise that resolves to a plan whose ID matched the specified ID.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function getPlan(_id: string): Promise<Plan>
getPlan Parameters
NAME
TYPE
DESCRIPTION
Plan ID.
Returns
Fulfilled - The retrieved plan's information.
Return Type:
NAME
TYPE
DESCRIPTION
Date plan was created.
Plan ID.
Date plan was last updated.
Whether the buyer can start the plan at a later date.
Default: false
.
Whether the plan is archived. Archived plans are not visible and can't be purchased anymore, but existing purchases remain in effect.
Whether the buyer is allowed to cancel their plan. If false
, calling the cancelOrder()
function returns an error.
Default: false
.
Plan description.
ID of the form associated with the plan at checkout.
Whether the plan has any orders (including pending and unpaid orders).
Number of times the same buyer can purchase the plan. Currently limited to support:
- Empty value or a value of
0
, meaning no limitation. - Value of
1
, meaning limited to one purchase per buyer.
Plan name.
List of text strings that promote what is included with this plan.
For example, "Plenty of parking" or "Free gift on your birthday".
Plan price, payment schedule, and expiration.
Whether the plan is marked as primary. If true
, the plan is highlighted on the site with a custom ribbon.
Default: false
.
Whether the plan is public (visible to site visitors and members).
URL-friendly version of plan name. Unique across all plans in the same site.
Any terms and conditions that apply to the plan. This information will be displayed during checkout.
Was this helpful?
1import { plans} from 'wix-pricing-plans.v2';23/* Sample _id value: '838f2c9d-c8d0-4799-a10a-e2f23849db10' */45export async function myGetPlanFunction(_id) {6 try {7 const myPlan = await plans.getPlan(_id);89 return myPlan;10 } catch (error) {11 console.error(error);12 // Handle the error13 }14}1516/* Promise resolves to:17 * {18 * "_createdDate": "2024-01-07T07:28:42.863Z",19 * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10",20 * "_updatedDate": "2024-01-07T08:36:07.520Z",21 * "allowFutureStartDate": false,22 * "archived": false,23 * "buyerCanCancel": true,24 * "description": "Complete with all features. One month free trial.",25 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",26 * "hasOrders": false,27 * "maxPurchasesPerBuyer": 0,28 * "name": "Premium Plan - annual - 30 day trial",29 * "perks": {30 * "values": [31 * "Unlimited video library streaming access",32 * "File sharing enabled for all channels"33 * ]34 * },35 * "pricing": {36 * "freeTrialDays": 30,37 * "price": {38 * "currency": "EUR",39 * "value": "500"40 * },41 * "subscription": {42 * "cycleCount": 2,43 * "cycleDuration": {44 * "count": 1,45 * "unit": "YEAR"46 * }47 * }48 * },49 * "primary": false,50 * "public": true,51 * "slug": "premium-plan-annual-30-day-trial-1",52 * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies."53 * }54 */
1import { Permissions, webMethod } from 'wix-web-module';2import { plans } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '838f2c9d-c8d0-4799-a10a-e2f23849db10' */67export const myGetPlanFunction = webMethod(Permissions.Anyone, async (_id) => {8 try {9 const elevatedGetPlan = elevate(plans.getPlan);10 const myPlan = await elevatedGetPlan(_id);1112 return myPlan;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/* Promise resolves to:20 * {21 * "_createdDate": "2024-01-07T07:28:42.863Z",22 * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10",23 * "_updatedDate": "2024-01-07T08:36:07.520Z",24 * "allowFutureStartDate": false,25 * "archived": false,26 * "buyerCanCancel": true,27 * "description": "Complete with all features. One month free trial.",28 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",29 * "hasOrders": false,30 * "maxPurchasesPerBuyer": 0,31 * "name": "Premium Plan - annual - 30 day trial",32 * "perks": {33 * "values": [34 * "Unlimited video library streaming access",35 * "File sharing enabled for all channels"36 * ]37 * },38 * "pricing": {39 * "freeTrialDays": 30,40 * "price": {41 * "currency": "EUR",42 * "value": "500"43 * },44 * "subscription": {45 * "cycleCount": 2,46 * "cycleDuration": {47 * "count": 1,48 * "unit": "YEAR"49 * }50 * }51 * },52 * "primary": false,53 * "public": true,54 * "slug": "premium-plan-annual-30-day-trial-1",55 * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies."56 * }57 */
The populatePlansDropdown
function retrieves all plans and then populates them into the #plansDropdown
. The #plansDropdown
and #clonePlanBtn
are set to disabled
by default.
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 elevatedListPlans = elevate(plans.listPlans);10const elevatedGetPlan = elevate(plans.getPlan);11const elevatedCreatePlan = elevate(plans.createPlan);1213export const listPlans = webMethod(Permissions.Anyone, async () => {14 try {15 const response = await elevatedListPlans();16 const allPlans = response.plans;1718 return allPlans;19 } catch (error) {20 console.error(error);21 // Handle the error22 }23});2425export const getPlan = webMethod(Permissions.Anyone, async (planId) => {26 try {27 const selectedPlan = await elevatedGetPlan(planId);2829 return selectedPlan;30 } catch (error) {31 console.error(error);32 // Handle the error33 }34});3536export const createPlan = webMethod(Permissions.Anyone, async (plan) => {37 try {38 const newPlan = await elevatedCreatePlan(plan);3940 return newPlan;41 } catch (error) {42 console.error(error);43 // Handle the error44 }45});464748/*************49 * Page code *50 *************/5152import { listPlans, getPlan, createPlan } from 'backend/plan-functions.web';53$w.onReady(async function () {54 $w('#plansDropdown').disable();55 $w('#clonePlanBtn').disable();56 populatePlansDropdown();5758 let selectedPlan;5960 $w('#plansDropdown').onChange(async () => {61 const planId = $w('#plansDropdown').value;62 selectedPlan = await getPlan(planId);6364 // Set default value for the new plan name65 $w('#planName').value = `${selectedPlan.name}-duplicate`66 $w('#clonePlanBtn').enable();67 });6869 $w('#clonePlanBtn').onClick(async () => {70 const newPlan = selectedPlan;71 // Use inputs to set the new plan name and price72 newPlan.name = $w('#planName').value;73 newPlan.pricing.price.value = $w('#price').value;7475 await createPlan(newPlan);76 });77});7879async function populatePlansDropdown() {80 const plans = await listPlans();81 $w('#plansDropdown').options = plans.map((plan) => {82 return {83 label: plan.name,84 value: plan._id85 }86 });87 $w('#plansDropdown').enable();88}