@nordhealth/provet-pay-elements
v0.19.2
Published
Embeddable Provet Pay card tokenizer — the Adyen Web v6 Sessions flow, mounted on the consumer’s own page and backed by Provet.
Keywords
Readme
@nordhealth/provet-pay-elements
Add a card step to a web page, and let a shopper save a payment card in Provet, through Provet Pay, Nordhealth's payment service.
@nordhealth/provet-pay-elements draws a card form into an element chosen by the page, checks the card with a zero-value ($0) authorization at Adyen, and hands the page back a Provet card id. It never charges the card: charging happens later, on the server, using that id. Provet keeps the saved card, so a feature such as a health plan signup can use it for later payments.
- Nothing to host. One JavaScript file, with its styles inside. Install it, call
mount(). - No card number on the page. Adyen's card fields are iframes Adyen creates; the number never reaches the page or the package.
- No secrets in the browser. The component runs on a short-lived token, bound to one shopper, that the backend mints.
- 3-D Secure included. A challenge appears inside the form; a redirect-based one returns to the page and is settled by the component.
Contents: Prerequisites · Integration requirements · Quick start · API · Errors · Translations · Appearance · Content Security Policy · How it works · Versioning
Prerequisites
The component works only for integrations that Nordhealth has allowlisted. To get access, email [email protected].
Three things must be in place before the card form can load on a page.
| # | Requirement | Set up by | Why |
| --- | -------------------------------------------------------------------------------------- | ------------------ | --------------------------------------------------------- |
| 1 | The page's origin is in the CORS allow list of Provet (CARD_ELEMENT_ALLOWED_ORIGINS) | Provet, on request | The browser blocks calls to Provet from any other origin |
| 2 | The same origin is registered with Adyen as an allowed origin for the client key | Provet, on request | Adyen renders the card fields only on a registered origin |
| 3 | A backend that mints the browser token | The integrator | See step 1 |
Send each origin, for example https://booking.example.com, for each environment (test and production), to [email protected].
Local development on the test environment. These local origins already work: http://localhost and http://127.0.0.1 on ports 3000, 4200, 5173, 6002, 7200 and 8080. Each origin is listed exactly, because Adyen does not accept a port wildcard. On any other port the component shows "Could not reach the server. Check your connection and try again." and the card fields do not appear. Ask for the port at the same address. In production, partners use their own domains, so this applies to the test environment only.
If the card form never appears and the browser console shows a blocked cross-origin request to provetcloud.com or an Adyen origin error, requirement 1 or 2 is missing for that origin.
The Provet setup supplies the rest: an OAuth application that may use the card_tokenization scope, the clinic's instance id (provetId) and department id (departmentId), and the shopper's client id (clientId).
Integration requirements
Every page that embeds the component follows all of these. Some are explained in more detail further down; this list is the complete set.
- Register every origin. Show the component only on origins Provet has added for Provet and for Adyen. See Prerequisites.
- Serve the page over HTTPS. Every page that shows the component uses
https:. Plainhttp:works only for local development on the test environment. - Keep secrets on the backend. The OAuth client secret and the API token stay on the server. The browser gets only the short-lived browser token. See step 1.
- Take the shopper from your own session. The backend takes the shopper's
clientIdfrom the user signed in to your site. It never takes it from anything the browser sends, and it mints a token only for that signed-in user. - Use the package as delivered. Load the published file unchanged, from npm or the CDN. Do not inject scripts into the component, place overlays over it, or change the elements it renders, beyond what Appearance describes.
- Do not proxy its calls. The component talks to Provet and Adyen directly. Do not route, intercept or rewrite those calls.
- Allow what it loads. If the page sets a Content Security Policy, allow what Content Security Policy lists.
- Keep the version current. Pin a version as Versioning describes, and upgrade regularly. Read CHANGELOG.md before each upgrade.
- Use it only for the agreed flow. Use the component only for the card step it was set up for with Provet, for example a health plan signup.
- Report security incidents. Tell Provet through your usual support contact, without delay, if the page, its backend or its credentials may be compromised.
Provet may suspend the component for an integrator that does not follow these requirements, or whose page is compromised. Provet will tell the integrator when it does.
Quick start
1. Mint a browser token on the backend
The component authenticates with a token that is valid for one shopper and for at most 10 minutes, with no refresh token. The backend makes two calls to the token endpoint of Provet, POST https://<provet-instance>/<provetId>/oauth2/token/, authenticating as its OAuth application (client id and secret, HTTP Basic).
First, an API token with the card_tokenization scope:
grant_type=client_credentials
scope=card_tokenizationThen exchange it (RFC 8693 token exchange) for the browser token, naming the shopper as the audience:
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=<the token from the first call>
subject_token_type=urn:ietf:params:oauth:token-type:access_token
scope=card_tokenization
audience=client:<clientId>Take clientId from the signed-in user on the server, never from anything the browser sends. Keep the first token and the client secret on the backend; send the browser only the exchanged token.
A minimal endpoint (Node 18+, Express):
const PROVET = 'https://provetcloud.com' // the Provet instance
const PROVET_ID = 922 // the instance id
const basic = Buffer.from(
`${process.env.CLIENT_ID}:${process.env.CLIENT_SECRET}`
).toString('base64')
const tokenCall = async (params) => {
const response = await fetch(`${PROVET}/${PROVET_ID}/oauth2/token/`, {
method: 'POST',
headers: {
Authorization: `Basic ${basic}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams(params),
})
if (!response.ok) throw new Error(`Provet answered ${response.status}`)
return (await response.json()).access_token
}
app.post('/api/card-token', requireSignedInShopper, async (req, res, next) => {
try {
const apiToken = await tokenCall({
grant_type: 'client_credentials',
scope: 'card_tokenization',
})
const token = await tokenCall({
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token: apiToken,
subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',
scope: 'card_tokenization',
audience: `client:${req.user.providerClientId}`, // from the session, not the request
})
res.json({ token })
} catch (error) {
next(error)
}
})2. Add the component to the page
With a bundler:
npm install @nordhealth/provet-pay-elementsimport { mount } from '@nordhealth/provet-pay-elements'Without a bundler, copy node_modules/@nordhealth/provet-pay-elements/dist/loader/provet-pay-elements.umd.js to the site's own server and load it with a script tag; it defines window.ProvetPayElements:
<script src="/assets/provet-pay-elements.umd.js"></script>
<!-- then: ProvetPayElements.mount(...) -->3. Give the component a container and mount it
The container is any empty block element on the page. The component renders its form inside it and removes everything it added when unmount() is called. Pass the element itself or a CSS selector.
A complete plain-JavaScript page:
<!DOCTYPE html>
<html>
<head>
<!-- the card labels use non-ASCII characters; without this they render garbled -->
<meta charset="utf-8" />
</head>
<body>
<h1>Save your card</h1>
<!-- the container: empty, on the page -->
<div id="card"></div>
<p id="result"></p>
<script src="/assets/provet-pay-elements.umd.js"></script>
<script>
async function fetchToken() {
const response = await fetch('/api/card-token', { method: 'POST' })
if (!response.ok) {
throw new Error(`Token request failed (${response.status})`)
}
const { token } = await response.json()
if (!token) {
throw new Error('Token response did not include a token')
}
return token
}
fetchToken()
.then((token) => {
ProvetPayElements.mount('#card', {
auth: {
token: token, // from step 1
provetId: 922, // the clinic's instance id
clientId: 2624, // the shopper: the id put in the token's audience
departmentId: 42, // the clinic's department id
refreshToken: fetchToken, // optional: a new token when the current one expires
},
onSuccess: function (result) {
// Send result.card.id to the backend, for example as payment_card when signing up.
document.getElementById('result').textContent =
'Saved card ' + result.card.id
},
onRefused: function (result) {
// result.resultCode is Refused, Cancelled or Error; the form shows a notice and the shopper can try again.
},
onError: function (error) {
console.error(error.type, error.message)
},
})
})
.catch((error) => {
document.getElementById('result').textContent =
'Could not load the card form'
console.error(error)
})
</script>
</body>
</html>With a bundler the call is the same, using mount from the import.
The component is on the page's origin, so the page must be served from an origin Provet has allowed (Prerequisites).
4. Use the result
onSuccess({ card }) is the only success signal. card.id is the Provet card id: pass it to the feature that needs a saved card, for example as payment_card when signing a patient up to a health plan.
If the shopper already has saved cards, the component offers them first.
| Where the card comes from | onSuccess receives | Chargeable |
| --------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Entered in the form | { card: { id }, resultCode } | A few seconds later, when Adyen's confirmation reaches Provet. The id can be used straight away; the feature waits for the card to become active. |
| Picked from the saved cards | { card: { id, brand, last4, expiration_date, default } } | Already active |
After a card is saved, the form is replaced by a "Card saved" confirmation and the back control hides, so the same form cannot be submitted twice.
API
mount(container, options)
Returns { unmount(), changeLocale(locale) }. container is an HTMLElement or a CSS selector; a selector that matches nothing throws.
| Option | Type | Required | Description |
| ------------------- | -------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| auth.token | string | yes | The browser token from step 1. |
| auth.provetId | string \| number | yes | The clinic's Provet instance id (the tenant). |
| auth.clientId | string \| number | yes | The shopper's Provet client id: the client:<id> put in the token's audience. Not an OAuth client id. It must match the token; see below. |
| auth.departmentId | string \| number | yes | The clinic's Provet department id. It picks the Adyen store for the card check; Provet refuses a department without Provet Pay. |
| auth.provetOrigin | string | no | The Provet instance the token came from, for example https://us.provetcloud.com. Defaults to the instance the package was built for. |
| auth.refreshToken | () => Promise<string> | no | Returns a new token after the current one is refused with 401. See Tokens. |
| recurringModel | 'subscription' \| 'one-off' | no | What the card will be used for: Provet stores it for Adyen's Subscription or CardOnFile model. Defaults to 'subscription'. |
| locale | string | no | Adyen's locale, for example fi-FI. The card fields and the component's text follow it. Defaults to en-GB. See Translations. |
| translations | object | no | Adyen's translations, keyed by locale, for the card fields and the component's text. See Translations. |
| styles | object | no | Adyen's styles for the card fields. See Appearance. |
| disclaimerMessage | { message, linkText, link } | no | Adyen's disclaimerMessage: a line under the card fields, for instance the shopper's consent. See below. |
| appearance | object | no | The component's own colors, radius and font. See Appearance. |
| onSuccess | ({ card, resultCode }) => void | yes | The shopper is done with a card. resultCode is Adyen's, for example Authorised, for a card saved in the form; a picked card has none. |
| onRefused | ({ resultCode }) => void | no | The card check ended Refused, Cancelled or Error, Adyen's resultCode. The form says so and the shopper can try again. |
| onError | ({ type, message }) => void | no | Something went wrong: the component could not load or continue, or Adyen reported an error and the form stays for another try. See Errors. |
| onReady | () => void | no | Called when the shopper first has something to act on: the saved cards, or the card fields once Adyen says they are ready. Again on changeLocale. |
A missing required field, a provetOrigin that is not a Provet instance, a clientId that is not a Provet client id, a locale that is not a string, translations that are not an object of objects keyed by locale, or a container that already holds the form make mount() throw an error with code config_invalid before anything is shown or requested.
provetOrigin matters when the Provet instance is not the one the package was built for. Provet runs one instance per domain (https://provetcloud.com, https://us.provetcloud.com, and others), so pass the right one if it differs. Only Provet origins are accepted.
Adyen asks for the shopper's consent before a card is stored for later payments, and for the shopper to be told how it will be charged (Adyen). Say it on the page, or pass it as disclaimerMessage; %{linkText} in message becomes a link to link, which must be a full https: address or Adyen leaves the line out.
clientId must be the client the token was exchanged for, written as in the token's audience client:<id>: digits only. The component cannot check it against the token, because the client is only in Provet's records. It binds the unfinished session to the auth it was mounted with (Provet instance, tenant, client and department) and resumes it only for a mount with the same auth, so always pass the same client to both. When the page switches to another client, unmount and mount again with that client's token and id.
handle.unmount()
Removes everything the component added to the container. After it, no callback fires, except onSuccess for a card whose save was already under way, and auth.refreshToken is not called. A session the component was opening is kept, so mounting again for the same shopper resumes it instead of opening a second one.
Mounts for the same shopper on one page share one card session: a mount that starts while another is still opening the session waits for it. React StrictMode's mount, unmount and mount opens one session. Two forms on screen for one shopper show that same session, so mount the component once per shopper.
A container holds one form. Mounting into it again for the same shopper throws config_invalid and keeps the first form; mounting into it for another shopper stops the first form as well and throws. In React, an effect that awaits the token checks that it was not cleaned up before it calls mount().
handle.changeLocale(locale)
Set locale on the options object you passed to mount(), or call changeLocale(locale), and the form starts again in that locale, which takes what the locale option takes. mount() turns that property into a setter until unmount(). A frozen or sealed object keeps its plain property, so call changeLocale there, and wherever you do not keep the options object. translations stay as given to mount(), so give the text for every language you switch to there.
const options = { auth, translations, onSuccess }
const handle = mount('#card', options)
options.locale = 'sv-SE' // or: handle.changeLocale('sv-SE')Adyen takes its locale only when its checkout starts, and 6.40.1 keeps that language through its own update(), so the card fields start again too: what the shopper typed into them is cleared, and onReady is called again once the form is back. An open card session is resumed rather than a second one opened, so a shopper who opened the card form comes back to it; otherwise the saved cards show again. Starting again calls Provet again, so once the token has expired it needs auth.refreshToken.
It does nothing for the locale the form already has, while a card check is running (from the save button until its result, 3-D Secure included), once the card is saved, after Adyen has ended the session for too many attempts (until "Add a new card" opens a new session), or after unmount(). Called while the form is still opening a card session, it waits for that session instead of opening a second one. A locale that is not a string throws config_invalid and leaves the form as it is.
Tokens
The token lasts at most 10 minutes. When Provet answers a call with 401:
- with
auth.refreshToken, the component calls it once, retries the same call with the new token, and continues. IfrefreshTokenrejects, or does not answer within 60 seconds, the failure is reported asauth_error; - without it, the expiry is reported as
auth_error.
refreshToken must return a token for the same client. It is not called after unmount(), and a token it returns after unmount() is not used.
A 403 means the token authenticates but does not have the card_tokenization scope. It is reported as auth_error at once and refreshToken is not called, because the backend would mint the same token again.
Errors
mount() throws config_invalid for a bad configuration. Everything else reaches onError({ type, message }). When the component cannot load or continue, the form shows a red banner worded for what went wrong (the provetPay.errors.* texts in Translations); the banner carries the cause as data-provet-pay-elements-error: one of network, auth_error, auth_forbidden, session_error, session_expired, attempts_exceeded, config_invalid, cancelled or technical, the key it shows. If the card form fails while the back control is showing, the control stays: going back resets the form, on its card session, and offers the saved cards again, so onSuccess can still follow that onError. When Adyen reports an error while its card fields are loaded and on the page, for instance a call during the card check that fails, the form stays with the provetPay.notices.error notice and the shopper can try again in place. The exceptions are Adyen's attempt limit and the form's time running out, below. onError is called either way, never onRefused, so it does not always mean the form is gone. message is a diagnostic for your logs and for support, not for the shopper: the component's own messages are English, but a session_error can carry Provet's message, which Provet words in the browser's language.
| type | Meaning | What to do |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| auth_error | The token expired, was refused, or lacks the scope. | Mint a new token and mount again. A 403 points at the OAuth application's scopes. |
| session_error | Provet or Adyen could not open or continue the card session: an unavailable service, a department without Provet Pay, and so on. | Offer to try again; log the message. |
| technical | Anything else, including an origin Adyen does not accept or a card setup that was cancelled. | Log the message; it helps support. |
A failed check is not an error: it calls onRefused({ resultCode }) and the shopper tries again in place. Adyen ends a card session once the shopper has made too many attempts (it does not publish the number). The next attempt then ends the component with onError (session_error, "This card form had too many attempts. Try again later, or use another card."), and the banner shows provetPay.errors.attempts_exceeded. Do not mount the component again automatically on this error: a new mount opens a new session, which is a decision about this shopper for the page to make. The notice says what happened, with the provetPay.notices.* texts: "The card was declined. Try another card." for Refused, "The card check was cancelled. Try again." for Cancelled, and "Something went wrong while checking the card. Try again, or use another card." for Error. After a failed 3-D Secure check Adyen removes the card fields, so the component mounts them again; the name on the card is put back, but the card number, expiry date and security code cannot be, and the shopper types those again.
A card form takes card details for 55 minutes after it opens its session. Adyen ends a card session an hour after it opens, without telling anyone, and its fields would take a card it then refuses; the last 5 minutes are kept for a 3-D Secure check started just before. When the time is up, the card fields are cleared and the form ends with onError (session_error), and the banner shows provetPay.errors.session_expired, "Your session has expired, please reload the page". A card check already under way finishes first: a saved card still calls onSuccess, and a refused one ends the form. A Save that Adyen refuses because the session has expired ends the form the same way. The component opens no new session on its own: a reload or a new mount() opens one, and so does "Add a new card" when the shopper goes back to their saved cards. If the saved cards are on screen when the time is up, the form's session is dropped with no banner.
Translations
The card fields (card number, expiry date, security code, name on the card, the save button) are Adyen's, and so are the locale and translations options: they reach Adyen exactly as given, with en-GB for a locale left out, so Adyen's localization docs apply as written. The component's own text (the saved-card list, the notices, the error banner, the back control) follows the same two options, read Adyen's way.
Choosing the language. Pass one of Adyen's locales, for example fi-FI, sv-SE or no-NO. Without one, the component uses en-GB (DEFAULT_LOCALE) for its text and passes it to Adyen. Adyen takes the exact locale, else the first it has with the same two letters, else US English. Adyen ships no British English, so with en-GB its card fields read US English, with Adyen's keys from your translations for the English locale it settles on, if any. The component's text follows the same rule over the locales it has text for (the dictionaries it ships, and your translations entries that hold provetPay.* keys), with British English instead of US English. This version ships British English; other languages ship as they are translated. To change it after mounting, set locale on the options object or call changeLocale.
Adding or changing text. translations is Adyen's custom translations: an object keyed by locale, each holding keys and their text. Adyen's keys change the card fields; the provetPay.* keys below change the component's text. A locale that neither Adyen nor the component ships works the same way, as Adyen documents: pass it as locale and give its text in translations. The defaults are exported to read or build on: DEFAULT_LOCALE ('en-GB') and DEFAULT_TRANSLATIONS, the component's British English text, typed as a complete, read-only PayCardTranslations.
// Your words for the default British English: no locale needed.
mount('#card', {
auth,
translations: {
'en-GB': {
'provetPay.cardSaved': 'Card stored',
'payButton.saveDetails': 'Save card',
},
},
onSuccess,
})
// Swedish: Adyen ships it for the card fields; you give the component's text.
mount('#card', {
auth,
locale: 'sv-SE',
translations: {
'sv-SE': {
'provetPay.cardSaved': 'Kortet har sparats',
'provetPay.savedCards.heading': 'Använd ett sparat kort',
},
},
onSuccess,
})As in Adyen, your text for a locale is used for the locale locale resolves to, over the component's own text for it, and anything left out comes from British English. Your text reaches the page as text, never as HTML. Placeholders are Adyen's %{name}. provetPay.savedCards.choose counts the cards as Adyen counts: __1, __2 and so on for an exact number, __plural for any other number above one, and the key itself otherwise.
Adyen 6.40.1 shows its Brazilian Portuguese text for pt-PT and its Simplified Chinese for zh-TW, because it picks its own files by the first two letters; Adyen's keys for those locales in translations correct it.
The keys are part of the API: apart from the provetPay.savedCards.remove* keys below the table, none is renamed or removed without a breaking release. The TypeScript type PayCardTranslations lists them with their British English text.
| Key | British English |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| provetPay.backToSavedCards | Back to saved cards |
| provetPay.loading | Loading the card form (read by screen readers) |
| provetPay.cardSaved | Card saved |
| provetPay.savedCards.heading | Use a saved card |
| provetPay.savedCards.choose | Choose your saved card (one card) |
| provetPay.savedCards.choose__plural | Choose one of your %{count} saved cards |
| provetPay.savedCards.list | Saved cards (read by screen readers) |
| provetPay.savedCards.addNew | Add a new card |
| provetPay.savedCards.noNumber | Saved card (a card with no number on record) |
| provetPay.savedCards.expiry | (EXP: %{date}) |
| provetPay.savedCards.remove | Remove %{card} |
| provetPay.savedCards.removeQuestion | Remove this saved card? |
| provetPay.savedCards.removeConfirm | Remove |
| provetPay.savedCards.removeCancel | Cancel |
| provetPay.notices.refused | The card was declined. Try another card. |
| provetPay.notices.cancelled | The card check was cancelled. Try again. |
| provetPay.notices.error | Something went wrong while checking the card. Try again, or use another card. |
| provetPay.errors.network | Could not reach the server. Check your connection and try again. |
| provetPay.errors.auth_error, provetPay.errors.auth_forbidden | The card form is not available right now. Reload the page and try again. |
| provetPay.errors.session_error | The card form could not be opened. Try again later. |
| provetPay.errors.session_expired | Your session has expired, please reload the page |
| provetPay.errors.attempts_exceeded | This card form had too many attempts. Try again later, or use another card. |
| provetPay.errors.cancelled | The card setup was cancelled. |
| provetPay.errors.config_invalid, provetPay.errors.technical | Something went wrong while setting up the card. |
provetPay.savedCards.remove, provetPay.savedCards.removeQuestion, provetPay.savedCards.removeConfirm and provetPay.savedCards.removeCancel belong to removing a saved card, which this version does not offer yet; they may change before it does.
Appearance
The card UI draws itself from its own design tokens: a light palette, no background or padding of its own, and a system font. It depends on no stylesheet from the page, and its rules reach only the element it creates, so the page is untouched.
Two options match the component to the page's design:
mount('#card', {
auth,
onSuccess,
appearance: {
variables: { colorAccent: '#5b21b6', borderRadius: '8px' },
},
styles: { base: { color: '#1f2733' } },
})variables change the component's own colors, radius and font, and Adyen's card fields follow:
| variables | Changes |
| -------------- | ------------------------------------------------ |
| colorAccent | field focus ring and active outline |
| colorButton | Adyen's pay button |
| colorText | field labels and the text inside the card fields |
| colorBorder | field outlines |
| colorSurface | the saved-card dropdown and dialog backgrounds |
| colorError | field error text and outline |
| borderRadius | field corners |
| fontFamily | the text inside the card fields |
styles is Adyen's option for the card fields, as Adyen documents it: CSS by field state (base, error, validated, placeholder). The fields are cross-origin iframes, so only concrete values ('#1f2733', '16px') work there, never var(…).
cssVariables sets raw --pp-* or --adyen-sdk-* properties and wins over variables on the component's own UI; for instance --pp-color-success colors the "Card saved" check. Inside Adyen's card fields, colorText, fontFamily and colorError from variables win over cssVariables, and styles wins over both.
The component sets ten of Adyen's --adyen-sdk-* properties on its own root, so page values for those ten do not reach the card fields: set them with cssVariables. The others still follow the page. Adyen's class names can still be overridden, with a selector more specific than Adyen's, because the component's stylesheet comes after the page's.
The "Back to saved cards" control the component adds carries the class provet-pay-elements-back, and the container gets provet-pay-elements. Both can be styled by the page.
Content Security Policy
If the page sets a Content Security Policy, allow what the component and Adyen load. {env} is test or live, the Adyen environment Provet returns with each session.
| Directive | Allow | Because |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| connect-src | the Provet instance, https://checkoutshopper-{env}.adyen.com, https://checkoutanalytics-{env}.adyen.com, https://checkoutshopper-{env}.cdn.adyen.com | the component calls Provet; Adyen calls its session API and analytics, and fetches the non-English translations it ships, from that CDN |
| frame-src | https://checkoutshopper-{env}.adyen.com and the card issuers' 3-D Secure pages | the card fields and Adyen's risk check are iframes from that host, and a 3-D Secure challenge opens the issuer's page in an iframe |
| form-action | the card issuers' 3-D Secure pages | Adyen posts the 3-D Secure challenge to the issuer as a form |
| img-src | https://checkoutshopper-{env}.cdn.adyen.com and data: | card brand logos come from the CDN, and Adyen's stylesheet draws some icons as data: SVGs |
| style-src | 'unsafe-inline', only for browsers without constructable stylesheets | the component adds its styles as a constructed stylesheet, which CSP does not block; without one it falls back to a <style> element |
Adyen publishes no list of issuer hosts, so frame-src and form-action need https: in practice.
How it works
the page (its own origin)
└── @nordhealth/provet-pay-elements one JavaScript file
├── Provet checkout-sessions · saved-cards
└── Adyen card fields · the $0 authorization · 3-D Secure- The backend exchanges its credentials for a browser token bound to one shopper.
- The page mounts the component with that token. The component first lists the shopper's saved cards from Provet; a refused token stops here, before anything else happens.
- To add a card, the component asks Provet to open a session. Provet creates a pending card and opens the Adyen session; the browser only ever talks to Provet and Adyen.
- The shopper types the card into Adyen's fields. Adyen runs the
$0authorization and any 3-D Secure challenge, then tells the component, which callsonSuccesswith the pending card's id. - Adyen's confirmation reaches Provet a few seconds later and turns the pending card into an active one. Nothing on the page polls for that.
Saving the same card twice creates two Provet cards that share one Adyen token.
3-D Secure
Most challenges appear inside the form. When an issuer needs a full-page redirect, the browser returns to the page with redirectResult in the address. Mount the component there again with the same options: it settles the session it stored before the redirect, unless Adyen's sessionId names another session, removes redirectResult and sessionId from the address so a reload does not submit them twice, and calls onSuccess when the check passed. A failed check brings the form back with its notice and calls onRefused, and a call to Adyen that fails calls onError, as in the form. The return address is the page's path without its query string, so a page that needs query parameters to render should keep them somewhere else, for instance its own storage, before the shopper leaves for the challenge.
The component stores the unfinished session in sessionStorage under a key made from provetOrigin, provetId, clientId and departmentId, together with that auth and the recurringModel and page it was opened for. A refresh or a redirect resumes it only for a mount with the same auth, so a second shopper in the same tab starts their own. A mount with another recurringModel, or on another page, opens its own session, unless the address carries the stored session's 3-D Secure result. A session whose form has had its 55 minutes is not resumed either, unless the address carries its 3-D Secure result. It never stores the token. A session stored by an earlier version of the component is not resumed. Adyen keeps its own copy of the session in localStorage.
Versioning
The package follows semantic versioning. Pin a minor version (~1.0.0) and read CHANGELOG.md before upgrading; breaking changes are announced ahead of time.
Working on the package itself: see DEVELOPMENT.md in the package's directory of the pay-js repository.
