-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from develodesign/AddJStoHead
Defer beforeRegistration Hook if config value `addPaypalJsToHead` is …
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,35 @@ $ git clone [email protected]:develodesign/vsf-payment-paypal.git ./vue-storefront/ | |
```json | ||
"paypal": { | ||
"clientId": "", | ||
"addJsToGlobalHead": true, | ||
"endpoint": { | ||
"complete": "/api/ext/paypal/complete", | ||
"setExpressCheckout": "/api/ext/paypal/setExpressCheckout" | ||
} | ||
} | ||
``` | ||
|
||
#### Add JS to Head | ||
If you want to defer adding the JS to head globally, you can set `addJsToGlobalHead` to `false` | ||
|
||
This will defer the beforeRegistration hook and then you can add the below into the mounted lifecycle on your checkout component where you will import the Paypal button. | ||
|
||
```js | ||
mounted () { | ||
if (!isServer && window.paypalScriptLoaded === undefined) { | ||
const storeView = currentStoreView() | ||
const { currencyCode } = storeView.i18n | ||
const clientId = config.paypal.hasOwnProperty('clientId') ? config.paypal.clientId : '' | ||
const sdkUrl = `https://www.paypal.com/sdk/js?client-id=${clientId}¤cy=${currencyCode}&disable-funding=card,credit,mybank,sofort` | ||
var script = document.createElement('script') | ||
script.setAttribute('src', sdkUrl) | ||
document.head.appendChild(script) | ||
window.paypalScriptLoaded = true | ||
} | ||
} | ||
|
||
``` | ||
|
||
## Registration the Paypal module | ||
|
||
Let's edit `config/modules.ts` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters