@@ -2,6 +2,7 @@ import nock from "nock";
2
2
import { createClient } from "../__mocks__/base" ;
3
3
import { paymentMethodsSuccess } from "../__mocks__/checkout/paymentMethodsSuccess" ;
4
4
import { paymentsSuccess } from "../__mocks__/checkout/paymentsSuccess" ;
5
+ import { paymentsRedirectAction } from "../__mocks__/checkout/paymentsRedirectAction" ;
5
6
import { paymentDetailsSuccess } from "../__mocks__/checkout/paymentsDetailsSuccess" ;
6
7
// import {paymentSessionSuccess} from "../__mocks__/checkout/paymentSessionSucess";
7
8
import { originKeysSuccess } from "../__mocks__/checkout/originkeysSuccess" ;
@@ -14,6 +15,7 @@ import HttpClientException from "../httpClient/httpClientException";
14
15
import { checkout } from "../typings" ;
15
16
import { IRequest } from "../typings/requestOptions" ;
16
17
import { SessionResultResponse } from "../typings/checkout/sessionResultResponse" ;
18
+ import { payments3DS2NativeAction } from "../__mocks__/checkout/payments3DS2NativeAction" ;
17
19
18
20
const merchantAccount = process . env . ADYEN_MERCHANT ! ;
19
21
const reference = "Your order number" ;
@@ -79,8 +81,11 @@ function getPaymentLinkSuccess(expiresAt: Date): checkout.PaymentLinkResponse {
79
81
url : "PaymentLinkResponse.url" ,
80
82
id : "mocked_id" ,
81
83
merchantAccount,
82
- status : checkout . PaymentLinkResponse . StatusEnum . Active
83
- } ;
84
+ status : checkout . PaymentLinkResponse . StatusEnum . Active ,
85
+ requiredShopperFields : [
86
+ checkout . PaymentLinkResponse . RequiredShopperFieldsEnum . BillingAddress ,
87
+ checkout . PaymentLinkResponse . RequiredShopperFieldsEnum . ShopperEmail ]
88
+ } ;
84
89
}
85
90
86
91
function createPaymentLinkRequest ( ) : checkout . PaymentLinkRequest {
@@ -108,7 +113,10 @@ function createPaymentLinkRequest(): checkout.PaymentLinkRequest {
108
113
country : "BR" ,
109
114
stateOrProvince : "SP"
110
115
} ,
111
- reference
116
+ reference,
117
+ requiredShopperFields : [
118
+ checkout . PaymentLinkRequest . RequiredShopperFieldsEnum . BillingAddress ,
119
+ checkout . PaymentLinkRequest . RequiredShopperFieldsEnum . ShopperEmail ]
112
120
} ;
113
121
}
114
122
@@ -154,7 +162,7 @@ describe("Checkout", (): void => {
154
162
"returnUrl": "https://your-company.com/...",
155
163
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
156
164
}` ) ;
157
- const paymentRequest : checkout . PaymentRequest = await checkout . ObjectSerializer . deserialize ( requestJson , "PaymentRequest" ) ;
165
+ const paymentRequest : checkout . PaymentRequest = await checkout . ObjectSerializer . deserialize ( requestJson , "PaymentRequest" , " ") ;
158
166
expect ( paymentRequest . returnUrl ) . toEqual ( "https://your-company.com/..." ) ;
159
167
expect ( paymentRequest . amount . value ) . toBe ( 1000 ) ;
160
168
const paymentMethodDetails : checkout . ApplePayDetails = paymentRequest . paymentMethod as checkout . ApplePayDetails ;
@@ -239,7 +247,6 @@ describe("Checkout", (): void => {
239
247
240
248
} ) ;
241
249
242
-
243
250
test ( "should make a payment." , async ( ) : Promise < void > => {
244
251
scope . post ( "/payments" )
245
252
. reply ( 200 , paymentsSuccess ) ;
@@ -311,7 +318,7 @@ describe("Checkout", (): void => {
311
318
}
312
319
} ) ;
313
320
314
- test ( "should have valid payment link" , async ( ) : Promise < void > => {
321
+ test ( "should create valid payment link" , async ( ) : Promise < void > => {
315
322
const expiresAt = "2019-12-17T10:05:29Z" ;
316
323
const paymentLinkSuccess : checkout . PaymentLinkResponse = getPaymentLinkSuccess ( new Date ( expiresAt ) ) ;
317
324
@@ -321,6 +328,28 @@ describe("Checkout", (): void => {
321
328
expect ( paymentSuccessLinkResponse ) . toBeTruthy ( ) ;
322
329
} ) ;
323
330
331
+ test ( "should create valid payment link with installmentOptions" , async ( ) : Promise < void > => {
332
+ const expiresAt = "2019-12-17T10:05:29Z" ;
333
+ const paymentLinkSuccess : checkout . PaymentLinkResponse = getPaymentLinkSuccess ( new Date ( expiresAt ) ) ;
334
+
335
+ scope . post ( "/paymentLinks" ) . reply ( 200 , paymentLinkSuccess ) ;
336
+
337
+ const request : checkout . PaymentLinkRequest = createPaymentLinkRequest ( ) ;
338
+ request . installmentOptions = {
339
+ card : {
340
+ plans : [
341
+ checkout . CheckoutSessionInstallmentOption . PlansEnum . Bonus ,
342
+ checkout . CheckoutSessionInstallmentOption . PlansEnum . BuynowPaylater
343
+ ]
344
+ }
345
+ } ;
346
+ const paymentSuccessLinkResponse = await checkoutService . PaymentLinksApi . paymentLinks ( request ) ;
347
+ expect ( paymentSuccessLinkResponse ) . toBeTruthy ( ) ;
348
+ expect ( paymentSuccessLinkResponse . id ) . toBeTruthy ( ) ;
349
+ expect ( paymentSuccessLinkResponse . id ) . toBe ( "mocked_id" ) ;
350
+ expect ( paymentSuccessLinkResponse . requiredShopperFields ?. length ) . toBe ( 2 ) ;
351
+ } ) ;
352
+
324
353
test ( "should get payment link" , async ( ) : Promise < void > => {
325
354
const expiresAt = "2019-12-17T10:05:29Z" ;
326
355
const paymentLinkSuccess : checkout . PaymentLinkResponse = getPaymentLinkSuccess ( new Date ( expiresAt ) ) ;
@@ -401,6 +430,46 @@ describe("Checkout", (): void => {
401
430
expect ( paymentsResponse . additionalData ) . toBeTruthy ( ) ;
402
431
} ) ;
403
432
433
+ test ( "should return shopper redirect with a card payment." , async ( ) : Promise < void > => {
434
+ scope . post ( "/payments" )
435
+ . reply ( 200 , paymentsRedirectAction ) ;
436
+
437
+ const paymentsRequest : checkout . PaymentRequest = createPaymentsCheckoutRequest ( ) ;
438
+ const paymentsResponse : checkout . PaymentResponse = await checkoutService . PaymentsApi . payments ( paymentsRequest ) ;
439
+
440
+ expect ( paymentsResponse . pspReference ) . toBeTruthy ( ) ;
441
+ expect ( paymentsResponse . resultCode ) . toBeTruthy ( ) ;
442
+ expect ( paymentsResponse . resultCode ) . toEqual ( "RedirectShopper" ) ;
443
+ expect ( paymentsResponse . action ) . toBeTruthy ( ) ;
444
+ // check type redirect
445
+ expect ( paymentsResponse . action ?. type ) . toBeTruthy ( ) ;
446
+ expect ( paymentsResponse . action ?. type ) . toEqual ( "redirect" ) ;
447
+ // TODO check action is polymorphic
448
+ //expect(paymentsResponse.action).toBeInstanceOf(CheckoutRedirectAction);
449
+ //expect(paymentsResponse.action?.url).toBe("https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS/redirect...");
450
+
451
+ } ) ;
452
+
453
+ test ( "should return Native 3DS2 with a card payment." , async ( ) : Promise < void > => {
454
+ scope . post ( "/payments" )
455
+ . reply ( 200 , payments3DS2NativeAction ) ;
456
+
457
+ const paymentsRequest : checkout . PaymentRequest = createPaymentsCheckoutRequest ( ) ;
458
+ const paymentsResponse : checkout . PaymentResponse = await checkoutService . PaymentsApi . payments ( paymentsRequest ) ;
459
+
460
+ expect ( paymentsResponse . pspReference ) . toBeTruthy ( ) ;
461
+ expect ( paymentsResponse . resultCode ) . toBeTruthy ( ) ;
462
+ expect ( paymentsResponse . resultCode ) . toEqual ( "IdentifyShopper" ) ;
463
+ expect ( paymentsResponse . action ) . toBeTruthy ( ) ;
464
+ // check type threeDS2
465
+ expect ( paymentsResponse . action ?. type ) . toBeTruthy ( ) ;
466
+ expect ( paymentsResponse . action ?. type ) . toEqual ( "threeDS2" ) ;
467
+ // TODO check action is polymorphic
468
+ //expect(paymentsResponse.action).toBeInstanceOf(CheckoutThreeDS2Action);
469
+ //expect(paymentsResponse.action?.subtype).toEqual("threeDS2");
470
+
471
+ } ) ;
472
+
404
473
test ( "should get origin keys" , async ( ) : Promise < void > => {
405
474
const checkoutUtility = new CheckoutAPI ( client ) ;
406
475
const originKeysRequest : checkout . UtilityRequest = {
@@ -508,6 +577,25 @@ describe("Checkout", (): void => {
508
577
expect ( sessionsResponse . expiresAt . getFullYear ( ) ) . toBeGreaterThan ( 0 ) ;
509
578
} ) ;
510
579
580
+ test ( "should create a session with installmentOptions." , async ( ) : Promise < void > => {
581
+ scope . post ( "/sessions" )
582
+ . reply ( 200 , sessionsSuccess ) ;
583
+
584
+ const sessionsRequest : checkout . CreateCheckoutSessionRequest = createSessionRequest ( ) ;
585
+ sessionsRequest . installmentOptions = {
586
+ card : {
587
+ plans : [
588
+ checkout . CheckoutSessionInstallmentOption . PlansEnum . Bonus ,
589
+ checkout . CheckoutSessionInstallmentOption . PlansEnum . BuynowPaylater
590
+ ]
591
+ }
592
+ } ;
593
+ const sessionsResponse : checkout . CreateCheckoutSessionResponse = await checkoutService . PaymentsApi . sessions ( sessionsRequest ) ;
594
+ expect ( sessionsResponse . sessionData ) . toBeTruthy ( ) ;
595
+ expect ( sessionsResponse . expiresAt ) . toBeInstanceOf ( Date ) ;
596
+ expect ( sessionsResponse . expiresAt . getFullYear ( ) ) . toBeGreaterThan ( 0 ) ;
597
+ } ) ;
598
+
511
599
test ( "Should get card details" , async ( ) : Promise < void > => {
512
600
scope . post ( "/cardDetails" )
513
601
. reply ( 200 , {
0 commit comments