@paypal/checkout-components 5.0.291 → 5.0.292
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/__sdk__.js +3 -0
- package/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +1 -1
- package/src/api/api.js +54 -0
- package/src/api/shopper-insights/component.jsx +197 -0
- package/src/api/shopper-insights/component.test.js +282 -0
- package/src/api/shopper-insights/interface.js +13 -0
- package/src/api/shopper-insights/validation.js +137 -0
- package/src/api/shopper-insights/validation.test.js +155 -0
- package/src/constants/api.js +29 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import { vi, describe, expect } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { validateMerchantConfig, validateMerchantPayload } from "./validation";
|
|
5
|
+
|
|
6
|
+
vi.mock("@paypal/sdk-client/src", () => {
|
|
7
|
+
return {
|
|
8
|
+
sendCountMetric: vi.fn(),
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe("shopper insights merchant SDK config validation", () => {
|
|
13
|
+
test("should throw if sdk token is not passed", () => {
|
|
14
|
+
expect(() =>
|
|
15
|
+
validateMerchantConfig({
|
|
16
|
+
sdkToken: "",
|
|
17
|
+
pageType: "",
|
|
18
|
+
userIDToken: "",
|
|
19
|
+
clientToken: "",
|
|
20
|
+
})
|
|
21
|
+
).toThrowError(
|
|
22
|
+
"script data attribute sdk-client-token is required but was not passed"
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should throw if page type is not passed", () => {
|
|
27
|
+
expect(() =>
|
|
28
|
+
validateMerchantConfig({
|
|
29
|
+
sdkToken: "sdk-token",
|
|
30
|
+
pageType: "",
|
|
31
|
+
userIDToken: "",
|
|
32
|
+
clientToken: "",
|
|
33
|
+
})
|
|
34
|
+
).toThrowError(
|
|
35
|
+
"script data attribute page-type is required but was not passed"
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("should throw if ID token is passed", () => {
|
|
40
|
+
expect(() =>
|
|
41
|
+
validateMerchantConfig({
|
|
42
|
+
sdkToken: "sdk-token",
|
|
43
|
+
pageType: "product-listing",
|
|
44
|
+
userIDToken: "id-token",
|
|
45
|
+
clientToken: "",
|
|
46
|
+
})
|
|
47
|
+
).toThrowError(
|
|
48
|
+
"use script data attribute sdk-client-token instead of user-id-token"
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("shopper insights merchant payload validation", () => {
|
|
54
|
+
test("should have successful validation if email is only passed", () => {
|
|
55
|
+
expect(() =>
|
|
56
|
+
validateMerchantPayload({
|
|
57
|
+
customer: {
|
|
58
|
+
email: "email@test.com",
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
).not.toThrowError();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("should have successful validation if phone is only passed", () => {
|
|
65
|
+
expect(() =>
|
|
66
|
+
validateMerchantPayload({
|
|
67
|
+
customer: {
|
|
68
|
+
phone: {
|
|
69
|
+
countryCode: "1",
|
|
70
|
+
nationalNumber: "2345678901",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
).not.toThrowError();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("should have successful validation if email and phone is passed", () => {
|
|
78
|
+
expect(() =>
|
|
79
|
+
validateMerchantPayload({
|
|
80
|
+
customer: {
|
|
81
|
+
email: "email@test.com",
|
|
82
|
+
phone: {
|
|
83
|
+
countryCode: "1",
|
|
84
|
+
nationalNumber: "2345678901",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
).not.toThrowError();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("should throw if email or phone is not passed", () => {
|
|
92
|
+
expect(() =>
|
|
93
|
+
validateMerchantPayload({
|
|
94
|
+
customer: {},
|
|
95
|
+
})
|
|
96
|
+
).toThrowError(
|
|
97
|
+
"Expected shopper information to include an email or phone number"
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("should throw if countryCode or nationalNumber in phone is not passed or is empty", () => {
|
|
102
|
+
expect(() =>
|
|
103
|
+
validateMerchantPayload({
|
|
104
|
+
customer: {
|
|
105
|
+
phone: {
|
|
106
|
+
nationalNumber: "",
|
|
107
|
+
countryCode: "",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
).toThrowError(
|
|
112
|
+
"Expected shopper information to include an email or phone number"
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect(() =>
|
|
116
|
+
validateMerchantPayload(
|
|
117
|
+
// $FlowFixMe
|
|
118
|
+
{ customer: { phone: {} } }
|
|
119
|
+
)
|
|
120
|
+
).toThrowError(
|
|
121
|
+
"Expected shopper information to include an email or phone number"
|
|
122
|
+
);
|
|
123
|
+
expect.assertions(2);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("should throw if phone is in an invalid format", () => {
|
|
127
|
+
expect(() =>
|
|
128
|
+
validateMerchantPayload({
|
|
129
|
+
customer: { phone: { countryCode: "1", nationalNumber: "2.354" } },
|
|
130
|
+
})
|
|
131
|
+
).toThrowError(
|
|
132
|
+
"Expected shopper information to a valid phone number format"
|
|
133
|
+
);
|
|
134
|
+
expect(() =>
|
|
135
|
+
validateMerchantPayload({
|
|
136
|
+
customer: { phone: { countryCode: "1", nationalNumber: "2-354" } },
|
|
137
|
+
})
|
|
138
|
+
).toThrowError(
|
|
139
|
+
"Expected shopper information to a valid phone number format"
|
|
140
|
+
);
|
|
141
|
+
expect.assertions(2);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("should throw if email is in an invalid format", () => {
|
|
145
|
+
expect(() =>
|
|
146
|
+
validateMerchantPayload({
|
|
147
|
+
customer: {
|
|
148
|
+
email: "123",
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
).toThrowError(
|
|
152
|
+
"Expected shopper information to include a valid email format"
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
export const HEADERS = {
|
|
4
|
+
AUTHORIZATION: "authorization",
|
|
5
|
+
CONTENT_TYPE: "content-type",
|
|
6
|
+
PARTNER_ATTRIBUTION_ID: "paypal-partner-attribution-id",
|
|
7
|
+
CLIENT_METADATA_ID: "paypal-client-metadata-id",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const ELIGIBLE_PAYMENT_METHODS = "v2/payments/find-eligible-methods";
|
|
11
|
+
|
|
12
|
+
export const FPTI_TRANSITION = {
|
|
13
|
+
SHOPPER_INSIGHTS_API_INIT: "sdk_shopper_insights_recommended_init",
|
|
14
|
+
SHOPPER_INSIGHTS_API_SUCCESS: "sdk_shopper_insights_recommended_success",
|
|
15
|
+
SHOPPER_INSIGHTS_API_ERROR: "sdk_shopper_insights_recommended_error",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const SHOPPER_INSIGHTS_METRIC_NAME =
|
|
19
|
+
"pp.app.paypal_sdk.api.shopper_insights.count";
|
|
20
|
+
|
|
21
|
+
export type MerchantPayloadData = {|
|
|
22
|
+
customer: {|
|
|
23
|
+
email?: string,
|
|
24
|
+
phone?: {|
|
|
25
|
+
countryCode?: string,
|
|
26
|
+
nationalNumber?: string,
|
|
27
|
+
|},
|
|
28
|
+
|},
|
|
29
|
+
|};
|