Skip to content

Commit 3e52b93

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

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
@@ -50,6 +50,18 @@ describe('ScriptLoader', () => {
5050
expect(document.body.appendChild)
5151
.toHaveBeenCalledTimes(1);
5252
});
53+
54+
it('attaches script tag to document with data attributes', async () => {
55+
await loader.loadScript(
56+
'https://code.jquery.com/jquery-3.2.1.min.js',
57+
{'data-attribute1': '1', 'data-attribute2': '2'});
58+
59+
expect(script.attributes.getNamedItem('data-attribute1')!.value)
60+
.toEqual('1');
61+
62+
expect(script.attributes.getNamedItem('data-attribute2')!.value)
63+
.toEqual('2');
64+
});
5365
});
5466

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

src/script-loader.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ export interface PreloadScriptOptions {
22
prefetch: boolean;
33
}
44

5+
export interface ScriptAttributes {
6+
[key: string]: string;
7+
}
8+
59
export default class ScriptLoader {
610
private _scripts: { [key: string]: Promise<Event> } = {};
711
private _preloadedScripts: { [key: string]: Promise<Event> } = {};
812

9-
loadScript(src: string): Promise<Event> {
13+
loadScript(src: string, scriptAttributes?: ScriptAttributes): Promise<Event> {
1014
if (!this._scripts[src]) {
1115
this._scripts[src] = new Promise((resolve, reject) => {
1216
const script = document.createElement('script') as LegacyHTMLScriptElement;
1317

18+
for (const key in scriptAttributes) {
19+
if (scriptAttributes.hasOwnProperty(key)) {
20+
script.setAttribute(key, scriptAttributes[key]);
21+
}
22+
}
23+
1424
script.onload = event => resolve(event);
1525
script.onreadystatechange = event => resolve(event);
1626
script.onerror = event => {

0 commit comments

Comments
 (0)