createPlan( )
Creates a pricing plan.
Description
The createPlan()
function returns a Promise that resolves to a newly-created pricing plan after it has successfully been created.
The passed PlanInfo
object must contain a pricing model. A pricing model is one of the following:
- A subscription: A subscription with recurring payments and how often the plan recurs. Subscriptions can have free trial days.
- A plan that does not renew: A single payment for a specific duration that does not renew.
- An unlimited plan: A single payment for an unlimited amount of time (until cancelled).
Pricing plans created by this function are available to the site owner in the Pricing Plans section in the Dashboard.
Only users with "Manage Pricing Plans" permissions can create plans.
Syntax
function createPlan(planInfo: CreatePlanInfo): Promise<Plan>
createPlan Parameters
NAME
TYPE
DESCRIPTION
The information for the plan being created.
Returns
Fulfilled - The created plan. Rejected - Error message.
Return Type:
NAME
TYPE
DESCRIPTION
Plan ID.
Plan name.
Plan description.
List of text strings that promote the pricing plan (for example, "Plenty of parking" or "Free gift on your birthday").
Plan price, payment schedule, and expiration.
Whether the plan is public (visible to site visitors).
Whether the plan is archived. Archived plans are not visible and can't be purchased anymore, but existing purchases remain in effect.
Whether the plan is marked as primary. If true
, the plan is highlighted on the site with a custom ribbon. Defaults to false
.
Whether the plan has any orders (including pending and unpaid orders).
Date plan was created.
Date plan was last updated.
URL-friendly version of the plan name. Unique across all plans in the same site.
Whether the buyer can start the plan at a later date.
Whether the buyer is allowed to cancel their plan. If false
, calling the cancelOrder()
function returns an error.
Whether the same buyer can purchase the plan multiple times. 1
means the buyer can only purchase the plan once. An empty value or 0
means no limitation.
Any terms and conditions that apply to the plan. This information is displayed during checkout.
Was this helpful?
Create a plan
1/*******************************2 * Backend code - plans.jsw *3 *******************************/45import wixPricingPlansBackend from 'wix-pricing-plans-backend';67export function myCreatePlanFunction(planInfo) {8 return wixPricingPlansBackend.createPlan(planInfo);9}1011/*************12 * Page code *13 *************/1415import { myCreatePlanFunction } from 'backend/plans';1617// …1819const planInfo = {20 "name": "Gold",21 "description": "Gold membership to the MyGame World of Online Gaming",22 "perks": [23 "Multiplayer",24 "Multiple devices",25 "No ads",26 "Unlimited access"27 ],28 "pricing": {29 "price": {30 "value": "10.00",31 "currency": "USD"32 },33 "singlePaymentUnlimited": true34 },35 "public": true,36 "maxPurchasesPerBuyer": 1,37 "allowFutureStartDate": true,38 "buyerCanCancel": true,39 "termsAndConditions": "No sharing access with others!"40 }4142myCreatePlanFunction(planInfo)43 .then((plan) => {44 // plan created45 const planId = plan._id;46 const description = plan.description;47 console.log(plan);48 })49 .catch((error) => {50 // plan not created51 const createError = error;52 });535455/* Full plan object:56 *57 * {58 * "_id": "1ff7b4c8-877b-7896-11aa-6c69ae0b18eb",59 * "name": "Gold",60 * "description": "Gold membership to the MyGame World of Online Gaming",61 * "perks": [62 * "Multiplayer",63 * "Multiple devices",64 * "No ads",65 * "Unlimited access"66 * ],67 * "pricing": {68 * "price": {69 * "value": "10.00",70 * "currency": "USD"71 * },72 * "singlePaymentUnlimited": true73 * },74 * "public": true,75 * "archived": false,76 * "primary": false,77 * "hasOrders": false,78 * "_createdDate": "2020-12-21T09:38:14.939Z",79 * "_updatedDate": "2020-12-21T09:38:14.939Z",80 * "slug": "gold",81 * "maxPurchasesPerBuyer": 1,82 * "allowFutureStartDate": true,83 * "buyerCanCancel": true,84 * "termsAndConditions": "No sharing access with others!"85 * }86 */