Skip to main content

4. Add hosted fields

<div id="fields"></div>

Initialize the hosted fields

<script>
epay
.setSessionId("<SESSION_ID>")
.setSessionKey("<SESSION_KEY>")
.setCallbacks({
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();

epay.mountFields("fields", {
theme: "default",
language: "da", // Optional parameter ["da", "en", "sv", "no"]
variables: {
colorText: "#2e3033",
},
});
</script>

Cardholder 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.

epay.mountFields("fields", {
theme: "default",
fields: {
name: { enabled: true, value: "" },
},
});

Styling

Merchants can style the hosted fields to match their branding.

To stay compliant and protect cardholder data the styling options follow very strict validation requirements. ePay only allow simple styling rules such as color codes, css unit sizing and fonts.

Themes

NameDescription
defaultThe default ePay inspired styling.

Variables

General
VariableDescription
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.
Spacing between the input fields (horizontal and vertical)
VariableDescription
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.
Displaying icons and brands
VariableDescription
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).
Label elements
VariableDescription
labelColorThe font color for labels.
labelFontSizeThe font size for labels.
labelFontWeightThe font weight for labels.
labelMarginBottomThe spacing below labels.
Input elements
VariableDescription
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 hosted fields.
windowBackgroundColorThe background color of the window containing the hosted fields.
windowBorderStyleThe border style of the window containing the hosted fields.
windowBorderRadiusThe border radius of the window containing the hosted fields.
windowBorderColorThe border color of the window containing the hosted fields.
Color specific
VariableDescription
colorDangerThe color used to indicate problems or input validation errors.
colorPrimaryThe primary theme color for the hosted fields.

JavaScript events

The javascript functions below can be set to receive notifications from the client with information of the current transaction state.

NameDescription
clientReadyDispatched once the client has verified the session id and secret.
invalidSessionDispatched if the client cannot verify the session id and secret.
challengeIssuedDispatched before a client redirect to the challenge page. Return false to cancel follow-up events.
transactionAcceptedDispatched on transaction success. Funds are guaranteed.
transactionDeclinedDispatched on transaction rejection.
feeUpdatedDispatched when the transaction fee is calculated
clientRedirectDispatched before any client redirect. Return false to cancel redirect behaviour.
invalidInputDispatched if the payment method input cannot be used for processing.
inputValidityDispatched on end user payment method input during validity checks.
inputSubmitDispatched on user submit by submitting the fields directly within the fields.
sessionExpiredDispatched if the session has expired. Return false to cancel follow-up events.
errorDispatched on any error not covered by other events.
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.

Event Data

Each javascript function takes in one parameter, which is an object of data.

Dynamic Amount

To set the transaction amount when dynamicAmount is true, use the client method epay.setPaymentOptions({amount: 100}).

When directly integrating hosted fields with dynamic amounts enabled, merchants must allow end users to select their own payment amount.

Merchants can utilize pre-auth webhooks to accept or reject the selected transaction amount in case it falls outside acceptable ranges.

info

Most merchants are advised against using dynamic amounts due to increased integration complexity.

This requires server-side verification of the selected amount during the pre-authorization webhook. For simplicity, most merchants should have customers select the payment amount before initializing the payment session at ePay.