@paypal/checkout-components 5.0.388 → 5.0.389
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/package.json
CHANGED
|
@@ -34,21 +34,36 @@ const parseSdkConfig = ({ sdkConfig, logger }): SdkConfig => {
|
|
|
34
34
|
return sdkConfig;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const parseMerchantPayload = ({
|
|
37
|
+
export const parseMerchantPayload = ({
|
|
38
38
|
merchantPayload,
|
|
39
39
|
}: {|
|
|
40
40
|
merchantPayload: MerchantPayloadData,
|
|
41
41
|
|}): requestData => {
|
|
42
|
-
const {
|
|
43
|
-
|
|
42
|
+
const {
|
|
43
|
+
threeDSRequested,
|
|
44
|
+
verificationMethod,
|
|
45
|
+
amount,
|
|
46
|
+
currency,
|
|
47
|
+
nonce,
|
|
48
|
+
transactionContext,
|
|
49
|
+
} = merchantPayload;
|
|
50
|
+
|
|
51
|
+
let cardVerificationMethod = "SCA_WHEN_REQUIRED";
|
|
52
|
+
|
|
53
|
+
if (verificationMethod) {
|
|
54
|
+
cardVerificationMethod = verificationMethod;
|
|
55
|
+
} else if (threeDSRequested !== undefined) {
|
|
56
|
+
cardVerificationMethod = threeDSRequested
|
|
57
|
+
? "SCA_ALWAYS"
|
|
58
|
+
: "SCA_WHEN_REQUIRED";
|
|
59
|
+
}
|
|
60
|
+
|
|
44
61
|
return {
|
|
45
62
|
intent: "THREE_DS_VERIFICATION",
|
|
46
63
|
payment_source: {
|
|
47
64
|
card: {
|
|
48
65
|
single_use_token: nonce,
|
|
49
|
-
verification_method:
|
|
50
|
-
? "SCA_ALWAYS"
|
|
51
|
-
: "SCA_WHEN_REQUIRED",
|
|
66
|
+
verification_method: cardVerificationMethod,
|
|
52
67
|
},
|
|
53
68
|
},
|
|
54
69
|
amount: {
|
|
@@ -128,7 +143,7 @@ export class ThreeDomainSecureComponent {
|
|
|
128
143
|
// eslint-disable-next-line compat/compat
|
|
129
144
|
return new Promise((resolve, reject) => {
|
|
130
145
|
let authenticationState,
|
|
131
|
-
liabilityShift
|
|
146
|
+
liabilityShift;
|
|
132
147
|
const cancelThreeDS = () => {
|
|
133
148
|
return ZalgoPromise.try(() => {
|
|
134
149
|
this.logger.warn("3DS Cancelled");
|
|
@@ -137,7 +152,6 @@ export class ThreeDomainSecureComponent {
|
|
|
137
152
|
instance.close();
|
|
138
153
|
resolve({
|
|
139
154
|
authenticationState: "cancelled",
|
|
140
|
-
liabilityShift: "false",
|
|
141
155
|
nonce: this.fastlaneNonce,
|
|
142
156
|
});
|
|
143
157
|
});
|
|
@@ -147,12 +161,14 @@ export class ThreeDomainSecureComponent {
|
|
|
147
161
|
payerActionUrl: this.authenticationURL,
|
|
148
162
|
onSuccess: async (res) => {
|
|
149
163
|
const { reference_id, liability_shift, success } = res;
|
|
164
|
+
// $FlowFixMe incompatible type payload
|
|
165
|
+
this.logger.info("helios_response", JSON.stringify(res));
|
|
150
166
|
let enrichedNonce;
|
|
151
167
|
// Helios returns a boolen parameter: "success"
|
|
152
168
|
// It will be true for all cases where liability is shifted to merchant
|
|
153
|
-
// and false for downstream failures and errors
|
|
169
|
+
// and false for downstream failures and errors where liability_shift= NO|UNKNOWN.
|
|
154
170
|
authenticationState = success ? "succeeded" : "errored";
|
|
155
|
-
liabilityShift = liability_shift
|
|
171
|
+
liabilityShift = liability_shift;
|
|
156
172
|
|
|
157
173
|
// call BT mutation to update fastlaneNonce with 3ds data
|
|
158
174
|
// reference_id will be available for all usecases(success/failure)
|
|
@@ -6,7 +6,7 @@ import { FPTI_KEY } from "@paypal/sdk-constants/src";
|
|
|
6
6
|
|
|
7
7
|
import { ValidationError } from "../lib";
|
|
8
8
|
|
|
9
|
-
import { ThreeDomainSecureComponent } from "./component";
|
|
9
|
+
import { ThreeDomainSecureComponent, parseMerchantPayload } from "./component";
|
|
10
10
|
|
|
11
11
|
const defaultSdkConfig = {
|
|
12
12
|
authenticationToken: "sdk-client-token",
|
|
@@ -237,3 +237,119 @@ describe("three domain secure component - initialization", () => {
|
|
|
237
237
|
});
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
|
+
|
|
241
|
+
describe(" three domain secure component - parseMerchantPayload", () => {
|
|
242
|
+
const baseMerchantPayload = {
|
|
243
|
+
amount: "100.00",
|
|
244
|
+
currency: "USD",
|
|
245
|
+
nonce: "test-nonce-123",
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
it("should default to SCA_WHEN_REQUIRED when no 3DS parameters provided", () => {
|
|
249
|
+
const result = parseMerchantPayload({
|
|
250
|
+
merchantPayload: baseMerchantPayload,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expect(result).toEqual({
|
|
254
|
+
intent: "THREE_DS_VERIFICATION",
|
|
255
|
+
payment_source: {
|
|
256
|
+
card: {
|
|
257
|
+
single_use_token: "test-nonce-123",
|
|
258
|
+
verification_method: "SCA_WHEN_REQUIRED",
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
amount: {
|
|
262
|
+
currency_code: "USD",
|
|
263
|
+
value: "100.00",
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("should use verificationMethod when provided", () => {
|
|
269
|
+
const payload = {
|
|
270
|
+
...baseMerchantPayload,
|
|
271
|
+
verificationMethod: "SCA_ALWAYS",
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const result = parseMerchantPayload({ merchantPayload: payload });
|
|
275
|
+
|
|
276
|
+
expect(result.payment_source.card.verification_method).toBe("SCA_ALWAYS");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should prioritize verificationMethod over threeDSRequested", () => {
|
|
280
|
+
const payload = {
|
|
281
|
+
...baseMerchantPayload,
|
|
282
|
+
threeDSRequested: false,
|
|
283
|
+
verificationMethod: "SCA_ALWAYS",
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const result = parseMerchantPayload({ merchantPayload: payload });
|
|
287
|
+
|
|
288
|
+
expect(result.payment_source.card.verification_method).toBe("SCA_ALWAYS");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("should use threeDSRequested when verificationMethod not provided", () => {
|
|
292
|
+
const payloadWithTrue = {
|
|
293
|
+
...baseMerchantPayload,
|
|
294
|
+
threeDSRequested: true,
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const payloadWithFalse = {
|
|
298
|
+
...baseMerchantPayload,
|
|
299
|
+
threeDSRequested: false,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const resultTrue = parseMerchantPayload({
|
|
303
|
+
merchantPayload: payloadWithTrue,
|
|
304
|
+
});
|
|
305
|
+
const resultFalse = parseMerchantPayload({
|
|
306
|
+
merchantPayload: payloadWithFalse,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(resultTrue.payment_source.card.verification_method).toBe(
|
|
310
|
+
"SCA_ALWAYS"
|
|
311
|
+
);
|
|
312
|
+
expect(resultFalse.payment_source.card.verification_method).toBe(
|
|
313
|
+
"SCA_WHEN_REQUIRED"
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("should include transactionContext when provided", () => {
|
|
318
|
+
const payload = {
|
|
319
|
+
...baseMerchantPayload,
|
|
320
|
+
transactionContext: {
|
|
321
|
+
soft_descriptor: "PAYPAL *TEST",
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const result = parseMerchantPayload({ merchantPayload: payload });
|
|
326
|
+
|
|
327
|
+
expect(result).toMatchObject({
|
|
328
|
+
intent: "THREE_DS_VERIFICATION",
|
|
329
|
+
payment_source: {
|
|
330
|
+
card: {
|
|
331
|
+
single_use_token: "test-nonce-123",
|
|
332
|
+
verification_method: "SCA_WHEN_REQUIRED",
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
amount: {
|
|
336
|
+
currency_code: "USD",
|
|
337
|
+
value: "100.00",
|
|
338
|
+
},
|
|
339
|
+
soft_descriptor: "PAYPAL *TEST",
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("should handle SCA_WHEN_REQUIRED in verificationMethod", () => {
|
|
344
|
+
const payload = {
|
|
345
|
+
...baseMerchantPayload,
|
|
346
|
+
verificationMethod: "SCA_WHEN_REQUIRED",
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const result = parseMerchantPayload({ merchantPayload: payload });
|
|
350
|
+
|
|
351
|
+
expect(result.payment_source.card.verification_method).toBe(
|
|
352
|
+
"SCA_WHEN_REQUIRED"
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
@@ -31,17 +31,18 @@ export function destroy(err?: mixed) {
|
|
|
31
31
|
export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInterface> =
|
|
32
32
|
{
|
|
33
33
|
__get__: () => {
|
|
34
|
+
const accessToken = getSDKToken() || getUserIDToken();
|
|
34
35
|
const threeDomainSecureInstance = new ThreeDomainSecureComponent({
|
|
35
36
|
logger: getLogger(),
|
|
36
|
-
restClient: new RestClient({ accessToken
|
|
37
|
+
restClient: new RestClient({ accessToken }),
|
|
37
38
|
graphQLClient: new GraphQLClient({
|
|
38
39
|
baseURL:
|
|
39
40
|
getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX,
|
|
40
|
-
accessToken
|
|
41
|
+
accessToken,
|
|
41
42
|
}),
|
|
42
43
|
// $FlowIssue ZalgoPromise vs Promise
|
|
43
44
|
sdkConfig: {
|
|
44
|
-
authenticationToken:
|
|
45
|
+
authenticationToken: accessToken,
|
|
45
46
|
paypalApiDomain: getPayPalAPIDomain(),
|
|
46
47
|
clientID: getClientID(),
|
|
47
48
|
},
|
|
@@ -8,6 +8,7 @@ export type MerchantPayloadData = {|
|
|
|
8
8
|
currency: string,
|
|
9
9
|
nonce: string,
|
|
10
10
|
threeDSRequested?: boolean,
|
|
11
|
+
verificationMethod?: "SCA_ALWAYS" | "SCA_WHEN_REQUIRED",
|
|
11
12
|
transactionContext?: Object,
|
|
12
13
|
idToken?: string,
|
|
13
14
|
|};
|
|
@@ -73,7 +74,7 @@ export type SdkConfig = {|
|
|
|
73
74
|
|};
|
|
74
75
|
|
|
75
76
|
export type ThreeDSResponse = {|
|
|
76
|
-
liabilityShift
|
|
77
|
+
liabilityShift?: string,
|
|
77
78
|
authenticationState: string,
|
|
78
79
|
nonce?: string,
|
|
79
80
|
|};
|