Skip to content

Commit 77b4e4c

Browse files
committed
feat: camelCase instead of kebab-case for params
BREAKING CHANGE: this is a breaking change for the TypeScript types.
1 parent ec977f1 commit 77b4e4c

13 files changed

+116
-116
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { loadScript } from "@paypal/paypal-js";
6464
let paypal;
6565

6666
try {
67-
paypal = await loadScript({ "client-id": "test" });
67+
paypal = await loadScript({ clientId: "test" });
6868
} catch (error) {
6969
console.error("failed to load the PayPal JS SDK script", error);
7070
}
@@ -83,7 +83,7 @@ if (paypal) {
8383
```js
8484
import { loadScript } from "@paypal/paypal-js";
8585

86-
loadScript({ "client-id": "test" })
86+
loadScript({ clientId: "test" })
8787
.then((paypal) => {
8888
paypal
8989
.Buttons()
@@ -99,14 +99,14 @@ loadScript({ "client-id": "test" })
9999

100100
### Passing Arguments
101101

102-
The `loadScript` function accepts an object for configuring the JS SDK. It's used for setting query parameters and script attributes.
102+
The `loadScript` function accepts an object for configuring the JS SDK. It's used for setting query parameters and script attributes. It accepts parameters in camelCase or kebab-case.
103103

104104
#### Query Parameters
105105

106106
The following example adds `client-id` and `currency` as query string parameters:
107107

108108
```js
109-
loadScript({ "client-id": "YOUR_CLIENT_ID", currency: "EUR" });
109+
loadScript({ clientId: "YOUR_CLIENT_ID", currency: "EUR" });
110110
```
111111

112112
Which will load the following `<script>` asynchronously:
@@ -119,7 +119,7 @@ By default, the JS SDK only loads the buttons component. The `components` query
119119

120120
```js
121121
loadScript({
122-
"client-id": "YOUR_CLIENT_ID",
122+
clientId: "YOUR_CLIENT_ID",
123123
components: "buttons,marks,messages",
124124
});
125125
```
@@ -134,12 +134,12 @@ View the [full list of supported query parameters](https://developer.paypal.com/
134134

135135
#### Data Attributes
136136

137-
All options prefixed with `data-` are considered attributes. The following example adds `data-page-type` as an attribute:
137+
All options prefixed with `data` are considered attributes. The following example adds `data-page-type` as an attribute:
138138

139139
```js
140140
loadScript({
141-
"client-id": "YOUR_CLIENT_ID",
142-
"data-page-type": "checkout",
141+
clientId: "YOUR_CLIENT_ID",
142+
dataPageType: "checkout",
143143
});
144144
```
145145

@@ -154,16 +154,16 @@ Which will load the following `<script>` asynchronously:
154154

155155
View the [full list of supported script parameters](https://developer.paypal.com/sdk/js/configuration/#link-scriptparameters).
156156

157-
#### Merchant ID Array
157+
#### Merchant Id Array
158158

159-
The `merchant-id` option accepts an array to simplify the implementation for Multi-Seller Payments. With this approach the caller doesn't have to worry about managing the two different merchant id values (`data-merchant-id` and `merchant-id`).
159+
The `merchantId` option accepts an array to simplify the implementation for Multi-Seller Payments. With this approach the caller doesn't have to worry about managing the two different merchant id values (`data-merchant-id` and `merchant-id`).
160160

161-
**Here's an example with multiple `merchant-id` values:**
161+
**Here's an example with multiple `merchantId` values:**
162162

163163
```js
164164
loadScript({
165-
"client-id": "YOUR_CLIENT_ID",
166-
"merchant-id": ["123", "456", "789"],
165+
clientId: "YOUR_CLIENT_ID",
166+
merchantId: ["123", "456", "789"],
167167
});
168168
```
169169

@@ -180,8 +180,8 @@ Which will load the following `<script>` and use `merchant-id=*` to properly con
180180

181181
```js
182182
loadScript({
183-
"client-id": "YOUR_CLIENT_ID",
184-
"merchant-id": ["123"],
183+
clientId: "YOUR_CLIENT_ID",
184+
merchantId: ["123"],
185185
});
186186
```
187187

@@ -191,14 +191,14 @@ When there's only one, the merchant-id is passed in using the query string.
191191
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&merchant-id=123"></script>
192192
```
193193

194-
#### sdkBaseURL
194+
#### sdkBaseUrl
195195

196-
For local development, the `sdkBaseURL` option can be used to set the base url of the JS SDK:
196+
For local development, the `sdkBaseUrl` option can be used to set the base url of the JS SDK:
197197

198198
```js
199199
loadScript({
200-
"client-id": "YOUR_CLIENT_ID",
201-
sdkBaseURL: "http://localhost.paypal.com:8000/sdk/js",
200+
clientId: "YOUR_CLIENT_ID",
201+
sdkBaseUrl: "http://localhost.paypal.com:8000/sdk/js",
202202
});
203203
```
204204

@@ -237,7 +237,7 @@ The paypal-js script is also available on the [unpkg CDN](https://unpkg.com/). T
237237
<body>
238238
<div id="paypal-buttons"></div>
239239
<script>
240-
window.paypalLoadScript({ "client-id": "test" }).then((paypal) => {
240+
window.paypalLoadScript({ clientId: "test" }).then((paypal) => {
241241
paypal.Buttons().render("#paypal-buttons");
242242
});
243243
</script>

e2e-tests/browser-global.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ <h1>Demo with window.paypalLoadScript</h1>
1010
<script src="../../dist/iife/paypal-js.min.js"></script>
1111
<script>
1212
var options = {
13-
"client-id": "test",
14-
"data-page-type": "checkout",
13+
clientId: "test",
14+
dataPageType: "checkout",
1515
};
1616

1717
window.paypalLoadScript(options).then(function (paypal) {

e2e-tests/load-cached-script.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ <h1>Load Cached Script</h1>
1111
import { loadScript } from "../../dist/esm/paypal-js.js";
1212

1313
const options = {
14-
"client-id": "test",
15-
"data-page-type": "checkout",
14+
clientId: "test",
15+
dataPageType: "checkout",
1616
};
1717

1818
// initial load and render

e2e-tests/reload-script.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ <h1>Reload Script Demo</h1>
1111
import { loadScript } from "../../dist/esm/paypal-js.js";
1212

1313
const options = {
14-
"client-id": "test",
15-
"data-page-type": "checkout",
14+
clientId: "test",
15+
dataPageType: "checkout",
1616
currency: document.querySelector("#currency").value,
1717
};
1818

e2e-tests/validation-errors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>Validation Errors</h1>
3434
.addEventListener("click", () => {
3535
// Error: client-id not recognized for either production or sandbox: invalid-client-id-value
3636
loadScript({
37-
"client-id": "invalid-client-id-value",
37+
clientId: "invalid-client-id-value",
3838
}).catch((err) => setErrorMessage(err));
3939
});
4040
</script>

src/load-script.node.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { loadScript, loadCustomScript } from "./load-script";
66

77
test("should still resolve when global window object does not exist", async () => {
8-
await expect(loadScript({ "client-id": "test" })).resolves.toBeNull();
8+
await expect(loadScript({ clientId: "test" })).resolves.toBeNull();
99
await expect(
1010
loadCustomScript({ url: "https://www.example.com/index.js" })
1111
).resolves.toBeUndefined();

src/load-script.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("loadScript()", () => {
3434
test("should insert <script> and resolve the promise", async () => {
3535
expect(window.paypal).toBe(undefined);
3636

37-
const response = await loadScript({ "client-id": "test" });
37+
const response = await loadScript({ clientId: "test" });
3838
expect(insertScriptElementSpy).toHaveBeenCalledTimes(1);
3939
expect(response).toEqual(window.paypal);
4040
});
@@ -47,7 +47,7 @@ describe("loadScript()", () => {
4747
'<script src="https://www.paypal.com/sdk/js?client-id=test"></script>';
4848
window.paypal = paypalNamespace;
4949

50-
const response = await loadScript({ "client-id": "test" });
50+
const response = await loadScript({ clientId: "test" });
5151
expect(insertScriptElementSpy).not.toHaveBeenCalled();
5252
expect(response).toEqual(window.paypal);
5353
});
@@ -59,8 +59,8 @@ describe("loadScript()", () => {
5959
expect(windowObject.paypal2).toBe(undefined);
6060

6161
const response = await Promise.all([
62-
loadScript({ "client-id": "test", "data-namespace": "paypal1" }),
63-
loadScript({ "client-id": "test", "data-namespace": "paypal2" }),
62+
loadScript({ clientId: "test", dataNamespace: "paypal1" }),
63+
loadScript({ clientId: "test", dataNamespace: "paypal2" }),
6464
]);
6565

6666
expect(insertScriptElementSpy).toHaveBeenCalledTimes(2);
@@ -78,7 +78,7 @@ describe("loadScript()", () => {
7878
expect(window.paypal).toBe(undefined);
7979

8080
try {
81-
await loadScript({ "client-id": "test" });
81+
await loadScript({ clientId: "test" });
8282
} catch (err) {
8383
expect(insertScriptElementSpy).toHaveBeenCalledTimes(1);
8484
const { message: errorMessage } = err as Record<string, string>;

src/utils.test.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ describe("objectToQueryString()", () => {
2121
describe("processOptions()", () => {
2222
test("returns dataAttributes and url", () => {
2323
const options = {
24-
"client-id": "test",
24+
clientId: "test",
2525
currency: "USD",
26-
"data-page-type": "checkout",
27-
"some-random-key": "some-random-value",
26+
dataPageType: "checkout",
27+
someRandomKey: "some-random-value",
2828
};
2929

3030
const { url, dataAttributes } = processOptions(options);
@@ -37,8 +37,8 @@ describe("processOptions()", () => {
3737

3838
test("sets a custom base url", () => {
3939
const { url } = processOptions({
40-
"client-id": "test",
41-
sdkBaseURL: "http://localhost.paypal.com:8000/sdk/js",
40+
clientId: "test",
41+
sdkBaseUrl: "http://localhost.paypal.com:8000/sdk/js",
4242
});
4343

4444
expect(url).toBe(
@@ -47,16 +47,16 @@ describe("processOptions()", () => {
4747
});
4848

4949
test("default values when only client-id is passed in", () => {
50-
const { url, dataAttributes } = processOptions({ "client-id": "test" });
50+
const { url, dataAttributes } = processOptions({ clientId: "test" });
5151

5252
expect(url).toBe("https://www.paypal.com/sdk/js?client-id=test");
5353
expect(dataAttributes).toEqual({});
5454
});
5555

5656
test("supports passing an array of merchant ids", () => {
5757
const { url, dataAttributes } = processOptions({
58-
"client-id": "test",
59-
"merchant-id": ["123", "456", "789"],
58+
clientId: "test",
59+
merchantId: ["123", "456", "789"],
6060
});
6161

6262
expect(url).toBe(
@@ -67,8 +67,8 @@ describe("processOptions()", () => {
6767

6868
test("supports passing a single merchant id", () => {
6969
const { url, dataAttributes } = processOptions({
70-
"client-id": "test",
71-
"merchant-id": "123",
70+
clientId: "test",
71+
merchantId: "123",
7272
});
7373

7474
expect(url).toBe(
@@ -77,8 +77,8 @@ describe("processOptions()", () => {
7777
expect(dataAttributes).toEqual({});
7878

7979
const { url: url2, dataAttributes: dataAttributes2 } = processOptions({
80-
"client-id": "test",
81-
"merchant-id": ["123"],
80+
clientId: "test",
81+
merchantId: ["123"],
8282
});
8383

8484
expect(url2).toBe(
@@ -87,16 +87,27 @@ describe("processOptions()", () => {
8787
expect(dataAttributes2).toEqual({});
8888
});
8989

90-
test("falls back to data-merchant-id when merchant-id is not set", () => {
90+
test("supports passing options in kebab-case or camelCase format", () => {
9191
const { url, dataAttributes } = processOptions({
92+
// @ts-expect-error ignore invalid arguments error
9293
"client-id": "test",
93-
"data-merchant-id": "123,456,789",
94+
"merchant-id": ["123", "456", "789"],
9495
});
9596

9697
expect(url).toBe(
9798
"https://www.paypal.com/sdk/js?client-id=test&merchant-id=*"
9899
);
99100
expect(dataAttributes).toEqual({ "data-merchant-id": "123,456,789" });
101+
102+
const { url: url2, dataAttributes: dataAttributes2 } = processOptions({
103+
clientId: "test",
104+
merchantId: ["123", "456", "789"],
105+
});
106+
107+
expect(url2).toBe(
108+
"https://www.paypal.com/sdk/js?client-id=test&merchant-id=*"
109+
);
110+
expect(dataAttributes2).toEqual({ "data-merchant-id": "123,456,789" });
100111
});
101112
});
102113

0 commit comments

Comments
 (0)