@@ -71,6 +71,11 @@ export class ThreeDSecure extends RiskConcern {
71
71
'05' : { height : '100%' , width : '100%' }
72
72
}
73
73
74
+ static VALID_ACTION_TOKEN_TYPES = [
75
+ 'three_d_secure_action' ,
76
+ 'three_d_secure_proactive_action'
77
+ ] ;
78
+
74
79
/**
75
80
* Returns a strateggy for a given gateway type
76
81
*
@@ -94,18 +99,32 @@ export class ThreeDSecure extends RiskConcern {
94
99
* @param {Preflights } options.preflights
95
100
* @return {Promise }
96
101
*/
97
- static preflight ( { recurly, number, month, year, preflights } ) {
102
+ static preflight ( { recurly, number, month, year, cvv , preflights } ) {
98
103
return preflights . reduce ( ( preflight , result ) => {
99
104
return preflight . then ( ( finishedPreflights ) => {
100
- const { type } = result . gateway ;
105
+ const { type : gatewayType } = result . gateway ;
101
106
const { gateway_code } = result . params ;
102
- const strategy = ThreeDSecure . getStrategyForGatewayType ( type ) ;
103
- return strategy . preflight ( { recurly, number, month, year, ...result . params } )
104
- . then ( results => {
105
- return finishedPreflights . concat ( [ { processor : type , gateway_code, results } ] ) ;
107
+ const strategy = ThreeDSecure . getStrategyForGatewayType ( gatewayType ) ;
108
+ return strategy . preflight ( { recurly, number, month, year, cvv, ...result . params } )
109
+ . then ( ( { results, tokenType } ) => {
110
+ // return finishedPreflights.concat([{ processor: type, gateway_code, results}]);
111
+ return {
112
+ tokenType : finishedPreflights . tokenType || tokenType ,
113
+ // risk: {
114
+ // processor: gatewayType,
115
+ // gateway_code,
116
+ // risk
117
+ // // finishedPreflights.risk.concat(risk)
118
+ // }
119
+ risk : finishedPreflights . risk . concat ( {
120
+ processor : gatewayType ,
121
+ gateway_code,
122
+ results
123
+ } )
124
+ } ;
106
125
} ) ;
107
126
} ) ;
108
- } , Promise . resolve ( [ ] ) ) ;
127
+ } , Promise . resolve ( { risk : [ ] } ) ) ;
109
128
}
110
129
111
130
constructor ( { risk, actionTokenId, challengeWindowSize } ) {
@@ -183,6 +202,7 @@ export class ThreeDSecure extends RiskConcern {
183
202
three_d_secure_action_token_id : this . actionTokenId ,
184
203
results
185
204
} ;
205
+
186
206
debug ( 'submitting results for tokenization' , data ) ;
187
207
return this . recurly . request . post ( { route : '/tokens' , data } ) ;
188
208
}
@@ -219,6 +239,10 @@ export class ThreeDSecure extends RiskConcern {
219
239
}
220
240
221
241
function assertIsActionToken ( token ) {
222
- if ( token && token . type === 'three_d_secure_action' ) return ;
223
- throw errors ( 'invalid-option' , { name : 'actionTokenId' , expect : 'a three_d_secure_action_token_id' } ) ;
242
+ if ( ThreeDSecure . VALID_ACTION_TOKEN_TYPES . includes ( token ?. type ) ) return ;
243
+
244
+ throw errors ( 'invalid-option' , {
245
+ name : 'actionTokenId' ,
246
+ expect : `a token of type: ${ ThreeDSecure . VALID_ACTION_TOKEN_TYPES . join ( ',' ) } `
247
+ } ) ;
224
248
}
0 commit comments