Skip to content

Commit b72a3bb

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'mainline/develop' into develop
2 parents 0cc7c23 + 658b520 commit b72a3bb

File tree

74 files changed

+974
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+974
-580
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ public function getQuote()
155155
if ($this->getStoreId()) {
156156
if (!$this->getQuoteId()) {
157157
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
158+
$this->_quote->setIsActive(false);
158159
$this->_quote->setStoreId($this->getStoreId());
159-
160+
160161
$this->quoteRepository->save($this->_quote);
161162
$this->setQuoteId($this->_quote->getId());
162163
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ public function testGetQuoteWithoutQuoteId()
343343
'',
344344
false
345345
);
346+
346347
$this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock);
347348
$cartInterfaceMock->expects($this->once())
348349
->method('setCustomerGroupId')
@@ -357,7 +358,6 @@ public function testGetQuoteWithoutQuoteId()
357358
$quoteMock->expects($this->once())
358359
->method('setIsSuperMode')
359360
->with(true);
360-
361361
$this->assertEquals($quoteMock, $this->quote->getQuote());
362362
}
363363

app/code/Magento/Backend/view/adminhtml/templates/page/js/calendar.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require([
5151
showHour: false,
5252
showMinute: false,
5353
serverTimezoneSeconds: <?php echo (int) $block->getStoreTimestamp(); ?>,
54+
serverTimezoneOffset: <?php echo (int) $block->getTimezoneOffsetSeconds(); ?>,
5455
yearRange: '<?php /* @escapeNotVerified */ echo $block->getYearRange() ?>'
5556
}
5657
});

app/code/Magento/Braintree/Controller/Paypal/Review.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Controller\ResultFactory;
1111
use Magento\Braintree\Gateway\Config\PayPal\Config;
1212
use Magento\Braintree\Model\Paypal\Helper\QuoteUpdater;
13+
use Magento\Framework\Exception\LocalizedException;
1314

1415
/**
1516
* Class Review
@@ -21,6 +22,11 @@ class Review extends AbstractAction
2122
*/
2223
private $quoteUpdater;
2324

25+
/**
26+
* @var string
27+
*/
28+
private static $paymentMethodNonce = 'payment_method_nonce';
29+
2430
/**
2531
* Constructor
2632
*
@@ -52,13 +58,16 @@ public function execute()
5258

5359
try {
5460
$this->validateQuote($quote);
55-
$this->validateRequestData($requestData);
5661

57-
$this->quoteUpdater->execute(
58-
$requestData['nonce'],
59-
$requestData['details'],
60-
$quote
61-
);
62+
if ($this->validateRequestData($requestData)) {
63+
$this->quoteUpdater->execute(
64+
$requestData['nonce'],
65+
$requestData['details'],
66+
$quote
67+
);
68+
} elseif (!$quote->getPayment()->getAdditionalInformation(self::$paymentMethodNonce)) {
69+
throw new LocalizedException(__('We can\'t initialize checkout.'));
70+
}
6271

6372
/** @var \Magento\Framework\View\Result\Page $resultPage */
6473
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
@@ -82,13 +91,10 @@ public function execute()
8291

8392
/**
8493
* @param array $requestData
85-
* @return void
86-
* @throws \InvalidArgumentException
94+
* @return boolean
8795
*/
8896
private function validateRequestData(array $requestData)
8997
{
90-
if (empty($requestData['nonce']) || empty($requestData['details'])) {
91-
throw new \InvalidArgumentException('Data of request cannot be empty.');
92-
}
98+
return !empty($requestData['nonce']) && !empty($requestData['details']);
9399
}
94100
}

app/code/Magento/Braintree/Test/Unit/Controller/Paypal/ReviewTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function testExecuteException()
170170

171171
$quoteMock->expects(self::once())
172172
->method('getItemsCount')
173-
->willReturn(1);
173+
->willReturn(0);
174174

175175
$this->requestMock->expects(self::once())
176176
->method('getPostValue')
@@ -188,7 +188,54 @@ public function testExecuteException()
188188
->method('addExceptionMessage')
189189
->with(
190190
self::isInstanceOf('\InvalidArgumentException'),
191-
'Data of request cannot be empty.'
191+
'We can\'t initialize checkout.'
192+
);
193+
194+
$this->resultFactoryMock->expects(self::once())
195+
->method('create')
196+
->with(ResultFactory::TYPE_REDIRECT)
197+
->willReturn($resultRedirectMock);
198+
199+
$resultRedirectMock->expects(self::once())
200+
->method('setPath')
201+
->with('checkout/cart')
202+
->willReturnSelf();
203+
204+
self::assertEquals($this->review->execute(), $resultRedirectMock);
205+
}
206+
207+
public function testExecuteExceptionPaymentWithoutNonce()
208+
{
209+
$result = '{}';
210+
$quoteMock = $this->getQuoteMock();
211+
$resultRedirectMock = $this->getResultRedirectMock();
212+
213+
$quoteMock->expects(self::once())
214+
->method('getItemsCount')
215+
->willReturn(1);
216+
217+
$paymentMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Payment::class)
218+
->disableOriginalConstructor()
219+
->getMock();
220+
221+
$quoteMock->expects(self::once())
222+
->method('getPayment')
223+
->willReturn($paymentMock);
224+
225+
$this->requestMock->expects(self::once())
226+
->method('getPostValue')
227+
->with('result', '{}')
228+
->willReturn($result);
229+
230+
$this->checkoutSessionMock->expects(self::once())
231+
->method('getQuote')
232+
->willReturn($quoteMock);
233+
234+
$this->messageManagerMock->expects(self::once())
235+
->method('addExceptionMessage')
236+
->with(
237+
self::isInstanceOf(\Magento\Framework\Exception\LocalizedException::class),
238+
'We can\'t initialize checkout.'
192239
);
193240

194241
$this->resultFactoryMock->expects(self::once())

app/code/Magento/Braintree/view/frontend/templates/paypal/button.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $config = [
2727
data-locale="<?php /* @noEscape */ echo $block->getLocale(); ?>"
2828
data-amount="<?php /* @noEscape */ echo $block->getAmount(); ?>"
2929
id="<?php /* @noEscape */ echo $id; ?>"
30-
class="action-braintree-paypal-logo">
30+
class="action-braintree-paypal-logo" disabled>
3131
<img class="braintree-paypal-button-hidden"
3232
src="https://checkout.paypal.com/pwpp/2.17.6/images/pay-with-paypal.png"
3333
alt="Pay with PayPal"/>

app/code/Magento/Braintree/view/frontend/web/js/paypal/button.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
define(
66
[
7+
'rjsResolver',
78
'uiRegistry',
89
'uiComponent',
910
'underscore',
@@ -13,6 +14,7 @@ define(
1314
'domReady!'
1415
],
1516
function (
17+
resolver,
1618
registry,
1719
Component,
1820
_,
@@ -47,8 +49,10 @@ define(
4749
* @param {Object} integration
4850
*/
4951
onReady: function (integration) {
50-
registry.set(this.integrationName, integration);
51-
$('#' + this.id).removeAttr('disabled');
52+
resolver(function () {
53+
registry.set(this.integrationName, integration);
54+
$('#' + this.id).removeAttr('disabled');
55+
}, this);
5256
},
5357

5458
/**

app/code/Magento/Braintree/view/frontend/web/js/view/payment/adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define([
1515
return {
1616
apiClient: null,
1717
config: {},
18+
checkout: null,
1819

1920
/**
2021
* Get Braintree api client

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,11 @@ define(
184184
/**
185185
* Device data initialization
186186
*
187-
* @param {Object} braintreeInstance
187+
* @param {Object} checkout
188188
*/
189-
onReady: function (braintreeInstance) {
190-
this.additionalData['device_data'] = braintreeInstance.deviceData;
189+
onReady: function (checkout) {
190+
braintree.checkout = checkout;
191+
this.additionalData['device_data'] = checkout.deviceData;
191192
}
192193
};
193194

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

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ define([
1515
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
1616
'use strict';
1717

18-
var checkout;
19-
2018
return Component.extend({
2119
defaults: {
2220
template: 'Magento_Braintree/payment/paypal',
@@ -33,10 +31,10 @@ define([
3331

3432
/**
3533
* Triggers when widget is loaded
36-
* @param {Object} integration
34+
* @param {Object} checkout
3735
*/
38-
onReady: function (integration) {
39-
checkout = integration;
36+
onReady: function (checkout) {
37+
Braintree.checkout = checkout;
4038
this.enableButton();
4139
},
4240

@@ -144,25 +142,49 @@ define([
144142
this.paymentMethodNonce = paymentMethodNonce;
145143
},
146144

145+
/**
146+
* Update quote billing address
147+
* @param {Object}customer
148+
* @param {Object}address
149+
*/
150+
setBillingAddress: function (customer, address) {
151+
var billingAddress = {
152+
street: [address.streetAddress],
153+
city: address.locality,
154+
regionCode: address.region,
155+
postcode: address.postalCode,
156+
countryId: address.countryCodeAlpha2,
157+
firstname: customer.firstName,
158+
lastname: customer.lastName,
159+
telephone: customer.phone
160+
};
161+
162+
quote.billingAddress(billingAddress);
163+
},
164+
147165
/**
148166
* Prepare data to place order
149167
* @param {Object} data
150168
*/
151169
beforePlaceOrder: function (data) {
152170
this.setPaymentMethodNonce(data.nonce);
171+
172+
if (quote.billingAddress() === null && typeof data.details.billingAddress !== 'undefined') {
173+
this.setBillingAddress(data.details, data.details.billingAddress);
174+
}
153175
this.placeOrder();
154176
},
155177

156178
/**
157179
* Re-init PayPal Auth Flow
158180
*/
159181
reInitPayPal: function () {
160-
if (!checkout) {
161-
return;
182+
if (Braintree.checkout) {
183+
Braintree.checkout.teardown(function () {
184+
Braintree.checkout = null;
185+
});
162186
}
163-
checkout.teardown(function () {
164-
checkout = null;
165-
});
187+
166188
this.disableButton();
167189
this.clientConfig.paypal.amount = this.grandTotalAmount;
168190

@@ -175,7 +197,7 @@ define([
175197
*/
176198
payWithPayPal: function () {
177199
if (additionalValidators.validate()) {
178-
checkout.paypal.initAuthFlow();
200+
Braintree.checkout.paypal.initAuthFlow();
179201
}
180202
},
181203

@@ -200,8 +222,7 @@ define([
200222
* @returns {Object}
201223
*/
202224
getPayPalConfig: function () {
203-
var address = quote.shippingAddress(),
204-
totals = quote.totals(),
225+
var totals = quote.totals(),
205226
config = {};
206227

207228
config.paypal = {
@@ -212,16 +233,6 @@ define([
212233
currency: totals['base_currency_code'],
213234
locale: this.getLocale(),
214235
enableShippingAddress: true,
215-
shippingAddressOverride: {
216-
recipientName: address.firstname + ' ' + address.lastname,
217-
streetAddress: address.street[0],
218-
locality: address.city,
219-
countryCodeAlpha2: address.countryId,
220-
postalCode: address.postcode,
221-
region: address.regionCode,
222-
phone: address.telephone,
223-
editable: this.isAllowOverrideShippingAddress()
224-
},
225236

226237
/**
227238
* Triggers on any Braintree error
@@ -238,13 +249,39 @@ define([
238249
}
239250
};
240251

252+
config.paypal.shippingAddressOverride = this.getShippingAddress();
253+
241254
if (this.getMerchantName()) {
242255
config.paypal.displayName = this.getMerchantName();
243256
}
244257

245258
return config;
246259
},
247260

261+
/**
262+
* Get shipping address
263+
* @returns {Object}
264+
*/
265+
getShippingAddress: function () {
266+
var address = quote.shippingAddress();
267+
268+
if (address.postcode === null) {
269+
270+
return {};
271+
}
272+
273+
return {
274+
recipientName: address.firstname + ' ' + address.lastname,
275+
streetAddress: address.street[0],
276+
locality: address.city,
277+
countryCodeAlpha2: address.countryId,
278+
postalCode: address.postcode,
279+
region: address.regionCode,
280+
phone: address.telephone,
281+
editable: this.isAllowOverrideShippingAddress()
282+
};
283+
},
284+
248285
/**
249286
* Get merchant name
250287
* @returns {String}
@@ -279,6 +316,8 @@ define([
279316
* Disable submit button
280317
*/
281318
disableButton: function () {
319+
// stop any previous shown loaders
320+
fullScreenLoader.stopLoader();
282321
fullScreenLoader.startLoader();
283322
$('[data-button="place"]').attr('disabled', 'disabled');
284323
},

0 commit comments

Comments
 (0)