2
2
/* eslint-disable eslint-comments/disable-enable-pair */
3
3
/* eslint-disable no-restricted-globals, promise/no-native */
4
4
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" ;
7
7
import { FPTI_KEY } from "@paypal/sdk-constants/src" ;
8
- import { Overlay } from "../ui/overlay" ;
9
8
10
9
import { ValidationError } from "../lib" ;
11
10
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" ;
77
20
78
21
const parseSdkConfig = ( { sdkConfig, logger } ) : SdkConfig => {
79
22
if ( ! sdkConfig . authenticationToken ) {
@@ -98,11 +41,9 @@ const parseMerchantPayload = ({
98
41
// empty object
99
42
const { threeDSRequested, amount, currency, nonce, transactionContext } =
100
43
merchantPayload ;
101
-
102
44
// amount - validate that it's a string
103
45
// currency - validate that it's a string
104
46
// what validations are done on the API end - what client side validation is the API expecting
105
-
106
47
return {
107
48
intent : "THREE_DS_VERIFICATION" ,
108
49
payment_source : {
@@ -123,14 +64,14 @@ const parseMerchantPayload = ({
123
64
124
65
export interface ThreeDomainSecureComponentInterface {
125
66
isEligible ( ) : Promise < boolean > ;
126
- show ( ) : ZoidComponent < void > ;
67
+ show ( ) : Promise < threeDSResponse > ;
127
68
}
128
69
export class ThreeDomainSecureComponent {
129
70
logger : LoggerType ;
130
71
request : Request ;
131
72
sdkConfig : SdkConfig ;
132
73
authenticationURL : string ;
133
-
74
+ threeDSIframe : ZoidComponent ;
134
75
constructor ( {
135
76
logger,
136
77
request,
@@ -147,24 +88,24 @@ export class ThreeDomainSecureComponent {
147
88
148
89
async isEligible ( merchantPayload : MerchantPayloadData ) : Promise < boolean > {
149
90
const data = parseMerchantPayload ( { merchantPayload } ) ;
150
- console . log ( data ) ;
151
- console . log ( this . request ) ;
152
91
try {
153
92
// $FlowFixMe
154
93
const { status, links } = await this . request < requestData , responseBody > ( {
155
94
method : "POST" ,
156
- url : `${ this . sdkConfig . paypalApiDomain } /v2/payments/payment` ,
95
+ url : `https://te-test-qa.qa.paypal.com:12326 /v2/payments/payment` ,
157
96
data ,
158
97
accessToken : this . sdkConfig . authenticationToken ,
159
98
} ) ;
160
99
161
100
let responseStatus = false ;
162
- console . log ( links ) ;
163
101
if ( status === "PAYER_ACTION_REQUIRED" ) {
164
102
this . authenticationURL = links . find (
165
103
( link ) => link . rel === "payer-action"
166
104
) . href ;
167
105
responseStatus = true ;
106
+ this . threeDSIframe = getThreeDomainSecureComponent (
107
+ this . authenticationURL
108
+ ) ;
168
109
}
169
110
return responseStatus ;
170
111
} catch ( error ) {
@@ -173,69 +114,47 @@ export class ThreeDomainSecureComponent {
173
114
}
174
115
}
175
116
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 ( ) ;
229
130
} ) ;
131
+ } ;
230
132
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
+ // }
237
140
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
+ } ,
239
151
} ) ;
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 ) ;
240
159
}
241
160
}
0 commit comments