Skip to content

Commit fe07c6e

Browse files
committed
feat(common): PAYPAL-7 Pass in merchant ID on PayPal button script for PayPal Express Checkout
1 parent de482de commit fe07c6e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/script-loader.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ describe('ScriptLoader', () => {
7676
expect(document.body.appendChild)
7777
.toHaveBeenCalledTimes(1);
7878
});
79+
80+
it('attaches script tag to document with data attributes', async () => {
81+
await loader.loadScript(
82+
'https://code.jquery.com/jquery-3.2.1.min.js',
83+
{'data-attribute1': '1', 'data-attribute2': '2'});
84+
85+
expect(script.attributes.getNamedItem('data-attribute1')!.value)
86+
.toEqual('1');
87+
88+
expect(script.attributes.getNamedItem('data-attribute2')!.value)
89+
.toEqual('2');
90+
});
7991
});
8092

8193
describe('when script fails to load', () => {

src/script-loader.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export interface PreloadScriptOptions {
1010
prefetch: boolean;
1111
}
1212

13+
export interface ScriptAttributes {
14+
[key: string]: string;
15+
}
16+
1317
export default class ScriptLoader {
1418
private _scripts: { [key: string]: Promise<void> } = {};
1519
private _preloadedScripts: { [key: string]: Promise<void> } = {};
@@ -22,12 +26,18 @@ export default class ScriptLoader {
2226
private _requestSender: RequestSender
2327
) {}
2428

25-
loadScript(src: string, options?: LoadScriptOptions): Promise<void> {
29+
loadScript(src: string, options?: LoadScriptOptions, scriptAttributes?: ScriptAttributes): Promise<void> {
2630
if (!this._scripts[src]) {
2731
this._scripts[src] = new Promise((resolve, reject) => {
2832
const script = document.createElement('script') as LegacyHTMLScriptElement;
2933
const { async = false } = options || {};
3034

35+
for (const key in scriptAttributes) {
36+
if (scriptAttributes.hasOwnProperty(key)) {
37+
script.setAttribute(key, scriptAttributes[key]);
38+
}
39+
}
40+
3141
script.onload = () => resolve();
3242
script.onreadystatechange = () => resolve();
3343
script.onerror = event => {

0 commit comments

Comments
 (0)