diff --git a/playground/app.vue b/playground/app.vue
index 9fc4dbe..ea4ef5c 100644
--- a/playground/app.vue
+++ b/playground/app.vue
@@ -1,68 +1,3 @@
-
- Nuxt mollie payments components
-
- Credit Card
-
- {
- CreditCardToken = `${token} ✔️`
- CreditCardError = null
- }
- "
- @error="
- (message) => {
- CreditCardError = `${message} ❌`
- }
- "
- />
-
-
-
- Test Credit Number:
-
2223 0000 1047 9399
-
-
-
Error: {{ CreditCardError }}
-
Token: {{ CreditCardToken }}
-
-
- Ideal
-
- {
- IdealError = null
- }
- "
- @save-issuer-error="
- (message) => {
- IdealError = `${message} ❌`
- }
- "
- />
+
-
diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts
index f69c1b6..d80243b 100644
--- a/playground/nuxt.config.ts
+++ b/playground/nuxt.config.ts
@@ -1,4 +1,5 @@
export default defineNuxtConfig({
+ ssr: true,
extends: ['@shopware-pwa/composables-next/nuxt-layer'],
modules: ['../src/module', '@shopware-pwa/nuxt3-module'],
runtimeConfig: {
@@ -10,10 +11,11 @@ export default defineNuxtConfig({
},
},
/* config not needed with mollie > v4.4.0 */
- mollie: {
+ molliePaymentsComponents: {
defaultLocale: 'en_US',
profileId: 'pfl_E5EmGZ98YT',
testMode: true,
+ includeScriptGlobally: false,
},
devtools: { enabled: true },
})
diff --git a/playground/pages/index.vue b/playground/pages/index.vue
new file mode 100644
index 0000000..9fc4dbe
--- /dev/null
+++ b/playground/pages/index.vue
@@ -0,0 +1,68 @@
+
+
+ Nuxt mollie payments components
+
+ Credit Card
+
+ {
+ CreditCardToken = `${token} ✔️`
+ CreditCardError = null
+ }
+ "
+ @error="
+ (message) => {
+ CreditCardError = `${message} ❌`
+ }
+ "
+ />
+
+
+
+ Test Credit Number:
+
2223 0000 1047 9399
+
+
+
Error: {{ CreditCardError }}
+
Token: {{ CreditCardToken }}
+
+
+ Ideal
+
+ {
+ IdealError = null
+ }
+ "
+ @save-issuer-error="
+ (message) => {
+ IdealError = `${message} ❌`
+ }
+ "
+ />
+
+
diff --git a/playground/pages/without.vue b/playground/pages/without.vue
new file mode 100644
index 0000000..fa84479
--- /dev/null
+++ b/playground/pages/without.vue
@@ -0,0 +1,36 @@
+
+
+
+ Load Mollie script lazily
+ On this page the scripts load lazily, if the button is clicked.
+ To test this, the option isIncludedGlobally: false has to be set in nuxt config.
+
+
+
+
+ {
+ CreditCardToken = `${token} ✔️`
+ CreditCardError = null
+ }
+ "
+ @error="
+ (message) => {
+ CreditCardError = `${message} ❌`
+ }
+ "
+ />
+
+
+
+
+
diff --git a/src/runtime/composables/useMollie.ts b/src/runtime/composables/useMollie.ts
index 8eb9af9..79698a9 100644
--- a/src/runtime/composables/useMollie.ts
+++ b/src/runtime/composables/useMollie.ts
@@ -10,7 +10,7 @@ export function useMollie(args: CreateLocaleInstanceArgs = {}) {
async function init() {
// Wait for scripts to be loaded, then initialize the mollie instance.
- await $mollie.scriptLoadedPromise.then(() => {
+ await $mollie.loadMollieScript().then(() => {
$mollie.createMollieInstance(args)
isInitialized.value = true
})
diff --git a/src/runtime/plugins/plugin.client.ts b/src/runtime/plugins/plugin.client.ts
index 542e0ca..2e2783a 100644
--- a/src/runtime/plugins/plugin.client.ts
+++ b/src/runtime/plugins/plugin.client.ts
@@ -23,25 +23,29 @@ export default defineNuxtPlugin({
enforce: 'pre',
async setup(nuxtApp) {
- /*
+ /**
* Register mollie-script client-side for client-side rendering.
* If SSR is used, this will NOT register a second script, because it was already registered server side (see server-plugin)
*/
- const { promise: scriptLoadedPromise, resolve } = getPromiseWithResolvers()
- if (window.Mollie) {
- resolve(true)
- } else {
- useHead({
- script: [
- {
- src: 'https://js.mollie.com/v1/mollie.js',
- defer: true,
- onload() {
- resolve(true)
+ function loadMollieScript() {
+ const { promise, resolve } = getPromiseWithResolvers()
+ if (window.Mollie) {
+ resolve(true)
+ } else {
+ useHead({
+ script: [
+ {
+ src: 'https://js.mollie.com/v1/mollie.js',
+ defer: true,
+ onload() {
+ resolve(true)
+ },
},
- },
- ],
- })
+ ],
+ })
+ }
+
+ return promise
}
const runtimeConfig = useRuntimeConfig()
@@ -77,7 +81,7 @@ export default defineNuxtPlugin({
this.mollieInstance = this.mollieInstance || createLocaleInstance(args)
return this.mollieInstance
},
- scriptLoadedPromise,
+ loadMollieScript,
}
nuxtApp.provide('mollie', Mollie)
diff --git a/src/types.d.ts b/src/types.d.ts
index ac8065d..a8433ba 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -30,7 +30,7 @@ declare global {
export type MolliePlugin = {
mollieInstance: ReturnType | null
createMollieInstance(args: CreateLocaleInstanceArgs): void
- scriptLoadedPromise: Promise
+ loadMollieScript: () => Promise
}
declare module '#app' {
interface NuxtApp {