Search...
onOrderApproved( )
An event that triggers when an order is approved.
Description
The onOrderApproved()
event handler runs when an order is created and its status is updated to "APPROVED"
. The received OrderApprovedEvent
object contains information about the order that was approved and event metadata.
Note: Backend events don't work when previewing your site.
Syntax
function wixEcom_onOrderApproved(event: OrderApprovedEvent): void
onOrderApproved Parameters
NAME
TYPE
DESCRIPTION
event
Optional
OrderApprovedEvent
Information about the order that was approved and metadata for the event.
Returns
This function does not return anything.
Return Type:
void
Was this helpful?
An event fired when an order is approved
Copy Code
1// Place this code in the events.js file2// of your site's Backend section.3// Add the file if it doesn't exist.45export function wixEcom_onOrderApproved(event) {6 const orderId = event.data.order._id;7 const orderTotalPrice = event.data.order.priceSummary.totalPrice.amount;8 const eventId = event.metadata.id;9 console.log('Order approved', event)10}111213/* Full event object:14 *15 * {16 * "metadata": {17 * "id": "8f0a09a4-1fd1-4ff2-976a-21f1b2e0fe2f",18 * "entityId": "67668940-527d-4465-94c6-5475d8c7a412",19 * "eventTime": "2022-07-31T13:42:20.141721Z",20 * "triggeredByAnonymizeRequest": false21 * },22 * "data": {23 * "order": {24 * "_id": "67668940-527d-4465-94c6-5475d8c7a412",25 * "number": "10124",26 * "_createdDate": "2022-07-31T13:42:13.136Z",27 * "_updatedDate": "2022-07-31T13:42:20.026Z",28 * "lineItems": [29 * {30 * "_id": "00000000-0000-0000-0000-000000000001",31 * "productName": {32 * "original": "Brazilian Arabica",33 * "translated": "Brazilian Arabica"34 * },35 * "catalogReference": {36 * "catalogItemId": "0614129c-8777-9f3b-4dfe-b80a54df10d5",37 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",38 * "options": {39 * "options": {40 * "Weight": "500g",41 * "Ground for": "Stovetop"42 * },43 * "variantId": "00000000-0000-003f-0005-a316f7c67df7",44 * "customTextFields": {45 * "What would you like written on the custom label?": "Enjoy our finest coffee."46 * }47 * }48 * },49 * "quantity": 1,50 * "totalDiscount": {51 * "amount": "0",52 * "formattedAmount": "$0.00"53 * },54 * "descriptionLines": [55 * {56 * "name": {57 * "original": "Weight",58 * "translated": "Weight"59 * },60 * "plainText": {61 * "original": "500g",62 * "translated": "500g"63 * },64 * "lineType": "PLAIN_TEXT",65 * "plainTextValue": {66 * "original": "500g",67 * "translated": "500g"68 * }69 * },70 * {71 * "name": {72 * "original": "Ground for",73 * "translated": "Ground for"74 * },75 * "plainText": {76 * "original": "Stovetop",77 * "translated": "Stovetop"78 * },79 * "lineType": "PLAIN_TEXT",80 * "plainTextValue": {81 * "original": "Stovetop",82 * "translated": "Stovetop"83 * }84 * },85 * {86 * "name": {87 * "original": "What would you like written on the custom label?",88 * "translated": "What would you like written on the custom label?"89 * },90 * "plainText": {91 * "original": "Enjoy our finest coffee.",92 * "translated": "Enjoy our finest coffee."93 * },94 * "lineType": "PLAIN_TEXT",95 * "plainTextValue": {96 * "original": "Enjoy our finest coffee.",97 * "translated": "Enjoy our finest coffee."98 * }99 * }100 * ],101 * "image": "wix:image://v1/nsplsh_306d666a306a4a74306459~mv2_d_4517_2992_s_4_2.jpg#originWidth=4517&originHeight=2992",102 * "physicalProperties": {103 * "weight": 0.5,104 * "shippable": true105 * },106 * "itemType": {107 * "preset": "PHYSICAL"108 * },109 * "fulfillerId": "85e29287-a5bf-4c25-b303-a2ddc9d975e2",110 * "refundQuantity": 0,111 * "price": {112 * "amount": "48.75",113 * "formattedAmount": "$48.75"114 * },115 * "priceBeforeDiscounts": {116 * "amount": "48.75",117 * "formattedAmount": "$48.75"118 * },119 * "totalPriceBeforeTax": {120 * "amount": "48.75",121 * "formattedAmount": "$48.75"122 * },123 * "totalPriceAfterTax": {124 * "amount": "50.70",125 * "formattedAmount": "$50.70"126 * },127 * "paymentOption": "FULL_PAYMENT_ONLINE",128 * "taxDetails": {129 * "taxableAmount": {130 * "amount": "48.75",131 * "formattedAmount": "$48.75"132 * },133 * "taxRate": "0.04",134 * "totalTax": {135 * "amount": "1.95",136 * "formattedAmount": "$1.95"137 * }138 * }139 * }140 * ],141 * "buyerInfo": {142 * "contactId": "f61f30cd-7474-47b7-95a2-339c0fcacbd3",143 * "email": "janedoe@gmail.com",144 * "visitorId": "b52ec002-40dd-469c-9f9f-833988e8048d"145 * },146 * "paymentStatus": "PAID",147 * "fulfillmentStatus": "NOT_FULFILLED",148 * "buyerLanguage": "en",149 * "weightUnit": "LB",150 * "currency": "USD",151 * "taxIncludedInPrices": false,152 * "priceSummary": {153 * "subtotal": {154 * "amount": "48.75",155 * "formattedAmount": "$48.75"156 * },157 * "shipping": {158 * "amount": "5.0",159 * "formattedAmount": "$5.00"160 * },161 * "tax": {162 * "amount": "1.95",163 * "formattedAmount": "$1.95"164 * },165 * "discount": {166 * "amount": "0",167 * "formattedAmount": "$0.00"168 * },169 * "totalPrice": {170 * "amount": "55.70",171 * "formattedAmount": "$55.70"172 * },173 * "totalWithGiftCard": {174 * "amount": "55.70",175 * "formattedAmount": "$55.70"176 * },177 * "totalWithoutGiftCard": {178 * "amount": "55.70",179 * "formattedAmount": "$55.70"180 * }181 * },182 * "billingInfo": {183 * "address": {184 * "addressLine1": "525 5th Avenue",185 * "city": "New York",186 * "subdivision": "US-NY",187 * "country": "US",188 * "postalCode": "10173"189 * },190 * "contactDetails": {191 * "firstName": "Jane",192 * "lastName": "Doe",193 * "phone": "0555555555"194 * }195 * },196 * "shippingInfo": {197 * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc",198 * "code": "a0fde0a4-6f4e-3716-64be-c0acbde1696a",199 * "title": "U.S Shipping",200 * "logistics": {201 * "deliveryTime": "3 - 5 business days",202 * "shippingDestination": {203 * "address": {204 * "addressLine1": "525 5th Avenue",205 * "city": "New York",206 * "subdivision": "US-NY",207 * "country": "US",208 * "postalCode": "10173"209 * },210 * "contactDetails": {211 * "firstName": "Jane",212 * "lastName": "Doe",213 * "phone": "0555555555"214 * }215 * }216 * },217 * "cost": {218 * "price": {219 * "amount": "5",220 * "formattedAmount": "$5.00"221 * },222 * "totalPriceBeforeTax": {223 * "amount": "5",224 * "formattedAmount": "$5.00"225 * },226 * "totalPriceAfterTax": {227 * "amount": "5.0",228 * "formattedAmount": "$5.00"229 * },230 * "taxDetails": {231 * "taxRate": "0.0",232 * "totalTax": {233 * "amount": "0.0",234 * "formattedAmount": "$0.00"235 * }236 * },237 * "discount": {238 * "amount": "0",239 * "formattedAmount": "$0.00"240 * }241 * },242 * "region": {243 * "name": "Region 3"244 * }245 * },246 * "buyerNote": "This is a buyerNote",247 * "status": "APPROVED",248 * "archived": false,249 * "taxSummary": {250 * "totalTax": {251 * "amount": "1.95",252 * "formattedAmount": "$1.95"253 * },254 * "manualTaxRate": "0.04"255 * },256 * "appliedDiscounts": [],257 * "activities": [258 * {259 * "_createdDate": "2022-07-31T13:42:13.136Z",260 * "type": "ORDER_PLACED"261 * }262 * ],263 * "attributionSource": "UNSPECIFIED",264 * "createdBy": {265 * "visitorId": "b52ec002-40dd-469c-9f9f-833988e8048d"266 * },267 * "channelInfo": {268 * "type": "WEB"269 * },270 * "seenByAHuman": false,271 * "checkoutId": "62d01935-e0d3-4063-9e78-da099462e90c",272 * "customFields": [],273 * "cartId": "52fec024-4379-4a96-9237-9660030be6fe",274 * "payNow": {275 * "subtotal": {276 * "amount": "48.75",277 * "formattedAmount": "$48.75"278 * },279 * "shipping": {280 * "amount": "5.0",281 * "formattedAmount": "$5.00"282 * },283 * "tax": {284 * "amount": "1.95",285 * "formattedAmount": "$1.95"286 * },287 * "discount": {288 * "amount": "0",289 * "formattedAmount": "$0.00"290 * },291 * "totalPrice": {292 * "amount": "55.70",293 * "formattedAmount": "$55.70"294 * },295 * "totalWithGiftCard": {296 * "amount": "55.70",297 * "formattedAmount": "$55.70"298 * },299 * "totalWithoutGiftCard": {300 * "amount": "55.70",301 * "formattedAmount": "$55.70"302 * }303 * },304 * "balanceSummary": {305 * "balance": {306 * "amount": "0.0",307 * "formattedAmount": "$0.00"308 * }309 * }310 * }311 * }312 * }313 *314 */