> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: onPlanPurchased(event: PlanPurchasedEvent) # Method package: wixPricingPlansBackend # Method menu location: wixPricingPlansBackend --> Events --> onPlanPurchased # Method Link: https://dev.wix.com/docs/velo/apis/wix-pricing-plans-backend/events/on-plan-purchased.md # Method Description: An event that triggers when a member purchases a plan. **Deprecated.** This event has been deprecated, use the `onOrderPurchased()` event instead. The `onPlanPurchased()` event handler runs when a member purchases a pricing plan. The received `PlanPurchasedEvent` object contains order information about the plan, such as order ID, until when the order is valid, and so on. > **Note:** Backend events don't work when previewing your site. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## An event when a pricing plan is purchased ```javascript // Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. // For inserting data about a plan transaction: import wixData from 'wix-data'; export function wixPricingPlans_onPlanPurchased(event) { // Insert a title reflecting the type of transaction, and // the event's order object (json) into // the collection's data field. if (event.order.price.amount === 0) { let orderData = { "title": "Free plan purchased", "data": event.order }; wixData.insert("planEvents", orderData); } else { let orderData = { "title": "Regular plan purchased", "data": event.order }; wixData.insert("planEvents", orderData); } } /* Event object for a free, one-month purchase, ordered using Thailand baht currency: * * When the purchase is free, the `wixPayOrderId` is blank, * the `price.amount` is 0, and the paymentStatus is marked `PAID`. * * { * "order":{ * "paymentStatus":"PAID", * "validUntil":"2019-09-12T05:43:53.246Z", * "price":{ * "currency":"THB", * "amount":0 * }, * "validFrom":"2019-08-12T05:43:53.246Z", * "planName":"valid 1 week", * "wixPayOrderId":"", * "recurring":false, * "id":"b8401bab-8e5d-4bf6-944b-b2d56698d4c9", * "dateCreated":"2019-08-12T05:43:53.246Z", * "status":"ACTIVE", * "roleId":"", * "planDescription":"Platinum Plan", * "memberId":"42d90dcb-b9ad-47be-9a36-488be3dec679", * "orderType":"ONLINE", * "planId":"a52f41cc-8129-4812-9e1c-fafa2807a25d", * "validFor":{ * "forever":false, * "period":{ * "amount":1, * "unit":"MONTH" * } * } * } * } * * * Event object for a purchase that is valid until the user cancels: * * When the purchase is valid until the user cancels, `validFor.forever` is true, and * `validFor.forever.period.amount` is 0. * * { * "order":{ * "paymentStatus":"PAID", * "validUntil":"2019-09-12T05:43:53.246Z", * "price":{ * "currency":"USD", * "amount":0 * }, * "cancellationReason":"CANCELLATION_REASON_UNDEFINED", * "validFrom":"2019-08-12T05:43:53.246Z", * "planName":"valid 1 week", * "wixPayOrderId":"a52f41cc-8129-4812-9e1c-fafa2807a25d", * "recurring":false, * "id":"b8401bab-8e5d-4bf6-944b-b2d56698d4c9", * "dateCreated":"2019-08-12T05:43:53.246Z", * "status":"ACTIVE", * "roleId":"", * "planDescription":"Gold Plan", * "memberId":"42d90dcb-b9ad-47be-9a36-488be3dec679", * "orderType":"ONLINE", * "planId":"a52f41cc-8129-4812-9e1c-fafa2807a25d", * "validFor":{ * "forever":true, * "period":{ * "amount":0, * "unit":"MONTH" * } * } * } * } * */ ``` ---