Skip to content

[DO NOT MERGE] alpha: remove LSAT #2465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions src/three-domain-secure/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,15 @@ export class HTTPClient implements HTTPClientType {
}

export class RestClient extends HTTPClient {
request({ baseURL, ...rest }: HTTPRequestOptions): ZalgoPromise<{ ... }> {
return callRestAPI({
url: baseURL ?? this.baseURL ?? "",
accessToken: this.accessToken,
...rest,
});
}
authRequest({
request({
baseURL,
accessToken,
...rest
}: HTTPRequestOptions): ZalgoPromise<{ ... }> {
return request({
method: "post",
return callRestAPI({
url: baseURL ?? this.baseURL ?? "",
headers: {
// $FlowIssue
Authorization: `Basic ${accessToken}`,
},
accessToken: accessToken ?? this.accessToken,
...rest,
}).then(({ body }) => {
if (body && body.error === "invalid_client") {
throw new Error(
`Auth Api invalid client id: \n\n${JSON.stringify(body, null, 4)}`
);
}

if (!body || !body.access_token) {
throw new Error(
`Auth Api response error:\n\n${JSON.stringify(body, null, 4)}`
);
}

return body.access_token;
});
}
}
Expand Down
33 changes: 2 additions & 31 deletions src/three-domain-secure/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
/* eslint-disable no-restricted-globals, promise/no-native */
import { type LoggerType } from "@krakenjs/beaver-logger/src";
import { type ZoidComponent } from "@krakenjs/zoid/src";
import { base64encode } from "@krakenjs/belter/src";
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
import { FPTI_KEY, CURRENCY } from "@paypal/sdk-constants/src";

import { PAYMENT_3DS_VERIFICATION, AUTH } from "../constants/api";
import { PAYMENT_3DS_VERIFICATION } from "../constants/api";
import { ValidationError } from "../lib";

import type {
requestData,
responseBody,
GqlResponse,
MerchantPayloadData,
SdkConfig,
ThreeDSResponse,
TDSProps,
Request,
} from "./types";
import { getFastlaneThreeDS } from "./utils";
import type { GraphQLClient, RestClient } from "./api";
Expand Down Expand Up @@ -99,35 +96,9 @@ export class ThreeDomainSecureComponent {
const data = parseMerchantPayload({ merchantPayload });
this.fastlaneNonce = merchantPayload.nonce;

try {
const basicAuth = base64encode(`${this.sdkConfig.clientID}:`);
const authData = {
grant_type: `client_credentials`,
};

if (this.sdkConfig.merchantID?.length) {
// $FlowFixMe invalid error on key assignment
authData.target_subject = this.sdkConfig.merchantID[0];
}
// $FlowFixMe
const accessToken = await this.restClient.authRequest<Request, string>({
baseURL: `${this.sdkConfig.paypalApiDomain}${AUTH}`,
accessToken: `${basicAuth}`,
data: authData,
});
// $FlowIssue confusing ZalgoPromise return type with resolved string value
this.restClient.setAccessToken(accessToken);
} catch (error) {
this.logger.warn(error);
throw error;
}

try {
// $FlowFixMe
const { status, links } = await this.restClient.request<
requestData,
responseBody
>({
const { status, links } = await this.restClient.request({
method: "POST",
baseURL: `${this.sdkConfig.paypalApiDomain}/${PAYMENT_3DS_VERIFICATION}`,
data,
Expand Down
1 change: 0 additions & 1 deletion src/three-domain-secure/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const mockRestClient = {
},
],
}),
authRequest: vi.fn(),
};

const mockEligibilityRequest = (body = defaultEligibilityResponse) => {
Expand Down
4 changes: 1 addition & 3 deletions src/three-domain-secure/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getPayPalAPIDomain,
getSDKToken,
getClientID,
getMerchantID,
} from "@paypal/sdk-client/src";
import { destroy as zoidDestroy } from "@krakenjs/zoid/src";

Expand Down Expand Up @@ -34,7 +33,7 @@ export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInter
__get__: () => {
const threeDomainSecureInstance = new ThreeDomainSecureComponent({
logger: getLogger(),
restClient: new RestClient(),
restClient: new RestClient({ accessToken: getSDKToken() }),
graphQLClient: new GraphQLClient({
baseURL:
getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX,
Expand All @@ -45,7 +44,6 @@ export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInter
authenticationToken: getSDKToken(),
paypalApiDomain: getPayPalAPIDomain(),
clientID: getClientID(),
merchantID: getMerchantID(),
},
});
return devEnvOnlyExport({
Expand Down