Skip to main content

Web Integration

You can integrate Straumur's client-side library which meets the requirements for most online payment integrations.

With component, you can render a list of available payment methods anywhere on your website and collect payment details from your shoppers.

Requirements​

Before you begin to integrate, make sure you have followed the Basic Session Request guide.

Setting up your Frontend​

Recommended Version

The recommended version of straumur-web-component is 2.0.0. This version includes the latest features and bug fixes. Upgrading from 1.x? See Upgrading from 1.x.

Use the Straumur Web npm package:

  • npm install straumur-web-component@"^2.0.0" --save
  • Import Straumur Web into your application:

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

DOM Element for component​

Create a DOM container element on your checkout page where you want to render component and assign it a descriptive id.

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

If you are utilizing JavaScript frameworks like Vue or React, ensure that you use references rather than selectors and avoid re-rendering the DOM element.

Setup component​

Define a global configuration object to initialize the StraumurCheckout instance. This object should include configuration settings and event handlers.

Initialize the Payment Component Example​

const paymentConfiguration = {
environment: "test", // Change to 'live' for the live environment.
// Use sessionId from /embeddedcheckout/session response
sessionId: "ftsdre3h...e5h5as2q4",
onPaymentCompleted: (data) => {
console.info("onPaymentCompleted", data.resultCode);
},
onPaymentFailed: (data) => {
console.info("onPaymentFailed", data.resultCode);
},
};

const checkout = new StraumurCheckout(paymentConfiguration);

checkout.mount("#component-container");

Payment Component Parameters​

ParameterDescription
environmentUse test for staging/testing environment. When you are ready to accept live payments, change to live.
sessionIdThe payment sessionId identifier from your call to /embeddedcheckout/session.
onPaymentCompleted(data)Create an event handler, called when the payment is completed (Authorised, Pending, Received, …). Receives { resultCode }. See Payment result codes.
onPaymentFailed(data)Create an event handler, called when the payment failed (Refused, Cancelled or Error). Receives { resultCode }. See Payment result codes.
localeThe language used in the component. Available values are: is and en. Defaults to is.
themeThe color theme: light (default), dark or system, which follows the shopper's device setting. Pass an object to also choose the Google Pay and Apple Pay button styles. The theme only affects the component, never the rest of your page.
placeholdersOverrides the placeholders of the card fields. Any of: cardNumber, expiryDate, expiryMonth, expiryYear, securityCodeThreeDigits, securityCodeFourDigits.
localizationsOverrides the component's texts, per language (is / en) and key. Keys you don't provide keep the built-in text. For the complete list of keys, see the package's types on npm under the /dist folder.
instantPaymentsOne-click payment methods. googlepay and applepay are shown as express buttons above the other payment methods, in the order you list them. kortalan is shown as its own Straumur Kortalán button.
allowedPaymentMethodsRestricts which payment methods are rendered. Accepts an array containing any of card, storedcard, googlepay, applepay, kortalan. When omitted, every payment method returned by your session is shown.
orderPaymentMethodsThe top-to-bottom order of the payment methods. Accepts the same values as allowedPaymentMethods, plus instantpayments for the express button row. Methods you leave out are added after the ones you list, in the default order: instantpayments, kortalan, storedcard, card, googlepay, applepay.
openDefaultPaymentMethodThe payment method that is expanded when the component loads: card, firstStoredCard, googlepay or applepay. Ignored if that method isn't available. By default no method is expanded.
hideSubmitButtonSet to true to hide the built-in submit button on the card and stored-card forms, so you can drive submission from your own UI with submitCard(). Must be used together with onCardValidityChanged() to know when your custom button should be enabled. Defaults to false.
onCardValidityChanged()Create an event handler, called whenever the validity or active state of the currently selected card-type form (card or stored card) changes. Receives isValid and isActive. Must be used together with hideSubmitButton - it's the only signal for when your custom button should be enabled.
onApplePayValidateMerchant(validationURL)Only for merchants with their own Apple Pay certificate. See Apple Pay with your own certificate.
enableLoggingThe component sends Straumur diagnostics logs to help investigate payment problems. Defaults to true; set to false to turn it off. See Diagnostics logging.
const paymentConfiguration = {
environment: "test", // Change to 'live' for the live environment.
// Use sessionId from /embeddedcheckout/session response
sessionId: "ftsdre3h...e5h5as2q4",
onPaymentCompleted: (data) => {
console.info("onPaymentCompleted", data.resultCode);
},
onPaymentFailed: (data) => {
console.info("onPaymentFailed", data.resultCode);
},
locale: "en",
};

Instance Methods​

MethodDescription
mount(selector)Fetches the payment methods and renders the component into a CSS selector or DOM element.
setLanguage(locale)Switches the language: is or en, the same values as the locale parameter.
updateConfig(config)Merges new parameters (locale, localizations, theme, event handlers, …) and re-renders the component.
submitDetails(redirectResult, paymentCheckoutReference, selector)Completes a payment that returns to your page from a redirect. See Returning from a redirect.
submitCard()Submits the selected card form from your own button. See the Custom submit button example above.
destroy()Removes the component from the page.

Payment Flow​

When component is created and mounted, the shopper uses the interface to finalize the payment. Component manages the entire payment process you set up upfront.

Payment Result Codes​

Both event handlers receive { resultCode }:

  • Refused, Cancelled and Error call onPaymentFailed.
  • Every other result (Authorised, Pending, Received, …) calls onPaymentCompleted.

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

caution

If Straumur 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. Before you fulfil or cancel an order, check its result through the webhook or the Checkout Status Request.

Returning from a Redirect​

Some payments leave your page and come back to your return URL: 3-D Secure challenges that use a redirect, and Kortalán. The return URL has redirectResult and paymentCheckoutReference in its query string. On that page, complete the payment with submitDetails:

const params = new URLSearchParams(window.location.search);

const checkout = new StraumurCheckout({
environment: "test",
sessionId: "ftsdre3h...e5h5as2q4",
onPaymentCompleted: (data) => {
console.info("onPaymentCompleted", data.resultCode);
},
onPaymentFailed: (data) => {
console.info("onPaymentFailed", data.resultCode);
},
});

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

The component shows a loader while the result is fetched, then the result screen, and calls your event handler.

Payment Outcome​

Once the component has processed the payment, you should inform the shopper of the payment status. Straumur will notify you of the payment result via a webhook. A declined attempt does not end the session — the shopper can try again, and each attempt sends its own Authorization event. Expect one or more success: "false" events before a successful one; see One checkout, several Authorization events.

Payment Result Before Webhook​

To retrieve the payment result before receiving the webhook notification, follow these steps:

  1. Obtain the checkoutReference from the /embeddedcheckout response.
  2. Check the current payment status by following the Checkout Status Request.

Test Refusal Reason​

Work in progress! 👷🏻 ⚒️

Apple Pay and Google Pay​

If you wish to include Apple Pay and Google Pay as payment methods on your website, please contact our support at developers@straumur.is

Apple Pay with Your Own Certificate​

By default, Apple Pay uses 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({
environment: "live",
sessionId: "ftsdre3h...e5h5as2q4",
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 each time the shopper taps the Apple Pay button, with Apple's validationURL. Your server endpoint must:

  1. Check that the host of validationURL is exactly one of Apple's Apple Pay gateways: apple-pay-gateway.apple.com and cn-apple-pay-gateway.apple.com (production), or 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 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. The session expires after five minutes, so request a new 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 returned promise rejects, the Apple Pay sheet closes and the failure screen is shown.

Diagnostics Logging​

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

  • What is sent: events such as the component loading, the payment methods shown, the method the shopper selected, the card form becoming valid or invalid, field validation error codes, the payment result code and 3-D Secure challenges being shown, with the session id and the component version.
  • What is never sent: card numbers, expiry dates or security codes, or any part of them (the card fields are secure iframes the component cannot read), payment or 3-D Secure data, saved card details, your configuration values, and shopper details such as name, email, phone or address.

Logging never blocks or changes the payment.

Upgrading from 1.x​

Version 2.0 has two breaking changes. Neither changes how the component looks.

  1. Failed payments call onPaymentFailed. A Refused, Cancelled or Error result now calls onPaymentFailed({ resultCode }) instead of onPaymentCompleted. In 1.x every result, including refusals, called onPaymentCompleted. If you check resultCode inside onPaymentCompleted, move the failure branches to onPaymentFailed.
  2. setLanguage takes is / en, the same values as the locale parameter, instead of is-IS / en-US.

See the Web Component 2.0 release note for everything that changed.