onPlanPurchased( )


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 Declaration
Copy
function onPlanPurchased(event: PlanPurchasedEvent): void;
Method Parameters
eventPlanPurchasedEventRequired

The purchase data.

An event when a pricing plan is purchased

This example adds purchased plan event data to a manually-created planEvents database. The database has a data field.

When a plan is purchased and the onPlanPurchased event is triggered, the JSON format of the object is inserted into the data field.

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" * } * } * } * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?