updatePlan( )
Updates a pricing plan.
Description
The updatePlan()
function returns a Promise that resolves to an updated plan.
Updating a plan does not impact existing purchases made for the plan. All purchases keep the details of the original plan that was active at the time of the purchase.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updatePlan(_id: string, plan: UpdatePlan): Promise<Plan>
updatePlan Parameters
NAME
TYPE
DESCRIPTION
ID of the plan to update.
Returns
Fulfilled - The updated plan.
Rejected - Error message.
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: '025a0d1f-7076-4e27-9696-4a67075dc2aa'4 *5 * Sample plan value:6 * {7 * description: 'Bronze membership to the MyGame World of Online Gaming',8 * name: 'Bronze Plan'9 * }10 */1112export async function myUpdatePlanFunction(_id, plan) {13 try {14 const updatedPlan = await plans.updatePlan(_id, plan);1516 return updatedPlan;17 } catch(errors) {18 console.error(errors);19 // Handle the error20 }21}22/* Promise resolves to:23 * {24 * "_createdDate": "2024-01-04T12:51:42.249Z",25 * "_id": "025a0d1f-7076-4e27-9696-4a67075dc2aa",26 * "_updatedDate": "2024-01-07T12:53:53.562Z",27 * "allowFutureStartDate": true,28 * "archived": false,29 * "buyerCanCancel": true,30 * "description": "Bronze membership to the MyGame World of Online Gaming",31 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",32 * "hasOrders": false,33 * "maxPurchasesPerBuyer": 1,34 * "name": "Bronze Plan",35 * "perks": {36 * "values": [37 * "Multiplayer",38 * "Multiple devices",39 * "No ads",40 * "Unlimited access"41 * ]42 * },43 * "pricing": {44 * "price": {45 * "currency": "USD",46 * "value": "10.00"47 * },48 * "singlePaymentUnlimited": true49 * },50 * "primary": false,51 * "public": false,52 * "slug": "bronze-plan-1",53 * "termsAndConditions": "No sharing access with others!"54 * }55 */
1import { Permissions, webMethod } from 'wix-web-module';2import { plans } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '025a0d1f-7076-4e27-9696-4a67075dc2aa'6 *7 * Sample plan value:8 * {9 * description: 'Bronze membership to the MyGame World of Online Gaming',10 * name: 'Bronze Plan'11 * }12 */1314export const myUpdatePlanFunction = webMethod(Permissions.Anyone, async (_id, plan) => {15 try {16 const elevateUpdatePlan = elevate(plans.updatePlan);17 const updatedPlan = await elevateUpdatePlan(_id, plan);1819 return updatedPlan;20 } catch(errors) {21 console.error(errors);22 // Handle the error23 }24});25/* Promise resolves to:26 * {27 * "_createdDate": "2024-01-04T12:51:42.249Z",28 * "_id": "025a0d1f-7076-4e27-9696-4a67075dc2aa",29 * "_updatedDate": "2024-01-07T12:53:53.562Z",30 * "allowFutureStartDate": true,31 * "archived": false,32 * "buyerCanCancel": true,33 * "description": "Bronze membership to the MyGame World of Online Gaming",34 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",35 * "hasOrders": false,36 * "maxPurchasesPerBuyer": 1,37 * "name": "Bronze Plan",38 * "perks": {39 * "values": [40 * "Multiplayer",41 * "Multiple devices",42 * "No ads",43 * "Unlimited access"44 * ]45 * },46 * "pricing": {47 * "price": {48 * "currency": "USD",49 * "value": "10.00"50 * },51 * "singlePaymentUnlimited": true52 * },53 * "primary": false,54 * "public": false,55 * "slug": "bronze-plan-1",56 * "termsAndConditions": "No sharing access with others!"57 * }58 */59
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'6 *7 * Sample plan value:8 * {9 * allowFutureStartDate: false,10 * buyerCanCancel: true,11 * description: 'For new users just getting the feel of the product',12 * formId: 'ee62cefa-bdc2-4b5d-baab-6faeef83cecb',13 * hasOrders: false,14 * maxPurchasesPerBuyer: 0,15 * name: 'Simple Plan',16 * perks: {17 * values: [18 * 'Login member access',19 * 'Access to real-time articles',20 * 'Included in mailing list'21 * ]22 * },23 * pricing: {24 * price: {25 * currency: 'USD',26 * value: '3'27 * },28 * singlePaymentForDuration: {29 * count: 12,30 * unit: 'MONTH'31 * }32 * },33 * public: true,34 * slug: 'simple-plan',35 * termsAndConditions: 'I agree to refrain from sharing any of the exclusive content with non-members'36 * }37 */3839export const myUpdatePlanFunction = webMethod(Permissions.Anyone, async (_id, plan) => {40 try {41 const elevateUpdatePlan = elevate(plans.updatePlan);42 const updatedPlan = await elevateUpdatePlan(_id, plan);4344 return updatedPlan;45 } catch (error) {46 console.error(error);47 // Handle the error48 }49});5051/* Promise resolves to:52 * {53 * "_createdDate": "2024-01-07T07:13:04.076Z",54 * "_id": "0b9a1993-c1ff-4952-9575-915b48d1a5e0",55 * "_updatedDate": "2024-01-07T11:02:55.945Z",56 * "allowFutureStartDate": false,57 * "archived": false,58 * "buyerCanCancel": true,59 * "description": "For new users just getting the feel of the product",60 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",61 * "hasOrders": false,62 * "maxPurchasesPerBuyer": 0,63 * "name": "Simple Plan",64 * "perks": {65 * "values": [66 * "Login member access",67 * "Access to real-time articles",68 * "Included in mailing list"69 * ]70 * },71 * "pricing": {72 * "price": {73 * "value": "3",74 * "currency": "USD"75 * },76 * "singlePaymentForDuration": {77 * "count": 12,78 * "unit": "MONTH"79 * }80 * },81 * "primary": false,82 * "public": true,83 * "slug": "simple-plan"84 * "termsAndConditions": "I agree to refrain from sharing any of the exclusive content with non-members"85 * }86 */87