Skip to content

Commit 8993d97

Browse files
committed
MAGETWO-58676: [Github] #6296 PayPal Express payments fail as tries to remove stock twice
1 parent 02e1c6b commit 8993d97

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ public function start($returnUrl, $cancelUrl, $button = null)
545545
}
546546
$this->_api->setSuppressShipping(true);
547547
} else {
548+
549+
$billingAddress = $this->_quote->getBillingAddress();
550+
if ($billingAddress) {
551+
$this->_api->setBillingAddress($billingAddress);
552+
}
553+
548554
$address = $this->_quote->getShippingAddress();
549555
$isOverridden = 0;
550556
if (true === $address->validate()) {
@@ -675,6 +681,7 @@ public function returnFromPaypal($token)
675681
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
676682
$billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
677683
$quote->setBillingAddress($billingAddress);
684+
$quote->setCheckoutMethod($this->getCheckoutMethod());
678685

679686
// import payment info
680687
$payment = $quote->getPayment();

dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,56 @@ public function testReturnFromPaypal()
191191
$this->assertTrue($quote->getTotalsCollectedFlag());
192192
}
193193

194+
/**
195+
* Verify that guest customer quota has set type of checkout.
196+
*
197+
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
198+
* @magentoAppIsolation enabled
199+
* @magentoDbIsolation enabled
200+
*/
201+
public function testGuestReturnFromPaypal()
202+
{
203+
$quote = $this->_getFixtureQuote();
204+
$paypalConfigMock = $this->getMock('Magento\Paypal\Model\Config', [], [], '', false);
205+
$apiTypeFactory = $this->getMock('Magento\Paypal\Model\Api\Type\Factory', [], [], '', false);
206+
$paypalInfo = $this->getMock('Magento\Paypal\Model\Info', [], [], '', false);
207+
$checkoutModel = $this->_objectManager->create(
208+
'Magento\Paypal\Model\Express\Checkout',
209+
[
210+
'params' => ['quote' => $quote, 'config' => $paypalConfigMock],
211+
'apiTypeFactory' => $apiTypeFactory,
212+
'paypalInfo' => $paypalInfo
213+
]
214+
);
215+
216+
$api = $this->getMock(
217+
'Magento\Paypal\Model\Api\Nvp',
218+
['call', 'getExportedShippingAddress', 'getExportedBillingAddress'],
219+
[],
220+
'',
221+
false
222+
);
223+
$api->expects($this->any())->method('call')->will($this->returnValue([]));
224+
$apiTypeFactory->expects($this->any())->method('create')->will($this->returnValue($api));
225+
226+
$exportedBillingAddress = $this->_getExportedAddressFixture($quote->getBillingAddress()->getData());
227+
$api->expects($this->any())
228+
->method('getExportedBillingAddress')
229+
->will($this->returnValue($exportedBillingAddress));
230+
231+
$exportedShippingAddress = $this->_getExportedAddressFixture($quote->getShippingAddress()->getData());
232+
$api->expects($this->any())
233+
->method('getExportedShippingAddress')
234+
->will($this->returnValue($exportedShippingAddress));
235+
236+
$paypalInfo->expects($this->once())->method('importToPayment')->with($api, $quote->getPayment());
237+
238+
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
239+
240+
$checkoutModel->returnFromPaypal('token');
241+
$this->assertEquals(Onepage::METHOD_GUEST, $quote->getCheckoutMethod());
242+
}
243+
194244
/**
195245
* Prepare fixture for exported address
196246
*

0 commit comments

Comments
 (0)