Search.../

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.

Admin Method

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
string

ID of the plan to update.

plan
UpdatePlan

Returns

Fulfilled - The updated plan.

Rejected - Error message.

Return Type:

Promise<
Plan
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date plan was created.

_id
string

Plan ID.

_updatedDate
Date

Date plan was last updated.

allowFutureStartDate
boolean

Whether the buyer can start the plan at a later date.

Default: false.

archived
boolean

Whether the plan is archived. Archived plans are not visible and can't be purchased anymore, but existing purchases remain in effect.

buyerCanCancel
boolean

Whether the buyer is allowed to cancel their plan. If false, calling the cancelOrder() function returns an error.

Default: false.

description
string

Plan description.

formId
string

ID of the form associated with the plan at checkout.

hasOrders
boolean

Whether the plan has any orders (including pending and unpaid orders).

maxPurchasesPerBuyer
number

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.
name
string

Plan name.

perks
StringList

List of text strings that promote what is included with this plan.

For example, "Plenty of parking" or "Free gift on your birthday".

pricing
Pricing

Plan price, payment schedule, and expiration.

primary
boolean

Whether the plan is marked as primary. If true, the plan is highlighted on the site with a custom ribbon.

Default: false.

public
boolean

Whether the plan is public (visible to site visitors and members).

slug
string

URL-friendly version of plan name. Unique across all plans in the same site.

termsAndConditions
string

Any terms and conditions that apply to the plan. This information will be displayed during checkout.

Was this helpful?

Update a plan

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '025a0d1f-7076-4e27-9696-4a67075dc2aa'
5 *
6 * Sample plan value:
7 * {
8 * description: 'Bronze membership to the MyGame World of Online Gaming',
9 * name: 'Bronze Plan'
10 * }
11 */
12
13export async function myUpdatePlanFunction(_id, plan) {
14 try {
15 const elevateUpdatePlan = elevate(plans.updatePlan);
16 const updatedPlan = await elevateUpdatePlan(_id, plan);
17
18 return updatedPlan;
19 } catch(errors) {
20 console.error(errors);
21 // Handle the error
22 }
23}
24/* Promise resolves to:
25 * {
26 * "_createdDate": "2024-01-04T12:51:42.249Z",
27 * "_id": "025a0d1f-7076-4e27-9696-4a67075dc2aa",
28 * "_updatedDate": "2024-01-07T12:53:53.562Z",
29 * "allowFutureStartDate": true,
30 * "archived": false,
31 * "buyerCanCancel": true,
32 * "description": "Bronze membership to the MyGame World of Online Gaming",
33 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
34 * "hasOrders": false,
35 * "maxPurchasesPerBuyer": 1,
36 * "name": "Bronze Plan",
37 * "perks": {
38 * "values": [
39 * "Multiplayer",
40 * "Multiple devices",
41 * "No ads",
42 * "Unlimited access"
43 * ]
44 * },
45 * "pricing": {
46 * "price": {
47 * "currency": "USD",
48 * "value": "10.00"
49 * },
50 * "singlePaymentUnlimited": true
51 * },
52 * "primary": false,
53 * "public": false,
54 * "slug": "bronze-plan-1",
55 * "termsAndConditions": "No sharing access with others!"
56 * }
57 */
Update a plan with optional fields

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '0b9a1993-c1ff-4952-9575-915b48d1a5e0'
5 *
6 * Sample plan value:
7 * {
8 * allowFutureStartDate: false,
9 * buyerCanCancel: true,
10 * description: 'For new users just getting the feel of the product',
11 * formId: 'ee62cefa-bdc2-4b5d-baab-6faeef83cecb',
12 * hasOrders: false,
13 * maxPurchasesPerBuyer: 0,
14 * name: 'Simple Plan',
15 * perks: {
16 * values: [
17 * 'Login member access',
18 * 'Access to real-time articles',
19 * 'Included in mailing list'
20 * ]
21 * },
22 * pricing: {
23 * price: {
24 * currency: 'USD',
25 * value: '3'
26 * },
27 * singlePaymentForDuration: {
28 * count: 12,
29 * unit: 'MONTH'
30 * }
31 * },
32 * public: true,
33 * slug: 'simple-plan',
34 * termsAndConditions: 'I agree to refrain from sharing any of the exclusive content with non-members'
35 * }
36 */
37
38export async function myUpdatePlanFunction(_id, plan) {
39 try {
40 const elevateUpdatePlan = elevate(plans.updatePlan);
41 const updatedPlan = await elevateUpdatePlan(_id, plan);
42
43 return updatedPlan;
44 } catch (error) {
45 console.error(error);
46 // Handle the error
47 }
48}
49
50/* Promise resolves to:
51 * {
52 * "_createdDate": "2024-01-07T07:13:04.076Z",
53 * "_id": "0b9a1993-c1ff-4952-9575-915b48d1a5e0",
54 * "_updatedDate": "2024-01-07T11:02:55.945Z",
55 * "allowFutureStartDate": false,
56 * "archived": false,
57 * "buyerCanCancel": true,
58 * "description": "For new users just getting the feel of the product",
59 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
60 * "hasOrders": false,
61 * "maxPurchasesPerBuyer": 0,
62 * "name": "Simple Plan",
63 * "perks": {
64 * "values": [
65 * "Login member access",
66 * "Access to real-time articles",
67 * "Included in mailing list"
68 * ]
69 * },
70 * "pricing": {
71 * "price": {
72 * "value": "3",
73 * "currency": "USD"
74 * },
75 * "singlePaymentForDuration": {
76 * "count": 12,
77 * "unit": "MONTH"
78 * }
79 * },
80 * "primary": false,
81 * "public": true,
82 * "slug": "simple-plan"
83 * "termsAndConditions": "I agree to refrain from sharing any of the exclusive content with non-members"
84 * }
85 */
86
87
88