Question:
I am trying to get a list of the current member orders from the backend. The “onOrderCreated” event appears to be firing from my backend code properly. The event data appears to be correctly populated with the buyer/contact id’s…however the status is DRAFT. (Could this be the problem?). Since Wix does not have a test credit card capability… …I had to issue a 100% coupon for my testing. Anyway…once the event fires I want to get a list of the current member orders so I can cancel the old pricing plan order and just be left with the new one.
Product:
Wix Editor
What are you trying to achieve:
see above
What have you already tried:
Many syntactical variations.
Additional information:
Here is my code: (see comments for myLog results)
import { myLog } from 'backend/queries'; //writes to a my collection...works fine
import { orders } from 'wix-pricing-plans-backend';
export async function wixPricingPlans_onOrderCreated(event) {
var myPlan
var listedOrders
try {
await myLog("Made it to the event function for Pricing Plans"); //written to log
await myLog(event) //event is populated with buyer: member and contact and other data
that looks correct.
await myLog("orderId = ", event.entity._id); //is blank
await myLog("eventId = ", event.metadata.id); //is blank
await myLog("eventTime = ", event.metadata.eventTime); //is blank
myPlan = event.entity.planName;
await myLog("myPlan = " + myPlan); //populates correctly
try {
listedOrders = await orders.listCurrentMemberOrders();
return listedOrders;
} catch (error) {
await myLog("listedOrders error = ", error); // error is blank
await myLog(error) // error = { "details": {"applicationError": "description": "Forbidden",
"code": "MEMBER_REQUIRED", "data": {} }}}
}
} catch (error) {
myLog("Error in onOrderPurchased: ", error.message);
}
}
Here is the event object this is passed on the firing of the onOrderCreated.
{
“metadata”: {
“id”: “87d689df-3500-47e7-931e-7ab3ba69a971”,
“entityId”: “8cb1d004-ba6a-41e8-9d02-53c84930a6ae”,
“eventTime”: “2024-01-12T19:52:41.134252074Z”,
“triggeredByAnonymizeRequest”: false
},
“entity”: {
“planPrice”: “19.99”,
“_id”: “8cb1d004-ba6a-41e8-9d02-53c84930a6ae”,
“_createdDate”: “2024-01-12T19:52:40.523Z”,
“subscriptionId”: “d385c467-3dc3-4943-afb4-a0c36cfff6b6”,
“pausePeriods”: ,
“_updatedDate”: “2024-01-12T19:52:40.523Z”,
“planName”: “EVOLVE PLAN ($19.99/mo) PaidMonthly@”,
“buyer”: {
“memberId”: “ad986dff-90f6-4fb8-bd9e-cccdd0437659”,
“contactId”: “ad986dff-90f6-4fb8-bd9e-cccdd0437659”
},
“lastPaymentStatus”: “UNPAID”,
“status”: “DRAFT”,
“orderMethod”: “UNKNOWN”,
“planDescription”: “Evolve Your Vision By Going Deeper In Understanding Your Unique Custom Ideas !”,
“wixPayOrderId”: “12cffc1a-dcf4-46bc-916f-29bccb75a962”,
“formData”: {
“submissionData”: {}
},
“statusNew”: “DRAFT”,
“autoRenewCanceled”: false,
“cycles”: [
{
“index”: 1,
“startedDate”: “2024-01-12T19:52:40.523Z”,
“endedDate”: “2024-02-12T19:52:40.523Z”
}
],
“type”: “ONLINE”,
“planId”: “342b7a73-5f24-4356-94c9-d715e66a7035”,
“startDate”: “2024-01-12T19:52:40.523Z”,
“currentCycle”: {
“index”: 1,
“startedDate”: “2024-01-12T19:52:40.523Z”,
“endedDate”: “2024-02-12T19:52:40.523Z”
},
“pricing”: {
“subscription”: {
“cycleDuration”: {
“count”: 1,
“unit”: “MONTH”
},
“cycleCount”: 0
},
“prices”: [
{
“duration”: {
“cycleFrom”: 1
},
“price”: {
“total”: “19.99”,
“proration”: “0”,
“fees”: ,
“currency”: “USD”,
“subtotal”: “19.99”,
“discount”: “0”
}
}
]
},
“priceDetails”: {
“planPrice”: “19.99”,
“subscription”: {
“cycleDuration”: {
“count”: 1,
“unit”: “MONTH”
},
“cycleCount”: 0
},
“total”: “19.99”,
“currency”: “USD”,
“subtotal”: “19.99”,
“discount”: “0”
}
}
}