Creates a checkout.
The createCheckout()
function returns a Promise that resolves to the new checkout when it's created.
Notes:
options.lineItems
array.options.channelType
is required._id
for options.lineItems
is added, make sure that each _id
is unique.options.checkoutInfo.customFields
are added, then options.checkoutInfo.customFields.value
is required.function createCheckout(options: CreateCheckoutOptions): Promise<Checkout>;
Checkout creation options.
/**************************************
* Backend code - my-backend-file.jsw *
*************************************/
import { checkout } from "wix-ecom-backend";
export async function myCreateCheckoutFunction(options) {
try {
const newCheckout = await checkout.createCheckout(options);
console.log("Success! Checkout created, checkout:", newCheckout);
return newCheckout;
} catch (error) {
console.error(error);
// Handle the error
}
}
/*************
* Page code *
************/
import { myCreateCheckoutFunction } from "backend/my-backend-file";
// Sample options object:
const options = {
lineItems: [
{
quantity: 3,
catalogReference: {
// Wix Stores appId
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
// Wix Stores productId
catalogItemId: "c8539b66-7a44-fe18-affc-afec4be8562a",
},
},
],
channelType: "WEB",
};
myCreateCheckoutFunction(options)
.then((newCheckout) => {
console.log("Success! Checkout created:", newCheckout);
return newCheckout;
})
.catch((error) => {
console.error(error);
// Handle the error
});
/* Promise resolves to:
*
* {
* "_id": "8a27ba84-0814-4b0e-8db3-b6057a421bd9",
* "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": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "totalPriceBeforeTax": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "taxDetails": {
* "taxableAmount": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* },
* "taxRate": "0",
* "totalTax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "rateBreakdown": []
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.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": {
* "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": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.00"
* }
* },
* "calculationErrors": {
* "orderValidationErrors": []
* },
* "appliedDiscounts": [],
* "customFields": [],
* "weightUnit": "KG",
* "currency": "USD",
* "channelType": "WEB",
* "siteLanguage": "en",
* "buyerLanguage": "en",
* "completed": false,
* "taxIncludedInPrice": false,
* "createdBy": {
* "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
* },
* "_createdDate": "2022-07-18T13:39:03.023Z",
* "_updatedDate": "2022-07-18T13:39:03.023Z",
* "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": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "$30.00",
* "formattedConvertedAmount": "$30.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"
* }
* },
* "membershipOptions": {
* "eligibleMemberships": [],
* "invalidMemberships": [],
* "selectedMemberships": {
* "memberships": []
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.