How can I add additional data to the Order object so it can show up when the event is triggered in onOrderPurchased?
I call the createOnlineOrder function to create my Order object. Then I add additional data to the Order object. I call the startPayment function. Once the payment is processed, the onOrderPurchased function is triggered. The Order object is missing the additional data that I need.
When the onOrderPurchased function is triggered, I check the payment status. If the payment status is successful, I will insert data into the collection from the backend since it is more secured than doing so in the frontend. The additional data is needed for the collection.
Front End - I see the testData
order.testData = testData;
console.log(order);
await wixPayFrontend.startPayment(order.wixPayOrderId);
Backend/event.js - I do not see the testData.
export function wixPricingPlans_onOrderPurchased(event) {
console.log(event);
}
create order online api - This JSON was copied from the API page so the testData is not shown here. However, I have verified testData is there after I added it.
{
"order": {
"id": "5b4fe5c4-67fe-4d67-8239-5c6efc06300b",
"planId": "5779edd3-2994-4bf4-acfe-d739ad2d95ad",
"subscriptionId": "281c2e5b-64b2-4acc-adad-58782e1bc40d",
"wixPayOrderId": "8b4e15a2-4bd8-440d-979d-83d35da5c75a",
"buyer": {
"memberId": "805ce40a-9000-464e-85ed-5bb052d8beb7",
"contactId": "805ce40a-9000-464e-85ed-5bb052d8beb7"
},
"pricing": {
"subscription": {
"cycleDuration": {
"count": 1,
"unit": "MONTH"
},
"cycleCount": 0
},
"prices": [
{
"duration": {
"cycleFrom": 1
},
"price": {
"subtotal": "15.00",
"discount": "0",
"tax": {
"name": "Tax",
"rate": "21",
"amount": "3.15"
},
"total": "18.15",
"currency": "EUR"
}
}
]
},
"type": "ONLINE",
"status": "DRAFT",
"autoRenewCanceled": false,
"lastPaymentStatus": "UNPAID",
"startDate": "2022-06-02T11:26:04.496420Z",
"currentCycle": {
"index": 1,
"startedDate": "2022-06-02T11:26:04.496420Z",
"endedDate": "2022-07-02T11:26:04.496420Z"
},
"planName": "Gym membership",
"planDescription": "Get fit fast",
"planPrice": "15",
"createdDate": "2022-06-02T11:26:04.496420Z",
"updatedDate": "2022-06-02T11:26:04.496420Z"
}
}
on order purchased - This JSON was copied from the API page. This is the JSON that I would get. It is missing testData.
{
"metadata": {
"id":"f2e01b16-48c3-4365-89c7-1e3710639f50",
"entityId":"938ca26d-41e0-4aae-81a2-286ae9afd6ef",
"eventTime":"2022-07-26T14:59:49.951623Z",
"triggeredByAnonymizeRequest":false
},
"data": {
"order": {
"_id":"938ca26d-41e0-4aae-81a2-286ae9afd6ef",
"planId":"099e2c86-3b7e-4477-8c27-f77402b8cceb",
"subscriptionId":"1b879750-b4c3-4b17-9687-1f18f6b0ea19",
"wixPayOrderId":"3eb01dc8-45c7-426f-a910-13d8c6008532",
"buyer": {
"memberId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86",
"contactId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"
},
"priceDetails": {
"subtotal":"74.99",
"discount":"0",
"total":"74.99",
"planPrice":"74.99",
"currency":"EUR",
"subscription": {
"cycleDuration": {
"count":1,
"unit":"MONTH"
},
"cycleCount":3
}},
"pricing": {
"subscription": {
"cycleDuration": {
"count":1,
"unit":"MONTH"
},
"cycleCount":3
},
"prices": [{
"duration": {
"cycleFrom":1,
"numberOfCycles":3
},
"price": {
"subtotal":"74.99",
"discount":"0",
"total":"74.99",
"currency":"EUR"
}
}]},
"type":"OFFLINE",
"orderMethod":"UNKNOWN",
"status":"ACTIVE",
"autoRenewCanceled":false,
"lastPaymentStatus":"PAID",
"startDate":"2022-01-25T16:23:00.000Z",
"endDate":"2022-04-25T16:23:00.000Z",
"pausePeriods":[],
"earliestEndDate":"2022-04-25T16:23:00.000Z",
"currentCycle": {
"index":3,
"startedDate":"2022-03-25T16:23:00.000Z",
"endedDate":"2022-04-25T16:23:00.000Z"
},
"planName":"Platinum Pro",
"planDescription":"",
"planPrice":"74.99",
"_createdDate":"2022-07-26T14:59:49.314Z",
"_updatedDate":"2022-07-26T14:59:49.314Z"
}
}
}