Skip to content

Commit f59e74c

Browse files
author
Alexander Akimov
authored
Merge pull request #865 from magento-mpi/PR-bugfixes
[MPI] Bugfixes
2 parents 7599c36 + d4f16d9 commit f59e74c

File tree

7 files changed

+263
-75
lines changed

7 files changed

+263
-75
lines changed

app/code/Magento/Bundle/view/adminhtml/layout/adminhtml_order_shipment_view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceBlock name="shipment_items">
11-
<block class="Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer" name="shipment_item_bundle" as="shipment_item_bundle" template="sales/shipment/view/items/renderer.phtml"/>
11+
<block class="Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer" name="bundle" as="bundle" template="sales/shipment/view/items/renderer.phtml"/>
1212
</referenceBlock>
1313
</body>
1414
</page>

app/code/Magento/Paypal/Helper/Data.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1616
{
1717
const HTML_TRANSACTION_ID =
18-
'<a target="_blank" href="https://www.%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
18+
'<a target="_blank" href="https://www%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
1919

2020
/**
2121
* Cache for shouldAskToCreateBillingAgreement()
@@ -133,7 +133,7 @@ public function getHtmlTransactionId($methodCode, $txnId)
133133
if (in_array($methodCode, $this->methodCodes)) {
134134
/** @var \Magento\Paypal\Model\Config $config */
135135
$config = $this->configFactory->create()->setMethod($methodCode);
136-
$sandboxFlag = ($config->getValue('sandboxFlag') ? 'sandbox' : '');
136+
$sandboxFlag = ($config->getValue('sandboxFlag') ? '.sandbox' : '');
137137
return sprintf(self::HTML_TRANSACTION_ID, $sandboxFlag, $txnId);
138138
}
139139
return $txnId;

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

+31-30
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,9 @@ public function getCheckoutShortcutImageUrl()
387387
$pal = null;
388388
} elseif (!$pal) {
389389
$pal = null;
390-
$this->_getApi();
391390
try {
392-
$this->_api->callGetPalDetails();
393-
$pal = $this->_api->getPal();
391+
$this->_getApi()->callGetPalDetails();
392+
$pal = $this->_getApi()->getPal();
394393
$this->_configCacheType->save($pal, $cacheId);
395394
} catch (\Exception $e) {
396395
$this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId);
@@ -503,11 +502,10 @@ public function start($returnUrl, $cancelUrl, $button = null)
503502
$this->_quote->reserveOrderId();
504503
$this->quoteRepository->save($this->_quote);
505504
// prepare API
506-
$this->_getApi();
507505
$solutionType = $this->_config->getMerchantCountry() == 'DE'
508506
? \Magento\Paypal\Model\Config::EC_SOLUTION_TYPE_MARK
509507
: $this->_config->getValue('solutionType');
510-
$this->_api->setAmount($this->_quote->getBaseGrandTotal())
508+
$this->_getApi()->setAmount($this->_quote->getBaseGrandTotal())
511509
->setCurrencyCode($this->_quote->getBaseCurrencyCode())
512510
->setInvNum($this->_quote->getReservedOrderId())
513511
->setReturnUrl($returnUrl)
@@ -516,7 +514,7 @@ public function start($returnUrl, $cancelUrl, $button = null)
516514
->setPaymentAction($this->_config->getValue('paymentAction'));
517515
if ($this->_giropayUrls) {
518516
list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
519-
$this->_api->addData(
517+
$this->_getApi()->addData(
520518
[
521519
'giropay_cancel_url' => $cancelUrl,
522520
'giropay_success_url' => $successUrl,
@@ -526,13 +524,13 @@ public function start($returnUrl, $cancelUrl, $button = null)
526524
}
527525

528526
if ($this->_isBml) {
529-
$this->_api->setFundingSource('BML');
527+
$this->_getApi()->setFundingSource('BML');
530528
}
531529

532530
$this->_setBillingAgreementRequest();
533531

534532
if ($this->_config->getValue('requireBillingAddress') == PaypalConfig::REQUIRE_BILLING_ADDRESS_ALL) {
535-
$this->_api->setRequireBillingAddress(1);
533+
$this->_getApi()->setRequireBillingAddress(1);
536534
}
537535

538536
// suppress or export shipping address
@@ -541,15 +539,18 @@ public function start($returnUrl, $cancelUrl, $button = null)
541539
if ($this->_config->getValue('requireBillingAddress')
542540
== PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL
543541
) {
544-
$this->_api->setRequireBillingAddress(1);
542+
$this->_getApi()->setRequireBillingAddress(1);
545543
}
546-
$this->_api->setSuppressShipping(true);
544+
$this->_getApi()->setSuppressShipping(true);
547545
} else {
546+
547+
$this->_getApi()->setBillingAddress($this->_quote->getBillingAddress());
548+
548549
$address = $this->_quote->getShippingAddress();
549550
$isOverridden = 0;
550551
if (true === $address->validate()) {
551552
$isOverridden = 1;
552-
$this->_api->setAddress($address);
553+
$this->_getApi()->setAddress($address);
553554
}
554555
$this->_quote->getPayment()->setAdditionalInformation(
555556
self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN,
@@ -561,19 +562,19 @@ public function start($returnUrl, $cancelUrl, $button = null)
561562
/** @var $cart \Magento\Payment\Model\Cart */
562563
$cart = $this->_cartFactory->create(['salesModel' => $this->_quote]);
563564

564-
$this->_api->setPaypalCart($cart);
565+
$this->_getApi()->setPaypalCart($cart);
565566

566567
if (!$this->_taxData->getConfig()->priceIncludesTax()) {
567568
$this->setShippingOptions($cart, $address);
568569
}
569570

570-
$this->_config->exportExpressCheckoutStyleSettings($this->_api);
571+
$this->_config->exportExpressCheckoutStyleSettings($this->_getApi());
571572

572573
/* Temporary solution. @TODO: do not pass quote into Nvp model */
573-
$this->_api->setQuote($this->_quote);
574-
$this->_api->callSetExpressCheckout();
574+
$this->_getApi()->setQuote($this->_quote);
575+
$this->_getApi()->callSetExpressCheckout();
575576

576-
$token = $this->_api->getToken();
577+
$token = $this->_getApi()->getToken();
577578

578579
$this->_setRedirectUrl($button, $token);
579580

@@ -613,15 +614,15 @@ public function canSkipOrderReviewStep()
613614
*/
614615
public function returnFromPaypal($token)
615616
{
616-
$this->_getApi();
617-
$this->_api->setToken($token)
617+
$this->_getApi()
618+
->setToken($token)
618619
->callGetExpressCheckoutDetails();
619620
$quote = $this->_quote;
620621

621622
$this->ignoreAddressValidation();
622623

623624
// import shipping address
624-
$exportedShippingAddress = $this->_api->getExportedShippingAddress();
625+
$exportedShippingAddress = $this->_getApi()->getExportedShippingAddress();
625626
if (!$quote->getIsVirtual()) {
626627
$shippingAddress = $quote->getShippingAddress();
627628
if ($shippingAddress) {
@@ -640,8 +641,8 @@ public function returnFromPaypal($token)
640641

641642
// import shipping method
642643
$code = '';
643-
if ($this->_api->getShippingRateCode()) {
644-
$code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode());
644+
if ($this->_getApi()->getShippingRateCode()) {
645+
$code = $this->_matchShippingMethodCode($shippingAddress, $this->_getApi()->getShippingRateCode());
645646
if ($code) {
646647
// possible bug of double collecting rates :-/
647648
$shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
@@ -670,17 +671,18 @@ public function returnFromPaypal($token)
670671
} else {
671672
$billingAddress = $quote->getBillingAddress();
672673
}
673-
$exportedBillingAddress = $this->_api->getExportedBillingAddress();
674+
$exportedBillingAddress = $this->_getApi()->getExportedBillingAddress();
674675

675676
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
676677
$billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
677678
$quote->setBillingAddress($billingAddress);
679+
$quote->setCheckoutMethod($this->getCheckoutMethod());
678680

679681
// import payment info
680682
$payment = $quote->getPayment();
681683
$payment->setMethod($this->_methodType);
682-
$this->_paypalInfo->importToPayment($this->_api, $payment);
683-
$payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())
684+
$this->_paypalInfo->importToPayment($this->_getApi(), $payment);
685+
$payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_getApi()->getPayerId())
684686
->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token);
685687
$quote->collectTotals();
686688
$this->quoteRepository->save($quote);
@@ -724,8 +726,7 @@ public function getShippingOptionsCallbackResponse(array $request)
724726

725727
try {
726728
// obtain addresses
727-
$this->_getApi();
728-
$address = $this->_api->prepareShippingOptionsCallbackAddress($request);
729+
$address = $this->_getApi()->prepareShippingOptionsCallbackAddress($request);
729730
$quoteAddress = $this->_quote->getShippingAddress();
730731

731732
// compare addresses, calculate shipping rates and prepare response
@@ -738,7 +739,7 @@ public function getShippingOptionsCallbackResponse(array $request)
738739
$this->totalsCollector->collectAddressTotals($this->_quote, $quoteAddress);
739740
$options = $this->_prepareShippingOptions($quoteAddress, false, true);
740741
}
741-
$response = $this->_api->setShippingOptions($options)->formatShippingOptionsCallback();
742+
$response = $this->_getApi()->setShippingOptions($options)->formatShippingOptionsCallback();
742743

743744
// log request and response
744745
$debugData['response'] = $response;
@@ -956,7 +957,7 @@ protected function _setBillingAgreementRequest()
956957
if (!$this->_agreementFactory->create()->needToCreateForCustomer($this->_customerId)) {
957958
return $this;
958959
}
959-
$this->_api->setBillingType($this->_api->getBillingAgreementType());
960+
$this->_getApi()->setBillingType($this->_getApi()->getBillingAgreementType());
960961
return $this;
961962
}
962963

@@ -1129,7 +1130,7 @@ public function getCustomerSession()
11291130
private function setShippingOptions(PaypalCart $cart, Address $address = null)
11301131
{
11311132
// for included tax always disable line items (related to paypal amount rounding problem)
1132-
$this->_api->setIsLineItemsEnabled($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS));
1133+
$this->_getApi()->setIsLineItemsEnabled($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS));
11331134

11341135
// add shipping options if needed and line items are available
11351136
$cartItems = $cart->getAllItems();
@@ -1140,7 +1141,7 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null)
11401141
if (!$this->_quote->getIsVirtual()) {
11411142
$options = $this->_prepareShippingOptions($address, true);
11421143
if ($options) {
1143-
$this->_api->setShippingOptionsCallbackUrl(
1144+
$this->_getApi()->setShippingOptionsCallbackUrl(
11441145
$this->_coreUrl->getUrl(
11451146
'*/*/shippingOptionsCallback',
11461147
['quote_id' => $this->_quote->getId()]

app/code/Magento/Paypal/Test/Unit/Helper/DataTest.php

+61-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
class DataTest extends \PHPUnit_Framework_TestCase
99
{
10+
/**
11+
* @var string
12+
*/
13+
private static $htmlTransactionId =
14+
'<a target="_blank" href="https://www%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
15+
16+
/**
17+
* @var string
18+
*/
19+
private static $txnId = 'XXX123123XXX';
20+
1021
/**
1122
* @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
1223
*/
@@ -37,13 +48,10 @@ protected function setUp()
3748
\Magento\Payment\Model\Method\InstanceFactory::class
3849
)->disableOriginalConstructor()->getMock();
3950

40-
$this->configMock = $this->getMock(
41-
\Magento\Paypal\Model\Config::class,
42-
[],
43-
[],
44-
'',
45-
false
46-
);
51+
$this->configMock = $this->getMockBuilder(\Magento\Paypal\Model\Config::class)
52+
->disableOriginalConstructor()
53+
->getMock();
54+
4755
$configMockFactory = $this->getMockBuilder(\Magento\Paypal\Model\ConfigFactory::class)
4856
->disableOriginalConstructor()
4957
->setMethods(['create'])
@@ -138,34 +146,68 @@ public function getBillingAgreementMethodsDataProvider()
138146
}
139147

140148
/**
149+
* Sandbox mode
150+
* Expected link <a target="_blank" href="https://www.sandbox.paypal.com/...</a>
151+
*
141152
* @param string $methodCode
142-
* @param string $htmlTransactionId
143153
* @dataProvider testGetHtmlTransactionIdProvider
144154
*/
145-
public function testGetHtmlTransactionId($methodCode, $htmlTransactionId)
155+
public function testGetHtmlTransactionSandboxLink($methodCode)
146156
{
147-
$txnId = 'XXX123123XXX';
148-
$htmlTransactionId = sprintf($htmlTransactionId, 'sandbox', $txnId);
157+
$expectedLink = sprintf(self::$htmlTransactionId, '.sandbox', self::$txnId);
149158

150-
$this->configMock->expects($this->any())
159+
$this->configMock->expects($this->once())
151160
->method('getValue')
152-
->with($this->stringContains('sandboxFlag'))
161+
->with('sandboxFlag')
153162
->willReturn(true);
154163

155-
$this->assertEquals($htmlTransactionId, $this->_helper->getHtmlTransactionId($methodCode, $txnId));
164+
$this->assertEquals(
165+
$expectedLink,
166+
$this->_helper->getHtmlTransactionId($methodCode, self::$txnId)
167+
);
168+
}
169+
170+
/**
171+
* Real mode
172+
* Expected link <a target="_blank" href="https://www.paypal.com/... </a>
173+
*
174+
* @param string $methodCode
175+
* @dataProvider testGetHtmlTransactionIdProvider
176+
*/
177+
public function testGetHtmlTransactionRealLink($methodCode)
178+
{
179+
$expectedLink = sprintf(self::$htmlTransactionId, '', self::$txnId);
180+
181+
$this->configMock->expects($this->once())
182+
->method('getValue')
183+
->with('sandboxFlag')
184+
->willReturn(false);
185+
186+
$this->assertEquals(
187+
$expectedLink,
188+
$this->_helper->getHtmlTransactionId($methodCode, self::$txnId)
189+
);
156190
}
157191

158192
/**
159193
* @return array
160194
*/
161195
public function testGetHtmlTransactionIdProvider()
162196
{
163-
$htmlTransactionId =
164-
'<a target="_blank" href="https://www.%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
165197
return [
166-
['paypal_express', $htmlTransactionId],
167-
['payflow_express', 'XXX123123XXX'],
168-
['hosted_pro', $htmlTransactionId]
198+
['paypal_express'],
199+
['hosted_pro']
169200
];
170201
}
202+
203+
/**
204+
* Invokes with method not in payment list
205+
* Expected result just returned txtId: "XXX123123XXX"
206+
*/
207+
public function testGetHtmlTransactionMethodNotInPaymentList()
208+
{
209+
$methodCode = 'payflow_express';
210+
211+
$this->assertEquals(self::$txnId, $this->_helper->getHtmlTransactionId($methodCode, self::$txnId));
212+
}
171213
}

app/code/Magento/Shipping/view/adminhtml/layout/adminhtml_order_shipment_new.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
1515
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1616
<block class="Magento\Shipping\Block\Adminhtml\Create\Items" name="order_items" template="create/items.phtml">
17-
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="shipment_item_default" as="shipment_item_default" template="Magento_Shipping::create/items/renderer/default.phtml"/>
17+
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="default" as="default" template="Magento_Shipping::create/items/renderer/default.phtml"/>
1818
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
1919
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
2020
<block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>

app/code/Magento/Shipping/view/adminhtml/layout/adminhtml_order_shipment_view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
1515
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1616
<block class="Magento\Shipping\Block\Adminhtml\View\Items" name="shipment_items" template="view/items.phtml">
17-
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="shipment_item_default" as="shipment_item_default" template="Magento_Shipping::view/items/renderer/default.phtml"/>
17+
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="default" as="default" template="Magento_Shipping::view/items/renderer/default.phtml"/>
1818
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
1919
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
2020
<block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>

0 commit comments

Comments
 (0)