To use the Checkout API, install the @wix/ecom
package using npm or Yarn:
npm install @wix/ecom
or
yarn add @wix/ecom
Then import { checkout }
from @wix/ecom
:
import { checkout } from "@wix/ecom";
Adds catalog line items and/or custom line items to a checkout.
The addToCheckout()
function returns a Promise that resolves to the updated checkout when the specified items have been added.
Note: When adding catalog items, options.lineItems.catalogReference
is required.
function addToCheckout(
_id: string,
options: AddToCheckoutOptions,
): Promise<AddToCheckoutResponse>;
Checkout ID.
Items to be added to checkout.
import { checkout } from "@wix/ecom";
async function addToCheckout(id, options) {
const response = await checkout.addToCheckout(id, options);
}
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.
import { checkout } from "@wix/ecom";
async function createCheckout(options) {
const response = await checkout.createCheckout(options);
}
Creates an order from a specified checkout.
The createOrder()
function returns a Promise that resolves to the new order's ID and paymentGatewayOrderID
when the order is created.
Pass the paymentGatewayOrderId
as the paymentId
param to the startPayment()
function to allow a customer to pay for their order.
Note: The following requirements must be met for an order to be created from a checkout.
checkout._id
to Get Checkout and take a look at the calculationErrors
field.availability.status
of "AVAILABLE"
or "PARTIALLY_AVAILABLE"
.priceSummary.total
is greater than 0, the billingInfo.address
field must be provided.shippingInfo.shippingDestination.address
and shippingInfo.selectedCarrierServiceOption
fields must be provided.shippingInfo.selectedCarrierServiceOption.logistics.pickupDetails
field must be provided.function createOrder(
_id: string,
options: CreateOrderOptions,
): Promise<CreateOrderResponse>;
Checkout ID.
Further order creation options.
import { checkout } from "@wix/ecom";
async function createOrder(id, options) {
const response = await checkout.createOrder(id, options);
}
Retrieves a checkout.
The getCheckout()
function returns a Promise that resolves when the specified checkout is retrieved.
function getCheckout(_id: string): Promise<Checkout>;
Checkout ID.
import { checkout } from "@wix/ecom";
async function getCheckout(id) {
const response = await checkout.getCheckout(id);
}
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Retrieves the checkout page URL of a specified checkout.
By default, a checkoutUrl
generates for a checkout and directs to a standard Wix checkout page.
However, if overrideCheckoutUrl
has a value, it will replace and set the value of checkoutUrl
.
function getCheckoutUrl(_id: string): Promise<GetCheckoutURLResponse>;
Checkout ID.
import { checkout } from "@wix/ecom";
async function getCheckoutUrl(id) {
const response = await checkout.getCheckoutUrl(id);
}
Marks a checkout as completed - checkout.complete
boolean is set to true
.
The markCheckoutAsCompleted()
function returns a Promise that resolves when the specified checkout is marked as completed.
function markCheckoutAsCompleted(_id: string): Promise<void>;
Checkout ID.
import { checkout } from "@wix/ecom";
async function markCheckoutAsCompleted(id) {
const response = await checkout.markCheckoutAsCompleted(id);
}
Removes the coupon from a specified checkout.
The removeCoupon()
function returns a Promise that resolves to the updated checkout when the coupon is removed from the specified checkout.
Note: A checkout can only hold 1 coupon.
function removeCoupon(_id: string): Promise<RemoveCouponResponse>;
ID of the checkout to remove the coupon from.
import { checkout } from "@wix/ecom";
async function removeCoupon(id) {
const response = await checkout.removeCoupon(id);
}
Removes the gift card from a specified checkout.
The removeGiftCard()
function returns a Promise that resolves to the updated checkout when the gift card is removed from the specified checkout.
Note: A checkout can only hold 1 gift card.
function removeGiftCard(_id: string): Promise<RemoveGiftCardResponse>;
ID of the checkout to remove the gift card from.
import { checkout } from "@wix/ecom";
async function removeGiftCard(id) {
const response = await checkout.removeGiftCard(id);
}
Removes line items from the specified checkout.
The removeLineItems()
function returns a Promise that resolves to the updated checkout when the line items are removed from the specified checkout.
function removeLineItems(
_id: string,
lineItemIds: Array<string>,
): Promise<RemoveLineItemsResponse>;
ID of the checkout to remove line items from.
IDs of the line items to be removed.
To find the IDs of the checkout line items you'd like to remove, pass the checkout._id
to getCheckout() and look for the IDs under lineItems
and/or customLineItems
.
import { checkout } from "@wix/ecom";
async function removeLineItems(id, lineItemIds) {
const response = await checkout.removeLineItems(id, lineItemIds);
}
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Removes the overrideCheckoutUrl
from a specified checkout.
When overrideCheckoutUrl
is removed, the checkoutUrl
will be set to the default, standard
Wix checkout page URL.
function removeOverrideCheckoutUrl(
_id: string,
): Promise<RemoveOverrideCheckoutUrlResponse>;
ID of the checkout to remove the override checkout url from.
import { checkout } from "@wix/ecom";
async function removeOverrideCheckoutUrl(id) {
const response = await checkout.removeOverrideCheckoutUrl(id);
}
Updates a checkout.
The updateCheckout()
function returns a Promise that resolves to the updated checkout when the specified properties are updated.
Notes:
checkout.buyerInfo.email
may not be removed once it is set.function updateCheckout(
_id: string,
checkout: UpdateCheckout,
options: UpdateCheckoutOptions,
): Promise<Checkout>;
Checkout ID.
Checkout update options.
import { checkout } from "@wix/ecom";
async function updateCheckout(id, checkout, options) {
const response = await checkout.updateCheckout(id, checkout, options);
}
Updates the quantity of one or more line items in a checkout.
This endpoint is only for updating the quantity of line items. To entirely remove a line item from
the checkout, use removeLineItems()
.
To add a new line item to the checkout, use addToCheckout()
.
This endpoint checks the amount of stock remaining for this line item. If the specified quantity
is greater than the remaining stock, then the quantity
returned in the response is the total amount
of remaining stock.
function updateLineItemsQuantity(
_id: string,
lineItems: Array<LineItemQuantityUpdate>,
): Promise<UpdateLineItemsQuantityResponse>;
Checkout ID.
Line item info to update.
import { checkout } from "@wix/ecom";
async function updateLineItemsQuantity(id, lineItems) {
const response = await checkout.updateLineItemsQuantity(id, lineItems);
}
Triggered when an order created from this checkout is successfully paid for or when a checkout is marked as completed.
function onCheckoutCompleted(handler: function): void;
handler(event: CheckoutCompletedEnvelope): void | Promise<void>
import { checkout } from "@wix/ecom";
checkout.onCheckoutCompleted((event) => {
// handle your event here
});
Triggered when a checkout is created.
function onCheckoutCreated(handler: function): void;
handler(event: CheckoutCreatedEnvelope): void | Promise<void>
import { checkout } from "@wix/ecom";
checkout.onCheckoutCreated((event) => {
// handle your event here
});
Triggered when a checkout is updated.
function onCheckoutUpdated(handler: function): void;
handler(event: CheckoutUpdatedEnvelope): void | Promise<void>
import { checkout } from "@wix/ecom";
checkout.onCheckoutUpdated((event) => {
// handle your event here
});