@@ -28,26 +28,20 @@ import {paymentSessionSuccess} from "../__mocks__/checkout/paymentSessionSucess"
2828import { paymentsResultMultibancoSuccess } from "../__mocks__/checkout/paymentsResultMultibancoSuccess" ;
2929import { paymentsResultSuccess } from "../__mocks__/checkout/paymentsResultSucess" ;
3030import Client from "../client" ;
31- import { TYPE_SCHEME } from "../typings/constants/apiConstants" ;
3231import Checkout from "../services/checkout" ;
33- import {
34- Amount ,
35- DetailsRequest ,
36- PaymentMethodsRequest ,
37- PaymentRequest ,
38- PaymentResponse ,
39- PaymentSetupRequest , PaymentVerificationRequest
40- } from "../typings/checkout" ;
4132import HttpClientException from "../httpClient/httpClientException" ;
4233
43- function createAmountObject ( currency : string , value : number ) : Amount {
34+ const merchantAccount = "MagentoMerchantTest" ;
35+ const reference = "Your order number" ;
36+
37+ function createAmountObject ( currency : string , value : number ) : ICheckout . Amount {
4438 return {
4539 currency,
4640 value,
4741 } ;
4842}
4943
50- function createPaymentsDetailsRequest ( ) : DetailsRequest {
44+ function createPaymentsDetailsRequest ( ) : ICheckout . DetailsRequest {
5145 return {
5246 details : {
5347 MD : "mdValue" ,
@@ -57,31 +51,31 @@ function createPaymentsDetailsRequest(): DetailsRequest {
5751 } ;
5852}
5953
60- export function createPaymentsCheckoutRequest ( ) : PaymentRequest {
54+ export function createPaymentsCheckoutRequest ( ) : ICheckout . PaymentRequest {
6155 const paymentMethodDetails = {
6256 cvc : "737" ,
6357 expiryMonth : "10" ,
6458 expiryYear : "2018" ,
6559 holderName : "John Smith" ,
6660 number : "4111111111111111" ,
67- type : TYPE_SCHEME ,
61+ type : "scheme" ,
6862 } ;
6963
7064 return {
7165 amount : createAmountObject ( "USD" , 1000 ) ,
72- merchantAccount : "MagentoMerchantTest" ,
66+ merchantAccount,
7367 paymentMethod : paymentMethodDetails ,
74- reference : "Your order number" ,
68+ reference,
7569 returnUrl : "https://your-company.com/..." ,
7670 } ;
7771}
7872
79- function createPaymentSessionRequest ( ) : PaymentSetupRequest {
73+ function createPaymentSessionRequest ( ) : ICheckout . PaymentSetupRequest {
8074 return {
8175 amount : createAmountObject ( "USD" , 1000 ) ,
8276 countryCode : "NL" ,
83- merchantAccount : "MagentoMerchantTest" ,
84- reference : "Your order number" ,
77+ merchantAccount,
78+ reference,
8579 returnUrl : "https://your-company.com/..." ,
8680 } ;
8781}
@@ -101,8 +95,8 @@ describe("Checkout", (): void => {
10195 scope . post ( "/payments" )
10296 . reply ( 200 , paymentsSuccess ) ;
10397
104- const paymentsRequest : PaymentRequest = createPaymentsCheckoutRequest ( ) ;
105- const paymentsResponse : PaymentResponse = await checkout . payments ( paymentsRequest ) ;
98+ const paymentsRequest : ICheckout . PaymentRequest = createPaymentsCheckoutRequest ( ) ;
99+ const paymentsResponse : ICheckout . PaymentResponse = await checkout . payments ( paymentsRequest ) ;
106100 expect ( paymentsResponse . pspReference ) . toEqual ( "8535296650153317" ) ;
107101 } ) ;
108102
@@ -111,15 +105,15 @@ describe("Checkout", (): void => {
111105 scope . post ( "/payments" )
112106 . reply ( 401 ) ;
113107
114- const paymentsRequest : PaymentRequest = createPaymentsCheckoutRequest ( ) ;
108+ const paymentsRequest : ICheckout . PaymentRequest = createPaymentsCheckoutRequest ( ) ;
115109 await checkout . payments ( paymentsRequest ) ;
116110 } catch ( e ) {
117111 expect ( e instanceof HttpClientException ) . toBeTruthy ( ) ;
118112 }
119113 } ) ;
120114
121115 it ( "should have valid payment methods" , async ( ) : Promise < void > => {
122- const paymentMethodsRequest : PaymentMethodsRequest = { merchantAccount : "MagentoMerchantTest" } ;
116+ const paymentMethodsRequest : ICheckout . PaymentMethodsRequest = { merchantAccount : "MagentoMerchantTest" } ;
123117
124118 scope . post ( "/paymentMethods" )
125119 . reply ( 200 , paymentMethodsSuccess ) ;
@@ -133,6 +127,50 @@ describe("Checkout", (): void => {
133127 }
134128 } ) ;
135129
130+ it ( "should have valid payment link" , async ( ) : Promise < void > => {
131+ const amount = createAmountObject ( "BRL" , 1000 ) ;
132+ const expiresAt = "2019-12-17T10:05:29Z" ;
133+ const paymentLinkRequest : ICheckout . CreatePaymentLinkRequest = {
134+ allowedPaymentMethods : [ "scheme" , "boletobancario" ] ,
135+ amount,
136+ countryCode : "BR" ,
137+ merchantAccount,
138+ shopperReference : "shopperReference" ,
139+ shopperEmail : "test@email.com" ,
140+ shopperLocale : "pt_BR" ,
141+ billingAddress : {
142+ street : "Roque Petroni Jr" ,
143+ postalCode : "59000060" ,
144+ city : "São Paulo" ,
145+ houseNumberOrName : "999" ,
146+ country : "BR" ,
147+ stateOrProvince : "SP"
148+ } ,
149+ deliveryAddress : {
150+ street : "Roque Petroni Jr" ,
151+ postalCode : "59000060" ,
152+ city : "São Paulo" ,
153+ houseNumberOrName : "999" ,
154+ country : "BR" ,
155+ stateOrProvince : "SP"
156+ } ,
157+ expiresAt,
158+ reference
159+ } ;
160+
161+ const paymentLinkSuccess : ICheckout . CreatePaymentLinkResponse = {
162+ amount,
163+ expiresAt,
164+ reference,
165+ url : "paymentLinkResponse.url"
166+ } ;
167+
168+ scope . post ( "/paymentLinks" ) . reply ( 200 , paymentLinkSuccess ) ;
169+
170+ const paymentSuccessLinkResponse = await checkout . paymentLinks ( paymentLinkRequest ) ;
171+ expect ( paymentLinkSuccess ) . toEqual ( paymentSuccessLinkResponse ) ;
172+ } ) ;
173+
136174 it ( "should have payment details" , async ( ) : Promise < void > => {
137175 scope . post ( "/payments/details" )
138176 . reply ( 200 , paymentDetailsSuccess ) ;
@@ -146,7 +184,7 @@ describe("Checkout", (): void => {
146184 scope . post ( "/paymentSession" )
147185 . reply ( 200 , paymentSessionSuccess ) ;
148186 const checkout : Checkout = new Checkout ( client ) ;
149- const paymentSessionRequest : PaymentSetupRequest = createPaymentSessionRequest ( ) ;
187+ const paymentSessionRequest : ICheckout . PaymentSetupRequest = createPaymentSessionRequest ( ) ;
150188 const paymentSessionResponse = await checkout . paymentSession ( paymentSessionRequest ) ;
151189 expect ( paymentSessionResponse . paymentSession ) . not . toBeUndefined ( ) ;
152190 } ) ;
@@ -156,7 +194,7 @@ describe("Checkout", (): void => {
156194 scope . post ( "/payments/result" )
157195 . reply ( 200 , paymentsResultSuccess ) ;
158196 const checkout = new Checkout ( client ) ;
159- const paymentResultRequest : PaymentVerificationRequest = {
197+ const paymentResultRequest : ICheckout . PaymentVerificationRequest = {
160198 payload : "This is a test payload" ,
161199 } ;
162200 const paymentResultResponse = await checkout . paymentResult ( paymentResultRequest ) ;
@@ -180,8 +218,8 @@ describe("Checkout", (): void => {
180218 . reply ( 200 , paymentsResultMultibancoSuccess ) ;
181219
182220 const checkout : Checkout = new Checkout ( client ) ;
183- const paymentsRequest : PaymentRequest = createPaymentsCheckoutRequest ( ) ;
184- const paymentsResponse : PaymentResponse = await checkout . payments ( paymentsRequest ) ;
221+ const paymentsRequest : ICheckout . PaymentRequest = createPaymentsCheckoutRequest ( ) ;
222+ const paymentsResponse : ICheckout . PaymentResponse = await checkout . payments ( paymentsRequest ) ;
185223 expect ( paymentsResponse . pspReference ) . toEqual ( "8111111111111111" ) ;
186224
187225 if ( paymentsResponse . additionalData ) {
0 commit comments