Skip to content

Commit f66a713

Browse files
MC-16375: Unable to pay with Braintree Paypal (Payment Action = Authorize and Capture) for Gift Card as Guest
- Fix braintree paypal quote address
1 parent 6e534ad commit f66a713

File tree

3 files changed

+72
-10
lines changed

3 files changed

+72
-10
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Plugin;
9+
10+
use Magento\Quote\Api\CartRepositoryInterface;
11+
use Magento\Quote\Api\Data\PaymentInterface;
12+
use Magento\Quote\Api\CartManagementInterface;
13+
14+
/**
15+
* Plugin for CartManagementInterface to disable quote address validation
16+
*/
17+
class DisableQuoteAddressValidation
18+
{
19+
/**
20+
* @var CartRepositoryInterface
21+
*/
22+
private $quoteRepository;
23+
24+
/**
25+
* @param CartRepositoryInterface $quoteRepository
26+
*/
27+
public function __construct(
28+
CartRepositoryInterface $quoteRepository
29+
) {
30+
$this->quoteRepository = $quoteRepository;
31+
}
32+
33+
/**
34+
* Disable quote address validation before place order
35+
*
36+
* @param CartManagementInterface $subject
37+
* @param \Closure $proceed
38+
* @param int $cartId
39+
* @param PaymentInterface|null $payment
40+
* @return int
41+
* @throws \Magento\Framework\Exception\NoSuchEntityException
42+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
43+
*/
44+
public function aroundPlaceOrder(
45+
CartManagementInterface $subject,
46+
\Closure $proceed,
47+
int $cartId,
48+
PaymentInterface $payment = null
49+
) {
50+
$quote = $this->quoteRepository->get($cartId);
51+
if ($quote->getPayment()->getMethod() == 'braintree_paypal' &&
52+
$quote->getCheckoutMethod() == CartManagementInterface::METHOD_GUEST) {
53+
$billingAddress = $quote->getBillingAddress();
54+
$billingAddress->setShouldIgnoreValidation(true);
55+
$quote->setBillingAddress($billingAddress);
56+
}
57+
return $proceed($cartId, $payment);
58+
}
59+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,5 +626,6 @@
626626

627627
<type name="Magento\Quote\Api\CartManagementInterface">
628628
<plugin name="order_cancellation" type="Magento\Braintree\Plugin\OrderCancellation"/>
629+
<plugin name="disable_quote_address_validation" type="Magento\Braintree\Plugin\DisableQuoteAddressValidation"/>
629630
</type>
630631
</config>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,17 @@ define([
187187
*/
188188
setBillingAddress: function (customer, address) {
189189
var billingAddress = {
190-
street: [address.streetAddress],
191-
city: address.locality,
190+
street: [address.line1],
191+
city: address.city,
192192
postcode: address.postalCode,
193-
countryId: address.countryCodeAlpha2,
193+
countryId: address.countryCode,
194194
email: customer.email,
195195
firstname: customer.firstName,
196196
lastname: customer.lastName,
197-
telephone: customer.phone
197+
telephone: customer.phone,
198+
regionCode: address.state
198199
};
199-
200-
billingAddress['region_code'] = address.region;
200+
201201
billingAddress = createBillingAddress(billingAddress);
202202
quote.billingAddress(billingAddress);
203203
},
@@ -209,10 +209,12 @@ define([
209209
beforePlaceOrder: function (payload) {
210210
this.setPaymentPayload(payload);
211211

212-
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null) &&
213-
typeof payload.details.billingAddress !== 'undefined'
214-
) {
215-
this.setBillingAddress(payload.details, payload.details.billingAddress);
212+
if (this.isRequiredBillingAddress() || quote.billingAddress() === null) {
213+
if (typeof payload.details.billingAddress !== 'undefined') {
214+
this.setBillingAddress(payload.details, payload.details.billingAddress);
215+
} else {
216+
this.setBillingAddress(payload.details, payload.details.shippingAddress);
217+
}
216218
}
217219

218220
if (this.isSkipOrderReview()) {

0 commit comments

Comments
 (0)