1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable no-empty-function */
3
+
1
4
import PayTheoryHostedField from '../pay-theory-hosted-field' ;
2
5
import common from '../../common' ;
3
6
import {
@@ -87,7 +90,7 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
87
90
protected _completed = false ;
88
91
89
92
// Used to track if the element was the one that was used when transact was called
90
- protected _isTransactingElement : boolean = false ;
93
+ protected _isTransactingElement = false ;
91
94
92
95
// Used to track if the element is ready to communicate with the transacting iframe
93
96
protected _isReady = false ;
@@ -249,30 +252,33 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
249
252
}
250
253
}
251
254
252
- async connectedCallback ( ) {
255
+ connectedCallback ( ) {
253
256
// Set up a listener for the hosted field to message saying it is ready for the pt-token to be sent
254
257
this . _removeHostTokenListener = common . handleHostedFieldMessage (
255
- // @ts -ignore
256
258
( event : { type : unknown ; element : ElementTypes } ) => {
257
259
return (
258
260
event . type === 'pt-static:pt_token_ready' &&
259
261
this . _transactingIFrameId . includes ( event . element )
260
262
) ;
261
263
} ,
262
- this . sendPtToken ,
264
+ ( ) => this . sendPtToken ( ) ,
263
265
) ;
264
266
265
267
this . _removeFeeListener = common . handleHostedFieldMessage (
266
268
( event : { type : unknown } ) => event . type === 'pt-static:calculated_fee' ,
267
- this . handleFeeMessage ,
269
+ ( message : {
270
+ type : string ;
271
+ body : { fee : number ; payment_type : string } ;
272
+ field : ElementTypes ;
273
+ } ) => this . handleFeeMessage ( message ) ,
268
274
) ;
269
275
270
276
this . _removeFeeCalcReconnect = common . handleHostedFieldMessage (
271
277
( event : { type : unknown } ) => event . type === 'pt-static:fee_calc_reconnect' ,
272
- this . handleFeeCalcReconnect ,
278
+ ( message : { type : string ; field : ElementTypes } ) => this . handleFeeCalcReconnect ( message ) ,
273
279
) ;
274
280
275
- await super . connectedCallback ( ) ;
281
+ super . connectedCallback ( ) ;
276
282
}
277
283
278
284
disconnectedCallback ( ) {
@@ -286,7 +292,6 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
286
292
data . fee_mode = data . fee_mode ?? this . _feeMode ?? defaultFeeMode ;
287
293
data . metadata = data . metadata ?? this . _metadata ;
288
294
this . _isTransactingElement = true ;
289
- // @ts -ignore
290
295
const response = await common . sendTransactingMessage ( element , data . payTheoryData . billing_info ) ;
291
296
if ( response . type === ERROR_STEP ) {
292
297
this . _isTransactingElement = false ;
@@ -334,7 +339,7 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
334
339
common . hostedFieldsEndpoint ,
335
340
) ;
336
341
const result = await this . resetToken ( ) ;
337
- if ( result ) {
342
+ if ( result . type === ResponseMessageTypes . READY ) {
338
343
this . _isTransactingElement = false ;
339
344
this . initialized = false ;
340
345
// Successfully sent the cancel message and reset the token
@@ -355,7 +360,6 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
355
360
) : Promise < TokenizedPaymentMethodMessage | ErrorMessage > {
356
361
this . _isTransactingElement = true ;
357
362
this . _initialized = true ;
358
- // @ts -ignore
359
363
const response = await common . sendTransactingMessage ( element , data . billingInfo ) ;
360
364
if ( response . type === ERROR_STEP ) {
361
365
this . _isTransactingElement = false ;
0 commit comments