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
Welcome to the ePay.js reference documentation. This guide provides a complete overview of how to integrate ePay.js into your web application for secure and seamless payment processing. **Before integrating ePay.js, you need:** - An ePay account - An API key for server-side authentication - A Point of Sale ID to identify your business The first thing you need to do is to **[initialize a payment session](/api/initialize-payment-session)**. This needs to be done server side, as it requires your API key. The response from the server will include a link to the ePay.js client, which includes the [session ID](/get-started/core-concepts#sessions) for the payment session. The link is available in the `javascript` field of the response object. You will also need to save the session ID (`id`) and the session key (`key`) for the payment session, as you will need to provide these when initializing the ePay.js client. :::info Please note, that the ePay client needs to be fetched each time a new payment session is initialized and therefore can't be cached. :::
Include ePay.js
Once the payment session is initialized, include the ePay.js script in your webpage using the URL from the `javascript`-field in the session response. This can be done by adding the following line of code inside the `<head></head>` tag your website.
Initialize the ePay.js client
After including ePay.js, initialize the client using your Session ID (`session.id`) and Session Key (`key`) from the session response. In the `.setCallbacks` method, you can set up event listeners to handle different events during the payment process. However, this is optional. ### JavaScript events The javascript functions below can be set to receive notifications from the client with information of the current transaction state. Each javascript function takes in one parameter, which is an object of data. :::info All events have a default handler that makes sure the payment is processed as expected. If merchants wants to modify this flow, like handling redirects differently, they can register a handler with their own logic and return false to disable the default handler. Do note that ePay cannot guarantee correct handling of events in this case. :::
clientReadyThe client is initialized and ready.
invalidSessionThe provided session id or key is invalid.
challengeIssuedA challenge flow, such as 3-D Secure, has started.
transactionAcceptedThe transaction was accepted.
transactionDeclinedThe transaction was declined.
feeUpdatedThe transaction fee information changed.
clientRedirectThe client is about to redirect the shopper.
invalidInputThe hosted fields contain invalid input.
inputValidityInput validity changed.
inputSubmitThe hosted fields were submitted.
sessionExpiredThe current session expired.
errorAn error occurred in the client.
Mounting the fields mountFields
The mountFields method is used to integrate and display hosted payment fields into a specified container on your webpage. After initializing the payment session, you call mountFields to embed the fields in a given HTML element and configure their appearance, behavior, and additional input options. The method takes a container identifier (typically the ID of a `<div>` element. In our example we used `fields` as an ID) where the Blocks will be mounted. In addition to specifying the container, you pass a configuration object that controls several aspects: - `theme` - `language` - `fields` - `variables` :::info The configuration object is optional. :::
Theme theme
Determines the overall style of the payment fields in Blocks (for example, Â "default" provides an ePay-inspired look).
defaultThe default ePay inspired styling.
Language language
Optionally sets the language for labels and messages.
daDanish
enEnglish
svSwedish
noNorwegian
deGerman
bgBulgarian
etEstonian
fiFinnish
frFrench
elGreek
gaIrish
itItalian
hrCroatian
lvLatvian
ltLithuanian
mtMaltese
nlDutch
plPolish
ptPortuguese
roRomanian
skSlovak
slSlovenian
esSpanish
csCzech
huHungarian
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:
focusBoolean: Controls whether the field should be focused on mount. Default is true.
showSupportedSchemesBoolean: Controls the visibility of supported schemes. Default is true.
showBrandSelectorBoolean: Controls the visibility of the card brand selector. Default is true.
:::warning `showBrandSelector` EU PSD2 requires the card brand selector (`showBrandSelector`) to be displayed. :::
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.
colorTextThe font color of text, used for labels and input content.
borderRadiusThe border radius for inputs and the window.
borderColorThe default border color for inputs and the window.
fontFamilyThe font used for labels, input content, and placeholders.
gridColumnSpacingHorizontal spacing between input fields in the grid layout.
gridRowSpacingVertical spacing between input fields in the grid layout.
gridTemplateColumnsDefines the column structure of the grid layout.
iconDisplayControls the visibility of icons in the fields (e.g., block or none).
cardBrandDisplayControls the visibility of card brand icons (e.g., block or none).
supportedSchemesDisplayControls the visibility of supported schemes (e.g., flex or none).
labelColorThe font color for labels.
labelFontSizeThe font size for labels.
labelFontWeightThe font weight for labels.
labelMarginBottomThe spacing below labels.
inputColorThe font color for user input.
inputBorderRadiusThe border radius for input fields.
inputBorderColorThe border color for input fields.
inputFocusBorderColorThe border color when an input field is in focus.
inputFontSizeThe font size for input fields.
inputPaddingThe padding inside input fields.
inputPlaceholderColorThe font color for placeholder text in input fields.
inputBackgroundColorThe background color for input fields.
inputBoxShadowThe box shadow for input fields.
inputFocusBoxShadowThe box shadow for input fields when they are in focus.
windowPaddingThe padding around the window containing the payment fields.
windowBackgroundColorThe background color of the window containing the payment fields.
windowBorderStyleThe border style of the window containing the payment fields.
windowBorderRadiusThe border radius of the window containing the payment fields.
windowBorderColorThe border color of the window containing the payment fields.
colorDangerThe color used to indicate problems or input validation errors.
colorPrimaryThe primary theme color for the payment fields.
Clearing the fields clearFields
The `clearFields` method resets all input fields in the Blocks component — including PAN (card number), CVC, and expiry — without unmounting or reloading the component. It is typically used if a user wants to re-enter card details after submitting or cancelling a payment attempt.
clearFieldsidStringThe same container identifier (e.g. fields) used when calling epay.mountFields(id).
id that was used to mount the fields using mountFields. If the ID does not match, the method will have no effect.Payment options setPaymentOptions
The `setPaymentOptions()` method is used to configure the payment options by setting the amount and store parameters for the transaction. This method is particularly useful when dynamic amounts are enabled, or when you need to store the payment method for future quick deposits. #### `amount` <span className="text-slate-600 text-sm">Number</span> Sets the payment amount when dynamic amount mode is enabled. The amount is typically provided in minor currency units (for example, `10000` might represent 100.00 in your currency). #### `store` <span className="text-slate-600 text-sm">Boolean</span> When set to `true`, the payment method is saved for future use (e.g., quick deposits). This functionality requires cardholder approval in Denmark, which can be obtained via a checkbox or similar method. * Requires `customerId` when [initializing the payment session](/api/initialize-payment-session).
Get stored Payment options getStoredPaymentMethods
This method retrieves all stored payment methods (cards) for the current user. The stored cards are scoped based on the `customerId` provided during session initialization. If no `customerId` is set during session initialization, the method will return an empty array. :::info While this method can be used to fetch stored cards, it is expected that you might not need it if you are already managing your own account system. :::
Get supported Payment method types getSupportedPaymentMethodTypes
This method retrieves available supported payment method types for the current session. The method is context-aware, meaning it will dynamically filter payment methods depending on the session data, and your account settings. It will match the requirement of specific payment method types to the current session. This method can be used by partners / plugins who needs to dynamically build their UI depending on the context of the current merchant or payment. The method returns a list of object with the following keys: - **name**: The name of the payment method (Not static) - **url**: Url to a payment method logo - **method**: Reference to the method to call, to initialize a payment of this type To uniquely identify a payment method, merchant should refer to the key of the object and not the `name` property.
Create transaction createTransaction(options)
This method creates a transaction based on the provided options. The options are similar to those used with `epay.setPaymentOptions()`. In addition, you can include the key paymentMethodId to initiate a quick card-on-file using stored card details. The options passed into `epay.createTransaction()` are merged with any options that were previously set using `epay.setPaymentOptions()`. Adding the `paymentMethodId` key in the options will trigger a card-on-file using the stored card data.
Cancel transaction CancelTransaction()
This method cancels any current transaction for the session. It is only possible to cancel a transaction before any operations attempts, such as authorizations, has begun. This can be useful for merchants implementing surcharge confirmation dialogs, where this method can be used to cancel the transaction if a cardholder does not wish to confirm the surcharge.
Process transaction process()
If a transaction processing is halted for any reason, such as a surcharge confirmation, the transaction processing can be resumed by calling `epay.process()`. This method is typically not needed to implement, unless your implementation pauses processing midway.
Delete stored Payment Method deleteStoredPaymentMethod(paymentMethodId)
This method allows the customer to delete a stored card via the frontend. Once a stored payment method is deleted, it can no longer be used for card-on-file. This action is typically initiated by the customer and ensures that their stored card data is removed from future transactions (e.g., card-on-file).
Calculate fee for stored payment method calculateStoredPaymentMethodFee()
This method calculates the fee for a specific stored payment method (such as a saved card). It requires a `paymentMethodId`, which can be obtained from a previously retrieved `paymentMethod` object using `epay.getStoredPaymentMethods()`. If `request` is not provided or does not include an amount, the default amount from the current session will be used. This method is useful if you want to show the expected transaction fee to your users before initiating a payment.
calculateStoredPaymentMethodFeepaymentMethodIdStringID of the stored payment method.
requestObject (optional)Optional request payload used when you want to calculate the fee with a specific amount.
amount, where the amount is provided in the smallest currency unit (e.g. 100 = 1.00).Start age verification startAgeVerification()
This method initiates the age verification process. If neither URL is provided, the current window location is used as the fallback.
startAgeVerificationsuccessUrlString (optional)URL to redirect to upon successful verification.
failureUrlString (optional)URL to redirect to if verification fails.
Get payment data for request getGooglePayPaymentData(merchantId)
Returns object for request to [isReadyToPay](https://developers.google.com/pay/api/web/reference/client#isReadyToPay) and [loadPaymentData](https://developers.google.com/pay/api/web/reference/client#loadPaymentData) `allowedCardNetworks` - in the returned data - is based on what is available on the current session. The `merchantId` is assigned by Google and available in the [Google Pay & Wallet Console](https://pay.google.com/business/console/)
getGooglePayPaymentDatamerchantIdString (optional)Explicit merchantId to send to Google Pay. If omitted, the id is taken from the merchant configuration.
Get networks supported by Google Pay getGooglePaySupportedNetworks()
Returns list of card networks available on the current session and supported by Google Pay.
Get Google Pay client getGooglePaymentsClient(options)
Returns Google Pay client to call Google Pay endpoint.