An event that triggers when a checkout is completed. This happens either when an order is created from a checkout, or after using markCheckoutAsCompleted()
.
The onCheckoutCompleted()
event handler runs when a checkout is completed. The received CheckoutCompleted
object contains information about the checkout that was completed and event metadata.
Note: Backend events don't work when previewing your site.
function wixEcom_onCheckoutCompleted(event: CheckoutCompleted): void;
Information about the checkout that was completed and event metadata.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixEcom_onCheckoutCompleted(event) {
const checkoutSubtotal = event.entity.subtotal.amount;
const checkoutId = event.entity._id;
const checkoutComplete = event.entity.completed;
const eventId = event.metadata.id;
console.log("Checkout completed", event);
}
/* Full event object:
*
* {
* "metadata": {
* "id": "d94b500b-3906-434f-bd90-92c521e4f0e3",
* "entityId": "81b73bc6-d403-4afe-8464-226f9505b1c2",
* "eventTime": "2022-10-27T11:58:12.667470Z",
* "triggeredByAnonymizeRequest": false
* },
* "data": {
* "checkout": {
* "_id": "81b73bc6-d403-4afe-8464-226f9505b1c2",
* "lineItems": [
* {
* "_id": "00000000-0000-0000-0000-000000000001",
* "quantity": 3,
* "catalogReference": {
* "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
* },
* "productName": {
* "original": "Shirt",
* "translated": "Shirt"
* },
* "url": "https://example.wixsite.com",
* "price": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "lineItemPrice": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "fullPrice": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "priceBeforeDiscounts": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "totalPriceAfterTax": {
* "amount": "20",
* "convertedAmount": "20",
* "formattedAmount": "$20.00",
* "formattedConvertedAmount": "$20.00"
* },
* "totalPriceBeforeTax": {
* "amount": "20",
* "convertedAmount": "20",
* "formattedAmount": "$20.00",
* "formattedConvertedAmount": "$20.00"
* },
* "taxDetails": {
* "taxableAmount": {
* "amount": "20",
* "convertedAmount": "20",
* "formattedAmount": "$20.00",
* "formattedConvertedAmount": "$20.00"
* },
* "taxRate": "0",
* "totalTax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "rateBreakdown": []
* },
* "discount": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "descriptionLines": [],
* "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE"
* },
* "physicalProperties": {
* "sku": "364115376135191",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE",
* "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"
* }
* ],
* "shippingInfo": {
* "carrierServiceOptions": []
* },
* "buyerInfo": {
* "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
* "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
* },
* "conversionCurrency": "USD",
* "priceSummary": {
* "subtotal": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "total": {
* "amount": "20",
* "convertedAmount": "20",
* "formattedAmount": "$20.00",
* "formattedConvertedAmount": "$20.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "calculationErrors": {
* "orderValidationErrors": []
* },
* "appliedDiscounts": [
* {
* "discountType": "GLOBAL",
* "lineItemIds": [],
* "coupon": {
* "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77",
* "code": "SUMMERSALE10",
* "amount": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "name": "SUMMERSALE10",
* "couponType": "MoneyOff"
* }
* }
* ],
* "customFields": [],
* "weightUnit": "KG",
* "currency": "USD",
* "channelType": "WEB",
* "siteLanguage": "en",
* "buyerLanguage": "en",
* "completed": true,
* "taxIncludedInPrice": false,
* "createdBy": {
* "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
* },
* "_createdDate": "2022-10-27T11:42:17.059Z",
* "_updatedDate": "2022-10-27T11:58:12.657Z",
* "payNow": {
* "subtotal": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "total": {
* "amount": "20",
* "convertedAmount": "20",
* "formattedAmount": "$20.00",
* "formattedConvertedAmount": "$20.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "payLater": {
* "subtotal": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "membershipOptions": {
* "eligibleMemberships": [],
* "invalidMemberships": [],
* "selectedMemberships": {
* "memberships": []
* }
* },
* "additionalFees": []
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.