@combeenation/custom-code-sdk
    Preparing search index...

    Function finishConfiguration

    • Creates a finish of the current configuration by running all the Configurator's finish actions and optionally passes the resulting data to the parent page.

      Parameters

      • options:
            | FinishConfigurationBaseOptions & { sendDataToParentPage: false }
            | FinishConfigurationBaseOptions & {
                sendDataToParentPage: true;
                transformParentPageData: (
                    finishResult: FinishResultData,
                ) => ParentPageCheckoutData & { [key: string]: SerializableJsonValue };
            }
        • FinishConfigurationBaseOptions & { sendDataToParentPage: false }
        • FinishConfigurationBaseOptions & {
              sendDataToParentPage: true;
              transformParentPageData: (
                  finishResult: FinishResultData,
              ) => ParentPageCheckoutData & { [key: string]: SerializableJsonValue };
          }
          • sendDataToParentPage: true

            If true, the data returned by transformParentPageData will be passed to the function window.Combeenation.onConfigurationFinished(data) on the parent page (or one of its older aliases like Combeenation.onCheckout etc.).

          • transformParentPageData: (
                finishResult: FinishResultData,
            ) => ParentPageCheckoutData & { [key: string]: SerializableJsonValue }

            Provides the checkout data which is passed to the parent page after the configuration is finished.

            This is meant to forward the checkout result of the finish. Things to note:

            1. This function is required because the SDK can't know which of the finish action results in finishResult.actionResults (keyed by finish action type name, e.g. ShopCheckout or Checkout) is the actual checkout result, so you have to select it here.
            2. Don't change checkoutParameters, since checkoutParametersHash is built from it on the server and wouldn't match anymore.
            3. You may add additional (JSON-serializable) data to the returned object, which is passed to the parent page along with the checkout data.
            finishConfiguration({
            sendDataToParentPage: true,
            transformParentPageData: finishResult => {
            const checkout = Object.values(finishResult.actionResults ?? {}).find(
            (r): r is CheckoutFinishActionResponse => r.type === FinishActionResponseTypes.Checkout
            );
            if (!checkout) throw new Error('No checkout finish action result');

            return {
            id: checkout.cfgnId,
            authentication: checkout.authToken,
            checkoutParameters: checkout.checkoutParameters ?? '',
            checkoutParametersHash: checkout.checkoutParametersHash ?? '',
            queryParameters: Object.fromEntries(new URLSearchParams(window.location.search)),
            } satisfies ParentPageCheckoutData;
            },
            });

      Returns Promise<FinishResultData | undefined>

      The finish result or undefined if the finish failed.