@dintero/checkout-web-sdk

中文文档
0.14.2发布于 2026/10/13MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.8万

Dintero Checkout SDK for web frontends

原始使用文档
文档目录18 节
  1. Before you start
  2. Installation
  3. Using the SDK for an embedded checkout
  4. Minimal example
  5. Full inline HTML JavaScript example
  6. Typescript example
  7. Setting payment product type
  8. Handling Checkout Express address updates using the onAddre…
  9. Updating an Checkout Express-session
  10. Validating session before payment
  11. Debug logging
  12. Age verification events
  13. Using the SDK for a redirect checkout
  14. Bugs
  15. Security
  16. Browser support
  17. Building from source
  18. Creating a new release

Dintero Checkout JavaScript SDK for frontend applications Actions Status npm latest version

Use this SDK in your frontend application to

  • embed an existing Dintero Checkout payment session in an iframe on your website
  • redirect the end user to the full page version of the Dintero Checkout for an existing payment session

Note that this SDK is for redirecting or embedding existing payment sessions. You cannot use this SDK to send requests to the Checkout API or to crate new payment sessions.

Learn more about the Dintero Checkout at docs.dintero.com

Before you start

We cannot guarantee the delivery of events from the embedded checkout to the SDK client runtime. The sessions machine-to-machine callback_url will be delivered at least once. Read more about the callback_url parameter in our api spec.

For payments on devices with the Vipps app installed, after payment is completed in the Vipps app, the end user will be returned to the browser where the return_url on the payment is opened in a new browser tab leaving the site that has the embedded checkout still open in a background browser tab on the device. In this case the SDK cannot guarantee that the handlers for onPaymentAuthorized or onPaymentError will be called.

If no custom handler are added for onPaymentError, onPaymentAuthorized and onPaymentCanceled the SDK will redirect the user to the return_url in the payment session.

Installation

NPM package

npm install @dintero/checkout-web-sdk

Using the SDK for an embedded checkout

The Dintero Checkout will be added to the <div id="checkout-container"></div> DOM-node.

Minimal example

When payment is completed, the SDK will redirect the end user to the return_url defined in the payment session.

<script type="text/javascript">
    const container = document.getElementById("checkout-container");

    dintero.embed({
        container,
        sid: "T11223344.<short-uuid>",
    });
</script>

Full inline HTML JavaScript example

The checkout sdk will add a polyfill for promises if the browser does not support promises natively.

<script type="text/javascript">
    const container = document.getElementById("checkout-container");

    dintero
        .embed({
            container,
            sid: "T11223344.<short-uuid>",
            popOut: false, // optional parameter to enable pop out mode
            language: "no", // optional parameter, an ISO 639-1 two-letter language code
            debug: false, // optional parameter, log SDK activity to the console, do not use for production
            onSession: function (event, checkout) {
                console.log("session", event.session);
            },
            onPayment: function (event, checkout) {
                console.log("transaction_id", event.transaction_id);
                console.log("href", event.href);
                checkout.destroy();
            },
            onPaymentError: function (event, checkout) {
                console.log("href", event.href);
                checkout.destroy();
            },
            onSessionCancel: function (event, checkout) {
                console.log("href", event.href);
                checkout.destroy();
            },
            onSessionNotFound: function (event, checkout) {
                console.log("session not found (expired)", event.type);
                checkout.destroy();
            },
            onSessionLocked: function (event, checkout, callback) {
                console.log("pay_lock_id", event.pay_lock_id);
                callback(); // refresh session
            },
            onSessionLockFailed: function (event, checkout) {
                console.log("session lock failed");
            },
            onActivePaymentType: function (event, checkout) {
                console.log(
                    "payment product type selected",
                    event.payment_product_type,
                );
            },
            onAddressCallback: function (event, checkout, callback) {
                console.log("address callback to handle express session address updates", event.session);
                callback({
                    success: true,
                    error: undefined,
                });
            },
            onValidateSession: function (event, checkout, callback) {
                console.log("validating session", event.session);
                callback({
                    success: true,
                    clientValidationError: undefined,
                });
            },
            onAgeVerificationStarted: function (event, checkout) {
                console.log("age verification started");
            },
            onAgeVerificationFailed: function (event, checkout) {
                console.log("age verification failed", event.error);
            },
            onAgeVerificationEnded: function (event, checkout) {
                console.log("age verification ended", event.result);
            },
        })
        .then(function (checkout) {
            console.log("checkout", checkout);
        });
</script>

Typescript example

import {
    embed,
    SessionLoaded,
    SessionUpdated,
    SessionPayment,
    SessionPaymentError,
    SessionCancel,
    SessionNotFound,
    AgeVerificationStarted,
    AgeVerificationFailed,
    AgeVerificationEnded,
} from "@dintero/checkout-web-sdk";

const container = document.getElementById("checkout-container");

const checkout = await embed({
    container,
    sid: "T11223344.<short-uuid>",
    popOut: false, // optional parameter to enable pop out mode
    language: "no", // optional parameter, an ISO 639-1 two-letter language code
    debug: false, // optional parameter, log SDK activity to the console, never in production
    onSession: (event: SessionLoaded | SessionUpdated) => {
        console.log("session", event.session);
    },
    onPayment: (
        event: SessionPaymentAuthorized | SessionPaymentOnHold,
        checkout,
    ) => {
        console.log("transaction_id", event.transaction_id);
        console.log("href", event.href);
        checkout.destroy();
    },
    onPaymentError: (event: SessionPaymentError, checkout) => {
        console.log("href", event.href);
        checkout.destroy();
    },
    onSessionCancel: (event: SessionCancel, checkout) => {
        console.log("href", event.href);
        checkout.destroy();
    },
    onSessionNotFound: (event: SessionNotFound, checkout) => {
        console.log("session not found (expired)", event.type);
        checkout.destroy();
    },
    onSessionLocked: (event: SessionLocked, checkout, callback) => {
        console.log("pay_lock_id", event.pay_lock_id);
        callback(); // refresh session
    },
    onSessionLockFailed: (event: SessionLockFailed, checkout) => {
        console.log("session lock failed");
    },
    onActivePaymentType: function (event: ActivePaymentProductType, checkout) {
        console.log(
            "payment product type selected",
            event.payment_product_type,
        );
    },
    onAddressCallback: function (event: AddressCallback, checkout, callback) {
        console.log("address callback to handle express session address updates", event.session);
        callback({
            success: true,
            error: undefined,
        });
    },
    onValidateSession: function (event: ValidateSession, checkout, callback) {
        console.log("validating session", event.session);
        callback({
            success: true,
            clientValidationError: undefined,
        });
    },
    onAgeVerificationStarted: (event: AgeVerificationStarted, checkout) => {
        console.log("age verification started");
    },
    onAgeVerificationFailed: (event: AgeVerificationFailed, checkout) => {
        console.log("age verification failed", event.error);
    },
    onAgeVerificationEnded: (event: AgeVerificationEnded, checkout) => {
        console.log("age verification ended", event.result);
    },
});

Setting payment product type

The payment product type can be set with the returned setActivePaymentProductType()function when embedding the checkout.

Select "vipps" payment product type:

checkout.setActivePaymentProductType("vipps");

Resetting selection (so no option is selected in the checkout):

checkout.setActivePaymentProductType();

Handling Checkout Express address updates using the onAddressCallback

If the onAddressCallback is provided the checkout will not perform the machine to machine address update callback defined in the payment session object at express.shipping_address_callback_url. Instead the SDK runtime has to handle the address update flow.

The onAddressCallback function is invoked when an end user submits their address details (the shipping and billing addresses) in an embedded Checkout Express session. The callback function is invoked with an updated session that is not yet persisted in the Dintero backend. The checkout will be locked and payment will be paused until the provided callback function is called, or checkout.submitAddressCallbackResult is called with the result.

When onAddressCallback is invoked you will have to perform a server-to-server session update with shipping options or other details that have changed. Once the session has been updated you need to call the provided callback function with a result.

When session has been updated successfully, return a successful result:

{
    success: true;
}

If the session update failed, return the result with an error message:

{
   success: false,
   error: "<reason for session update failure>"
}

Example implementation:

onAddressCallback: function(event, checkout, callback) {
     // Perform a server-to-server session update
     getShippingOptionsForAddressAndUpdateSession(event.session).then(() => {
        callback({
            success: true,
        });
     }).catch((err) => {
        callback({
            success: false,
            error: toErrorMessage(err), 
        });
     });
},

Note: When implementing the onAddressCallback, there is no need to manually lock the session and refresh it. The checkout will automatically lock the payment and refresh the session when the callback function is used to return a result.

Updating an Checkout Express-session

To update an existing Checkout Express-session, follow these steps:

  1. Lock the session with the SDK
  2. Perform a server-to-server session update
  3. Refresh the session with the SDK

Locking the session

Call lockSession on the checkout object:

checkout
    .lockSession()
    .then(function (sessionLockedEvent) {
        // initiate server side session update and then refresh the session
    })
    .catch(function (sessionLockFailedEvent) {
        // handle failure to lock
    });

lockSession() returns a promise that is resolved when the SessionLocked event is received from the checkout or rejected if the SessionLockFailed event is received.

When the session is successfully locked, you'll get a callback at onSessionLocked. If locking the session fails, there will be a callback at onSessionLockFailed.

While the session is locked, all editing and paying in the checkout is disabled.

Perform a server-to-server session update

See session update for details on what parts of the session can be updated, and how.

Refreshing the session

After updating the session, call refreshSession on the checkout object:

checkout.refreshSession();

or use the callback in onSessionLocked:

onSessionLocked: (event, checkout, callback) => {
    console.log("pay_lock_id", event.pay_lock_id);
    callback(); // refresh session
};

refreshSession() returns a promise that is resolved when the SessionUpdated event is received from the checkout.

Editing and paying in the checkout is enabled again when a session without a pay_lock is loaded by the checkout.

Validating session before payment

To validate the session and perform actions before the session is paid, use the onSessionValidation-handler.

The checkout will be locked and payment will be paused until the provided callback function is called, or checkout.submitValidationResult is called with the result.

When validated successfully, return a successful result:

{
    success: true;
}

If the validation is not successful, return the result with an error message:

{
   success: false,
   clientValidationError: "session is not in sync with cart"
}

Example implementation:

onValidateSession: function(event, checkout, callback) {
     // Call the ecommerce solution to make sure the session is sync with the cart
     callback({
         success: false,
         clientValidationError: "session is not in sync with cart",
     });
},

Debug logging

Set debug: true in the options passed to embed() or redirect() to make the SDK log what it is doing to the browser console. Every entry is written with console.log and prefixed with [dintero-checkout-web-sdk].

:warning: Never enable debug in production. The log entries contain the full, unredacted payloads the SDK receives, including the payment session with the name, e-mail, phone number, addresses and order lines of the end user.

The SDK logs:

  • the options embed() or redirect() was called with, and the checkout url it resolved them to
  • the parameters of every on<Event> handler, logged right before the handler is invoked
  • the results submitted back to the SDK, both through the callback given to onValidateSession/onAddressCallback and through checkout.submitValidationResult()/checkout.submitAddressCallbackResult(), which are logged with the name of the function that was used
  • the functions called on the checkout instance: lockSession(), refreshSession(), setActivePaymentProductType(), submitValidationResult(), submitAddressCallbackResult() and destroy(), including the event lockSession() and refreshSession() resolve with, or the reason they are rejected
  • errors thrown by the handlers in the host application, which the SDK otherwise only reports with console.error

Example output for a session that is loaded, locked and refreshed:

[dintero-checkout-web-sdk] embed(options) {sid: "T11223344.<short-uuid>", debug: true, …}
[dintero-checkout-web-sdk] embed session url https://checkout.dintero.com/v1/view/…
[dintero-checkout-web-sdk] options.onSession() {type: "SessionLoaded", session: {…}} {…}
[dintero-checkout-web-sdk] checkout.lockSession()
[dintero-checkout-web-sdk] checkout.lockSession() resolved {type: "SessionLocked", …}
[dintero-checkout-web-sdk] options.onSessionLocked() {type: "SessionLocked", …} {…} f
[dintero-checkout-web-sdk] onSessionLocked callback()
[dintero-checkout-web-sdk] onSessionLocked callback() resolved {type: "SessionUpdated", …}

Nothing is logged when debug is left out or set to false. The wording of the log entries is a debugging aid and may change between releases.

Age verification events

If the payment session has age verification enabled, the checkout will show a gate that the end user must pass through an identity provider (eg. BankID) before the rest of the checkout is available. Use onAgeVerificationStarted, onAgeVerificationFailed and onAgeVerificationEnded to react to this flow from the embedding page.

  • onAgeVerificationStarted is called when the end user clicks through to start the identity provider flow.
  • onAgeVerificationFailed is called when verification could not be completed, eg. because the end user did not meet the minimum age requirement or authorization with the identity provider failed. The error field holds a reason, eg. "age-requirement-not-met". Note that the end user cancelling out of the identity provider is not treated as a failure - the gate is simply shown again so they can retry.
  • onAgeVerificationEnded is called once verification has passed and the gate is lifted. The result field is currently always "passed".

While age verification is in progress, lockSession(), refreshSession(), and setActivePaymentProductType() throw synchronously. Avoid these calls until verification finishes, or handle the error with try/catch; promise rejection handlers do not catch it.

onAgeVerificationStarted: function (event, checkout) {
    console.log("age verification started");
},
onAgeVerificationFailed: function (event, checkout) {
    console.log("age verification failed", event.error);
},
onAgeVerificationEnded: function (event, checkout) {
    console.log("age verification ended", event.result);
},

Using the SDK for a redirect checkout

The user is redirected to the Dintero Checkout to complete payment.

import { redirect } from "dintero-checkout-web-sdk";

const checkout = redirect({
    sid: "T11223344.<short-uuid>",
});

Bugs

Bugs can be reported to https://github.com/Dintero/Dintero.Checkout.Web.SDK/issues

Security

Contact us at [email protected]

Browser support

All major browsers above version N - 1, where N is the most recent version.

The SDK includes a polyfill for promises that is added to the global scope if promises are not supported by the browser.

Building from source

make build

The Dintero Checkout SDK is built with tsdown.

Creating a new release

  1. Enforce all commits to the master branch to be formatted according to the Angular Commit Message Format
  2. When merged to master, it will automatically be released with semantic-release

版本与发布记录

@dintero/checkout-web-sdk 共发布 117 个版本,首次发布于 2020/02/04;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.14.2latest2026/10/1330 天前
0.14.12026/09/102 个月前
0.14.02026/08/262 个月前
0.13.02026/08/262 个月前
0.12.202026/08/242 个月前
0.12.192026/07/243 个月前

关于 @dintero/checkout-web-sdk 的常见问题

@dintero/checkout-web-sdk 是什么?

Dintero Checkout SDK for web frontends

如何安装 @dintero/checkout-web-sdk?

在项目目录运行 npm install @dintero/checkout-web-sdk,或使用 pnpm add / yarn add / bun add。

@dintero/checkout-web-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dintero/checkout-web-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dintero/checkout-web-sdk 可以商用吗?

@dintero/checkout-web-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dintero/checkout-web-sdk 的下载量有多少?

根据 npm 官方下载统计,@dintero/checkout-web-sdk 在 2026/10/13 – 2026/11/11 这 30 天内被下载 17,872 次,日均约 596 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dintero/checkout-web-sdk 还在维护吗?

最新版本 0.14.2 发布于 2026/10/13(30 天前);至今共发布 117 个版本,其中过去 12 个月发布了 32 个;首次发布于 2020/02/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。