npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

straumur-web-component

v2.0.0

Published

Embeddable Straumur checkout widget: card, stored card, Google Pay, Apple Pay and Kortalán, built on Adyen Web.

Readme

straumur-web-component

An embeddable, PCI-friendly checkout component for accepting card, saved-card, Google Pay, Apple Pay and Kortalán payments through Straumur. It renders a complete payment UI into an element on your page and handles the payment flow (including 3‑D Secure) for you.

📚 Full documentation: https://docs.straumur.is — see Straumur Components and the Web Integration guide.

Installation

npm install straumur-web-component

Quick start

The component is driven by a session. First, create a session from your backend by calling Straumur's /embeddedcheckout/session endpoint — it returns a sessionId. Pass that sessionId to the component on the client.

Add a container element to your page:

<div id="component-container"></div>

Then initialize and mount the component:

import { StraumurCheckout } from "straumur-web-component";

const paymentConfiguration = {
  environment: "test", // "test" | "live"
  sessionId: "ftsdre3h...e5h5as2q4", // from your /embeddedcheckout/session response
  onPaymentCompleted: (data) => {
    console.info("Payment completed", data.resultCode);
  },
  onPaymentFailed: (data) => {
    console.info("Payment failed", data.resultCode);
  },
  locale: "en", // "is" | "en"
  instantPayments: ["applepay", "googlepay"],
  placeholders: {
    cardNumber: "1234 5678 9012 3456",
  },
  localizations: {
    en: {
      "cards.title": "Card Information",
    },
  },
};

const checkout = new StraumurCheckout(paymentConfiguration);
checkout.mount("#component-container");

Using the CDN / script tag (no bundler)

The package also ships an IIFE build that exposes a global StraumurWeb. Pin the exact version in production, so a new release can't change the widget under you:

<div id="component-container"></div>
<script src="https://unpkg.com/[email protected]"></script>
<script>
  const checkout = new StraumurWeb.StraumurCheckout({
    environment: "test",
    sessionId: "ftsdre3h...e5h5as2q4",
  });
  checkout.mount("#component-container");
</script>

Configuration

Passed to the StraumurCheckout constructor:

| Option | Type | Required | Description | | ---------------------------- | ---------------------------------------------------------- | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------- | | sessionId | string | ✅ | The session id from your /embeddedcheckout/session response. | | environment | "test" \| "live" | ✅ | Selects the Straumur staging or production backend. | | locale | "is" \| "en" | | UI language. Defaults to Icelandic (is). | | theme | "light" \| "dark" \| "system" \| ThemeConfiguration | | Color theme, optionally with wallet button styles — see Theming. | | onPaymentCompleted | (data: { resultCode }) => void | | Called when the payment flow completes (see result codes below). | | onPaymentFailed | (data: { resultCode }) => void | | Called when the payment flow fails (see result codes below). | | instantPayments | ("googlepay" \| "applepay" \| "kortalan")[] | | One-click methods: wallets as express buttons above the standard methods, Kortalán as its own card — see Choosing methods. | | allowedPaymentMethods | PaymentMethod[] | | Only show these of the session's methods. Omit to show all. | | orderPaymentMethods | PaymentMethodOrder[] | | Top-to-bottom order of the methods — see Choosing methods. | | openDefaultPaymentMethod | "card" \| "firstStoredCard" \| "googlepay" \| "applepay" | | Method to expand on load. Ignored if unavailable. Default: none expanded. | | hideSubmitButton | boolean | | Hide the built-in card pay button and use your own — see Your own pay button. | | onCardValidityChanged | (isValid: boolean, isActive: boolean) => void | | Card form state for your own pay button. | | onApplePayValidateMerchant | (validationURL: string) => Promise<object> | | Apple Pay with your own certificate — see Apple Pay with your own certificate. | | placeholders | object | | Input placeholders — see below. | | localizations | object | | Override built-in copy per language and key. | | enableLogging | boolean | | Send diagnostics logs to Straumur. Default true; false turns it off — see Diagnostics logging. |

Choosing methods

PaymentMethod is one of "card", "storedcard", "googlepay", "applepay" and "kortalan". Which ones appear is decided by the session (and the shopper's device, for the wallets); allowedPaymentMethods can only narrow that list.

orderPaymentMethods takes the same tokens plus "instantpayments" (the express wallet row). The default order is ["instantpayments", "kortalan", "storedcard", "card", "googlepay", "applepay"]; any available method you leave out is appended in that order, so nothing is hidden just by being omitted. A wallet listed in instantPayments only ever renders in the express row.

Kortalán in instantPayments never joins the wallet row. It renders as its own card, a heading ("Split your payment with Straumur Kortalán") above the branded Straumur Kortalán button, with no radio button, in the "kortalan" position of orderPaymentMethods. The same card is shown when Kortalán is the only payment method.

Kortalán is listed by the backend only when the store has it enabled and Kortalán accepts the basket's amount, so it can come and go between sessions. Paying with it redirects the shopper to Kortalán; handle the return with submitDetails, exactly like a redirect-based 3-D Secure flow.

placeholders

Any subset of: cardNumber, expiryDate, expiryMonth, expiryYear, securityCodeThreeDigits, securityCodeFourDigits.

localizations

Override any translation key per language ("is" / "en"). Provided strings take precedence over the built-in translations; missing keys fall back to the defaults. The 1.x full tags ("is-IS" / "en-US") are still accepted as keys.

localizations: {
  en: { "cards.title": "Card Information" },
  is: { "cards.title": "Kortaupplýsingar" },
}

Theming

Set theme to "light" (default), "dark", or "system":

const checkout = new StraumurCheckout({ sessionId, environment: "test", theme: "system" });

To also choose the Google Pay / Apple Pay button styles, pass a ThemeConfiguration object. A button style you omit follows the widget mode (light widget → light button, dark → black):

theme: {
  mode: "dark", // "light" | "dark" | "system"
  googlePayButtonTheme: "white", // "dark" | "white"
  applePayButtonTheme: "light", // "dark" | "light"
}

"system" follows the shopper's OS/browser prefers-color-scheme and switches live if they change it. The theme is scoped to the widget and never affects the surrounding page. Change it at runtime with updateConfig({ theme: "dark" }).

Overriding the colors

The widget's colors are CSS custom properties, so you can override any of them. Scope your rule under your own container element (the one you pass to mount()) — that gives it higher specificity than the built-in styles, so your values win without needing !important:

/* Customize the dark theme (target [data-theme="dark"]); drop it to customize light. */
#component-container .straumur__root-component[data-theme="dark"] {
  --straumur__color-white: #101418; /* surfaces / backgrounds */
  --straumur__color-text: #f5f7fa; /* body text */
  --straumur__color-primary: #f5f7fa; /* buttons and accents */
  --straumur__color-secondary: #9aa7b5; /* muted text */
  --straumur__color-border: #2b323b; /* borders */
}

The full set of tokens is defined in src/styles/main.css. Note: the card number / expiry / CVC inputs are rendered inside Adyen's secure iframes, which CSS custom properties cannot reach — their text colors are set internally and won't follow a heavily customized palette.

Your own pay button

Set hideSubmitButton: true to drop the built-in card pay button, render your own, and drive it with onCardValidityChanged and submitCard():

const payButton = document.querySelector("#my-pay-button");

const checkout = new StraumurCheckout({
  sessionId,
  environment: "test",
  hideSubmitButton: true,
  // isActive: a card-type method (new or saved card) is selected and ready; hide your button otherwise.
  // isValid: its fields are complete; disable your button until then.
  onCardValidityChanged: (isValid, isActive) => {
    payButton.hidden = !isActive;
    payButton.disabled = !isValid;
  },
});

payButton.addEventListener("click", () => checkout.submitCard());

submitCard() returns true if a card-type method was active and submission started (the outcome arrives through onPaymentCompleted / onPaymentFailed), false otherwise. Repeated clicks while a payment is in flight are ignored. The wallets and Kortalán keep their own buttons.

Returning from a redirect

Some flows leave your page — a redirect-based 3-D Secure challenge, or Kortalán — and come back to your return URL with redirectResult and paymentCheckoutReference in the query string. Complete the payment on that page with submitDetails:

const params = new URLSearchParams(window.location.search);
const checkout = new StraumurCheckout({ sessionId, environment: "test", onPaymentCompleted, onPaymentFailed });

// The third argument is where to render the result screen; it's only needed if you don't also mount().
checkout.submitDetails(params.get("redirectResult"), params.get("paymentCheckoutReference"), "#component-container");

It shows a loader while the result is fetched, then the result screen, and calls your callbacks.

Apple Pay with your own certificate

By default Apple Pay runs on Adyen's Apple Pay certificate and needs nothing from you. If you use your own Apple Pay merchant identifier and certificates, validate the Apple Pay session yourself with onApplePayValidateMerchant:

const checkout = new StraumurCheckout({
  sessionId,
  environment: "live",
  onApplePayValidateMerchant: async (validationURL) => {
    const response = await fetch("https://your-shop.example/apple-pay-session", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ validationURL }),
    });
    if (!response.ok) throw new Error("Apple Pay merchant validation failed");
    return response.json(); // Apple's merchant session, unmodified
  },
});

It is called on every Apple Pay tap with Apple's validationURL. Your server endpoint must:

  1. Check that validationURL's host is exactly one of Apple's Apple Pay gateways: apple-pay-gateway.apple.com and cn-apple-pay-gateway.apple.com (production), and apple-pay-gateway-cert.apple.com and cn-apple-pay-gateway-cert.apple.com (sandbox). See Apple's Setting up your server. Never call a URL taken from the browser without checking it.
  2. POST to it over mutual TLS with your Merchant Identity Certificate, with the body { "merchantIdentifier": "<your merchant id>", "displayName": "<shop name>", "initiative": "web", "initiativeContext": "<your checkout domain>" }.
  3. Return Apple's response to the browser unchanged. It's an opaque session that expires after five minutes, so request a fresh one on every tap. See Apple's Requesting an Apple Pay payment session.

Before you start:

  • Verify your checkout domain with Apple under your merchant identifier (/.well-known/apple-developer-merchantid-domain-association).
  • Make sure your Payment Processing Certificate is set up with Straumur's Adyen account, so payments can be decrypted.

If the promise rejects, the Apple Pay sheet closes and the failure screen is shown.

Diagnostics logging

To help investigate payment problems, the widget sends Straumur a log of what happened during the checkout. Logging is on by default; pass enableLogging: false to turn it off.

What is sent. Events with a timestamp and a sequence number, for example: the widget mounted, the payment methods that loaded (their types, such as scheme or googlepay), the method the shopper selected, the pay button or Enter key, the card form becoming valid or invalid, a field's validation error code (for example error.va.sf-cc-num.04), the payment result code and which result screen was shown, a 3-D Secure challenge being shown, timeouts and error names. Each batch also carries the session id, the widget version, and once per checkout the language, theme and integration mode. Straumur's server records the browser's user agent with each request.

What is never sent. Card numbers, expiry dates, security codes or any part of them (the card fields are Adyen iframes the widget cannot read), encrypted card data, Adyen payment or 3-D Secure payloads, stored-card ids or tokens, Apple Pay validation URLs or merchant sessions, the values of your configuration (such as placeholders, translations or callbacks), and shopper details such as name, email, phone or address. Every event type has a fixed list of allowed fields; anything else is dropped in the browser before sending.

How it is sent. In batches of up to 20 events, a few seconds apart, as a background request to the same Straumur host as the payment, with no cookies. When the page is hidden or closed the remaining events are sent with navigator.sendBeacon. A failed batch is retried a few times and then dropped. Logging never blocks or changes the payment: it runs off the payment path, and every error inside it is swallowed.

Accessibility

Payment results are announced to assistive tech (role="alert" for failures, role="status" for success), card fields are labelled, the dual-brand selector is keyboard-operable, and focus follows into a 3-D Secure challenge when it takes over the widget.

Instance methods

const checkout = new StraumurCheckout(config);

| Method | Description | | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | | mount(selector) | Fetches the payment methods and renders the component into a CSS selector or HTMLElement. Async. | | setLanguage(locale) | Switches the UI language at runtime ("en" or "is", same codes as the locale option). | | updateConfig(partial) | Merges new options (locale, localizations, theme, callbacks, …) and re-renders. | | submitDetails(redirectResult, paymentCheckoutReference?, selector?) | Completes a redirect-based flow (3‑D Secure, Kortalán) — see Returning from a redirect. | | submitCard() | Submits the active card form from your own button; returns whether it started — see Your own pay button. | | destroy() | Unmounts the component and cleans up. |

Payment result codes

Both callbacks receive a resultCode. Following Adyen Web 6 semantics, Refused, Cancelled, and Error invoke onPaymentFailed; every other outcome (Authorised, Received, Pending, …) invokes onPaymentCompleted. onPaymentFailed always receives a resultCode — if the underlying provider reports a failure without one, it is delivered as Error.

The shopper sees a success screen for Authorised, a "being processed" screen for Pending / Received, and a failure screen otherwise.

If the Straumur API doesn't answer a payment request within 90 seconds, the shopper is told the payment couldn't be confirmed and onPaymentFailed receives Error — but the payment may still have gone through. Treat the server-side result (your webhook / payment status) as the source of truth before fulfilling or cancelling an order.

Breaking changes in v2.0.0

  1. onPaymentFailed: a Refused, Cancelled or Error outcome now invokes onPaymentFailed({ resultCode }) instead of onPaymentCompleted (in 1.x every gateway response, including refusals, invoked onPaymentCompleted). If your integration branched on resultCode inside onPaymentCompleted, move the failure branches to onPaymentFailed.
  2. setLanguage: takes "is" / "en", the same codes as the locale option, instead of "is-IS" / "en-US".

Neither affects rendering; they change how your code handles results and switches language.

License

MIT