React + TypeScript bindings for Mollie Components / Mollie.js v1.
This is a community wrapper, not an official Mollie package.
- Loads
https://js.mollie.com/v1/mollie.jsonce. MollieProviderfor initialization.- Generic
MollieComponentmatchingmollie.createComponent(type, options). - Shortcuts for
card,cardHolder,cardNumber,verificationCode,expiryDate. - React callbacks for
change,focus,blur. useMollieToken()formollie.createToken().- TypeScript declarations included.
- SSR-safe loader: Mollie.js is only loaded in the browser.
npm install @exalandapp/react-mollie-componentsReact and React DOM are peer dependencies.
import {
MollieProvider,
MollieCardNumber,
MollieCardHolder,
MollieExpiryDate,
MollieVerificationCode,
useMollieToken,
} from '@exalandapp/react-mollie-components';
function CheckoutForm() {
const createToken = useMollieToken();
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const { token, error } = await createToken();
if (error || !token) {
console.error(error);
return;
}
await fetch('/api/payments', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ cardToken: token }),
});
}
return (
<form onSubmit={onSubmit}>
<MollieCardHolder />
<MollieCardNumber />
<MollieExpiryDate />
<MollieVerificationCode />
<button type="submit">Pay</button>
</form>
);
}
export default function Checkout() {
return (
<MollieProvider
profileId="pfl_xxxxxxxxxx"
options={{ locale: 'fr_FR' }}
>
<CheckoutForm />
</MollieProvider>
);
}This maps directly to Mollie's mollie.createComponent(type, options) API.
<MollieComponent
type="cardNumber"
options={{
styles: {
base: {
fontSize: '16px',
color: '#111827',
'::placeholder': { color: '#9ca3af' },
},
},
}}
onChange={(event) => console.log(event)}
/>Supported type values:
cardcardHoldercardNumberverificationCodeexpiryDate
<MollieCard
options={{
components: {
cardHolder: { label: 'Titulaire' },
cardNumber: { label: 'Numéro de carte' },
expiryDate: { label: 'Expiration' },
verificationCode: { label: 'CVC' },
},
}}
/>import { useMollieStatus } from '@exalandapp/react-mollie-components';
function Status() {
const { loading, error, mollie } = useMollieStatus();
if (loading) return <span>Chargement…</span>;
if (error) return <span>{error.message}</span>;
return <span>{mollie ? 'Mollie prêt' : 'Indisponible'}</span>;
}createToken() returns a card token intended to be sent to your backend. Keep Mollie API keys and payment creation logic on the server; never expose a secret API key in React/browser code.
- Replace
@exalandapp/react-mollie-componentsinpackage.json, the README and the example with your real npm scope/name. - Replace repository/homepage URLs.
- Install dependencies and build:
npm install
npm run typecheck
npm run build- Authenticate and publish:
npm login
npm publish --access publicThis package targets the Mollie.js v1 API documented with Mollie(profileId), mollie.createComponent(...), and mollie.createToken().
Mollie also has a newer v2 Checkout/Components API in private beta. It is a different API and is intentionally not mixed into this wrapper.