Wix Pricing Plans events are fired in your site's backend when certain events occur with plans. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to pricing plan events.
Note: Backend events don't work when previewing your site.
To add a pricing plans event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.
Event handler functions are defined using the following pattern:
export function <wixAppName>_<eventName>(event) { }
For example, an event handler that handles pricing plan updates looks like this:
export function wixPricingPlans_onPlanUpdated(event) {}
As an order progresses through its lifecycle from order creation until order completion, various events get triggered. The order's status is updated accordingly.
For example, the following describes the events and statuses for an online, recurring order:
Timeline of Events | Events Triggered | Order Status |
---|---|---|
1) Online, recurring order created | orderCreated | DRAFT |
2) Payment arranged, start date later | orderPurchased | PENDING |
3) Start date arrives | orderStarted, orderCycleStarted | ACTIVE |
4) Next cycle arrives | orderCycleStarted | ACTIVE |
5) Last cycle finishes | orderEnded | ENDED |
The following flowchart details order events and statuses.
Triggered when an order is canceled and effectiveAt
is set to NEXT_PAYMENT_DATE
.
This webhook is not triggered in the following scenarios:
effectiveAt
is set to IMMEDIATELY
. Instead, at the time of cancellation, Order Canceled is triggered.effectiveAt
was set to NEXT_PAYMENT_DATE
. Instead, at the time of expiration, Order Canceled and Order Ended are triggered.function wixPricingPlans_onOrderAutoRenewCanceled(
event: OrderAutoRenewCanceledEvent,
): void;
Information about the order whose auto-renewal is canceled and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderAutoRenewCanceled(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
const eventTime = event.metadata.eventTime;
console.log(
`Order autorenew was cancelled for order ID ${orderId} by buyer ID ${buyerContactId}, for plan ID ${planId} on ${eventTime}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-01-28T09:49:21.041Z",
* "_id": "82d99338-5653-459a-a751-b57483f7cfb5",
* "_updatedDate": "2024-02-07T13:22:47.459Z",
* "autoRenewCanceled": true,
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "NEXT_PAYMENT_DATE"
* },
* "currentCycle": {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* },
* "cycles": [
* {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* }
* ],
* "endDate": "2024-04-27T09:49:21.041Z",
* "earliestEndDate": "2026-04-27T09:49:21.041Z",
* "formData": {
* "submissionData": {}
* },
* "freeTrialDays": 90,
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "3 mo free trial with discount for 1 year",
* "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
* "planName": "Beginner's Plan",
* "planPrice": "50",
* "priceDetails": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "freeTrialDays": 90,
* "planPrice": "50",
* "subtotal": "50.00",
* "total": "50.00",
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 2
* },
* "price": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "50.00",
* "total": "50.00"
* }
* }
* ],
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "startDate": "2024-01-28T09:49:21.041Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",
* "type": "OFFLINE",
* "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"
* }
* },
* "metadata": {
* "entityId": "82d99338-5653-459a-a751-b57483f7cfb5",
* "eventTime": "2024-02-07T13:22:47.641175778Z",
* "id": "ef926c78-1c7a-4ffd-a8c4-fa59bdcf09c1",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order is canceled.
This webhook is triggered either immediately or at the end of the current payment cycle, as follows:
effectiveAt
is set to IMMEDIATELY
, the webhook is triggered immediately when canceled.effectiveAt
is set to NEXT_PAYMENT_DATE
, the webhook is triggered at the end of the current payment cycle. In this case, the Order Auto Renew Canceled Webhook is triggered immediately.function wixPricingPlans_onOrderCanceled(event: OrderCanceledEvent): void;
Information about the canceled order and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderCanceled(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planName;
const eventTime = event.metadata.endDate;
console.log(
`Order ID ${orderId} was canceled by buyer ID ${buyerContactId}, for plan ID ${planId} at ${eventTime}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "IMMEDIATELY"
* },
* "order": {
* "_createdDate": "2024-02-04T09:02:48.592Z",
* "_id": "e6f12ae0-2618-41e7-a643-31ca2ee51e2b",
* "_updatedDate": "2024-02-06T07:31:59.180Z",
* "buyer": {
* "contactId": "3fc889f6-18e8-4fd9-a509-27db9f037f26",
* "memberId": "3fc889f6-18e8-4fd9-a509-27db9f037f26"
* },
* "cycles": [
* {
* "endedDate": "2024-02-06T07:31:59.123Z",
* "index": 1,
* "startedDate": "2024-02-04T09:02:48.592Z"
* }
* ],
* "endDate": "2024-02-06T07:31:59.123Z",
* "formData": {
* "submissionData": {}
* },
* "lastPaymentStatus": "PAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "Full feature enablement - lifetime plan",
* "planId": "b20feb39-a452-453e-96ee-01036adcd04e",
* "planName": "Premium Plan - Lifetime Membership",
* "planPrice": "1000",
* "priceDetails": {
* "coupon": {
* "_id": "07de4c3a-536b-4c30-adb9-991935da1681",
* "amount": "1000.00",
* "code": "sale-day"
* },
* "currency": "USD",
* "discount": "1000.00",
* "planPrice": "1000",
* "singlePaymentUnlimited": true,
* "subtotal": "1000.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "1000.00",
* "fees": [],
* "proration": "0",
* "subtotal": "1000.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-02-04T09:02:48.592Z",
* "status": "CANCELED",
* "statusNew": "CANCELED",
* "subscriptionId": "02e297ba-c270-4415-9f77-748507bb7b9d",
* "type": "ONLINE",
* "wixPayOrderId": "8f012204-4d60-457b-8772-b0cf92a11d84"
* }
* },
* "metadata": {
* "entityId": "e6f12ae0-2618-41e7-a643-31ca2ee51e2b",
* "eventTime": "2024-02-06T07:31:59.288259731Z",
* "id": "85a7ec5f-2ab4-4582-9a1d-5845c5f38e87",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order is created.
function wixPricingPlans_onOrderCreated(event: OrderCreated): void;
Information about the created order and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderCreated(event) {
const orderId = event.entity._id;
const createdDate = event.entity._createdDate;
const buyer = event.entity.buyer;
console.log(
`The order with ID ${event.orderId} to purchase the ${event.plan.name} plan was created on ${createdDate} by the buyer ${buyer}. The full event object:`,
event,
);
}
/* Full event object:
* {
* "entity": {
* "_createdDate": "2024-01-25T11:45:05.036Z",
* "_id": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "_updatedDate": "2024-01-25T11:45:05.036Z",
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* }
* ],
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "1b282868-0a1e-42c6-9123-3a611b0014bf"
* },
* "lastPaymentStatus": "NOT_APPLICABLE",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "",
* "planId": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
* "planName": "Default",
* "planPrice": "0",
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-01-25T11:45:05.036Z",
* "status": "ACTIVE",
* "statusNew": "DRAFT",
* "subscriptionId": "e9fff457-bc89-4c8c-94c0-1d162711c9a6",
* "type": "ONLINE"
* },
* "metadata": {
* "entityId": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "eventTime": "2024-01-25T11:45:06.457639259Z",
* "id": "6a0b2d17-6211-4394-b3e4-9c1a1bb1b1cc",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered at the start of a new payment cycle for an existing order.
Not triggered at the initial start of an offline order.
function wixPricingPlans_onOrderCycleStarted(
event: OrderCycleStartedEvent,
): void;
Information about the order whose payment cycle started and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderCycleStarted(event) {
const orderId = event.data.order._id;
const transactionId = event.data.transactionId;
const eventTime = event.metadata.eventTime;
console.log(
`Order ID ${orderId} has started its order cycle with transaction ID ${transactionId} at ${eventTime}. The full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "cycleNumber": 1,
* "order": {
* "_createdDate": "2024-01-25T11:45:05.036Z",
* "_id": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "_updatedDate": "2024-01-25T11:45:05.036Z",
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* }
* ],
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "1b282868-0a1e-42c6-9123-3a611b0014bf"
* },
* "lastPaymentStatus": "NOT_APPLICABLE",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "",
* "planId": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
* "planName": "Default",
* "planPrice": "0",
* "priceDetails": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "planPrice": "0",
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-01-25T11:45:05.036Z",
* "status": "ACTIVE",
* "statusNew": "DRAFT",
* "subscriptionId": "e9fff457-bc89-4c8c-94c0-1d162711c9a6",
* "type": "ONLINE"
* }
* },
* "metadata": {
* "entityId": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "eventTime": "2024-01-25T11:45:06.852478956Z",
* "id": "9481d95b-3fd6-423c-af43-5198bed9691c",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order's endDate
is postponed.
function wixPricingPlans_onOrderEndDatePostponed(
event: OrderEndDatePostponedEvent,
): void;
Information about the order that is postponed and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderEndDatePostponed(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
console.log(
`Order ID of ${orderId} was postponed for plan ID ${planId} for buyer contact ID ${buyerContactId}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-01-28T09:49:21.041Z",
* "_id": "82d99338-5653-459a-a751-b57483f7cfb5",
* "_updatedDate": "2024-02-07T13:22:47.459Z",
* "autoRenewCanceled": true,
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "NEXT_PAYMENT_DATE"
* },
* "currentCycle": {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* },
* "cycles": [
* {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* }
* ],
* "endDate": "2024-04-27T09:49:21.041Z",
* "earliestEndDate": "2026-04-27T09:49:21.041Z",
* "formData": {
* "submissionData": {}
* },
* "freeTrialDays": 90,
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "3 mo free trial with discount for 1 year",
* "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
* "planName": "Beginner's Plan",
* "planPrice": "50",
* "priceDetails": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "freeTrialDays": 90,
* "planPrice": "50",
* "subtotal": "50.00",
* "total": "50.00",
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 2
* },
* "price": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "50.00",
* "total": "50.00"
* }
* }
* ],
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "startDate": "2024-01-28T09:49:21.041Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",
* "type": "OFFLINE",
* "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"
* }
* },
* "metadata": {
* "entityId": "82d99338-5653-459a-a751-b57483f7cfb5",
* "eventTime": "2024-02-07T13:22:47.641175778Z",
* "id": "ef926c78-1c7a-4ffd-a8c4-fa59bdcf09c1",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order ends.
This webhook is triggered:
effectiveAt
is set to IMMEDIATELY
.function wixPricingPlans_onOrderEnded(event: OrderEndedEvent): void;
Information about the order that ended and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderEnded(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
const endDate = event.data.endDate;
console.log(
`Order ID ${orderId} with buyer ID ${buyerContactId}, ended for the plan ID ${planId} on ${endDate}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-02-01T10:27:58.453Z",
* "_id": "9af3cbe6-fe27-4fdb-a0b0-892289b03d22",
* "_updatedDate": "2024-02-11T08:13:44.674Z",
* "buyer": {
* "contactId": "402ec90c-235a-45c4-b4cc-52204d5f6b00",
* "memberId": "402ec90c-235a-45c4-b4cc-52204d5f6b00"
* },
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "IMMEDIATELY"
* },
* "cycles": [
* {
* "endedDate": "2024-02-11T08:13:44.588Z",
* "index": 1,
* "startedDate": "2024-02-01T10:27:58.453Z"
* }
* ],
* "endDate": "2024-02-11T08:13:44.588Z",
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "10206732-e789-40e9-957d-2c7f3398efc6"
* },
* "lastPaymentStatus": "PAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [
* {
* "pauseDate": "2024-02-04T10:02:03.726Z",
* "resumeDate": "2024-02-04T13:05:04.465Z",
* "status": "ENDED"
* }
* ],
* "planDescription": "",
* "planId": "0da57ac8-c3d0-4687-8aea-4100781b6386",
* "planName": "Expensive Plan",
* "planPrice": "10000",
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "10000.00",
* "fees": [],
* "proration": "0",
* "subtotal": "10000.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "priceDetails": {
* "coupon": {
* "_id": "07de4c3a-536b-4c30-adb9-991935da1681",
* "amount": "10000.00",
* "code": "sale-day"
* },
* "currency": "USD",
* "discount": "10000.00",
* "planPrice": "10000",
* "singlePaymentUnlimited": true,
* "subtotal": "10000.00",
* "total": "0"
* },
* "startDate": "2024-02-01T10:27:58.453Z",
* "status": "CANCELED",
* "statusNew": "CANCELED",
* "subscriptionId": "0cd18587-a637-4327-a05c-ab4e86bd59fe",
* "type": "ONLINE",
* "wixPayOrderId": "4012ab0c-f1cb-4632-917e-f611de27dcad"
* }
* },
* "metadata": {
* "entityId": "9af3cbe6-fe27-4fdb-a0b0-892289b03d22",
* "eventTime": "2024-02-11T08:13:44.817334927Z",
* "id": "601feaeb-7306-4428-b768-906f12938004",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an offline order is marked as paid.
function wixPricingPlans_onOrderMarkedAsPaid(
event: OrderMarkedAsPaidEvent,
): void;
Information about the offline order that was paid and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderMarkedAsPaid(event) {
const orderId = event.entity._id;
const paidDate = event.metadata.eventTime;
const planId = event.data.planId;
const buyerContactId = event.entity.buyer.contactId;
console.log(
`Order ID ${event.orderId} to purchase plan ID ${planId} was paid on ${paidDate} by the buyer contact ID ${buyerContactId}. The full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-02-01T10:27:58.453Z",
* "_id": "9af3cbe6-fe27-4fdb-a0b0-892289b03d22",
* "_updatedDate": "2024-02-11T08:13:44.674Z",
* "buyer": {
* "contactId": "402ec90c-235a-45c4-b4cc-52204d5f6b00",
* "memberId": "402ec90c-235a-45c4-b4cc-52204d5f6b00"
* },
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "IMMEDIATELY"
* },
* "cycles": [
* {
* "endedDate": "2024-02-11T08:13:44.588Z",
* "index": 1,
* "startedDate": "2024-02-01T10:27:58.453Z"
* }
* ],
* "endDate": "2024-02-11T08:13:44.588Z",
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "10206732-e789-40e9-957d-2c7f3398efc6"
* },
* "lastPaymentStatus": "PAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [
* {
* "pauseDate": "2024-02-04T10:02:03.726Z",
* "resumeDate": "2024-02-04T13:05:04.465Z",
* "status": "ENDED"
* }
* ],
* "planDescription": "",
* "planId": "0da57ac8-c3d0-4687-8aea-4100781b6386",
* "planName": "Expensive Plan",
* "planPrice": "10000",
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "10000.00",
* "fees": [],
* "proration": "0",
* "subtotal": "10000.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "priceDetails": {
* "coupon": {
* "_id": "07de4c3a-536b-4c30-adb9-991935da1681",
* "amount": "10000.00",
* "code": "sale-day"
* },
* "currency": "USD",
* "discount": "10000.00",
* "planPrice": "10000",
* "singlePaymentUnlimited": true,
* "subtotal": "10000.00",
* "total": "0"
* },
* "startDate": "2024-02-01T10:27:58.453Z",
* "status": "CANCELED",
* "statusNew": "CANCELED",
* "subscriptionId": "0cd18587-a637-4327-a05c-ab4e86bd59fe",
* "type": "ONLINE",
* "wixPayOrderId": "4012ab0c-f1cb-4632-917e-f611de27dcad"
* }
* },
* "metadata": {
* "entityId": "9af3cbe6-fe27-4fdb-a0b0-892289b03d22",
* "eventTime": "2024-02-11T08:13:44.817334927Z",
* "id": "601feaeb-7306-4428-b768-906f12938004",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order is paused.
function wixPricingPlans_onOrderPaused(event: OrderPausedEvent): void;
Information about the order that is paused and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderPaused(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
console.log(
`Order ID of ${orderId} was paused for plan ID ${planId} for buyer contact ID ${buyerContactId}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-01-28T09:49:21.041Z",
* "_id": "82d99338-5653-459a-a751-b57483f7cfb5",
* "_updatedDate": "2024-02-07T13:22:47.459Z",
* "autoRenewCanceled": true,
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "cancellation": {
* "cause": "OWNER_ACTION",
* "effectiveAt": "NEXT_PAYMENT_DATE"
* },
* "currentCycle": {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* },
* "cycles": [
* {
* "endedDate": "2024-04-27T09:49:21.041Z",
* "index": 0,
* "startedDate": "2024-01-28T09:49:21.041Z"
* }
* ],
* "endDate": "2024-04-27T09:49:21.041Z",
* "earliestEndDate": "2026-04-27T09:49:21.041Z",
* "formData": {
* "submissionData": {}
* },
* "freeTrialDays": 90,
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "3 mo free trial with discount for 1 year",
* "planId": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
* "planName": "Beginner's Plan",
* "planPrice": "50",
* "priceDetails": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "freeTrialDays": 90,
* "planPrice": "50",
* "subtotal": "50.00",
* "total": "50.00",
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 2
* },
* "price": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "50.00",
* "total": "50.00"
* }
* }
* ],
* "subscription": {
* "cycleCount": 2,
* "cycleDuration": {
* "count": 1,
* "unit": "YEAR"
* }
* }
* },
* "startDate": "2024-01-28T09:49:21.041Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "305f8fc9-3724-4cac-9f67-4e29f2c46def",
* "type": "OFFLINE",
* "wixPayOrderId": "2f0e79d8-f15d-46c6-ac1a-10ec7a2030fb"
* }
* },
* "metadata": {
* "entityId": "82d99338-5653-459a-a751-b57483f7cfb5",
* "eventTime": "2024-02-07T13:22:47.641175778Z",
* "id": "ef926c78-1c7a-4ffd-a8c4-fa59bdcf09c1",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered for any of the following purchase events:
function wixPricingPlans_onOrderPurchased(event: OrderPurchasedEvent): void;
Information about the order that was purchased and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderPurchased(event) {
const orderId = event.data.order._id;
const eventTime = event.metadata.eventTime;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
console.log(
`Order ${orderId}: Buyer contact ID ${buyerContactId} purchased plan ${planId} at ${eventTime}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-01-25T11:45:05.036Z",
* "_id": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "_updatedDate": "2024-01-25T11:45:05.036Z",
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* }
* ],
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "1b282868-0a1e-42c6-9123-3a611b0014bf"
* },
* "lastPaymentStatus": "NOT_APPLICABLE",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "",
* "planId": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
* "planName": "Default",
* "planPrice": "0",
* "priceDetails": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "planPrice": "0",
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-01-25T11:45:05.036Z",
* "status": "ACTIVE",
* "statusNew": "DRAFT",
* "subscriptionId": "e9fff457-bc89-4c8c-94c0-1d162711c9a6",
* "type": "ONLINE"
* }
* },
* "metadata": {
* "entityId": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "eventTime": "2024-01-25T11:45:06.792096634Z",
* "id": "0f740093-c77c-4f3e-a307-3e86f659ec74",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a paused order is resumed.
function wixPricingPlans_onOrderResumed(event: OrderResumedEvent): void;
Information about the order that was resumed and metadata for the event
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderResumed(event) {
const orderId = event.data.order._id;
const planId = event.data.planId;
const eventTime = event.metadata.eventTime;
console.log(
`Order ID ${orderId} was resumed for plan ID ${planId} at ${eventTime}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-02-11T09:11:13.012Z",
* "_id": "3feb1cf5-bf38-47c4-81cb-06b61ca11c8a",
* "_updatedDate": "2024-02-11T09:14:57.750Z",
* "buyer": {
* "contactId": "3fc889f6-18e8-4fd9-a509-27db9f037f26",
* "memberId": "3fc889f6-18e8-4fd9-a509-27db9f037f26"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-02-11T09:11:13.012Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-02-11T09:11:13.012Z"
* }
* ],
* "formData": {
* "submissionData": {}
* },
* "lastPaymentStatus": "PAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [
* {
* "pauseDate": "2024-02-11T09:14:57.750Z",
* "resumeDate": "2024-02-11T09:28:13.186Z",
* "status": "ENDED"
* }
* ],
* "planDescription": "Full feature enablement - lifetime plan",
* "planId": "e901222b-c137-4bc7-adc3-c1efa3c880a2",
* "planName": "Quality Plan - Lifetime",
* "planPrice": "1500",
* "priceDetails": {
* "coupon": {
* "_id": "07de4c3a-536b-4c30-adb9-991935da1681",
* "amount": "1500.00",
* "code": "sale-day"
* },
* "currency": "USD",
* "discount": "1500.00",
* "planPrice": "1500",
* "subtotal": "1500.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "1500.00",
* "fees": [],
* "proration": "0",
* "subtotal": "1500.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-02-11T09:11:13.012Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "d3290015-f808-4f08-a4a0-6732acbf2a43",
* "type": "ONLINE",
* "wixPayOrderId": "36a79fab-c436-4bf0-b3be-14e9f75cf263"
* }
* },
* "metadata": {
* "entityId": "3feb1cf5-bf38-47c4-81cb-06b61ca11c8a",
* "eventTime": "2024-02-11T09:28:13.343708694Z",
* "id": "c020a4af-1647-4301-b821-d6ee72b7a462",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order's startDate
is changed.
function wixPricingPlans_onOrderStartDateChanged(
event: OrderStartDateChangedEvent,
): void;
Information about the order whose start date changed and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderStartDateChanged(event) {
const orderId = event.data.order._id;
const buyerContactId = event.data.buyer.contactId;
const startDate = event.startDate;
console.log(
`Start date for order ID ${orderId} was changed to ${startDate} by contact ID ${buyerContactId}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-02-14T11:15:57.921Z",
* "_id": "a15b2fdf-f21c-4d3e-bae2-12a344cc4cad",
* "_updatedDate": "2024-02-14T11:16:45.641Z",
* "buyer": {
* "contactId": "600e2577-6414-42a5-b35b-839e166eaf5a",
* "memberId": "600e2577-6414-42a5-b35b-839e166eaf5a"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-02-16T22:00:00.000Z"
* }
* ],
* "formData": {
* "submissionData": {}
* },
* "lastPaymentStatus": "UNPAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "Full feature enablement - lifetime plan",
* "planId": "e901222b-c137-4bc7-adc3-c1efa3c880a2",
* "planName": "Quality Plan - Lifetime",
* "planPrice": "1500",
* "priceDetails": {
* "currency": "USD",
* "discount": "0",
* "planPrice": "1500",
* "subtotal": "1500.00",
* "tax": {
* "amount": "97.50",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "1597.50"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "1500.00",
* "tax": {
* "amount": "97.50",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "1597.50"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-02-16T22:00:00.000Z",
* "status": "DRAFT",
* "statusNew": "DRAFT",
* "subscriptionId": "78933e41-6482-4545-a7e0-483ec74cfa97",
* "type": "ONLINE",
* "wixPayOrderId": "97aa019c-13f2-4e2a-a8a2-62cd9ffa6ef0"
* }
* },
* "metadata": {
* "entityId": "a15b2fdf-f21c-4d3e-bae2-12a344cc4cad",
* "eventTime": "2024-02-14T11:16:45.787406262Z",
* "id": "05924d5a-5f1e-4f9a-ba77-f3a784661d41",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when an order reaches its startDate
. Applies to both purchased and free orders.
function wixPricingPlans_onOrderStarted(event: OrderStartedEvent): void;
Information about the order that started and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderStarted(event) {
const orderId = event.data.order._id;
const eventTime = event.metadata.eventTime;
const buyerContactId = event.data.buyer.contactId;
const planId = event.data.planId;
console.log(
`New order started: Order ID ${orderId} at ${eventTime} by contact ID ${buyerContactId} to purchase plan ${planId}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "order": {
* "_createdDate": "2024-01-25T11:45:05.036Z",
* "_id": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "_updatedDate": "2024-01-25T11:45:05.036Z",
* "buyer": {
* "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
* "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-01-25T11:45:05.036Z"
* }
* ],
* "formData": {
* "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
* "submissionData": {},
* "submissionId": "1b282868-0a1e-42c6-9123-3a611b0014bf"
* },
* "lastPaymentStatus": "NOT_APPLICABLE",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "",
* "planId": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
* "planName": "Default",
* "planPrice": "0",
* "priceDetails": {
* "currency": "EUR",
* "discount": "0",
* "planPrice": "0",
* "singlePaymentUnlimited": true,
* "subtotal": "0.00",
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "EUR",
* "discount": "0",
* "fees": [],
* "proration": "0",
* "subtotal": "0.00",
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-01-25T11:45:05.036Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "e9fff457-bc89-4c8c-94c0-1d162711c9a6",
* "type": "ONLINE"
* }
* },
* "metadata": {
* "entityId": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
* "eventTime": "2024-01-25T11:45:05.860485075Z",
* "id": "f02f2b76-5044-4f82-b6de-82548a65b37a",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered for any of the following update events:
function wixPricingPlans_onOrderUpdated(event: OrderUpdated): void;
Information about the order that was updated and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixPricingPlans_onOrderUpdated(event) {
const orderId = event.data.order._id;
const eventTime = event.metadata.eventTime;
const buyerContactId = event.data.buyer.contactId;
console.log(
`Order update: Order ID ${orderId} was updated at ${eventTime} by contact ID ${buyerContactId}. Full event object:`,
event,
);
}
/* Full event object:
* {
* "entity": {
* "_createdDate": "2024-02-06T06:56:57.193Z",
* "_id": "537a3f44-57bf-4658-9833-47357198d88d",
* "_updatedDate": "2024-02-06T06:57:24.932Z",
* "buyer": {
* "contactId": "695568ff-1dc2-49ff-83db-2b518d35692b",
* "memberId": "695568ff-1dc2-49ff-83db-2b518d35692b"
* },
* "currentCycle": {
* "index": 1,
* "startedDate": "2024-02-06T06:56:57.193Z"
* },
* "cycles": [
* {
* "index": 1,
* "startedDate": "2024-02-06T06:56:57.193Z"
* }
* ],
* "formData": {
* "submissionData": {}
* },
* "lastPaymentStatus": "PAID",
* "orderMethod": "UNKNOWN",
* "pausePeriods": [],
* "planDescription": "Full feature enablement - lifetime plan",
* "planId": "e901222b-c137-4bc7-adc3-c1efa3c880a2",
* "planName": "Quality Plan - Lifetime",
* "planPrice": "1500",
* "priceDetails": {
* "coupon": {
* "_id": "07de4c3a-536b-4c30-adb9-991935da1681",
* "amount": "1500.00",
* "code": "sale-day"
* },
* "currency": "USD",
* "discount": "1500.00",
* "planPrice": "1500",
* "singlePaymentUnlimited": true,
* "subtotal": "1500.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* },
* "pricing": {
* "prices": [
* {
* "duration": {
* "cycleFrom": 1,
* "numberOfCycles": 1
* },
* "price": {
* "currency": "USD",
* "discount": "1500.00",
* "fees": [],
* "proration": "0",
* "subtotal": "1500.00",
* "tax": {
* "amount": "0",
* "includedInPrice": false,
* "name": "Tax",
* "rate": "6.5"
* },
* "total": "0"
* }
* }
* ],
* "singlePaymentUnlimited": true
* },
* "startDate": "2024-02-06T06:56:57.193Z",
* "status": "ACTIVE",
* "statusNew": "ACTIVE",
* "subscriptionId": "24bd018a-a4a2-4ca4-b83b-b4af9d6d8eb4",
* "type": "ONLINE",
* "wixPayOrderId": "2e0c2738-8541-43f5-842b-37c7e94e9f4c"
* },
* "metadata": {
* "entityId": "537a3f44-57bf-4658-9833-47357198d88d",
* "eventTime": "2024-02-06T06:57:26.229867928Z",
* "id": "5212464e-f2c6-423f-b768-05401295b94d",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a pricing plan is archived.
function wixPricingPlansV2_onPlanArchived(event: PlanArchivedEvent): void;
export function wixPricingPlansV2_onPlanArchived(event) {
const eventId = event.metadata.id;
const entityId = event.data.plan._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.