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
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.
- Using the NPM Package
- Embed the Script into your HTML
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";
The package also ships a script build that exposes a global StraumurWeb. Pin the exact version, so a new release can't change the component on your page without you testing it:
<script src="https://unpkg.com/straumur-web-component@2.0.0"></script>
<script>
const checkout = new StraumurWeb.StraumurCheckout({
environment: "test",
sessionId: "ftsdre3h...e5h5as2q4",
});
checkout.mount("#component-container");
</script>
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>
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
| Parameter | Description |
|---|---|
| environment | Use test for staging/testing environment. When you are ready to accept live payments, change to live. |
| sessionId | The 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. |
| locale | The language used in the component. Available values are: is and en. Defaults to is. |
| theme | The 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. |
| placeholders | Overrides the placeholders of the card fields. Any of: cardNumber, expiryDate, expiryMonth, expiryYear, securityCodeThreeDigits, securityCodeFourDigits. |
| localizations | Overrides 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. |
| instantPayments | One-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. |
| allowedPaymentMethods | Restricts 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. |
| orderPaymentMethods | The 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. |
| openDefaultPaymentMethod | The 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. |
| hideSubmitButton | Set 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. |
| enableLogging | The component sends Straumur diagnostics logs to help investigate payment problems. Defaults to true; set to false to turn it off. See Diagnostics logging. |
- Locale
- Theme
- Placeholders
- Localization
- Instant payments
- Allowed payment methods
- Order payment methods
- Custom submit button
- Update config
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",
};
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);
},
theme: "system", // "light" | "dark" | "system"
};
// Or, to also choose the wallet button styles:
// theme: {
// mode: "dark", // "light" | "dark" | "system"
// googlePayButtonTheme: "white", // "dark" | "white"
// applePayButtonTheme: "light", // "dark" | "light"
// },
A wallet button style you leave out follows the theme: light buttons on a light component, black buttons on a dark one.
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);
},
placeholders: {
cardNumber: "1234 5678 9012 3456",
},
};
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);
},
localizations: {
en: { "cards.title": "Card Information" },
is: { "cards.title": "Kortaupplýsingar" },
}
};
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);
},
instantPayments: ["applepay", "googlepay", "kortalan"],
};
Google Pay and Apple Pay are shown as express buttons above the other payment methods. Kortalán is not part of that row: it is shown as its own card, with a heading and the Straumur Kortalán button, in the kortalan position of orderPaymentMethods.
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);
},
allowedPaymentMethods: ["card", "storedcard"],
};
Which payment methods are available is decided by your session (and, for Google Pay and Apple Pay, the shopper's device). allowedPaymentMethods can only narrow that list.
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);
},
// Card first, then saved cards; the remaining methods follow in the default order.
orderPaymentMethods: ["card", "storedcard"],
// Expand the card form when the component loads.
openDefaultPaymentMethod: "card",
};
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);
},
// Hides the built-in submit button.
hideSubmitButton: true,
// Reports validity/active state so your own button can be enabled/disabled accordingly.
onCardValidityChanged: (isValid, isActive) => {
document.getElementById("custom-pay-button").disabled = !(isValid && isActive);
},
};
const checkout = new StraumurCheckout(paymentConfiguration);
checkout.mount("#component-container");
document.getElementById("custom-pay-button").addEventListener("click", () => {
checkout.submitCard(); // Triggers the active card form's submit, same as clicking the built-in button.
});
submitCard() returns true if a card form was selected and the payment started, and false otherwise. Clicks while a payment is in progress are ignored. Google Pay, Apple Pay and Kortalán keep their own buttons.
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 paymentCheckout = new StraumurCheckout(paymentConfiguration);
// ...
// Mount the checkout component into container, either through reference or DOM selector depending if you are using some JavaScript frameworks or not.
paymentCheckout.mount("#paymentContainer");
// ...
// This will re-render with the new configuration (in this case, locale/language).
paymentCheckout.updateConfig({ locale: "en" });
// ...
// This will re-render with the new configuration (in this case, locale/language and custom localization/translation).
paymentCheckout.updateConfig({ locale: "en", localizations: { en: { "cards.title": "My Card Title" } } });
// ...
// Only switches the language.
paymentCheckout.setLanguage("is");
Instance Methods
| Method | Description |
|---|---|
| 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,CancelledandErrorcall 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.
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:
- Obtain the
checkoutReferencefrom the/embeddedcheckoutresponse. - 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:
- Check that the host of
validationURLis exactly one of Apple's Apple Pay gateways:apple-pay-gateway.apple.comandcn-apple-pay-gateway.apple.com(production), orapple-pay-gateway-cert.apple.comandcn-apple-pay-gateway-cert.apple.com(sandbox). See Apple's Setting up your server. Never call a URL from the browser without checking it. POSTto 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>" }.- 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.
- Failed payments call
onPaymentFailed. ARefused,CancelledorErrorresult now callsonPaymentFailed({ resultCode })instead ofonPaymentCompleted. In 1.x every result, including refusals, calledonPaymentCompleted. If you checkresultCodeinsideonPaymentCompleted, move the failure branches toonPaymentFailed. setLanguagetakesis/en, the same values as thelocaleparameter, instead ofis-IS/en-US.
See the Web Component 2.0 release note for everything that changed.