@@ -293,6 +293,7 @@ public function testReturnFromPaypal()
293
293
/**
294
294
* The case when handling address data from Paypal button.
295
295
* System's address fields are replacing from export Paypal data.
296
+ * Billing and Shipping address are the same
296
297
*
297
298
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
298
299
* @magentoAppIsolation enabled
@@ -307,39 +308,131 @@ public function testReturnFromPaypalButton()
307
308
$ this ->checkoutModel ->returnFromPaypal ('token ' );
308
309
309
310
$ shippingAddress = $ quote ->getShippingAddress ();
311
+ $ billingAddress = $ quote ->getBillingAddress ();
312
+ $ prefix = '' ;
313
+
314
+ $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['shipping ' ]['street ' ]], $ shippingAddress ->getStreet ());
315
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['firstname ' ], $ shippingAddress ->getFirstname ());
316
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['city ' ], $ shippingAddress ->getCity ());
317
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['telephone ' ], $ shippingAddress ->getTelephone ());
318
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['email ' ], $ shippingAddress ->getEmail ());
319
+
320
+ $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['shipping ' ]['street ' ]], $ billingAddress ->getStreet ());
321
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['firstname ' ], $ billingAddress ->getFirstname ());
322
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['city ' ], $ billingAddress ->getCity ());
323
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['telephone ' ], $ billingAddress ->getTelephone ());
324
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['email ' ], $ billingAddress ->getEmail ());
325
+ }
326
+
327
+ /**
328
+ * The case when handling address data from Paypal button.
329
+ * System's address fields are replacing from export Paypal data.
330
+ * Billing and Shipping address are different
331
+ *
332
+ * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
333
+ * @magentoAppIsolation enabled
334
+ * @magentoDbIsolation enabled
335
+ */
336
+ public function testReturnFromPaypalButtonWithReturnBillingAddress ()
337
+ {
338
+ $ quote = $ this ->getFixtureQuote ();
339
+ $ this ->paypalConfig ->expects ($ this ->exactly (2 ))
340
+ ->method ('getValue ' )
341
+ ->with ('requireBillingAddress ' )
342
+ ->willReturn (1 );
343
+ $ this ->prepareCheckoutModel ($ quote );
344
+ $ quote ->getPayment ()->setAdditionalInformation (Checkout::PAYMENT_INFO_BUTTON , 1 );
345
+
346
+ $ this ->checkoutModel ->returnFromPaypal ('token ' );
347
+
348
+ $ shippingAddress = $ quote ->getShippingAddress ();
349
+ $ billingAddress = $ quote ->getBillingAddress ();
310
350
$ prefix = '' ;
311
351
312
- $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['street ' ]], $ shippingAddress ->getStreet ());
313
- $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['firstname ' ], $ shippingAddress ->getFirstname ());
314
- $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['city ' ], $ shippingAddress ->getCity ());
315
- $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['telephone ' ], $ shippingAddress ->getTelephone ());
316
- $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['email ' ], $ shippingAddress ->getEmail ());
352
+ $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['shipping ' ]['street ' ]], $ shippingAddress ->getStreet ());
353
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['firstname ' ], $ shippingAddress ->getFirstname ());
354
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['city ' ], $ shippingAddress ->getCity ());
355
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['telephone ' ], $ shippingAddress ->getTelephone ());
356
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['shipping ' ]['email ' ], $ shippingAddress ->getEmail ());
357
+
358
+ $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['billing ' ]['street ' ]], $ billingAddress ->getStreet ());
359
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['firstname ' ], $ billingAddress ->getFirstname ());
360
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['city ' ], $ billingAddress ->getCity ());
361
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['telephone ' ], $ billingAddress ->getTelephone ());
362
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['email ' ], $ billingAddress ->getEmail ());
317
363
}
318
364
319
365
/**
320
366
* The case when handling address data from the checkout.
321
367
* System's address fields are not replacing from export PayPal data.
368
+ * Billing and Shipping address are the same
322
369
*
323
370
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
324
371
* @magentoAppIsolation enabled
325
372
* @magentoDbIsolation enabled
326
373
*/
327
374
public function testReturnFromPaypalIfCheckout ()
328
375
{
376
+ $ prefix = 'exported ' ;
329
377
$ quote = $ this ->getFixtureQuote ();
330
- $ this ->prepareCheckoutModel ($ quote );
378
+ $ this ->prepareCheckoutModel ($ quote, $ prefix );
331
379
$ quote ->getPayment ()->setAdditionalInformation (Checkout::PAYMENT_INFO_BUTTON , 0 );
332
380
381
+ $ originalShippingAddress = $ quote ->getShippingAddress ();
382
+ $ originalBillingAddress = $ quote ->getBillingAddress ();
383
+
333
384
$ this ->checkoutModel ->returnFromPaypal ('token ' );
334
385
335
386
$ shippingAddress = $ quote ->getShippingAddress ();
387
+ $ billingAddress = $ quote ->getBillingAddress ();
388
+
389
+ $ this ->assertEquals ($ originalShippingAddress ->getStreet (), $ shippingAddress ->getStreet ());
390
+ $ this ->assertEquals ($ originalShippingAddress ->getFirstname (), $ shippingAddress ->getFirstname ());
391
+ $ this ->assertEquals ($ originalShippingAddress ->getCity (), $ shippingAddress ->getCity ());
392
+ $ this ->assertEquals ($ originalShippingAddress ->getTelephone (), $ shippingAddress ->getTelephone ());
336
393
394
+ $ this ->assertEquals ($ originalBillingAddress ->getStreet (), $ billingAddress ->getStreet ());
395
+ $ this ->assertEquals ($ originalBillingAddress ->getFirstname (), $ billingAddress ->getFirstname ());
396
+ $ this ->assertEquals ($ originalBillingAddress ->getCity (), $ billingAddress ->getCity ());
397
+ $ this ->assertEquals ($ originalBillingAddress ->getTelephone (), $ billingAddress ->getTelephone ());
398
+ }
399
+
400
+ /**
401
+ * The case when handling address data from the checkout.
402
+ * System's address fields are replacing billing address from export PayPal data.
403
+ * Billing and Shipping address are different
404
+ *
405
+ * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
406
+ * @magentoAppIsolation enabled
407
+ * @magentoDbIsolation enabled
408
+ */
409
+ public function testReturnFromPaypalIfCheckoutWithReturnBillingAddress ()
410
+ {
337
411
$ prefix = 'exported ' ;
412
+ $ quote = $ this ->getFixtureQuote ();
413
+ $ this ->paypalConfig ->expects ($ this ->exactly (2 ))
414
+ ->method ('getValue ' )
415
+ ->with ('requireBillingAddress ' )
416
+ ->willReturn (1 );
417
+ $ this ->prepareCheckoutModel ($ quote , $ prefix );
418
+ $ quote ->getPayment ()->setAdditionalInformation (Checkout::PAYMENT_INFO_BUTTON , 0 );
419
+
420
+ $ originalShippingAddress = $ quote ->getShippingAddress ();
421
+
422
+ $ this ->checkoutModel ->returnFromPaypal ('token ' );
338
423
339
- $ this ->assertNotEquals ([$ prefix . $ this ->getExportedData ()['street ' ]], $ shippingAddress ->getStreet ());
340
- $ this ->assertNotEquals ($ prefix . $ this ->getExportedData ()['firstname ' ], $ shippingAddress ->getFirstname ());
341
- $ this ->assertNotEquals ($ prefix . $ this ->getExportedData ()['city ' ], $ shippingAddress ->getCity ());
342
- $ this ->assertNotEquals ($ prefix . $ this ->getExportedData ()['telephone ' ], $ shippingAddress ->getTelephone ());
424
+ $ shippingAddress = $ quote ->getShippingAddress ();
425
+ $ billingAddress = $ quote ->getBillingAddress ();
426
+
427
+ $ this ->assertEquals ($ originalShippingAddress ->getStreet (), $ shippingAddress ->getStreet ());
428
+ $ this ->assertEquals ($ originalShippingAddress ->getFirstname (), $ shippingAddress ->getFirstname ());
429
+ $ this ->assertEquals ($ originalShippingAddress ->getCity (), $ shippingAddress ->getCity ());
430
+ $ this ->assertEquals ($ originalShippingAddress ->getTelephone (), $ shippingAddress ->getTelephone ());
431
+
432
+ $ this ->assertEquals ([$ prefix . $ this ->getExportedData ()['billing ' ]['street ' ]], $ billingAddress ->getStreet ());
433
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['firstname ' ], $ billingAddress ->getFirstname ());
434
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['city ' ], $ billingAddress ->getCity ());
435
+ $ this ->assertEquals ($ prefix . $ this ->getExportedData ()['billing ' ]['telephone ' ], $ billingAddress ->getTelephone ());
343
436
}
344
437
345
438
/**
@@ -363,7 +456,7 @@ public function testReturnFromPayPalForCustomerWithEmptyAddresses(): void
363
456
364
457
$ billingAddress = $ quote ->getBillingAddress ();
365
458
366
- $ this ->performQuoteAddressAssertions ($ billingAddress , $ this ->getExportedData ());
459
+ $ this ->performQuoteAddressAssertions ($ billingAddress , $ this ->getExportedData ()[ ' billing ' ] );
367
460
}
368
461
369
462
/**
@@ -437,7 +530,7 @@ private function performQuoteAddressAssertions(Address $address, array $expected
437
530
*
438
531
* @param Quote $quote
439
532
*/
440
- private function prepareCheckoutModel (Quote $ quote )
533
+ private function prepareCheckoutModel (Quote $ quote, $ prefix = '' )
441
534
{
442
535
$ this ->checkoutModel = $ this ->objectManager ->create (
443
536
Checkout::class,
@@ -448,11 +541,11 @@ private function prepareCheckoutModel(Quote $quote)
448
541
]
449
542
);
450
543
451
- $ exportedBillingAddress = $ this ->getExportedAddressFixture ($ this ->getExportedData ());
544
+ $ exportedBillingAddress = $ this ->getExportedAddressFixture ($ this ->getExportedData ()[ ' billing ' ], $ prefix );
452
545
$ this ->api ->method ('getExportedBillingAddress ' )
453
546
->willReturn ($ exportedBillingAddress );
454
547
455
- $ exportedShippingAddress = $ this ->getExportedAddressFixture ($ this ->getExportedData ());
548
+ $ exportedShippingAddress = $ this ->getExportedAddressFixture ($ this ->getExportedData ()[ ' shipping ' ], $ prefix );
456
549
$ this ->api ->method ('getExportedShippingAddress ' )
457
550
->willReturn ($ exportedShippingAddress );
458
551
@@ -468,16 +561,30 @@ private function prepareCheckoutModel(Quote $quote)
468
561
private function getExportedData (): array
469
562
{
470
563
return [
471
- 'email ' => 'customer@example.com ' ,
472
- 'firstname ' => 'John ' ,
473
- 'lastname ' => 'Doe ' ,
474
- 'country ' => 'US ' ,
475
- 'region ' => 'Colorado ' ,
476
- 'region_id ' => '13 ' ,
477
- 'city ' => 'Denver ' ,
478
- 'street ' => '66 Pearl St ' ,
479
- 'postcode ' => '80203 ' ,
480
- 'telephone ' => '555-555-555 ' ,
564
+ 'shipping ' => [
565
+ 'email ' => 'customer@example.com ' ,
566
+ 'firstname ' => 'John ' ,
567
+ 'lastname ' => 'Doe ' ,
568
+ 'country ' => 'US ' ,
569
+ 'region ' => 'Colorado ' ,
570
+ 'region_id ' => '13 ' ,
571
+ 'city ' => 'Denver ' ,
572
+ 'street ' => '66 Pearl St ' ,
573
+ 'postcode ' => '80203 ' ,
574
+ 'telephone ' => '555-555-555 '
575
+ ],
576
+ 'billing ' => [
577
+ 'email ' => 'customer@example.com ' ,
578
+ 'firstname ' => 'Jane ' ,
579
+ 'lastname ' => 'Doe ' ,
580
+ 'country ' => 'US ' ,
581
+ 'region ' => 'Texas ' ,
582
+ 'region_id ' => '13 ' ,
583
+ 'city ' => 'Austin ' ,
584
+ 'street ' => '1100 Congress Ave ' ,
585
+ 'postcode ' => '78701 ' ,
586
+ 'telephone ' => '555-555-555 '
587
+ ]
481
588
];
482
589
}
483
590
0 commit comments