Skip to content
⌘K
InboxAsk a human

JavaScript SDK - Web Implementation

Updated by Lukas Dumskis

The Volume Vanilla JavaScript component allows you to integrate Volume quickly and easily into your web application.


Importing the Script

To use the Volume component, include the script on your webpage:

<script src="https://js.volumepay.io/Volume-0.9.3.min.js"></script>

If you prefer to always fetch the latest version, use:

<script src="https://js.volumepay.io"></script>

Initializing the Component

After importing the script, create a Volume instance:

const volume = new window.Volume({ environment: "SANDBOX", applicationId: "5fd31d88-e59a-467e-b084-5c01430afced", country: "GB", disablePayButton: false, isWebView: false, eventConsumer: (event) => console.log("Volume Event:", event), errorConsumer: (error) => console.error(JSON.stringify(error)), payLabel: "Pay $", agentType: "WEB_BROWSER" });

Configuration Options

Key

Type

Default

Description

environment

"SANDBOX" / "LIVE"

—

Environment to connect to

applicationId

string

—

Your application ID

disableVolumeStyling

boolean

false

If true, Volume CSS will not be loaded

disableTailwindStyling [DEPRECATED]

boolean

false

Tailwind classes will not be applied

disablePayButton

boolean

false

Disable the Pay button on initialization

eventConsumer

function

—

Callback for Volume events

errorConsumer

function

—

Callback for errors

payLabel

string

"Pay by Bank App"

Custom label for the pay button

agentType

"WEB_BROWSER" / "MOBILE_APPLICATION"

"WEB_BROWSER"

Determines which callback URL to use

isWebView

boolean

false

Adds #OPEN_AS_APPLINK postfix for WebView handling


Creating a Payment

let generatedMerchantPaymentId = generateMerchantPaymentId(); volume.createPayment({ amount: 6.22, currency: "EUR", merchantPaymentId: generatedMerchantPaymentId, paymentReference: "payment reference", // max 18 chars metadata: { email: "email@mail.com" }, agentType: "MOBILE_APPLICATION" });

Important Fields

  • amount – numeric value, up to 2 decimal places

  • merchantPaymentId – UUID, unique per payment

  • paymentReference – visible to the client in banking app, max 18 characters

  • metadata – optional JSON object (nested allowed, max 5000 characters)

Valid example for metadata:

metadata: { email: "email@mail.com", id: "0001", type: "donut", batters: { batter: [{ id: "1001", type: "Regular" }] } }

Supported Countries

Country

Code

Currency

United Kingdom

GB

GBP

Germany

DE

EUR

France

FR

EUR

Netherlands

NL

EUR

Spain

ES

EUR

Belgium

BE

EUR


Injecting the Component

volume.injectComponent("volume-element-container");

The component will render inside the element with the given ID.


Enabling / Disabling the Pay Button

volume.toggleButton(true); // enable volume.toggleButton(false); // disable

Merchant Payment ID Regeneration

Each time the PAYMENT_INITIATED event is emitted, you must generate a new unique merchantPaymentId.


Error Handling

const volume = new window.Volume({ ... errorConsumer: (error) => { console.error("Error:", JSON.stringify(error)); } });

Error object attributes:

  • location – ErrorLocation

  • error – description string

Example:

{ error: "Input validation error: field=[paymentRequest.reference], value=[TOO LONG], error=[max 18 characters]", location: "payWithBankInstitution" }

ErrorLocation values:

const ErrorLocation = { payWithBankInstitution: "payWithBankInstitution", fetchInstitutions: "fetchInstitutions" }

Programmatic Payment Initiation

Instead of requiring user clicks:

volume.createPayment({ amount: 6.22, ... }); volume.payWithInstitution("monzo");

Programmatic Institution Selection

volume.createPayment({ amount: 6.22, ... }); volume.openInstitutionSelection();

Note: If institutions are not yet fetched, the list will appear once data is ready.


Styling

  • Volume Styling: Controlled via disableVolumeStyling (default false)

  • Tailwind Styling: Deprecated since version 0.5


Testing

  • Use SANDBOX before switching to live

  • Sandbox testing opens banking environment in browser, not the actual app

  • Refer to Sandbox Banks Credentials


WebView Support

  • Android WebView does not handle App Links correctly

  • Use isWebView: true to append #OPEN_AS_APPLINK to URLs

  • Handle the URL in your app and remove the postfix before redirecting

if (url.endsWith("#OPEN_AS_APPLINK")) { val urlWithoutFragment = url.replace("#OPEN_AS_APPLINK", "") val intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlWithoutFragment)) context.startActivity(intent) }

Sample project: WebViewExample

Direct implementation: NinjaWebViewClient.kt

Volume Events

Volume emits a variety of events during the payment lifecycle. Listening to these events allows your application to respond appropriately at each stage.


payment_initiated

This event is triggered when a user selects a specific bank institution—either by clicking its icon or programmatically via the payWithInstitution(institutionId) function.

⚠️ Important: The merchantPaymentId must be regenerated immediately when this event is triggered to ensure uniqueness.

const volume = new window.Volume({ ... eventConsumer: (event) => { console.log("A VOLUME EVENT:", event); if (event === 'payment_initiated') { regenerateMerchantPaymentId(); } } ... });

mounted

This event is emitted when the Volume component has been successfully mounted in the DOM.

'mounted'

institutions_fetched

This event occurs after the list of bank institutions has been successfully fetched from the Volume server.

'institutions_fetched'

pay_button_enabled

Triggered when the payment button is enabled via the toggleButton(true) function.

'pay_button_enabled'

pay_button_disabled

Triggered when the payment button is disabled via the toggleButton(false) function.

'pay_button_disabled'

bank_selection_opened

This event is emitted when the list of bank institutions is displayed, either by user action or programmatically using the openInstitutionSelection() function.

'bank_selection_opened'

awaiting_authorisation

This event occurs when the authorization URL generated by the Volume backend has been opened and the user has been redirected to the banking institution.

'awaiting_authorisation'

Listening to these events allows your application to synchronize UI elements, handle errors, and manage payment states effectively throughout the user journey.