@paypal/checkout-components 5.0.389 → 5.0.391
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +1 -1
- package/src/funding/credit/config.jsx +1 -0
- package/src/funding/funding.js +9 -0
- package/src/hosted-buttons/index.js +8 -6
- package/src/hosted-buttons/types.js +1 -1
- package/src/hosted-buttons/utils.js +11 -22
- package/src/hosted-buttons/utils.test.js +0 -30
- package/src/types.js +1 -0
package/package.json
CHANGED
package/src/funding/funding.js
CHANGED
|
@@ -89,6 +89,15 @@ export function isFundingEligible(
|
|
|
89
89
|
userAgent,
|
|
90
90
|
}: IsFundingEligibleOptions
|
|
91
91
|
): boolean {
|
|
92
|
+
// Temporary: Force credit to be eligible if the experiment is enabled
|
|
93
|
+
if (
|
|
94
|
+
source === FUNDING.CREDIT &&
|
|
95
|
+
experiment?.paypalCreditButtonCreateVaultSetupTokenExists &&
|
|
96
|
+
flow === BUTTON_FLOW.VAULT_WITHOUT_PURCHASE
|
|
97
|
+
) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
92
101
|
if (!fundingEligibility[source] || !fundingEligibility[source].eligible) {
|
|
93
102
|
return false;
|
|
94
103
|
}
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
renderDefaultButton,
|
|
15
15
|
renderForm,
|
|
16
16
|
renderStandaloneButton,
|
|
17
|
-
getTrackingId,
|
|
18
17
|
} from "./utils";
|
|
19
18
|
import type {
|
|
20
19
|
HostedButtonsComponent,
|
|
@@ -50,34 +49,37 @@ export const getHostedButtonsComponent = (): HostedButtonsComponent => {
|
|
|
50
49
|
selector,
|
|
51
50
|
});
|
|
52
51
|
|
|
53
|
-
const
|
|
52
|
+
const fptiTrackingParams =
|
|
53
|
+
window[
|
|
54
|
+
`__pp_form_fields_${hostedButtonId}`
|
|
55
|
+
]?.getFptiTrackingParams?.() || {};
|
|
54
56
|
|
|
55
57
|
const createOrder = buildHostedButtonCreateOrder({
|
|
56
58
|
enableDPoP,
|
|
57
59
|
hostedButtonId,
|
|
58
60
|
merchantId,
|
|
59
|
-
|
|
61
|
+
fptiTrackingParams,
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
const onApprove = buildHostedButtonOnApprove({
|
|
63
65
|
enableDPoP,
|
|
64
66
|
hostedButtonId,
|
|
65
67
|
merchantId,
|
|
66
|
-
|
|
68
|
+
fptiTrackingParams,
|
|
67
69
|
});
|
|
68
70
|
|
|
69
71
|
const onShippingAddressChange = buildHostedButtonOnShippingAddressChange({
|
|
70
72
|
enableDPoP,
|
|
71
73
|
hostedButtonId,
|
|
72
74
|
shouldIncludeShippingCallbacks,
|
|
73
|
-
|
|
75
|
+
fptiTrackingParams,
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
const onShippingOptionsChange = buildHostedButtonOnShippingOptionsChange({
|
|
77
79
|
enableDPoP,
|
|
78
80
|
hostedButtonId,
|
|
79
81
|
shouldIncludeShippingCallbacks,
|
|
80
|
-
|
|
82
|
+
fptiTrackingParams,
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
const buttonOptions: HostedButtonOptions = {
|
|
@@ -133,7 +133,7 @@ export type GetCallbackProps = {|
|
|
|
133
133
|
hostedButtonId: string,
|
|
134
134
|
merchantId?: string,
|
|
135
135
|
shouldIncludeShippingCallbacks?: boolean,
|
|
136
|
-
|
|
136
|
+
fptiTrackingParams?: { [key: string]: mixed },
|
|
137
137
|
|};
|
|
138
138
|
|
|
139
139
|
export type HostedButtonsInstance = {|
|
|
@@ -225,18 +225,6 @@ export function getElementFromSelector(
|
|
|
225
225
|
: selector;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
export function getTrackingId(
|
|
229
|
-
HostedButtonSelector: string | HTMLElement
|
|
230
|
-
): string {
|
|
231
|
-
if (typeof HostedButtonSelector !== "string") {
|
|
232
|
-
return "";
|
|
233
|
-
}
|
|
234
|
-
const ele = document.querySelector(
|
|
235
|
-
`${HostedButtonSelector} input[name="uuid"]`
|
|
236
|
-
);
|
|
237
|
-
return ele ? ele.getAttribute("value") || "" : "";
|
|
238
|
-
}
|
|
239
|
-
|
|
240
228
|
/**
|
|
241
229
|
* Attaches form fields (html) to the given selector, and
|
|
242
230
|
* initializes window.__pp_form_fields (htmlScript).
|
|
@@ -269,7 +257,7 @@ export const buildHostedButtonCreateOrder = ({
|
|
|
269
257
|
enableDPoP,
|
|
270
258
|
hostedButtonId,
|
|
271
259
|
merchantId,
|
|
272
|
-
|
|
260
|
+
fptiTrackingParams,
|
|
273
261
|
}: GetCallbackProps): CreateOrder => {
|
|
274
262
|
return async (data) => {
|
|
275
263
|
const userInputs =
|
|
@@ -280,7 +268,7 @@ export const buildHostedButtonCreateOrder = ({
|
|
|
280
268
|
const url = `${apiUrl}/v1/checkout/links/${hostedButtonId}/create-context`;
|
|
281
269
|
const method = "POST";
|
|
282
270
|
const headers = await buildRequestHeaders({ url, method, enableDPoP });
|
|
283
|
-
|
|
271
|
+
const funding_source = data.paymentSource.toUpperCase();
|
|
284
272
|
const response = await request({
|
|
285
273
|
url,
|
|
286
274
|
// $FlowIssue optional properties are not compatible with [key: string]: string
|
|
@@ -288,7 +276,7 @@ export const buildHostedButtonCreateOrder = ({
|
|
|
288
276
|
method,
|
|
289
277
|
body: JSON.stringify({
|
|
290
278
|
entry_point: entryPoint,
|
|
291
|
-
funding_source
|
|
279
|
+
funding_source,
|
|
292
280
|
merchant_id: merchantId,
|
|
293
281
|
...userInputs,
|
|
294
282
|
}),
|
|
@@ -297,9 +285,10 @@ export const buildHostedButtonCreateOrder = ({
|
|
|
297
285
|
const { body } = response;
|
|
298
286
|
getLogger()
|
|
299
287
|
.track({
|
|
288
|
+
...fptiTrackingParams,
|
|
300
289
|
[FPTI_KEY.CONTEXT_ID]: body.context_id,
|
|
301
290
|
[FPTI_KEY.EVENT_NAME]: "ncps_create_order",
|
|
302
|
-
|
|
291
|
+
funding_type: funding_source,
|
|
303
292
|
})
|
|
304
293
|
.flush();
|
|
305
294
|
return body.context_id || onError(body.details?.[0]?.issue || body.name);
|
|
@@ -313,7 +302,7 @@ export const buildHostedButtonOnApprove = ({
|
|
|
313
302
|
enableDPoP,
|
|
314
303
|
hostedButtonId,
|
|
315
304
|
merchantId,
|
|
316
|
-
|
|
305
|
+
fptiTrackingParams,
|
|
317
306
|
}: GetCallbackProps): OnApprove => {
|
|
318
307
|
return async (data) => {
|
|
319
308
|
const url = `${apiUrl}/v1/checkout/links/${hostedButtonId}/pay`;
|
|
@@ -333,9 +322,9 @@ export const buildHostedButtonOnApprove = ({
|
|
|
333
322
|
}).then((response) => {
|
|
334
323
|
getLogger()
|
|
335
324
|
.track({
|
|
325
|
+
...fptiTrackingParams,
|
|
336
326
|
[FPTI_KEY.CONTEXT_ID]: data.orderID,
|
|
337
327
|
[FPTI_KEY.EVENT_NAME]: "ncps_onapprove_order",
|
|
338
|
-
tracking_id: trackingId,
|
|
339
328
|
})
|
|
340
329
|
.flush();
|
|
341
330
|
|
|
@@ -359,7 +348,7 @@ export const buildHostedButtonOnShippingAddressChange = ({
|
|
|
359
348
|
enableDPoP,
|
|
360
349
|
hostedButtonId,
|
|
361
350
|
shouldIncludeShippingCallbacks,
|
|
362
|
-
|
|
351
|
+
fptiTrackingParams,
|
|
363
352
|
}: GetCallbackProps): OnShippingAddressChange | typeof undefined => {
|
|
364
353
|
if (shouldIncludeShippingCallbacks) {
|
|
365
354
|
return async (data, actions) => {
|
|
@@ -398,9 +387,9 @@ export const buildHostedButtonOnShippingAddressChange = ({
|
|
|
398
387
|
|
|
399
388
|
getLogger()
|
|
400
389
|
.track({
|
|
390
|
+
...fptiTrackingParams,
|
|
401
391
|
[FPTI_KEY.CONTEXT_ID]: orderID,
|
|
402
392
|
[FPTI_KEY.EVENT_NAME]: "ncps_shipping_address_change",
|
|
403
|
-
tracking_id: trackingId,
|
|
404
393
|
})
|
|
405
394
|
.flush();
|
|
406
395
|
};
|
|
@@ -411,7 +400,7 @@ export const buildHostedButtonOnShippingOptionsChange = ({
|
|
|
411
400
|
enableDPoP,
|
|
412
401
|
hostedButtonId,
|
|
413
402
|
shouldIncludeShippingCallbacks,
|
|
414
|
-
|
|
403
|
+
fptiTrackingParams,
|
|
415
404
|
}: GetCallbackProps): OnShippingOptionsChange | typeof undefined => {
|
|
416
405
|
if (shouldIncludeShippingCallbacks) {
|
|
417
406
|
return async (data, actions) => {
|
|
@@ -439,9 +428,9 @@ export const buildHostedButtonOnShippingOptionsChange = ({
|
|
|
439
428
|
|
|
440
429
|
getLogger()
|
|
441
430
|
.track({
|
|
431
|
+
...fptiTrackingParams,
|
|
442
432
|
[FPTI_KEY.CONTEXT_ID]: orderID,
|
|
443
433
|
[FPTI_KEY.EVENT_NAME]: "ncps_shipping_options_change",
|
|
444
|
-
tracking_id: trackingId,
|
|
445
434
|
})
|
|
446
435
|
.flush();
|
|
447
436
|
};
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
renderStandaloneButton,
|
|
22
22
|
applyContainerStyles,
|
|
23
23
|
renderDefaultButton,
|
|
24
|
-
getTrackingId,
|
|
25
24
|
} from "./utils";
|
|
26
25
|
|
|
27
26
|
vi.mock("@krakenjs/belter/src", async () => {
|
|
@@ -914,35 +913,6 @@ test("getElementFromSelector", () => {
|
|
|
914
913
|
expect(mockQuerySelector).toHaveBeenCalledWith(containerId);
|
|
915
914
|
});
|
|
916
915
|
|
|
917
|
-
describe("getTrackingId", () => {
|
|
918
|
-
const containerId = "#container-id";
|
|
919
|
-
|
|
920
|
-
test("returns uuid value when input element exists and has a value", () => {
|
|
921
|
-
const inputElement = document.createElement("input");
|
|
922
|
-
inputElement.setAttribute("name", "uuid");
|
|
923
|
-
inputElement.setAttribute("value", "test-uuid-123");
|
|
924
|
-
|
|
925
|
-
const containerElement = document.createElement("div");
|
|
926
|
-
containerElement.appendChild(inputElement);
|
|
927
|
-
|
|
928
|
-
vi.spyOn(document, "querySelector").mockImplementationOnce(
|
|
929
|
-
() => inputElement
|
|
930
|
-
);
|
|
931
|
-
|
|
932
|
-
const result = getTrackingId(containerId);
|
|
933
|
-
|
|
934
|
-
expect(result).toBe("test-uuid-123");
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
test("returns empty string when input element doesn't exist", () => {
|
|
938
|
-
vi.spyOn(document, "querySelector").mockImplementationOnce(() => null);
|
|
939
|
-
|
|
940
|
-
const result = getTrackingId(containerId);
|
|
941
|
-
|
|
942
|
-
expect(result).toBe("");
|
|
943
|
-
});
|
|
944
|
-
});
|
|
945
|
-
|
|
946
916
|
describe("getButtonPreferences", () => {
|
|
947
917
|
test("returns all button preferences if all are eligible", () => {
|
|
948
918
|
const params = {
|
package/src/types.js
CHANGED