Load and initialize nemuru.js
1. Load the library
The first step is to source the JavaScript library in your web client.
Nemuru distributes the library through a CDN distribution.
Once loaded, all widgets and functionalities are wrapped within the Nemuru
object made available.
In order to load the nemuru.js
library, you should include the following script tag in your html:
<script src="https://cdn.nemuru.com/assets/stg/nemuru.stg.js" async />
<script src="https://cdn.nemuru.com/assets/prod/nemuru.prod.js" async />
2. Initialize the library
In order to initilize the library, it is necessary to call the async method .init()
to identify the merchant and pre-load all the necessary data needed by the widgets and methods.
Additionally, this method allows you to pass down additional configuration parameters (currency, locale, etc). See the table below for more information:
await Nemuru.init({
clientId: "33dc5caf-cf56-4aea-bd85-95ad4997d96b",
configuration: {
currency: "EUR",
locale: "es-ES",
decimalSeparator: ",", // optional
thousandSeparator: ".", // optional
},
onError: (error) => console.log(error),
});
Field | Type | Required | Description | Example |
---|---|---|---|---|
clientId | string | Required | Your merchant ID provided by Nemuru. | "33dc5caf-cf56-4aea-bd85-95ad4997d96b" |
configuration | object | Required | Parameters to configure the library. | |
configuration.currency | string | Required | The currency code (https://en.wikipedia.org/wiki/ISO_4217). Possible values are: EUR . | "EUR" |
configuration.locale | string | Required | The locale defines the language and country used in the widgets/functions. Possible values are: [es-ES , en-US , ca-ES , fr-FR ] (RFC 1766). | "es-ES" |
configuration.decimalSeparator | string | Optional | The type of separator for decimals. Possible values are: [, , . , ]. Default value is , . | "," |
configuration.thousandSeparator | string | Optional | The type of separator for thousands. Possible values are: [, , . , ]. Default value is . . | "." |
onError | function | Optional | This callback fires every time there is an error. For example, the `clientId is not valid. |
Ensure calling the .init()
method is only done once - for example, when the library is completely loaded.
The following JavaScript code snippet serves as an example for loading and initiating the library.
const params = {
scriptUri: "https://cdn.nemuru.com/assets/stg/nemuru.stg.js",
clientId: "33dc5caf-cf56-4aea-bd85-95ad4997d96b",
configuration: {
currency: "EUR",
locale: "es-ES",
},
onError: (error) => console.log({ error }),
};
(function (i, s, o, g, r, a, m) {
let n, t;
let p = false;
n = s.createElement(o);
n.type = "text/javascript";
n.src = g.scriptUri;
n.async = true;
n.onload = n.onreadystatechange = async function () {
if (!p && (!this.readyState || this.readyState == "complete")) {
p = true;
Nemuru.init(g);
}
};
t = s.getElementsByTagName(o)[0];
t.parentNode.insertBefore(n, t);
})(window, document, "script", params);