@@ -33,6 +33,7 @@ import {
33
33
import { getShippingAddress } from '../../../shipping/shipping-addresses.mock' ;
34
34
import { PaymentArgumentInvalidError } from '../../errors' ;
35
35
import PaymentActionCreator from '../../payment-action-creator' ;
36
+ import PaymentMethod from '../../payment-method' ;
36
37
import PaymentMethodActionCreator from '../../payment-method-action-creator' ;
37
38
import { getPaymentMethodsState , getStripeV3 } from '../../payment-methods.mock' ;
38
39
import PaymentRequestTransformer from '../../payment-request-transformer' ;
@@ -136,6 +137,7 @@ describe('StripeV3PaymentStrategy', () => {
136
137
137
138
describe ( '#execute' , ( ) => {
138
139
let stripeV3Options : PaymentInitializeOptions ;
140
+ let paymentMethodMock : PaymentMethod ;
139
141
const stripeV3JsMock = getStripeV3JsMock ( ) ;
140
142
141
143
beforeEach ( ( ) => {
@@ -145,12 +147,6 @@ describe('StripeV3PaymentStrategy', () => {
145
147
jest . spyOn ( paymentMethodActionCreator , 'loadPaymentMethod' ) . mockReturnValue ( Promise . resolve ( ) ) ;
146
148
jest . spyOn ( orderActionCreator , 'submitOrder' ) . mockReturnValue ( Promise . resolve ( ) ) ;
147
149
jest . spyOn ( paymentActionCreator , 'submitPayment' ) . mockReturnValue ( Promise . resolve ( ) ) ;
148
- jest . spyOn ( paymentRequestSender , 'generatePaymentIntent' )
149
- . mockReturnValue ( Promise . resolve ( {
150
- body : {
151
- client_token : 'paymentIntent' ,
152
- } ,
153
- } ) ) ;
154
150
jest . spyOn ( paymentRequestTransformer , 'transform' ) . mockReturnValue ( {
155
151
state : 'state' ,
156
152
} ) ;
@@ -178,7 +174,7 @@ describe('StripeV3PaymentStrategy', () => {
178
174
expect ( stripeV3JsMock . handleCardPayment ) . toHaveBeenCalled ( ) ;
179
175
expect ( stripeV3JsMock . createPaymentMethod ) . toHaveBeenCalled ( ) ;
180
176
expect ( orderActionCreator . submitOrder ) . toHaveBeenCalled ( ) ;
181
- expect ( paymentRequestSender . generatePaymentIntent ) . toHaveBeenCalled ( ) ;
177
+ expect ( paymentMethodActionCreator . loadPaymentMethod ) . toHaveBeenCalled ( ) ;
182
178
expect ( paymentActionCreator . submitPayment ) . toHaveBeenCalled ( ) ;
183
179
expect ( response ) . toBe ( store . getState ( ) ) ;
184
180
} ) ;
@@ -294,6 +290,36 @@ describe('StripeV3PaymentStrategy', () => {
294
290
return expect ( response ) . rejects . toThrow ( StandardError ) ;
295
291
} ) ;
296
292
293
+ it ( 'throws an error when ClientToken is undefined' , async ( ) => {
294
+ paymentMethodMock = {
295
+ ...getStripeV3 ( ) ,
296
+ clientToken : undefined ,
297
+ initializationData : {
298
+ stripePublishableKey : 'key' ,
299
+ } ,
300
+ } ;
301
+ stripeV3JsMock . handleCardPayment = jest . fn (
302
+ ( ) => Promise . resolve ( getStripeV3HandleCardResponse ( ) )
303
+ ) ;
304
+
305
+ stripeV3JsMock . createPaymentMethod = jest . fn (
306
+ ( ) => Promise . resolve ( {
307
+ paymentMethod : {
308
+ id : 'paymentMethod' ,
309
+ } ,
310
+ } )
311
+ ) ;
312
+
313
+ jest . spyOn ( store . getState ( ) . paymentMethods , 'getPaymentMethod' )
314
+ . mockReturnValue ( paymentMethodMock ) ;
315
+ jest . spyOn ( stripeScriptLoader , 'load' ) . mockReturnValue ( Promise . resolve ( stripeV3JsMock ) ) ;
316
+
317
+ await strategy . initialize ( stripeV3Options ) ;
318
+ const response = strategy . execute ( getStripeV3OrderRequestBodyMock ( ) ) ;
319
+
320
+ return expect ( response ) . rejects . toThrow ( MissingDataError ) ;
321
+ } ) ;
322
+
297
323
it ( 'creates the order and submit payment with a signed user' , async ( ) => {
298
324
const elements = stripeV3JsMock . elements ( ) ;
299
325
const cardElement = elements . create ( 'card' , { } ) ;
@@ -326,14 +352,14 @@ describe('StripeV3PaymentStrategy', () => {
326
352
getStripePaymentMethodOptionsWithSignedUser ( )
327
353
) ;
328
354
expect ( stripeV3JsMock . handleCardPayment ) . toHaveBeenCalledWith (
329
- 'paymentIntent ' ,
355
+ 'clientToken ' ,
330
356
{
331
357
...getStripeCardPaymentOptionsWithSignedUser ( ) ,
332
358
payment_method : 'paymentMethod' ,
333
359
}
334
360
) ;
335
361
expect ( orderActionCreator . submitOrder ) . toHaveBeenCalled ( ) ;
336
- expect ( paymentRequestSender . generatePaymentIntent ) . toHaveBeenCalled ( ) ;
362
+ expect ( paymentMethodActionCreator . loadPaymentMethod ) . toHaveBeenCalled ( ) ;
337
363
expect ( paymentActionCreator . submitPayment ) . toHaveBeenCalled ( ) ;
338
364
expect ( response ) . toBe ( store . getState ( ) ) ;
339
365
} ) ;
@@ -371,14 +397,14 @@ describe('StripeV3PaymentStrategy', () => {
371
397
getStripePaymentMethodOptionsWithGuestUser ( )
372
398
) ;
373
399
expect ( stripeV3JsMock . handleCardPayment ) . toHaveBeenCalledWith (
374
- 'paymentIntent ' ,
400
+ 'clientToken ' ,
375
401
{
376
402
...getStripeCardPaymentOptionsWithGuestUser ( ) ,
377
403
payment_method : 'paymentMethod' ,
378
404
}
379
405
) ;
380
406
expect ( orderActionCreator . submitOrder ) . toHaveBeenCalled ( ) ;
381
- expect ( paymentRequestSender . generatePaymentIntent ) . toHaveBeenCalled ( ) ;
407
+ expect ( paymentMethodActionCreator . loadPaymentMethod ) . toHaveBeenCalled ( ) ;
382
408
expect ( paymentActionCreator . submitPayment ) . toHaveBeenCalled ( ) ;
383
409
expect ( response ) . toBe ( store . getState ( ) ) ;
384
410
} ) ;
@@ -416,14 +442,14 @@ describe('StripeV3PaymentStrategy', () => {
416
442
getStripePaymentMethodOptionsWithGuestUserWithoutAddress ( )
417
443
) ;
418
444
expect ( stripeV3JsMock . handleCardPayment ) . toHaveBeenCalledWith (
419
- 'paymentIntent ' ,
445
+ 'clientToken ' ,
420
446
{
421
447
...getStripeCardPaymentOptionsWithGuestUserWithoutAddress ( ) ,
422
448
payment_method : 'paymentMethod' ,
423
449
}
424
450
) ;
425
451
expect ( orderActionCreator . submitOrder ) . toHaveBeenCalled ( ) ;
426
- expect ( paymentRequestSender . generatePaymentIntent ) . toHaveBeenCalled ( ) ;
452
+ expect ( paymentMethodActionCreator . loadPaymentMethod ) . toHaveBeenCalled ( ) ;
427
453
expect ( paymentActionCreator . submitPayment ) . toHaveBeenCalled ( ) ;
428
454
expect ( response ) . toBe ( store . getState ( ) ) ;
429
455
} ) ;
@@ -463,14 +489,14 @@ describe('StripeV3PaymentStrategy', () => {
463
489
getStripePaymentMethodOptionsWithGuestUser ( )
464
490
) ;
465
491
expect ( stripeV3JsMock . handleCardPayment ) . toHaveBeenCalledWith (
466
- 'paymentIntent ' ,
492
+ 'clientToken ' ,
467
493
{
468
494
...getStripeCardPaymentOptionsWithGuestUser ( ) ,
469
495
payment_method : 'paymentMethod' ,
470
496
}
471
497
) ;
472
498
expect ( orderActionCreator . submitOrder ) . toHaveBeenCalled ( ) ;
473
- expect ( paymentRequestSender . generatePaymentIntent ) . toHaveBeenCalled ( ) ;
499
+ expect ( paymentMethodActionCreator . loadPaymentMethod ) . toHaveBeenCalled ( ) ;
474
500
expect ( paymentActionCreator . submitPayment ) . toHaveBeenCalled ( ) ;
475
501
expect ( response ) . toBe ( store . getState ( ) ) ;
476
502
} ) ;
0 commit comments