Skip to content

Commit 915822c

Browse files
authored
feat (3ds): remove LSAT and utilize sdk token (#2463)
* remove lsat and utilize sdk token * lint fix * flow fix
1 parent 71e09fa commit 915822c

File tree

4 files changed

+6
-63
lines changed

4 files changed

+6
-63
lines changed

src/three-domain-secure/api.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,15 @@ export class HTTPClient implements HTTPClientType {
3939
}
4040

4141
export class RestClient extends HTTPClient {
42-
request({ baseURL, ...rest }: HTTPRequestOptions): ZalgoPromise<{ ... }> {
43-
return callRestAPI({
44-
url: baseURL ?? this.baseURL ?? "",
45-
accessToken: this.accessToken,
46-
...rest,
47-
});
48-
}
49-
authRequest({
42+
request({
5043
baseURL,
5144
accessToken,
5245
...rest
5346
}: HTTPRequestOptions): ZalgoPromise<{ ... }> {
54-
return request({
55-
method: "post",
47+
return callRestAPI({
5648
url: baseURL ?? this.baseURL ?? "",
57-
headers: {
58-
// $FlowIssue
59-
Authorization: `Basic ${accessToken}`,
60-
},
49+
accessToken: accessToken ?? this.accessToken,
6150
...rest,
62-
}).then(({ body }) => {
63-
if (body && body.error === "invalid_client") {
64-
throw new Error(
65-
`Auth Api invalid client id: \n\n${JSON.stringify(body, null, 4)}`
66-
);
67-
}
68-
69-
if (!body || !body.access_token) {
70-
throw new Error(
71-
`Auth Api response error:\n\n${JSON.stringify(body, null, 4)}`
72-
);
73-
}
74-
75-
return body.access_token;
7651
});
7752
}
7853
}

src/three-domain-secure/component.jsx

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
/* eslint-disable no-restricted-globals, promise/no-native */
44
import { type LoggerType } from "@krakenjs/beaver-logger/src";
55
import { type ZoidComponent } from "@krakenjs/zoid/src";
6-
import { base64encode } from "@krakenjs/belter/src";
76
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
87
import { FPTI_KEY, CURRENCY } from "@paypal/sdk-constants/src";
98

10-
import { PAYMENT_3DS_VERIFICATION, AUTH } from "../constants/api";
9+
import { PAYMENT_3DS_VERIFICATION } from "../constants/api";
1110
import { ValidationError } from "../lib";
1211

1312
import type {
1413
requestData,
15-
responseBody,
1614
GqlResponse,
1715
MerchantPayloadData,
1816
SdkConfig,
1917
ThreeDSResponse,
2018
TDSProps,
21-
Request,
2219
} from "./types";
2320
import { getFastlaneThreeDS } from "./utils";
2421
import type { GraphQLClient, RestClient } from "./api";
@@ -99,35 +96,9 @@ export class ThreeDomainSecureComponent {
9996
const data = parseMerchantPayload({ merchantPayload });
10097
this.fastlaneNonce = merchantPayload.nonce;
10198

102-
try {
103-
const basicAuth = base64encode(`${this.sdkConfig.clientID}:`);
104-
const authData = {
105-
grant_type: `client_credentials`,
106-
};
107-
108-
if (this.sdkConfig.merchantID?.length) {
109-
// $FlowFixMe invalid error on key assignment
110-
authData.target_subject = this.sdkConfig.merchantID[0];
111-
}
112-
// $FlowFixMe
113-
const accessToken = await this.restClient.authRequest<Request, string>({
114-
baseURL: `${this.sdkConfig.paypalApiDomain}${AUTH}`,
115-
accessToken: `${basicAuth}`,
116-
data: authData,
117-
});
118-
// $FlowIssue confusing ZalgoPromise return type with resolved string value
119-
this.restClient.setAccessToken(accessToken);
120-
} catch (error) {
121-
this.logger.warn(error);
122-
throw error;
123-
}
124-
12599
try {
126100
// $FlowFixMe
127-
const { status, links } = await this.restClient.request<
128-
requestData,
129-
responseBody
130-
>({
101+
const { status, links } = await this.restClient.request({
131102
method: "POST",
132103
baseURL: `${this.sdkConfig.paypalApiDomain}/${PAYMENT_3DS_VERIFICATION}`,
133104
data,

src/three-domain-secure/component.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const mockRestClient = {
4545
},
4646
],
4747
}),
48-
authRequest: vi.fn(),
4948
};
5049

5150
const mockEligibilityRequest = (body = defaultEligibilityResponse) => {

src/three-domain-secure/interface.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
getPayPalAPIDomain,
66
getSDKToken,
77
getClientID,
8-
getMerchantID,
98
} from "@paypal/sdk-client/src";
109
import { destroy as zoidDestroy } from "@krakenjs/zoid/src";
1110

@@ -34,7 +33,7 @@ export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInter
3433
__get__: () => {
3534
const threeDomainSecureInstance = new ThreeDomainSecureComponent({
3635
logger: getLogger(),
37-
restClient: new RestClient(),
36+
restClient: new RestClient({ accessToken: getSDKToken() }),
3837
graphQLClient: new GraphQLClient({
3938
baseURL:
4039
getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX,
@@ -45,7 +44,6 @@ export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInter
4544
authenticationToken: getSDKToken(),
4645
paypalApiDomain: getPayPalAPIDomain(),
4746
clientID: getClientID(),
48-
merchantID: getMerchantID(),
4947
},
5048
});
5149
return devEnvOnlyExport({

0 commit comments

Comments
 (0)