@@ -34,6 +34,7 @@ describe('PaypalCommerceButtonStrategy', () => {
34
34
let paymentMethod : PaymentMethod ;
35
35
let render : ( ) => void ;
36
36
let orderID : string ;
37
+ let fundingSource : string ;
37
38
38
39
beforeEach ( ( ) => {
39
40
store = createCheckoutStore ( getCheckoutStoreState ( ) ) ;
@@ -63,11 +64,16 @@ describe('PaypalCommerceButtonStrategy', () => {
63
64
} ;
64
65
65
66
orderID = 'ORDER_ID' ;
67
+ fundingSource = 'paypal' ;
66
68
eventEmitter = new EventEmitter ( ) ;
67
69
paypal = getPaypalCommerceMock ( ) ;
68
70
69
71
render = jest . spyOn ( paypal , 'Buttons' )
70
72
. mockImplementation ( ( options : ButtonsOptions ) => {
73
+ eventEmitter . on ( 'onClick' , ( ) => {
74
+ options . onClick ( { fundingSource } ) ;
75
+ } ) ;
76
+
71
77
eventEmitter . on ( 'createOrder' , ( ) => {
72
78
options . createOrder ( ) ;
73
79
} ) ;
@@ -134,6 +140,7 @@ describe('PaypalCommerceButtonStrategy', () => {
134
140
await strategy . initialize ( options ) ;
135
141
136
142
expect ( paypal . Buttons ) . toHaveBeenCalledWith ( {
143
+ onClick : expect . any ( Function ) ,
137
144
createOrder : expect . any ( Function ) ,
138
145
onApprove : expect . any ( Function ) ,
139
146
style : paypalOptions . style ,
@@ -212,6 +219,21 @@ describe('PaypalCommerceButtonStrategy', () => {
212
219
. toHaveBeenCalledWith ( 'paypalcommerce' , 'b20deef40f9699e48671bbc3fef6ca44dc80e3c7' ) ;
213
220
} ) ;
214
221
222
+ it ( 'create order with credit (post request to server) when PayPalCommerce payment details are setup payment' , async ( ) => {
223
+ fundingSource = 'credit' ;
224
+
225
+ await strategy . initialize ( options ) ;
226
+
227
+ eventEmitter . emit ( 'onClick' ) ;
228
+
229
+ eventEmitter . emit ( 'createOrder' ) ;
230
+
231
+ await new Promise ( resolve => process . nextTick ( resolve ) ) ;
232
+
233
+ expect ( paypalCommerceRequestSender . setupPayment )
234
+ . toHaveBeenCalledWith ( 'paypalcommercecredit' , 'b20deef40f9699e48671bbc3fef6ca44dc80e3c7' ) ;
235
+ } ) ;
236
+
215
237
it ( 'post payment details to server to set checkout data when PayPalCommerce payment details are tokenized' , async ( ) => {
216
238
await strategy . initialize ( options ) ;
217
239
@@ -227,6 +249,25 @@ describe('PaypalCommerceButtonStrategy', () => {
227
249
} ) ) ;
228
250
} ) ;
229
251
252
+ it ( 'post payment details with credit to server to set checkout data when PayPalCommerce payment details are tokenized' , async ( ) => {
253
+ fundingSource = 'credit' ;
254
+
255
+ await strategy . initialize ( options ) ;
256
+
257
+ eventEmitter . emit ( 'onClick' ) ;
258
+
259
+ eventEmitter . emit ( 'approve' ) ;
260
+
261
+ await new Promise ( resolve => process . nextTick ( resolve ) ) ;
262
+
263
+ expect ( formPoster . postForm ) . toHaveBeenCalledWith ( '/checkout.php' , expect . objectContaining ( {
264
+ payment_type : 'paypal' ,
265
+ action : 'set_external_checkout' ,
266
+ provider : CheckoutButtonMethodType . PAYPALCOMMERCE + 'credit' ,
267
+ order_id : orderID ,
268
+ } ) ) ;
269
+ } ) ;
270
+
230
271
it ( 'throws error in tokenize payment without order id' , async ( ) => {
231
272
orderID = '' ;
232
273
await strategy . initialize ( options ) ;
@@ -268,6 +309,7 @@ describe('PaypalCommerceButtonStrategy', () => {
268
309
await strategy . initialize ( { ...options , paypalCommerce : { style } } ) ;
269
310
270
311
expect ( paypal . Buttons ) . toHaveBeenCalledWith ( {
312
+ onClick : expect . any ( Function ) ,
271
313
createOrder : expect . any ( Function ) ,
272
314
onApprove : expect . any ( Function ) ,
273
315
style : { height : 25 } ,
@@ -284,6 +326,7 @@ describe('PaypalCommerceButtonStrategy', () => {
284
326
await strategy . initialize ( { ...options , paypalCommerce : { style } } ) ;
285
327
286
328
expect ( paypal . Buttons ) . toHaveBeenCalledWith ( {
329
+ onClick : expect . any ( Function ) ,
287
330
createOrder : expect . any ( Function ) ,
288
331
onApprove : expect . any ( Function ) ,
289
332
style : { tagline : true , layout : 'horizontal' , height : 55 } ,
@@ -296,6 +339,7 @@ describe('PaypalCommerceButtonStrategy', () => {
296
339
await strategy . initialize ( { ...options , paypalCommerce : { style } } ) ;
297
340
298
341
expect ( paypal . Buttons ) . toHaveBeenCalledWith ( {
342
+ onClick : expect . any ( Function ) ,
299
343
createOrder : expect . any ( Function ) ,
300
344
onApprove : expect . any ( Function ) ,
301
345
style : { } ,
0 commit comments