@paypal/checkout-components 5.0.297-alpha.0 → 5.0.298
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/README.md +4 -0
- package/__sdk__.js +4 -4
- package/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +4 -5
- package/src/api/shopper-insights/validation.js +8 -7
- package/src/api/shopper-insights/validation.test.js +3 -1
- package/src/connect/component.jsx +28 -32
- package/src/connect/component.test.js +36 -29
- package/src/connect/interface.js +16 -9
- package/src/constants/api.js +1 -2
- package/src/constants/button.js +1 -0
- package/src/constants/class.js +1 -0
- package/src/funding/common.jsx +1 -1
- package/src/interface/hosted-buttons.js +1 -7
- package/src/ui/buttons/button.jsx +7 -3
- package/src/ui/buttons/props.js +19 -0
- package/src/ui/buttons/style.jsx +7 -2
- package/src/ui/buttons/styles/base.js +3 -0
- package/src/ui/buttons/styles/responsive.js +35 -5
- package/src/ui/buttons/util.js +5 -0
- package/src/zoid/buttons/component.jsx +385 -375
- package/src/api/api.js +0 -67
- package/src/api/shopper-insights/component.js +0 -203
- package/src/api/shopper-insights/component.test.js +0 -343
- package/src/api/shopper-insights/interface.js +0 -12
- package/src/connect/interface.test.js +0 -24
- package/src/connect/sendCountMetric.js +0 -25
package/src/api/api.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { getPartnerAttributionID, getSessionID } from "@paypal/sdk-client/src";
|
|
4
|
-
import { inlineMemoize, request } from "@krakenjs/belter/src";
|
|
5
|
-
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
|
|
6
|
-
|
|
7
|
-
import { HEADERS } from "../constants/api";
|
|
8
|
-
|
|
9
|
-
type RestAPIParams = {|
|
|
10
|
-
method?: string,
|
|
11
|
-
url: string,
|
|
12
|
-
data: Object,
|
|
13
|
-
accessToken: ?string,
|
|
14
|
-
|};
|
|
15
|
-
|
|
16
|
-
export function callRestAPI({
|
|
17
|
-
accessToken,
|
|
18
|
-
method,
|
|
19
|
-
url,
|
|
20
|
-
data,
|
|
21
|
-
}: RestAPIParams): ZalgoPromise<Object> {
|
|
22
|
-
const partnerAttributionID = getPartnerAttributionID() || "";
|
|
23
|
-
|
|
24
|
-
if (!accessToken) {
|
|
25
|
-
throw new Error(`No access token passed to API request ${url}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const requestHeaders = {
|
|
29
|
-
[HEADERS.AUTHORIZATION]: `Bearer ${accessToken}`,
|
|
30
|
-
[HEADERS.CONTENT_TYPE]: `application/json`,
|
|
31
|
-
[HEADERS.PARTNER_ATTRIBUTION_ID]: partnerAttributionID,
|
|
32
|
-
[HEADERS.CLIENT_METADATA_ID]: getSessionID(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return request({
|
|
36
|
-
method,
|
|
37
|
-
url,
|
|
38
|
-
headers: requestHeaders,
|
|
39
|
-
json: data,
|
|
40
|
-
}).then(({ status, body, headers: responseHeaders }) => {
|
|
41
|
-
if (status >= 300) {
|
|
42
|
-
const error = new Error(
|
|
43
|
-
`${url} returned status ${status}\n\n${JSON.stringify(body)}`
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// $FlowFixMe
|
|
47
|
-
error.response = { status, headers: responseHeaders, body };
|
|
48
|
-
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return body;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function callMemoizedRestAPI({
|
|
57
|
-
accessToken,
|
|
58
|
-
method,
|
|
59
|
-
url,
|
|
60
|
-
data,
|
|
61
|
-
}: RestAPIParams): ZalgoPromise<Object> {
|
|
62
|
-
return inlineMemoize(
|
|
63
|
-
callMemoizedRestAPI,
|
|
64
|
-
() => callRestAPI({ accessToken, method, url, data }),
|
|
65
|
-
[accessToken, method, url, JSON.stringify(data)]
|
|
66
|
-
);
|
|
67
|
-
}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getUserIDToken,
|
|
5
|
-
getPageType,
|
|
6
|
-
getClientToken,
|
|
7
|
-
getSDKToken,
|
|
8
|
-
getLogger,
|
|
9
|
-
getPayPalAPIDomain,
|
|
10
|
-
getCurrency,
|
|
11
|
-
getBuyerCountry,
|
|
12
|
-
getEnv,
|
|
13
|
-
getSessionState,
|
|
14
|
-
sendCountMetric,
|
|
15
|
-
} from "@paypal/sdk-client/src";
|
|
16
|
-
import { FPTI_KEY } from "@paypal/sdk-constants/src";
|
|
17
|
-
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
|
|
18
|
-
import { stringifyError } from "@krakenjs/belter/src";
|
|
19
|
-
|
|
20
|
-
import { callMemoizedRestAPI } from "../api";
|
|
21
|
-
import {
|
|
22
|
-
ELIGIBLE_PAYMENT_METHODS,
|
|
23
|
-
FPTI_TRANSITION,
|
|
24
|
-
SHOPPER_INSIGHTS_METRIC_NAME,
|
|
25
|
-
type MerchantPayloadData,
|
|
26
|
-
} from "../../constants/api";
|
|
27
|
-
|
|
28
|
-
import {
|
|
29
|
-
validateMerchantConfig,
|
|
30
|
-
validateMerchantPayload,
|
|
31
|
-
hasEmail,
|
|
32
|
-
hasPhoneNumber,
|
|
33
|
-
} from "./validation";
|
|
34
|
-
|
|
35
|
-
type RecommendedPaymentMethods = {|
|
|
36
|
-
isPayPalRecommended: boolean,
|
|
37
|
-
isVenmoRecommended: boolean,
|
|
38
|
-
|};
|
|
39
|
-
|
|
40
|
-
type getRecommendedPaymentMethodsRequestPayload = {|
|
|
41
|
-
customer: {|
|
|
42
|
-
country_code?: string,
|
|
43
|
-
email?: string,
|
|
44
|
-
phone?: {|
|
|
45
|
-
country_code: string,
|
|
46
|
-
national_number: string,
|
|
47
|
-
|},
|
|
48
|
-
|},
|
|
49
|
-
purchase_units: $ReadOnlyArray<{|
|
|
50
|
-
amount: {|
|
|
51
|
-
currency_code: string,
|
|
52
|
-
|},
|
|
53
|
-
|}>,
|
|
54
|
-
preferences: {|
|
|
55
|
-
include_account_details: boolean,
|
|
56
|
-
|},
|
|
57
|
-
|};
|
|
58
|
-
|
|
59
|
-
export type ShopperInsightsComponent = {|
|
|
60
|
-
getRecommendedPaymentMethods: (MerchantPayloadData) => ZalgoPromise<RecommendedPaymentMethods>,
|
|
61
|
-
|};
|
|
62
|
-
|
|
63
|
-
function createRecommendedPaymentMethodsRequestPayload(
|
|
64
|
-
merchantPayload: MerchantPayloadData
|
|
65
|
-
): getRecommendedPaymentMethodsRequestPayload {
|
|
66
|
-
const isNonProdEnvironment = getEnv() !== "production";
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
customer: {
|
|
70
|
-
...(isNonProdEnvironment && {
|
|
71
|
-
country_code: getBuyerCountry() || "US",
|
|
72
|
-
}),
|
|
73
|
-
// $FlowIssue
|
|
74
|
-
...(hasEmail(merchantPayload) && {
|
|
75
|
-
email: merchantPayload?.email,
|
|
76
|
-
}),
|
|
77
|
-
...(hasPhoneNumber(merchantPayload) && {
|
|
78
|
-
phone: {
|
|
79
|
-
country_code: merchantPayload?.phone?.countryCode,
|
|
80
|
-
national_number: merchantPayload?.phone?.nationalNumber,
|
|
81
|
-
},
|
|
82
|
-
}),
|
|
83
|
-
},
|
|
84
|
-
purchase_units: [
|
|
85
|
-
{
|
|
86
|
-
amount: {
|
|
87
|
-
currency_code: getCurrency(),
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
// getRecommendedPaymentMethods maps to include_account_details in the API
|
|
92
|
-
preferences: {
|
|
93
|
-
include_account_details: true,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function setShopperInsightsUsage() {
|
|
99
|
-
getSessionState((state) => {
|
|
100
|
-
return {
|
|
101
|
-
...state,
|
|
102
|
-
shopperInsights: {
|
|
103
|
-
getRecommendedPaymentMethodsUsed: true,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function getShopperInsightsComponent(): ShopperInsightsComponent {
|
|
110
|
-
const startTime = Date.now();
|
|
111
|
-
|
|
112
|
-
sendCountMetric({
|
|
113
|
-
name: SHOPPER_INSIGHTS_METRIC_NAME,
|
|
114
|
-
event: "init",
|
|
115
|
-
dimensions: {},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const sdkToken = getSDKToken();
|
|
119
|
-
const pageType = getPageType();
|
|
120
|
-
const clientToken = getClientToken();
|
|
121
|
-
const userIDToken = getUserIDToken();
|
|
122
|
-
|
|
123
|
-
getLogger().track({
|
|
124
|
-
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_INIT,
|
|
125
|
-
[FPTI_KEY.EVENT_NAME]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_INIT,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const shopperInsights = {
|
|
129
|
-
getRecommendedPaymentMethods: (merchantPayload) => {
|
|
130
|
-
validateMerchantConfig({ sdkToken, pageType, userIDToken, clientToken });
|
|
131
|
-
validateMerchantPayload(merchantPayload);
|
|
132
|
-
|
|
133
|
-
const requestPayload =
|
|
134
|
-
createRecommendedPaymentMethodsRequestPayload(merchantPayload);
|
|
135
|
-
|
|
136
|
-
return callMemoizedRestAPI({
|
|
137
|
-
method: "POST",
|
|
138
|
-
url: `${getPayPalAPIDomain()}/${ELIGIBLE_PAYMENT_METHODS}`,
|
|
139
|
-
data: requestPayload,
|
|
140
|
-
accessToken: sdkToken,
|
|
141
|
-
})
|
|
142
|
-
.then((body) => {
|
|
143
|
-
setShopperInsightsUsage();
|
|
144
|
-
|
|
145
|
-
const paypal = body?.eligible_methods?.paypal;
|
|
146
|
-
const venmo = body?.eligible_methods?.venmo;
|
|
147
|
-
|
|
148
|
-
const isPayPalRecommended =
|
|
149
|
-
(paypal?.eligible_in_paypal_network && paypal?.recommended) ||
|
|
150
|
-
false;
|
|
151
|
-
const isVenmoRecommended =
|
|
152
|
-
(venmo?.eligible_in_paypal_network && venmo?.recommended) || false;
|
|
153
|
-
const fptiRecommendedPaymentPayload = {
|
|
154
|
-
paypal: isPayPalRecommended ? "1" : "0",
|
|
155
|
-
venmo: isVenmoRecommended ? "1" : "0",
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
getLogger().track({
|
|
159
|
-
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_SUCCESS,
|
|
160
|
-
[FPTI_KEY.EVENT_NAME]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_SUCCESS,
|
|
161
|
-
[FPTI_KEY.RESPONSE_DURATION]: (Date.now() - startTime).toString(),
|
|
162
|
-
[FPTI_KEY.RECOMMENDED_PAYMENT]: JSON.stringify(
|
|
163
|
-
fptiRecommendedPaymentPayload
|
|
164
|
-
),
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
sendCountMetric({
|
|
168
|
-
name: SHOPPER_INSIGHTS_METRIC_NAME,
|
|
169
|
-
event: "success",
|
|
170
|
-
dimensions: {
|
|
171
|
-
isPayPalRecommended: String(isPayPalRecommended),
|
|
172
|
-
isVenmoRecommended: String(isVenmoRecommended),
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
return { isPayPalRecommended, isVenmoRecommended };
|
|
177
|
-
})
|
|
178
|
-
.catch((err) => {
|
|
179
|
-
sendCountMetric({
|
|
180
|
-
name: SHOPPER_INSIGHTS_METRIC_NAME,
|
|
181
|
-
event: "error",
|
|
182
|
-
dimensions: {
|
|
183
|
-
errorType: "api_error",
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
getLogger().track({
|
|
188
|
-
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_ERROR,
|
|
189
|
-
[FPTI_KEY.EVENT_NAME]: FPTI_TRANSITION.SHOPPER_INSIGHTS_API_ERROR,
|
|
190
|
-
[FPTI_KEY.RESPONSE_DURATION]: (Date.now() - startTime).toString(),
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
getLogger().error("shopper_insights_api_error", {
|
|
194
|
-
err: stringifyError(err),
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
throw err;
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
return shopperInsights;
|
|
203
|
-
}
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
|
|
3
|
-
import { getEnv, getBuyerCountry, getSDKToken } from "@paypal/sdk-client/src";
|
|
4
|
-
import { vi, describe, expect } from "vitest";
|
|
5
|
-
import { request } from "@krakenjs/belter/src";
|
|
6
|
-
|
|
7
|
-
import { ValidationError } from "../../lib";
|
|
8
|
-
|
|
9
|
-
import { getShopperInsightsComponent } from "./component";
|
|
10
|
-
|
|
11
|
-
vi.mock("@paypal/sdk-client/src", () => {
|
|
12
|
-
return {
|
|
13
|
-
sendCountMetric: vi.fn(),
|
|
14
|
-
getSDKToken: vi.fn(() => "sdk-token"),
|
|
15
|
-
getPageType: vi.fn(() => "product-details"),
|
|
16
|
-
getClientToken: vi.fn(() => ""),
|
|
17
|
-
getUserIDToken: vi.fn(() => ""),
|
|
18
|
-
getEnv: vi.fn(() => "production"),
|
|
19
|
-
getCurrency: vi.fn(() => "USD"),
|
|
20
|
-
getBuyerCountry: vi.fn(() => "US"),
|
|
21
|
-
getPayPalAPIDomain: vi.fn(() => "https://api.paypal.com"),
|
|
22
|
-
getPartnerAttributionID: vi.fn(() => ""),
|
|
23
|
-
getSessionID: vi.fn(() => "sdk-session-ID-123"),
|
|
24
|
-
getSessionState: vi.fn(),
|
|
25
|
-
getLogger: vi.fn(() => ({ track: vi.fn(), error: vi.fn() })),
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
vi.mock("@krakenjs/belter/src", async () => {
|
|
30
|
-
const actual = await vi.importActual("@krakenjs/belter/src");
|
|
31
|
-
return {
|
|
32
|
-
...actual,
|
|
33
|
-
request: vi.fn(() =>
|
|
34
|
-
ZalgoPromise.resolve({
|
|
35
|
-
status: 200,
|
|
36
|
-
headers: {},
|
|
37
|
-
body: {
|
|
38
|
-
eligible_methods: {
|
|
39
|
-
paypal: {
|
|
40
|
-
can_be_vaulted: false,
|
|
41
|
-
eligible_in_paypal_network: true,
|
|
42
|
-
recommended: true,
|
|
43
|
-
recommended_priority: 1,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("shopper insights component - getRecommendedPaymentMethods()", () => {
|
|
53
|
-
afterEach(() => {
|
|
54
|
-
vi.clearAllMocks();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("should get recommended payment methods using the shopper insights API", async () => {
|
|
58
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
59
|
-
const recommendedPaymentMethods =
|
|
60
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
61
|
-
email: "email@test.com",
|
|
62
|
-
phone: {
|
|
63
|
-
countryCode: "1",
|
|
64
|
-
nationalNumber: "2345678901",
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(request).toHaveBeenCalled();
|
|
69
|
-
expect(recommendedPaymentMethods).toEqual({
|
|
70
|
-
isPayPalRecommended: true,
|
|
71
|
-
isVenmoRecommended: false,
|
|
72
|
-
});
|
|
73
|
-
expect.assertions(2);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("should get recommended payment methods from memoized request for the exact same payload", async () => {
|
|
77
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
78
|
-
const payload = {
|
|
79
|
-
email: "email-1.0@test.com",
|
|
80
|
-
phone: {
|
|
81
|
-
countryCode: "1",
|
|
82
|
-
nationalNumber: "2345678901",
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
const response1 =
|
|
86
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods(payload);
|
|
87
|
-
expect(request).toHaveBeenCalled();
|
|
88
|
-
expect(request).toHaveBeenCalledTimes(1);
|
|
89
|
-
const response2 =
|
|
90
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods(payload);
|
|
91
|
-
|
|
92
|
-
expect(request).toHaveBeenCalled();
|
|
93
|
-
// This should not change as the payload is same
|
|
94
|
-
expect(request).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(response1).toEqual({
|
|
96
|
-
isPayPalRecommended: true,
|
|
97
|
-
isVenmoRecommended: false,
|
|
98
|
-
});
|
|
99
|
-
expect(response2).toEqual({
|
|
100
|
-
isPayPalRecommended: true,
|
|
101
|
-
isVenmoRecommended: false,
|
|
102
|
-
});
|
|
103
|
-
expect.assertions(6);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test("should not get recommended payment methods from memoized request for a different payload", async () => {
|
|
107
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
108
|
-
const response1 =
|
|
109
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
110
|
-
email: "email-1.1@test.com",
|
|
111
|
-
});
|
|
112
|
-
expect(request).toHaveBeenCalled();
|
|
113
|
-
expect(request).toHaveBeenCalledTimes(1);
|
|
114
|
-
const response2 =
|
|
115
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
116
|
-
email: "email-1.2@test.com",
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
expect(request).toHaveBeenCalled();
|
|
120
|
-
// This must change to 2 as the payload is different
|
|
121
|
-
expect(request).toHaveBeenCalledTimes(2);
|
|
122
|
-
expect(response1).toEqual({
|
|
123
|
-
isPayPalRecommended: true,
|
|
124
|
-
isVenmoRecommended: false,
|
|
125
|
-
});
|
|
126
|
-
expect(response2).toEqual({
|
|
127
|
-
isPayPalRecommended: true,
|
|
128
|
-
isVenmoRecommended: false,
|
|
129
|
-
});
|
|
130
|
-
expect.assertions(6);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("catch errors from the API", async () => {
|
|
134
|
-
// $FlowFixMe
|
|
135
|
-
request.mockImplementationOnce(() =>
|
|
136
|
-
ZalgoPromise.resolve({
|
|
137
|
-
status: 400,
|
|
138
|
-
headers: {},
|
|
139
|
-
body: {
|
|
140
|
-
name: "ERROR",
|
|
141
|
-
message: "This is an API error",
|
|
142
|
-
},
|
|
143
|
-
})
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
147
|
-
|
|
148
|
-
await expect(() =>
|
|
149
|
-
shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
150
|
-
email: "email@test.com",
|
|
151
|
-
phone: {
|
|
152
|
-
countryCode: "1",
|
|
153
|
-
nationalNumber: "2345678905",
|
|
154
|
-
},
|
|
155
|
-
})
|
|
156
|
-
).rejects.toThrow(
|
|
157
|
-
new Error(
|
|
158
|
-
`https://api.paypal.com/v2/payments/find-eligible-methods returned status 400\n\n{"name":"ERROR","message":"This is an API error"}`
|
|
159
|
-
)
|
|
160
|
-
);
|
|
161
|
-
expect(request).toHaveBeenCalled();
|
|
162
|
-
expect.assertions(2);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test("create payload with email and phone number", async () => {
|
|
166
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
167
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
168
|
-
email: "email10@test.com",
|
|
169
|
-
phone: {
|
|
170
|
-
countryCode: "1",
|
|
171
|
-
nationalNumber: "2345678906",
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(request).toHaveBeenCalledWith(
|
|
176
|
-
expect.objectContaining({
|
|
177
|
-
json: expect.objectContaining({
|
|
178
|
-
customer: expect.objectContaining({
|
|
179
|
-
email: "email10@test.com",
|
|
180
|
-
phone: expect.objectContaining({
|
|
181
|
-
country_code: "1",
|
|
182
|
-
national_number: "2345678906",
|
|
183
|
-
}),
|
|
184
|
-
}),
|
|
185
|
-
}),
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("create payload with email only", async () => {
|
|
191
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
192
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
193
|
-
email: "email2@test.com",
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
expect(request).toHaveBeenCalledWith(
|
|
197
|
-
expect.objectContaining({
|
|
198
|
-
json: expect.objectContaining({
|
|
199
|
-
customer: expect.objectContaining({
|
|
200
|
-
email: "email2@test.com",
|
|
201
|
-
}),
|
|
202
|
-
}),
|
|
203
|
-
})
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test("create payload with phone only", async () => {
|
|
208
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
209
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
210
|
-
email: "email5@test.com",
|
|
211
|
-
phone: {
|
|
212
|
-
countryCode: "1",
|
|
213
|
-
nationalNumber: "2345678901",
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
expect(request).toHaveBeenCalledWith(
|
|
218
|
-
expect.objectContaining({
|
|
219
|
-
json: expect.objectContaining({
|
|
220
|
-
customer: expect.objectContaining({
|
|
221
|
-
phone: expect.objectContaining({
|
|
222
|
-
country_code: "1",
|
|
223
|
-
national_number: "2345678901",
|
|
224
|
-
}),
|
|
225
|
-
}),
|
|
226
|
-
}),
|
|
227
|
-
})
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("should default purchase units with currency code in the payload", async () => {
|
|
232
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
233
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
234
|
-
email: "email6@test.com",
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
expect(request).toHaveBeenCalledWith(
|
|
238
|
-
expect.objectContaining({
|
|
239
|
-
json: expect.objectContaining({
|
|
240
|
-
purchase_units: expect.arrayContaining([
|
|
241
|
-
expect.objectContaining({
|
|
242
|
-
amount: expect.objectContaining({
|
|
243
|
-
currency_code: "USD",
|
|
244
|
-
}),
|
|
245
|
-
}),
|
|
246
|
-
]),
|
|
247
|
-
}),
|
|
248
|
-
})
|
|
249
|
-
);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("should use the SDK buyer-country parameter if country code is not passed in a non-prod env", async () => {
|
|
253
|
-
// $FlowFixMe
|
|
254
|
-
getEnv.mockImplementationOnce(() => "stage");
|
|
255
|
-
|
|
256
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
257
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
258
|
-
email: "email7@test.com",
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
expect(request).toHaveBeenCalledWith(
|
|
262
|
-
expect.objectContaining({
|
|
263
|
-
json: expect.objectContaining({
|
|
264
|
-
customer: expect.objectContaining({
|
|
265
|
-
country_code: "US",
|
|
266
|
-
}),
|
|
267
|
-
}),
|
|
268
|
-
})
|
|
269
|
-
);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test("should default US country code if SDK buyer-country parameter not passed in a non-prod env", async () => {
|
|
273
|
-
// $FlowFixMe
|
|
274
|
-
getEnv.mockImplementationOnce(() => "stage");
|
|
275
|
-
// $FlowFixMe
|
|
276
|
-
getBuyerCountry.mockImplementationOnce(() => "");
|
|
277
|
-
|
|
278
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
279
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
280
|
-
email: "email9@test.com",
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
expect(request).toHaveBeenCalledWith(
|
|
284
|
-
expect.objectContaining({
|
|
285
|
-
json: expect.objectContaining({
|
|
286
|
-
customer: expect.objectContaining({
|
|
287
|
-
country_code: "US",
|
|
288
|
-
}),
|
|
289
|
-
}),
|
|
290
|
-
})
|
|
291
|
-
);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
test("should not set country code in prod env in the payload", async () => {
|
|
295
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
296
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
297
|
-
email: "email@test.com",
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
// $FlowIssue
|
|
301
|
-
expect(request.mock.calls[0][0].json.customer.country_code).toEqual(
|
|
302
|
-
undefined
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test("should request recommended payment methods by setting account details in the payload", async () => {
|
|
307
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
308
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
309
|
-
email: "email9@test.com",
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
expect(request).toHaveBeenCalledWith(
|
|
313
|
-
expect.objectContaining({
|
|
314
|
-
json: expect.objectContaining({
|
|
315
|
-
preferences: expect.objectContaining({
|
|
316
|
-
include_account_details: true,
|
|
317
|
-
}),
|
|
318
|
-
}),
|
|
319
|
-
})
|
|
320
|
-
);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
test("ensure sdk-token is passed when using the getRecommendedPaymentMethods", async () => {
|
|
324
|
-
// $FlowFixMe
|
|
325
|
-
getSDKToken.mockImplementationOnce(() => undefined);
|
|
326
|
-
// $FlowFixMe
|
|
327
|
-
const shopperInsightsComponent = getShopperInsightsComponent();
|
|
328
|
-
const error = new ValidationError(
|
|
329
|
-
`script data attribute sdk-client-token is required but was not passed`
|
|
330
|
-
);
|
|
331
|
-
await expect(
|
|
332
|
-
async () =>
|
|
333
|
-
await shopperInsightsComponent.getRecommendedPaymentMethods({
|
|
334
|
-
email: "email@test.com",
|
|
335
|
-
phone: {
|
|
336
|
-
countryCode: "1",
|
|
337
|
-
nationalNumber: "2345678905",
|
|
338
|
-
},
|
|
339
|
-
})
|
|
340
|
-
).rejects.toThrowError(error);
|
|
341
|
-
expect.assertions(1);
|
|
342
|
-
});
|
|
343
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import type { LazyExport } from "../../types";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
getShopperInsightsComponent,
|
|
7
|
-
type ShopperInsightsComponent,
|
|
8
|
-
} from "./component";
|
|
9
|
-
|
|
10
|
-
export const ShopperInsights: LazyExport<ShopperInsightsComponent> = {
|
|
11
|
-
__get__: () => getShopperInsightsComponent(),
|
|
12
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { describe, expect, vi, beforeEach } from "vitest";
|
|
4
|
-
import { memoize } from "@krakenjs/belter/src";
|
|
5
|
-
|
|
6
|
-
import { getConnectComponent } from "./component";
|
|
7
|
-
import { Connect } from "./interface";
|
|
8
|
-
|
|
9
|
-
describe("interface.js", () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
memoize.clear();
|
|
12
|
-
});
|
|
13
|
-
vi.mock("./component", () => {
|
|
14
|
-
return {
|
|
15
|
-
getConnectComponent: vi.fn(() => ({})),
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
it("should call getConnectComponent with merchant props", async () => {
|
|
19
|
-
const merchantProps = { env: "test" };
|
|
20
|
-
|
|
21
|
-
await Connect(merchantProps);
|
|
22
|
-
expect(getConnectComponent).toBeCalledWith(merchantProps);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import { getLogger } from "@paypal/sdk-client/src";
|
|
3
|
-
|
|
4
|
-
// TODO: This will be pulled in to a shared sdk-client util
|
|
5
|
-
export const sendCountMetric = ({
|
|
6
|
-
dimensions,
|
|
7
|
-
event = "unused",
|
|
8
|
-
name,
|
|
9
|
-
value = 1,
|
|
10
|
-
}: {|
|
|
11
|
-
event?: string,
|
|
12
|
-
name: string,
|
|
13
|
-
value?: number,
|
|
14
|
-
dimensions: {
|
|
15
|
-
[string]: mixed,
|
|
16
|
-
},
|
|
17
|
-
// $FlowIssue return type
|
|
18
|
-
|}) =>
|
|
19
|
-
getLogger().metric({
|
|
20
|
-
dimensions,
|
|
21
|
-
metricEventName: event,
|
|
22
|
-
metricNamespace: name,
|
|
23
|
-
metricValue: value,
|
|
24
|
-
metricType: "counter",
|
|
25
|
-
});
|