Introduction

The Additional Fees service plugin (formerly SPI) is a service provider interface that allows site owners and collaborators to add additional fee calculations that don't come natively with Wix to their site. The service plugin allows you to change how apps, such as Wix Stores and Wix Bookings, calculate charges during checkout. Additional fees are calculated and seen in all eCommerce platform pages including cart, checkout, orders, and payments. Examples of additional fees are surcharges based on customer location, special handling during shipping, or gift wrapping.

Wix eCommerce calls the service plugin endpoint calculateAdditionalFees() to retrieve the relevant data for a site collaborator to add additional fees. Collaborators can then implement their own logic to calculate additional fees, and return the calculated fee data in the structure provided by Wix eCommerce.

Note that currency in the calculateAdditionalFees response must match your site's currency. You can find the currency of your site using the getPaymentCurrency() function.

Learn more:

To add a service plugin

  1. Add the plugin to your site.
  2. Update the getConfig() function in the -config.js file that is added to your site during step 1.
  3. Update the calculateAdditionalFees() function in the .js file that is added to your site during step 1.
Did this help?

calculateAdditionalFees( )


Calculates additional fees to include in the cart and checkout pages.

The calculateAdditionalFees function calculates additional fees to appear in the cart and checkout pages of a store's site. The function is automatically called by Wix when the cart totals are calculated, or when an action is performed in the cart and/or checkout pages. For example, when an item is added to the cart, or when a shipping location is specified.

Where to find calculateAdditionalFees()

When you add the Additional Fees service plugin, a folder is automatically added to your site. Use the .js file in the folder to write the code to calculate any additional fees to add to the cart or checkout.

For more information on calculating your additional fees, see Velo Tutorial: eCommerce Additional Fees Service Plugin.

Method Declaration
Copy
function calculateAdditionalFees(
  options: Options,
  context: Context,
): Promise<CalculateAdditionalFeesResponse>;
Method Parameters
optionsOptionsRequired

Options for line items and shipping options.


contextContextRequired

Metadata about the request.

Returns
Return Type:Promise<CalculateAdditionalFeesResponse>
Calculate additional fees for an order

This example calculates the additional fees for packaging fragile items from a store. If more than 5 fragile items are added to the cart, the fragile packaging is free.

JavaScript
import wixSiteBackend from "wix-site-backend"; export const calculateAdditionalFees = async (options) => { let additionalFees = []; const feePrice = calculateWrappingFee(options.lineItems); const currency = await wixSiteBackend.generalInfo.getPaymentCurrency(); if (feePrice) { additionalFees.push({ code: "fragile-packaging", name: "Fragile Packaging", price: String(feePrice), taxDetails: { taxable: true, }, }); } return { currency, additionalFees, }; }; // Check if an item is fragile. function isFragile(item) { const productName = item.productName.toLowerCase(); return productName.includes("glass") || productName.includes("ceramic"); } // Charge per fragile item. // Give away free packaging when ordering at least 5 items. function calculateWrappingFee(lineItems) { const minItemsForFreeWrapping = 5; let numFragileItems = 0; lineItems.forEach((item) => { if (isFragile(item)) { numFragileItems += item.quantity; } }); const shouldChargeFee = numFragileItems < minItemsForFreeWrapping; const price = shouldChargeFee ? numFragileItems : 0; return price; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

getConfig( )


Retrieves the configuration of your additional fees plugin.

Set your additional fees configuration in the return of the getConfig() function. Wix calls this function when you publish your site. Changes to the configuration don't take effect until you publish your site.

Currently no configurations are available for this plugin, so set getConfig() to return an empty object.

Where to find getConfig()

When you add the Additional Fees service plugin, a folder is automatically added to your site. Use the -config.js file in the folder to set the default configuration for your implementation of the service plugin.

For more information on setting your configuration, see Tutorial: Additional Fees Service Plugin.

Method Declaration
Copy
function getConfig(): Promise<AdditionalFeesConfigResponse>;
Request
This method does not take any parameters
Returns
Return Type:Promise<AdditionalFeesConfigResponse>
Example of a configuration file
JavaScript
// Place this code in the <my-extension-name>-config.js file // in the 'ecom-additional-fees' folder of the // Custom Extensions section on your site. export function getConfig() { return {}; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?