diff --git a/src/three-domain-secure/api.js b/src/three-domain-secure/api.js index 50f9b76a8..b1e7e4177 100644 --- a/src/three-domain-secure/api.js +++ b/src/three-domain-secure/api.js @@ -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; }); } } diff --git a/src/three-domain-secure/component.jsx b/src/three-domain-secure/component.jsx index b3ec2d0ea..9db2a501d 100644 --- a/src/three-domain-secure/component.jsx +++ b/src/three-domain-secure/component.jsx @@ -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"; @@ -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({ - 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, diff --git a/src/three-domain-secure/component.test.js b/src/three-domain-secure/component.test.js index 3420480c9..3e52ce7fe 100644 --- a/src/three-domain-secure/component.test.js +++ b/src/three-domain-secure/component.test.js @@ -45,7 +45,6 @@ const mockRestClient = { }, ], }), - authRequest: vi.fn(), }; const mockEligibilityRequest = (body = defaultEligibilityResponse) => { diff --git a/src/three-domain-secure/interface.js b/src/three-domain-secure/interface.js index f8c814eb0..5a6e69634 100644 --- a/src/three-domain-secure/interface.js +++ b/src/three-domain-secure/interface.js @@ -5,7 +5,6 @@ import { getPayPalAPIDomain, getSDKToken, getClientID, - getMerchantID, } from "@paypal/sdk-client/src"; import { destroy as zoidDestroy } from "@krakenjs/zoid/src"; @@ -34,7 +33,7 @@ export const ThreeDomainSecureClient: LazyExport { const threeDomainSecureInstance = new ThreeDomainSecureComponent({ logger: getLogger(), - restClient: new RestClient(), + restClient: new RestClient({ accessToken: getSDKToken() }), graphQLClient: new GraphQLClient({ baseURL: getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX, @@ -45,7 +44,6 @@ export const ThreeDomainSecureClient: LazyExport