Skip to main content

MONEI JS Reference

This reference documents every object and method available in MONEI's browser-side JavaScript library, monei.js.

You can use monei.js' APIs to integrate prebuilt Components for different payment methods into your own checkout flows across desktop and mobile.

Including monei.js

Include the monei.js script on the checkout page of your site — it should always be loaded directly from https://js.monei.com, rather than included in a bundle or hosted yourself.

<script src="https://js.monei.com/v3/monei.js"></script>

Using monei.js as a module

We also provide an npm package that makes it easier to load and use monei.js as a module.

npm i @monei-js/components

monei object

The monei object is your entrypoint to the rest of the monei.js SDK.

Component Instance API

Every MONEI Component (CardInput, PayPal, Bizum, PaymentRequest) returns a component instance with the following methods:

render(container)

Mounts the component into the DOM. Accepts a CSS selector string or an HTMLElement.

const cardInput = monei.CardInput({paymentId: '...', ...options});

// Using a CSS selector
cardInput.render('#card_input_container');

// Using an HTMLElement
cardInput.render(document.getElementById('card_input_container'));

submit(options?)

Tokenizes the current card data and returns a payment token. Available on CardInput instances only.

declare const submit: (options?: {cardholderName?: string}) => Promise<{
token?: string; // payment token
error?: string; // validation error
}>;

Example:

const {token, error} = await cardInput.submit({cardholderName: 'Jane Doe'});
if (error) {
// Show validation error to user
} else {
// Confirm payment with the token
await monei.confirmPayment({paymentId: '...', paymentToken: token});
}

updateProps(newProps)

Updates component props after render. Useful for reactive prop changes in vanilla JS. Returns a Promise that resolves when the update is delivered to the component.

// Update language dynamically
await cardInput.updateProps({language: 'es'});

// Update style
await cardInput.updateProps({
style: {
input: {fontSize: '18px'}
}
});
note

When using framework packages (React, Vue, Angular, Svelte), prop updates are handled automatically — you don't need to call updateProps() manually.

destroy()

Removes the component from the DOM and cleans up all internal resources (event listeners, iframe connections). After calling destroy(), the instance cannot be reused.

cardInput.destroy();

close()

Alias for destroy(). Removes the component and cleans up resources.

Framework Integration

MONEI Components are available as native components for popular frameworks. Each framework package handles mounting, prop syncing, and cleanup automatically.

PackageFrameworkGuide
@monei-js/react-componentsReactReact Components
@monei-js/vue-componentsVue 3Vue Components
@monei-js/angular-componentsAngularAngular Components
@monei-js/svelte-componentsSvelte 5Svelte Components
tip

The legacy .driver() API is deprecated. See the Migration Guide for upgrade instructions.

CardInput Component

CardInput is a customizable Component used to collect sensitive card information in your payment forms.

Create an instance of the CardInput Component.

const cardInput = monei.CardInput({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
...otherOptions
});

// render Component on the page
cardInput.render('#card_input_container');

CardInput options

PropTypeRequiredDescription
paymentIdstringYes*Payment ID from create payment. Generated token will be bound to this payment.
accountIdstringYes*Your MONEI account ID. Use with sessionId instead of paymentId to generate a token before creating the payment.
sessionIdstringCond.Unique session ID in your system. Provide a different sessionId for each customer to ensure the token-generating customer matches the paying customer. Required with accountId if passing a token to your server. Must match the value in create payment.
orderIdstringNoAlias for sessionId — normalizes to sessionId internally.
languagestringNoISO 639-1 language code. Supported: en, es, ca, pt, de, it, fr, nl, et, fi, lv, no, pl, ru. Auto-detected by default based on geolocation and browser preferences.
styleCardInputStyleNoCustomize appearance using CSS properties. See Style object below.
placeholdersobjectNoCustom input placeholders. See Placeholders below.
errorMessagesobjectNoCustom error messages. See Error messages below.
onFocus() => voidNoCalled when card input is focused.
onBlur() => voidNoCalled when card input is blurred.
onLoad() => voidNoCalled when card input is fully loaded.
onEnter() => voidNoCalled when user presses Enter inside card input.
onChange(event: CardInputOnChangeEvent) => voidNoCalled on every user input. Used for real-time validation.
onError(error: Error) => voidNoCalled when there is an error.

* Either paymentId or accountId is required. Cond. = required when using accountId.

CardInput placeholders

PropTypeDefault
cardNumberstring"Card number"
expiryDatestring"MM/YY"
cvcstring"CVC"

CardInput error messages

PropTypeDefault
emptyCardNumberstring"Enter a card number"
invalidCardNumberstring"Card number is invalid"
emptyExpiryDatestring"Enter an expiry date"
monthOutOfRangestring"Expiry month must be between 01 and 12"
yearOutOfRangestring"Expiry year cannot be in the past"
dateOutOfRangestring"Expiry date cannot be in the past"
invalidExpiryDatestring"Expiry date is invalid"
invalidCardTypestring"Card type is not supported"
emptyCVCstring"Enter a CVC"
invalidCVCstring"CVC is invalid"

CardInputOnChangeEvent

PropertyTypeDescription
isTouchedbooleanWhether the card input has been touched.
isSubmittedbooleanWhether the form has been submitted.
cardTypestring?Detected card type (e.g. visa, mastercard).
errorstring?Validation error message. Display this to the user.

CardInput Style object

components are styled using a Style object. It consists of CSS properties nested under objects for any of the following variants:

  • base object - base Component style
  • loading object - base Component style when Component is loading
  • invalid object - applied when the Component has invalid input
  • input object - applied to individual inputs
  • cardNumber object - applied to card number input
  • expiryDate object - applied to expiry date input
  • cvc object - applied to cvc input
  • icon object - applied to icon

The following pseudo-classes and pseudo-elements can also be styled using a nested object inside of a variant:

  • :focus
  • :hover
  • ::placeholder
  • ::selection
  • :-webkit-autofill
const style = {
base: {
height: '45px',
lineHeight: '45px',
padding: '8px 12px',
fontSize: '16px'
},
invalid: {
color: '#dc2727'
}
};

const cardInput = monei.CardInput({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
style: style,
...otherOptions
});

// render Component on the page
cardInput.render('#card_input_container');

createToken function

Deprecated

createToken() is deprecated. Use instance.submit() instead, which is available directly on the CardInput instance:

const {token, error} = await cardInput.submit();

See the Migration Guide for details.

Use this function to generate payment token.

note

Payment tokens generated by monei.js Components expire as soon as they are used or 5 days after creation.

Pass an instance of CardInput Component.

declare const createToken: (Component: MoneiComponent) => Promise<{
token?: string; // payment token
error?: string; // validation error
}>;

Example:

monei
.createToken(cardInput) // pass a reference to an instance of your CardInput Component
.then(function (result) {
console.log(result);
if (result.error) {
// Inform the user if there was an error.
} else {
// Confirm payment using the token.
moneiTokenHandler(result.token);
}
})
.catch(function (error) {
// Something went wrong while generating token
console.log(error);
});

PayPal Component

PayPal is a customizable Component that renders a PayPal payment button.

Create an instance of the PayPal Component.

const paypal = monei.PayPal({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
onSubmit(result) {
if (result.error) {
// Inform the user if there was an error.
} else {
// Confirm payment using the token.
moneiTokenHandler(result.token);
}
},
onError(error) {
console.log(error);
},
...otherOptions
});

// render Component on the page
paypal.render('#paypal_container');

PayPal options

PropTypeRequiredDescription
paymentIdstringYes*Payment ID from create payment. Generated token will be bound to this payment.
accountIdstringYes*Your MONEI account ID. Use with sessionId instead of paymentId to generate a token before creating the payment.
sessionIdstringCond.Unique session ID in your system. Provide a different sessionId for each customer to ensure the token-generating customer matches the paying customer. Required with accountId. Must match the value in create payment.
amountnumberCond.Amount in the smallest currency unit (e.g., 100 = 1.00 USD). Required with accountId.
currencystringCond.Three-letter ISO currency code, in uppercase. Required with accountId.
transactionType'SALE' | 'AUTH'NoControls when funds are captured. SALE (default): capture immediately. AUTH: authorize only, capture later.
languagestringNoLanguage for the PayPal button. Auto-detected by default. Supported languages.
cspNoncestringNoNonce value for Content Security Policy. Pass this if your page uses a CSP script-src nonce.
borderRadiusnumber | stringNoCustom border radius for the PayPal button container.
onSubmit(result: {token?: string; error?: string}) => voidYesCalled when the customer approves the payment.
onBeforeOpen() => booleanNoCalled before the PayPal window is opened. Return false to prevent the window from opening.
onLoad(isSupported: boolean) => voidNoCalled when PayPal is fully loaded. If PayPal is not supported, the component will not render and onLoad fires with false.
onError(error: Error) => voidNoCalled when there is an error.
styleobjectNoCustomize the button appearance. See style properties below.

* Either paymentId or accountId is required. Cond. = required when using accountId.

PayPal style

PropTypeDefaultDescription
heightnumber | stringButton height in pixels. Values from 25 to 55.
color'gold' | 'blue' | 'silver' | 'white' | 'black'Button color theme.
shape'pill' | 'rect'Button shape.
layout'horizontal' | 'vertical'Button layout when multiple buttons are available.
label'checkout' | 'credit' | 'pay' | 'buynow' | 'paypal' | 'installment'Button label text.
size'small' | 'medium' | 'large' | 'responsive'Button size preset.
borderRadiusnumber | stringCustom border radius for the button.

PaymentRequest Component

PaymentRequest is a customizable Component that renders a Google Pay or Apple Pay payment button depending on the browser and operating system of the user. PaymentRequest replaces the deprecated GooglePay component — it automatically shows Google Pay, Apple Pay, or Click to Pay based on device support.

note

Apple Pay requires domain verification in both development and production.

Create an instance of the PaymentRequest Component.

const paymentRequest = monei.PaymentRequest({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
onSubmit(result) {
if (result.error) {
// Inform the user if there was an error.
} else {
// Confirm payment using the token.
moneiTokenHandler(result.token);
}
},
onError(error) {
console.log(error);
},
...otherOptions
});

// render Component on the page
paymentRequest.render('#payment_request');

PaymentRequest options

PropTypeRequiredDescription
paymentIdstringYes*Payment ID from create payment. Generated token will be bound to this payment.
accountIdstringYes*Your MONEI account ID. Use with sessionId instead of paymentId to generate a token before creating the payment.
sessionIdstringCond.Unique session ID in your system. Provide a different sessionId for each customer to ensure the token-generating customer matches the paying customer. Required with accountId. Must match the value in create payment.
amountnumberCond.Amount in the smallest currency unit (e.g., 100 = 1.00 USD). Required with accountId.
currencystringCond.Three-letter ISO currency code, in uppercase. Required with accountId.
languagestringNoISO 639-1 language code. Supported: en, es, ca, pt, de, it, fr, nl, et, fi, lv, no, pl, ru. Auto-detected by default.
onSubmit(result: {token?: string; error?: string}) => voidYesCalled when the customer approves the payment.
onBeforeSubmit() => voidNoCalled before payment is submitted. Use for validation or analytics.
onBeforeOpen() => booleanNoCalled before the payment window is opened. Return false to prevent the window from opening.
onLoad(isSupported: boolean) => voidNoCalled when the component is fully loaded. If the payment method is not supported, the component will not render and onLoad fires with false.
onError(error: Error) => voidNoCalled when there is an error.
styleobjectNoCustomize the button appearance. See style properties below.

* Either paymentId or accountId is required. Cond. = required when using accountId.

PaymentRequest style

PropTypeDefaultDescription
heightstring | numberButton height in pixels. Values from 25 to 55.
color'default' | 'black' | 'white''default'Button color theme.
type'buy' | 'plain' | 'donate''plain'Button label: 'buy' = "Buy with Google Pay / Apple Pay", 'donate' = "Donate with Google Pay / Apple Pay", 'plain' = no additional text.
borderRadiusnumber | stringCustom border radius for the button.
fontFamilystringCustom font family for the button text.

Bizum Component

Bizum is a customizable Component that renders a Bizum payment button.

Create an instance of the Bizum Component.

const bizum = monei.Bizum({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
onSubmit(result) {
if (result.error) {
// Inform the user if there was an error.
} else {
// Confirm payment using the token.
moneiTokenHandler(result.token);
}
},
onError(error) {
console.log(error);
},
...otherOptions
});

// render Component on the page
bizum.render('#bizum');

Bizum options

PropTypeRequiredDescription
paymentIdstringYes*Payment ID from create payment. Generated token will be bound to this payment.
accountIdstringYes*Your MONEI account ID. Use with sessionId instead of paymentId to generate a token before creating the payment.
sessionIdstringCond.Unique session ID in your system. Provide a different sessionId for each customer to ensure the token-generating customer matches the paying customer. Required with accountId. Must match the value in create payment.
phoneNumberstringNoPre-fill the customer's phone number for the Bizum payment flow.
amountnumberCond.Amount in the smallest currency unit (e.g., 100 = 1.00 USD). Required with accountId.
currencystringCond.Three-letter ISO currency code, in uppercase. Required with accountId.
transactionType'SALE' | 'AUTH'NoControls when funds are captured. SALE (default): capture immediately. AUTH: authorize only, capture later.
fullscreenbooleanNoSet to true to open the Bizum payment window in fullscreen mode.
languagestringNoISO 639-1 language code. Supported: en, es, ca, pt, de, it, fr, nl, et, fi, lv, no, pl, ru. Auto-detected by default.
onSubmit(result: {token?: string; error?: string}) => voidYesCalled when the customer approves the payment.
onBeforeOpen() => booleanNoCalled before the Bizum window is opened. Return false to prevent the window from opening.
onOpen() => voidNoCalled when the Bizum payment window is opened.
onLoad(isSupported: boolean) => voidNoCalled when the component is fully loaded. If Bizum is not supported, the component will not render and onLoad fires with false.
onError(error: Error) => voidNoCalled when there is an error.
styleobjectNoCustomize the button appearance. See style properties below.

* Either paymentId or accountId is required. Cond. = required when using accountId.

Bizum style

PropTypeDefaultDescription
heightstring | numberButton height in pixels. Values from 25 to 55.
type'pay' | 'plain''plain'Button label: 'pay' = "Pay with Bizum", 'plain' = no additional text.
borderRadiusnumber | stringCustom border radius for the button.
fontFamilystringCustom font family for the button text.

confirmPayment function

After you generate the paymentToken using one of the Components, use this function to confirm the payment passing the obtained paymentToken. It will automatically show a popup window with a 3D Secure confirmation screen if required.

When called without a paymentToken, confirmPayment opens the MONEI Payment Modal where the customer can select a payment method and complete the payment. See Use Payment Modal for the full integration guide.

important

Not all payment methods are available in the Payment Modal. Apple Pay is not supported in the modal — use the PaymentRequest component instead.

You can provide additional customer information in parameters.

declare const confirmPayment: (params: ConfirmPaymentParams) => Promise<PaymentResult>;

Confirm payment params

ParamTypeRequiredDescription
paymentIdstringYesPayment ID from create payment
paymentTokenstringNoToken generated by monei.js. If present the popup opens directly to 3D Secure confirmation (if needed)
generatePaymentTokenbooleanNoIf true, generates a permanent token representing the payment method used
fullscreenbooleanNoIf true, opens a fullscreen confirmation window
languagestringNoTwo-letter ISO 639-1 language code. Supported: en, es, ca, pt, de, it, fr, nl, et, fi, lv, no, pl, ru. Overrides browser language
paymentMethodPaymentMethodNoPre-fill payment method details (e.g. cardholder name/email)
allowedPaymentMethodsstring[]NoRestrict available payment methods. Supported: card, googlePay, clickToPay, bizum, paypal
customDomainstringNoCustom domain for the payment popup. Required if you have a custom domain configured
customerCustomerNoCustomer information (name, email, phone)
billingDetailsBillingDetailsNoBilling address and contact details
shippingDetailsBillingDetailsNoShipping address and contact details (same shape as billingDetails)
style{width: string, height: string}NoPopup window dimensions (e.g. "400px", "100%")

PaymentMethod

FieldTypeDescription
card.cardholderNamestringCardholder name to pre-fill
card.cardholderEmailstringCardholder email to pre-fill

Check confirm payment for the full list of parameters.

Payment result

PropTypeDescription
idstringUnique identifier for the payment
statusstringThe status of the payment
amountpositive integerAmount intended to be collected by this payment. A positive integer representing how much to charge in the smallest currency unit (e.g., 100 cents to charge 1.00 USD)
currencystringThree-letter ISO currency code, in uppercase
accountIdstringMONEI account ID
orderIdstringAn order ID from your system. A unique identifier that can be used to reconcile the payment with your internal system
statusCodestringPayment status code
statusMessagestringHuman readable status message, can be displayed to a user
nextActionobjectIf present, tells you what actions you need to take for your customer to fulfill a payment using the provided source
nextAction.typestringThe type of next action
nextAction.mustRedirectbooleanWhether the customer must be redirected
nextAction.redirectUrlstringURL to redirect the customer to

Check payment object for the full description of each field

Example:

monei
.confirmPayment({
paymentId: 'af6029f80f5fc73a8ad2753eea0b1be0',
paymentToken: 'fe6786e08ded3191cf2f623e120a0bacda715bf2',
...otherOptions
})
.then(function (result) {
// Payment result
console.log(result);
})
.catch(function (error) {
// Something went wrong while confirming payment
console.log(error);
});