Looking for ePay classic docs? Go to docs.epay.dk
ePay documentationDocsePay documentation

ePay.js reference

Embed secure payment fields, trigger wallet flows, and manage payment state from your own checkout with a reference built for implementation speed.

Introduction

Example response: Initialize payment session
{  "paymentWindowUrl": "https://payments.epay.eu/payment-window?sessionId=01954c23-7baa-755c-839c-957efd4892c2&sessionKey=c1690a71-154c-4ab6-b789-ec21c9a224fb",  "session": {    "id": "01954c23-7baa-755c-839c-957efd4892c2",    "pointOfSaleId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",    "timeout": 20,    "instantCapture": "OFF",    "reference": "my-reference-1",    "amount": 100,    "currency": "DKK",    "textOnStatement": null,    "state": "PENDING",    "dynamicAmount": false,    "createdAt": "2025-02-28T10:39:08.713109269Z",    "expiresAt": "2025-02-28T10:59:08.713109269Z",    "notificationUrl": "https://my-notification-url.com",    "successUrl": "https://my-success-url.com",    "failureUrl": "https://my-failure-url.com",    "preAuthUrl": null,    "retryUrl": null,    "attributes": null,    "scaMode": "NORMAL",    "reportFailure": false,    "exemptions": [],    "subscriptionId": null,    "maxAttempts": 5,    "attempts": 0  },  "key": "c1690a71-154c-4ab6-b789-ec21c9a224fb",  "javascript": "https://payments.epay.eu/sessions/01954c23-7baa-755c-839c-957efd4892c2/client.js"}

Include ePay.js

Including ePay.js
<script  type="module"  src="https://payments.epay.eu/sessions/01954c23-7baa-755c-839c-957efd4892c2/client.js"></script>

Initialize the ePay.js client

Callbacks
clientReady

The client is initialized and ready.

invalidSession

The provided session id or key is invalid.

challengeIssued

A challenge flow, such as 3-D Secure, has started.

transactionAccepted

The transaction was accepted.

transactionDeclined

The transaction was declined.

feeUpdated

The transaction fee information changed.

clientRedirect

The client is about to redirect the shopper.

invalidInput

The hosted fields contain invalid input.

inputValidity

Input validity changed.

inputSubmit

The hosted fields were submitted.

sessionExpired

The current session expired.

error

An error occurred in the client.

Initialize the ePay.js client
epay  .setSessionId("<SESSION_ID>")  .setSessionKey("<SESSION_KEY>")  .setCallbacks({    // This method is optional    clientReady: clientReadyCallback,    invalidSession: invalidSessionCallback,    challengeIssued: challengeIssuedCallback,    transactionAccepted: transactionAcceptedCallback,    transactionDeclined: transactionDeclinedCallback,    feeUpdated: feeUpdatedCallback,    clientRedirect: clientRedirectCallback,    invalidInput: invalidInputCallback,    inputValidity: inputValidityCallback,    inputSubmit: inputSubmitCallback,    sessionExpired: sessionExpiredCallback,    error: errorCallback,  })  .init();

Mounting the fields mountFields

Theme theme

Determines the overall style of the payment fields in Blocks (for example,  "default" provides an ePay-inspired look).

Themes
default

The default ePay inspired styling.

Language language

Optionally sets the language for labels and messages.

Languages
da

Danish

en

English

sv

Swedish

no

Norwegian

de

German

bg

Bulgarian

et

Estonian

fi

Finnish

fr

French

el

Greek

ga

Irish

it

Italian

hr

Croatian

lv

Latvian

lt

Lithuanian

mt

Maltese

nl

Dutch

pl

Polish

pt

Portuguese

ro

Romanian

sk

Slovak

sl

Slovenian

es

Spanish

cs

Czech

hu

Hungarian

Additional Fields fields

By default, only the essential payment method fields are included. If you need extra fields, such as a cardholder name field use this object to enable them.

Cardholder name name

By default, there is no input field for the cardholder name. If you need to collect this information, you can enable it when mounting the fields by passing the fields object.

A prefilled cardholder name can be given by sending the fields.name.value parameter.

PAN field pan

The PAN field supports the following options:

PAN field options
focus

Boolean: Controls whether the field should be focused on mount. Default is true.

showSupportedSchemes

Boolean: Controls the visibility of supported schemes. Default is true.

showBrandSelector

Boolean: Controls the visibility of the card brand selector. Default is true.

Loader loader

Allows you to customize visual aspects of the loader, such as background color, border style, and height.

Styling Variables variables

Allows you to customize visual aspects such as text color, border radius, fonts, spacing, and more.

General
colorText

The font color of text, used for labels and input content.

borderRadius

The border radius for inputs and the window.

borderColor

The default border color for inputs and the window.

fontFamily

The font used for labels, input content, and placeholders.

Spacing between the input fields (horizontal and vertical)
gridColumnSpacing

Horizontal spacing between input fields in the grid layout.

gridRowSpacing

Vertical spacing between input fields in the grid layout.

gridTemplateColumns

Defines the column structure of the grid layout.

Displaying icons and brands
iconDisplay

Controls the visibility of icons in the fields (e.g., block or none).

cardBrandDisplay

Controls the visibility of card brand icons (e.g., block or none).

supportedSchemesDisplay

Controls the visibility of supported schemes (e.g., flex or none).

Label elements
labelColor

The font color for labels.

labelFontSize

The font size for labels.

labelFontWeight

The font weight for labels.

labelMarginBottom

The spacing below labels.

Input elements
inputColor

The font color for user input.

inputBorderRadius

The border radius for input fields.

inputBorderColor

The border color for input fields.

inputFocusBorderColor

The border color when an input field is in focus.

inputFontSize

The font size for input fields.

inputPadding

The padding inside input fields.

inputPlaceholderColor

The font color for placeholder text in input fields.

inputBackgroundColor

The background color for input fields.

inputBoxShadow

The box shadow for input fields.

inputFocusBoxShadow

The box shadow for input fields when they are in focus.

windowPadding

The padding around the window containing the payment fields.

windowBackgroundColor

The background color of the window containing the payment fields.

windowBorderStyle

The border style of the window containing the payment fields.

windowBorderRadius

The border radius of the window containing the payment fields.

windowBorderColor

The border color of the window containing the payment fields.

Color specific
colorDanger

The color used to indicate problems or input validation errors.

colorPrimary

The primary theme color for the payment fields.

Element to mount fields to
<div id="fields"></div>
Mounting the fields
epay.mountFields("fields", {  // The configuration object is optional  theme: "default",  language: "da",  fields: {    name: { enabled: true, value: "" },    pan: {      focus: true,      showSupportedSchemes: true,      showBrandSelector: true,    },  },  loader: {    backgroundColor: "transparent",    borderStyle: "none",    height: "150px",  },  variables: {    colorText: "#2e3033",  },});

Clearing the fields clearFields

clearFields
idString

The same container identifier (e.g. fields) used when calling epay.mountFields(id).

You must pass the same id that was used to mount the fields using mountFields. If the ID does not match, the method will have no effect.
Clearing the fields
epay.clearFields("fields");

Adding a payment button

Methods
epay.createCardTransaction()

Initializes and begins processing of a card (Blocks) based payment.

epay.createVippsMobilePayTransaction()

Initializes and begins processing of a Vipps-MobilePay based payment.

epay.createApplePayTransaction()

Initializes and begins processing of a ApplePay based payment.

epay.createGooglePayTransaction()

Initializes and begins processing of a GooglePay based payment.

epay.createAnydayTransaction()

Initializes and begins processing of a Anyday based payment.

epay.createViabillTransaction()

Initializes and begins processing of a Viabill based payment.

epay.createSwishTransaction()

Initializes and begins processing of a Swish based payment.

epay.createKlarnaTransaction()

Initializes and begins processing of a Klarna based payment.

Payment button: Card based payment
<button type="button" onclick="epay.createCardTransaction()">  Pay</button>

Payment options setPaymentOptions

Mounting the fields
epay.setPaymentOptions({amount: 10000, store: true});

Get stored Payment options getStoredPaymentMethods

Getting stored Payment Methods
epay  .getStoredPaymentMethods()  .then(data => {    console.log('Stored Payment Methods:', data.paymentMethods);  })  .catch(error => {    console.error('Error fetching stored payment methods:', error);  });

Get supported Payment method types getSupportedPaymentMethodTypes

Getting available Payment Method types
epay  .getSupportedPaymentMethodTypes()  .then(data => {    console.log('Supported Payment Methods:', data);  })  .catch(error => {    console.error('Error fetching supported payment methods:', error);  });/** Example:    {        "CARD": {            "name": "Card",            "url": "https://payments.epay.eu/assets/images/payment-options/credit-card.svg",            "method": fn(),        },        "VIPPS_MOBILEPAY": {            "name": "Vipps MobilePay",            "url": "https://payments.epay.eu/assets/images/payment-options/mobile-pay.svg"            "method": fn(),        },        "APPLE_PAY": {            "name": "ApplePay",            "url": "https://payments.epay.eu/assets/images/payment-options/apple-pay.svg"            "method": fn(),        }    }*/

Create transaction createTransaction(options)

Create transaction
epay  .createTransaction({    amount: 10000,        // Set the amount (e.g., 100.00 in minor units)    store: true,          // Option to store the card for card-on-file    paymentMethodId: 'stored-card-id' // Card-on-file using a stored card  })  .then(response => {    console.log('Transaction created successfully:', response);  })  .catch(error => {    console.error('Transaction creation failed:', error);  });

Cancel transaction CancelTransaction()

Cancel Transaction
epay.cancelTransaction()

Process transaction process()

Cancel Transaction
epay.process()

Delete stored Payment Method deleteStoredPaymentMethod(paymentMethodId)

Delete stored payment method
epay  .deleteStoredPaymentMethod(paymentMethodId)  .then((response) => {    console.log("Stored payment method deleted successfully:", response);  })  .catch((error) => {    console.error("Error deleting stored payment method:", error);  });

Calculate fee for stored payment method calculateStoredPaymentMethodFee()

calculateStoredPaymentMethodFee
paymentMethodIdString

ID of the stored payment method.

requestObject (optional)

Optional request payload used when you want to calculate the fee with a specific amount.

Supports amount, where the amount is provided in the smallest currency unit (e.g. 100 = 1.00).
Calculate fee for stored payment method
epay  .calculateStoredPaymentMethodFee("0295ec1b-a6b0-7701-8050-31b0add07282")  .then((fee) => {    console.log("Calculated Fee (default amount):", fee);  })  .catch((error) => {    console.error("Error calculating fee:", error);  });

Start age verification startAgeVerification()

startAgeVerification
successUrlString (optional)

URL to redirect to upon successful verification.

failureUrlString (optional)

URL to redirect to if verification fails.

Start age verification
epay.startAgeVerification({  successUrl: "https://xyz.com",  failureUrl: "https://zyz.com",});

Get payment data for request getGooglePayPaymentData(merchantId)

getGooglePayPaymentData
merchantIdString (optional)

Explicit merchantId to send to Google Pay. If omitted, the id is taken from the merchant configuration.

Get payment data for request
epay.getGooglePayPaymentData("ASDF1234");

Get networks supported by Google Pay getGooglePaySupportedNetworks()

Get networks supported by Google Pay
epay.getGooglePaySupportedNetworks();

Get Google Pay client getGooglePaymentsClient(options)

Returns Google Pay client to call Google Pay endpoint.

Get Google Pay client
epay.getGooglePaymentsClient();

Mount Google Pay button mountGooglePayButton(id, options, merchantId)

Mount Google Pay button
epay.mountGooglePayButton("googlePayContainer", {  buttonColor: "black",  buttonType: "buy",  buttonRadius: 48,  buttonSizeMode: "fill",});