Skip to content
⌘K
InboxAsk a human

React Web Component

Updated by Lukas Dumskis

Integrating Volume into your React application is fast and straightforward. This guide will help you get started in less than five minutes.


Getting Started

First, install the required package:


VolumeProvider

The VolumeProvider should wrap your application at the root level. It provides global configuration for all Volume components in your app.

import { VolumeProvider } from '@getvolume/react-web' export default function Root() { return ( <VolumeProvider applicationId="123456789" volumeEnvironment="sandbox" onEvent={handleEvent} > <App /> </VolumeProvider> ) }

Required Props

Key

Type

Example

Description

applicationId

string

123456789

Your Application ID from the Merchant Portal.

volumeEnvironment

string

sandbox

Environment to connect to: 'live', 'sandbox', or a custom URI.

Optional Props

Key

Type

Example

Description

onEvent

callback function

(event) => {...}

Triggered whenever a Volume event occurs.


Volume Event Callback

Volume emits events during the payment lifecycle. The onEvent callback allows you to handle these events in your app.

<VolumeProvider applicationId="123456789" volumeEnvironment="sandbox" onEvent={(event: VolumeEvent) => console.log(JSON.stringify(event))} > ... </VolumeProvider>

Event Object

interface VolumeEvent { type: VolumeEventType; time: number; // Unix timestamp meta?: {}; // Optional event-specific metadata }

Supported Event Types

enum VolumeEventType { GenericError = "GENERIC_ERROR", PaymentInitiated = "PAYMENT_INITIATED", ConfirmPageLoaded = "CONFIRM_PAGE_LOADED", BankSelectionLoaded = "BANK_SELECTION_LOADED", AwaitingAuthorisation = "AWAITING_AUTHORISATION", BankLaunchedLoaded = "BANK_LAUNCHED_LOADED", PaymentIdGenerated = "PAYMENT_ID_GENERATED" // desktop only }

⚠️ Desktop mode: Only the PaymentIdGenerated event is emitted.


Event Categories

Behavioral events – triggered by user actions:

Event

Description

Metadata

GENERIC_ERROR

Unknown error occurred

Error description string

PAYMENT_INITIATED

User clicked a bank icon

{ institution, merchantPaymentId, paymentId, reference, metadata }

AWAITING_AUTHORISATION

User clicked the confirm button

{ institution, reference }

UI events – triggered when views are loaded:

Event

Description

Metadata

BANK_SELECTION_LOADED

Bank selection page displayed

None

CONFIRM_PAGE_LOADED

Confirm page displayed

None

BANK_LAUNCHED_LOADED

Final confirmation page displayed

None

PAYMENT_ID_GENERATED

Payment ID generated in desktop mode

{ merchantPaymentId, paymentId, reference, metadata }


Styling

Include the following import to ensure the Volume button renders correctly:

import '@getvolume/react/dist/index.css'

⚠️ Without this, the button may not display properly.


Regenerating Merchant Payment ID

Each time the PaymentInitiated event is emitted, the merchantPaymentId must be regenerated to ensure uniqueness.


Using the Volume Button

Add the Volume component to your app:

import { Volume } from '@getvolume/react' export default function ProductPage() { return ( <Volume amount={50} currency="GBP" reference="Example Reference" country="GB" merchantPaymentId="123456" metadata={{ mydata: "myvalue" }} paymentStatusCallback={(status) => console.log(status)} componentViewTypeCallback={(viewType) => console.log(viewType)} /> ) }

Component Props

Key

Type

Constraints

Description

amount

number

min 0.01, 2 decimals

Payment amount

currency

string

ISO 4217

Payment currency

reference

string

Max 18 chars

Bank transfer reference

country

string

ISO 3166-1 alpha-2

Payment origin

merchantPaymentId

string

Max 50 chars, unique

Unique identifier for the payment

metadata

JSON object

Max 5000 chars serialized

Optional metadata passed back in webhooks

paymentStatusCallback

function

-

Triggered when payment status changes (desktop only)

componentViewTypeCallback

function

-

Provides the view type rendered (desktop/mobile)

isCompactMode

boolean

-

Displays button in compact mode

isButtonEnabled

boolean

-

Enable or disable the button

collectEmail

boolean

-

Collect payer email during confirmation

merchantProvidedPayerDetails

JSON object

-

Pre-populate payer details (see below)


metadata

The metadata prop must be a valid JSON object. Examples of invalid values:

metadata: 1 metadata: "test" metadata: [1,2,3]

Valid example:

metadata: { id: "0001", type: "donut", name: "Cake", batters: { batter: [{ id: "1001", type: "Regular" }] } }

paymentStatusCallback

Triggered only in desktop mode when QR code is visible.

interface PaymentStatusResponse { paymentStatus: PaymentStatus; errorDescription?: string; meta?: PaymentStatusMetadata; } enum PaymentStatus { NEW, AWAITING_AUTHORIZATION, AUTHORIZED, PENDING, COMPLETED, FAILED, UNDEFINED }

componentViewTypeCallback

Informs which view is displayed:

enum ComponentViewType { DESKTOP, MOBILE_NEW_CUSTOMER, MOBILE_RETURNING_CUSTOMER }

Merchant Provided Payer Details

Pre-populate payer information for faster UX, better conversion, and confirmation of payer identity.

merchantProvidedPayerDetails: { email: 'john.doe@example.com', name: 'John Doe', phone: '+44 20 7946 0958', account: { holderName, accountNumber, sortCode, iban }, address: { addressLine1, addressLine2, countryCode, town, postCode }, useForUxFlowOptimisation: true }

After Payment Callback

Once the payment is complete, users are redirected back from the banking app to your page. Documentation for handling the callback: Volume Callback.


Testing

Use the sandbox environment for testing before going live.

⚠️ Sandbox may not open the Banking app. Instead, the bank interface will open in a browser.

Check Sandbox Bank Credentials to test with Natwest and other sandbox banks.