Mollie object¶
https://js.mollie.com/v1/mollie.js
The Mollie
object in the Mollie JavaScript SDK is used to initialize the Mollie integration.
For a step-by-step tutorial on integrating Mollie Components, refer to the Mollie Components guide.
Mollie(profileId[, options])¶
profileId
stringrequiredpfl_3RkSN1zuPE
.options
options objectoptionalAny options you want to set. E.g. { locale: "nl_NL"}
locale
stringoptionalAllows you to preset the language to be used. When this parameter is not provided, the browser language will be used instead. If we also not support the browser language then it will be shown in English. We recommend you provide the language tag, since this is usually more accurate.
Possible values: en_US
nl_NL
nl_BE
fr_FR
fr_BE
de_DE
de_AT
de_CH
es_ES
ca_ES
pt_PT
it_IT
nb_NO
sv_SE
fi_FI
da_DK
is_IS
hu_HU
pl_PL
lv_LV
lt_LT
testmode
booleanoptionaltrue
to enable test mode. Test tokens will be recognizable by the test
suffix, e.g.
tkn_123abctest.mollie.createToken()¶
Calling the createToken
method will receive a token if successful. This token must then be sent to your back end
where it can be passed as the cardToken
parameter to the
Create payment endpoint.
This method has to be invoked from the submit
event of your checkout form:
Javascript¶
1 2 3 4 5 6 7 | form.addEventListener('submit', e => { e.preventDefault(); mollie.createToken().then(function(result) { // Handle the result this can be either result.token or result.error. }); }); |
ES6¶
1 2 3 4 5 | form.addEventListener('submit', async e => { e.preventDefault(); const { token, error } = await mollie.createToken(); }); |
mollie.createComponent(type[, options])¶
This will create a Component which the shopper uses to enter the card holder data. After creating, the components should be mounted in your checkout.
Refer to Component object to see which methods are available on the object.
For a credit card integration you need to create four components — one for each card holder data field.
type
stringrequiredThe createComponent
method will create an component ready to be mounted.
Possible values: "card"
| "cardHolder"
"cardNumber"
"verificationCode"
"expiryDate"
Note
Value "card"
can not be used together with other ones (because it already contain all of the others).
For more info, see Mollie Components.
options
options objectoptionalThe options you want to give to Mollie Components.
styles
styles objectoptionalcomponents
components objectoptionalOnly available for "card"
type. Allows you to customize individual
Components inside the card component.
cardHolder
individualComponent objectoptionalAllows you to customize card holder component inside the card component.
label
stringoptionalcardNumber
individualComponent objectoptionalAllows you to customize card number component inside the card component.
label
stringoptionalverificationCode
individualComponent objectoptionalAllows you to customize verification code component inside the card component.
label
stringoptionalexpiryDate
individualComponent objectoptionalAllows you to customize expiration date component inside the card component.
label
stringoptionalExample for cardHolder
component¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | var options = { styles: { base: { color: '#eee', fontSize: '10px', '::placeholder': { color: 'rgba(68, 68, 68, 0.2)', } } } } var cardNumberEl = mollie.createComponent('cardNumber', options) |
Example for card
component¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | var options = { styles: { base: { color: '#eee', fontSize: '10px', '::placeholder': { color: 'rgba(68, 68, 68, 0.2)', } } }, components: { cardHolder: { label: 'Custom card holder label' }, verificationCode: { label: 'Custom verification code label' } } } var cardNumberEl = mollie.createComponent('cardNumber', options) |