Skip to content

Commit 91f418e

Browse files
committed
Merge remote-tracking branch 'origin/AC-13828-v1' into spartans_pr_02022025_AC-13828
2 parents 79b630b + a60a22d commit 91f418e

File tree

4 files changed

+159
-4
lines changed

4 files changed

+159
-4
lines changed

app/code/Magento/Paypal/Model/Config.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Paypal\Model;
@@ -607,6 +607,25 @@ class Config extends AbstractConfig
607607
*/
608608
protected $cspNonceProvider;
609609

610+
/**
611+
* Payment methods to skip address validation
612+
*/
613+
public const PAYMENT_METHODS_SKIP_ADDRESS_VALIDATION = [
614+
self::METHOD_EXPRESS,
615+
self::METHOD_WPS_EXPRESS,
616+
self::METHOD_WPS_BML,
617+
self::METHOD_WPP_BML,
618+
self::METHOD_WPP_DIRECT,
619+
self::METHOD_PAYMENT_PRO,
620+
self::METHOD_WPP_PE_EXPRESS,
621+
self::METHOD_WPP_PE_BML,
622+
self::METHOD_PAYFLOWPRO,
623+
self::METHOD_PAYFLOWLINK,
624+
self::METHOD_PAYFLOWADVANCED,
625+
self::METHOD_HOSTEDPRO,
626+
self::METHOD_BILLING_AGREEMENT
627+
];
628+
610629
/**
611630
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
612631
* @param \Magento\Directory\Helper\Data $directoryHelper
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Plugin;
9+
10+
use Magento\Quote\Model\CustomerManagement;
11+
use Magento\Quote\Model\Quote as QuoteEntity;
12+
use Magento\Paypal\Model\Config as PaymentMethodConfig;
13+
14+
/**
15+
* Skip billing address validation for PayPal payment method
16+
*/
17+
class CustomerManagementPlugin
18+
{
19+
/**
20+
* Around plugin for the validateAddresses method
21+
*
22+
* @param CustomerManagement $subject
23+
* @param \Closure $proceed
24+
* @param QuoteEntity $quote
25+
* @return void
26+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
27+
*/
28+
public function aroundValidateAddresses(CustomerManagement $subject, \Closure $proceed, QuoteEntity $quote)
29+
{
30+
if ($quote->getCustomerIsGuest() &&
31+
in_array($quote->getPayment()->getMethod(), PaymentMethodConfig::PAYMENT_METHODS_SKIP_ADDRESS_VALIDATION)) {
32+
return;
33+
}
34+
$proceed($quote);
35+
}
36+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Test\Unit\Plugin;
9+
10+
use PHPUnit\Framework\MockObject\Exception;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Quote\Model\CustomerManagement;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Paypal\Plugin\CustomerManagementPlugin;
15+
use Magento\Quote\Model\Quote\Payment;
16+
17+
class CustomerManagementPluginTest extends TestCase
18+
{
19+
/**
20+
* @var CustomerManagementPlugin
21+
*/
22+
private $plugin;
23+
24+
/**
25+
* @var CustomerManagement
26+
*/
27+
private $customerManagement;
28+
29+
/**
30+
* @var Payment
31+
*/
32+
private $paymentMethod;
33+
34+
/**
35+
* @var Quote
36+
*/
37+
private $quote;
38+
39+
/**
40+
* @var callable
41+
*/
42+
private $proceed;
43+
44+
/**
45+
* @throws Exception
46+
*/
47+
protected function setUp(): void
48+
{
49+
$this->quote = $this->createMock(Quote::class);
50+
$this->paymentMethod = $this->createMock(Payment::class);
51+
$this->customerManagement = $this->createMock(CustomerManagement::class);
52+
$this->plugin = new CustomerManagementPlugin();
53+
}
54+
55+
/**
56+
* Test to skip address validation for PayPal payment method to guest customer
57+
*/
58+
public function testAroundValidateAddressesWithPaypal()
59+
{
60+
$this->paymentMethod->method('getMethod')->willReturn('paypal_express');
61+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
62+
$this->quote->method('getCustomerIsGuest')->willReturn(true);
63+
64+
$this->proceed = function ($quote) {
65+
$this->assertSame($quote, $this->quote);
66+
};
67+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
68+
}
69+
70+
/**
71+
* Test to proceed with address validation for other payment methods
72+
*/
73+
public function testAroundValidateAddressesWithOtherPaymentMethod()
74+
{
75+
$this->paymentMethod->method('getMethod')->willReturn('checkmo');
76+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
77+
$this->quote->method('getCustomerIsGuest')->willReturn(true);
78+
$this->proceed = function ($quote) {
79+
$this->assertSame($quote, $this->quote);
80+
};
81+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
82+
}
83+
84+
/**
85+
* Test to proceed with address validation when PayPal is selected and customer is not a guest
86+
*/
87+
public function testAroundValidateAddressesWithPaypalAndLoggedInCustomer()
88+
{
89+
$this->paymentMethod->method('getMethod')->willReturn('paypal_express');
90+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
91+
$this->quote->method('getCustomerIsGuest')->willReturn(false);
92+
$this->proceed = function ($quote) {
93+
$this->assertSame($quote, $this->quote);
94+
};
95+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
96+
}
97+
}

app/code/Magento/Paypal/etc/di.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2014 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -269,4 +269,7 @@
269269
</argument>
270270
</arguments>
271271
</type>
272+
<type name="Magento\Quote\Model\CustomerManagement">
273+
<plugin name="paypal_payment_skip_addresses_validate" type="Magento\Paypal\Plugin\CustomerManagementPlugin"/>
274+
</type>
272275
</config>

0 commit comments

Comments
 (0)