@@ -15,6 +15,7 @@ import { SessionResultResponse } from "../typings/checkout/sessionResultResponse
1515import { payments3DS2NativeAction } from "../__mocks__/checkout/payments3DS2NativeAction" ;
1616import { EnvironmentEnum } from "../config" ;
1717import { Types } from ".." ;
18+ import forwardResponse from "../__mocks__/checkout/forwardResponse.json" ;
1819
1920const merchantAccount = process . env . ADYEN_MERCHANT ! ;
2021const reference = "Your order number" ;
@@ -683,4 +684,48 @@ describe("Checkout", (): void => {
683684 expect ( resultOfPaymentSessionResponse . id ) . toEqual ( "CS12345678" ) ;
684685 expect ( resultOfPaymentSessionResponse . status ) . toEqual ( SessionResultResponse . StatusEnum . Completed ) ;
685686 } ) ;
687+
688+ test ( "Should forward token" , async ( ) : Promise < void > => {
689+ scope . post ( "/forward" )
690+ . reply ( 200 , forwardResponse ) ;
691+
692+ const body = {
693+ amount : {
694+ value : 100 ,
695+ currency : "USD"
696+ } ,
697+ paymentMethod : {
698+ creditCard : {
699+ holderName : "{{holderName}}" ,
700+ number : "{{number}}" ,
701+ expiryMonth : "{{expiryMonth}}" ,
702+ expiryYear : "{{expiryYear}}"
703+ }
704+ }
705+ } ;
706+
707+ const checkoutForwardRequest : Types . checkout . CheckoutForwardRequest = {
708+ merchantAccount : "YOUR_MERCHANT_ACCOUNT" ,
709+ shopperReference : "YOUR_SHOPPER_REFERENCE" ,
710+ storedPaymentMethodId : "M12345677890" ,
711+ baseUrl : "http://thirdparty.example.com" ,
712+ request : {
713+ httpMethod : Types . checkout . CheckoutOutgoingForwardRequest . HttpMethodEnum . Post ,
714+ urlSuffix : "/payments" ,
715+ credentials : "YOUR_CREDENTIALS_FOR_THE_THIRD_PARTY" ,
716+ headers : {
717+ "Authorization" : "Basic {{credentials}}" ,
718+ } ,
719+ body : JSON . stringify ( body ) ,
720+ }
721+ } ;
722+
723+ const response : Types . checkout . CheckoutForwardResponse = await checkoutService . RecurringApi . forward ( checkoutForwardRequest ) ;
724+
725+ expect ( response . pspReference ) . toEqual ( "PSP123456789" ) ;
726+ expect ( response . storedPaymentMethodId ) . toEqual ( "PAYMENT_METHOD_ID" ) ;
727+ expect ( response . response ) . toBeDefined ( ) ;
728+ expect ( response . response . status ) . toEqual ( 200 ) ;
729+ expect ( response . response . body ) . toContain ( "PAYMENT_METHOD_ID" ) ;
730+ } ) ;
686731} ) ;
0 commit comments