Skip to content

Commit bb9ad0d

Browse files
committed
update overlay, save 3ds comp on eligibility to class variable
1 parent dfa0504 commit bb9ad0d

File tree

7 files changed

+298
-204
lines changed

7 files changed

+298
-204
lines changed

Diff for: dist/button.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/test/button.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/three-domain-secure/component.jsx

+55-136
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,21 @@
22
/* eslint-disable eslint-comments/disable-enable-pair */
33
/* eslint-disable no-restricted-globals, promise/no-native */
44
import { type LoggerType } from "@krakenjs/beaver-logger/src";
5-
import { create, type ZoidComponent } from "@krakenjs/zoid/src";
6-
import { inlineMemoize, noop } from "@krakenjs/belter/src";
5+
import { type ZoidComponent } from "@krakenjs/zoid/src";
6+
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
77
import { FPTI_KEY } from "@paypal/sdk-constants/src";
8-
import { Overlay } from "../ui/overlay";
98

109
import { ValidationError } from "../lib";
1110

12-
type MerchantPayloadData = {|
13-
amount: string,
14-
currency: string,
15-
nonce: string,
16-
threeDSRequested?: boolean,
17-
transactionContext?: Object,
18-
|};
19-
20-
// eslint-disable-next-line no-undef
21-
type Request = <TRequestData, TResponse>({|
22-
method?: string,
23-
url: string,
24-
// eslint-disable-next-line no-undef
25-
data: TRequestData,
26-
accessToken: ?string,
27-
// eslint-disable-next-line no-undef
28-
|}) => Promise<TResponse>;
29-
30-
type requestData = {|
31-
intent: "THREE_DS_VERIFICATION",
32-
payment_source: {|
33-
card: {|
34-
single_use_token: string,
35-
verification_method: string,
36-
|},
37-
|},
38-
amount: {|
39-
currency_code: string,
40-
value: string,
41-
|},
42-
transaction_context?: {|
43-
soft_descriptor?: string,
44-
|},
45-
|};
46-
47-
type responseBody = {|
48-
payment_id: string,
49-
status: string,
50-
intent: string,
51-
payment_source: {|
52-
card: {|
53-
last_digits: string,
54-
type: string,
55-
name: string,
56-
expiry: string,
57-
|},
58-
|},
59-
amount: {|
60-
currency_code: string,
61-
value: string,
62-
|},
63-
transaction_context: {|
64-
soft_descriptor: string,
65-
|},
66-
links: $ReadOnlyArray<{|
67-
href: string,
68-
rel: string,
69-
method: string,
70-
|}>,
71-
|};
72-
73-
type SdkConfig = {|
74-
authenticationToken: ?string,
75-
paypalApiDomain: string,
76-
|};
11+
import {
12+
requestData,
13+
responseBody,
14+
Request,
15+
MerchantPayloadData,
16+
SdkConfig,
17+
threeDSResponse,
18+
} from "./types";
19+
import { getThreeDomainSecureComponent } from "./utils";
7720

7821
const parseSdkConfig = ({ sdkConfig, logger }): SdkConfig => {
7922
if (!sdkConfig.authenticationToken) {
@@ -98,11 +41,9 @@ const parseMerchantPayload = ({
9841
// empty object
9942
const { threeDSRequested, amount, currency, nonce, transactionContext } =
10043
merchantPayload;
101-
10244
// amount - validate that it's a string
10345
// currency - validate that it's a string
10446
// what validations are done on the API end - what client side validation is the API expecting
105-
10647
return {
10748
intent: "THREE_DS_VERIFICATION",
10849
payment_source: {
@@ -123,14 +64,14 @@ const parseMerchantPayload = ({
12364

12465
export interface ThreeDomainSecureComponentInterface {
12566
isEligible(): Promise<boolean>;
126-
show(): ZoidComponent<void>;
67+
show(): Promise<threeDSResponse>;
12768
}
12869
export class ThreeDomainSecureComponent {
12970
logger: LoggerType;
13071
request: Request;
13172
sdkConfig: SdkConfig;
13273
authenticationURL: string;
133-
74+
threeDSIframe: ZoidComponent;
13475
constructor({
13576
logger,
13677
request,
@@ -147,24 +88,24 @@ export class ThreeDomainSecureComponent {
14788

14889
async isEligible(merchantPayload: MerchantPayloadData): Promise<boolean> {
14990
const data = parseMerchantPayload({ merchantPayload });
150-
console.log(data);
151-
console.log(this.request);
15291
try {
15392
// $FlowFixMe
15493
const { status, links } = await this.request<requestData, responseBody>({
15594
method: "POST",
156-
url: `${this.sdkConfig.paypalApiDomain}/v2/payments/payment`,
95+
url: `https://te-test-qa.qa.paypal.com:12326/v2/payments/payment`,
15796
data,
15897
accessToken: this.sdkConfig.authenticationToken,
15998
});
16099

161100
let responseStatus = false;
162-
console.log(links);
163101
if (status === "PAYER_ACTION_REQUIRED") {
164102
this.authenticationURL = links.find(
165103
(link) => link.rel === "payer-action"
166104
).href;
167105
responseStatus = true;
106+
this.threeDSIframe = getThreeDomainSecureComponent(
107+
this.authenticationURL
108+
);
168109
}
169110
return responseStatus;
170111
} catch (error) {
@@ -173,69 +114,47 @@ export class ThreeDomainSecureComponent {
173114
}
174115
}
175116

176-
show() {
177-
return inlineMemoize(show, () => {
178-
const component = create({
179-
tag: "three-domain-secure-client",
180-
url: this.authenticationURL,
181-
182-
attributes: {
183-
iframe: {
184-
scrolling: "no",
185-
},
186-
},
187-
188-
containerTemplate: ({
189-
context,
190-
focus,
191-
close,
192-
frame,
193-
prerenderFrame,
194-
doc,
195-
event,
196-
props,
197-
}) => {
198-
console.log("$$$$ props", props);
199-
return (
200-
<Overlay
201-
context={context}
202-
close={close}
203-
focus={focus}
204-
event={event}
205-
frame={frame}
206-
prerenderFrame={prerenderFrame}
207-
content={props.content}
208-
nonce={props.nonce}
209-
/>
210-
).render(dom({ doc }));
211-
},
212-
213-
props: {
214-
xcomponent: {
215-
type: "string",
216-
queryParam: true,
217-
value: () => "1",
218-
},
219-
clientID: {
220-
type: "string",
221-
value: getClientID,
222-
queryParam: true,
223-
},
224-
content: {
225-
type: "object",
226-
required: false,
227-
},
228-
},
117+
show(): Promise<threeDSResponse> {
118+
if (!this.threeDSIframe) {
119+
throw new ValidationError(`Ineligible for three domain secure`);
120+
return;
121+
}
122+
const promise = new ZalgoPromise();
123+
const cancelThreeDS = () => {
124+
return ZalgoPromise.try(() => {
125+
// eslint-disable-next-line no-console
126+
console.log("cancelled");
127+
}).then(() => {
128+
// eslint-disable-next-line no-use-before-define
129+
instance.close();
229130
});
131+
};
230132

231-
if (component.isChild()) {
232-
window.xchild = {
233-
props: component.xprops,
234-
close: noop,
235-
};
236-
}
133+
const instance = this.threeDSIframe({
134+
onSuccess: (data) => {
135+
// const {threeDSRefID, authentication_status, liability_shift } = data;
136+
// let enrichedNonce;
137+
// if(threeDSRefID) {
138+
// enrichedNonce = await updateNonceWith3dsData(threeDSRefID, this.fastlaneNonce)
139+
// }
237140

238-
return component;
141+
return promise.resolve(data);
142+
},
143+
onClose: cancelThreeDS,
144+
onError: (err) => {
145+
return promise.reject(
146+
new Error(
147+
`Error with obtaining 3DS contingency, ${JSON.stringify(err)}`
148+
)
149+
);
150+
},
239151
});
152+
const TARGET_ELEMENT = {
153+
BODY: "body",
154+
};
155+
return instance
156+
.renderTo(window.parent, TARGET_ELEMENT.BODY)
157+
.then(() => promise)
158+
.finally(instance.close);
240159
}
241160
}

Diff for: src/three-domain-secure/component.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ describe("three domain secure component - isEligible method", () => {
7171
test.todo("create payload with correctly parameters", async () => {
7272
const threeDomainSecureClient = createThreeDomainSecureComponent();
7373
const mockedRequest = mockEligibilityRequest();
74-
const eligibility = await threeDomainSecureClient.isEligible(
75-
defaultMerchantPayload
76-
);
74+
await threeDomainSecureClient.isEligible(defaultMerchantPayload);
7775

7876
expect(mockedRequest).toHaveBeenCalledWith();
7977
});

Diff for: src/three-domain-secure/types.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* @flow */
2+
/* eslint-disable no-restricted-globals, promise/no-native */
3+
export type MerchantPayloadData = {|
4+
amount: string,
5+
currency: string,
6+
nonce: string,
7+
threeDSRequested?: boolean,
8+
transactionContext?: Object,
9+
|};
10+
11+
// eslint-disable-next-line no-undef
12+
export type Request = <TRequestData, TResponse>({|
13+
method?: string,
14+
url: string,
15+
// eslint-disable-next-line no-undef
16+
data: TRequestData,
17+
accessToken: ?string,
18+
// eslint-disable-next-line no-undef
19+
|}) => Promise<TResponse>;
20+
21+
export type requestData = {|
22+
intent: "THREE_DS_VERIFICATION",
23+
payment_source: {|
24+
card: {|
25+
single_use_token: string,
26+
verification_method: string,
27+
|},
28+
|},
29+
amount: {|
30+
currency_code: string,
31+
value: string,
32+
|},
33+
transaction_context?: {|
34+
soft_descriptor?: string,
35+
|},
36+
|};
37+
38+
export type responseBody = {|
39+
payment_id: string,
40+
status: string,
41+
intent: string,
42+
payment_source: {|
43+
card: {|
44+
last_digits: string,
45+
type: string,
46+
name: string,
47+
expiry: string,
48+
|},
49+
|},
50+
amount: {|
51+
currency_code: string,
52+
value: string,
53+
|},
54+
transaction_context: {|
55+
soft_descriptor: string,
56+
|},
57+
links: $ReadOnlyArray<{|
58+
href: string,
59+
rel: string,
60+
method: string,
61+
|}>,
62+
|};
63+
64+
export type SdkConfig = {|
65+
authenticationToken: ?string,
66+
paypalApiDomain: string,
67+
|};
68+
69+
export type threeDSResponse = {|
70+
liabilityShift: string,
71+
authenticationStatus: string,
72+
nonce?: string,
73+
|};
74+
75+
export type TDSResult = {||};
76+
77+
/* eslint-enable no-restricted-globals, promise/no-native */

0 commit comments

Comments
 (0)