Skip to content

Commit 37ca0b8

Browse files
Merge remote-tracking branch 'origin/MAGETWO-63573' into MPI-PR-2704
2 parents df9055d + a2368d9 commit 37ca0b8

File tree

16 files changed

+401
-239
lines changed

16 files changed

+401
-239
lines changed

app/code/Magento/Paypal/Block/Payflow/Advanced/Info.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\Paypal\Block\Payflow\Advanced;
67

78
/**
8-
* Payflow Advanced infoblock
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
9+
* @deprecated This class should not be used because parent class can handle client calls.
10+
* Class was not removed for backward compatibility.
11+
* @see \Magento\Paypal\Block\Payment\Info
1112
*/
12-
namespace Magento\Paypal\Block\Payflow\Advanced;
13-
1413
class Info extends \Magento\Paypal\Block\Payflow\Link\Info
1514
{
15+
1616
}

app/code/Magento/Paypal/Block/Payflow/Info.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
*/
66
namespace Magento\Paypal\Block\Payflow;
77

8-
use Magento\Paypal\Model;
9-
108
/**
11-
* Payflow payment info
9+
* @deprecated This class should not be used because parent class can handle client calls.
10+
* Class was not removed for backward compatibility.
11+
* @see \Magento\Paypal\Block\Payment\Info
1212
*/
1313
class Info extends \Magento\Paypal\Block\Payment\Info
1414
{
1515
/**
1616
* Don't show CC type
1717
*
1818
* @return false
19+
* @deprecated unused
1920
*/
2021
public function getCcTypeName()
2122
{

app/code/Magento/Paypal/Block/Payflow/Link/Info.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\Paypal\Block\Payflow\Link;
67

78
/**
8-
* Payflow link infoblock
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
9+
* @deprecated This class should not be used because parent class can handle client calls.
10+
* Class was not removed for backward compatibility.
11+
* @see \Magento\Paypal\Block\Payment\Info
1112
*/
12-
namespace Magento\Paypal\Block\Payflow\Link;
13-
1413
class Info extends \Magento\Paypal\Block\Payment\Info
1514
{
1615
/**
1716
* Don't show CC type
1817
*
1918
* @return false
19+
* @deprecated unused
2020
*/
2121
public function getCcTypeName()
2222
{

app/code/Magento/Paypal/Model/Payflow/Service/Response/Transaction.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
namespace Magento\Paypal\Model\Payflow\Service\Response;
77

88
use Magento\Framework\DataObject;
9-
109
use Magento\Payment\Model\Method\Logger;
1110
use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface;
1211
use Magento\Framework\Session\Generic;
13-
use Magento\Payment\Model\InfoInterface;
12+
use Magento\Paypal\Model\Payflowpro;
1413
use Magento\Quote\Api\CartRepositoryInterface;
1514
use Magento\Paypal\Model\Payflow\Transparent;
1615
use Magento\Quote\Api\PaymentMethodManagementInterface;
16+
use Magento\Quote\Model\Quote\Payment;
17+
use Magento\Sales\Api\Data\OrderPaymentInterface;
1718

1819
/**
1920
* Class Transaction
@@ -51,8 +52,6 @@ class Transaction
5152
private $logger;
5253

5354
/**
54-
* Constructor
55-
*
5655
* @param Generic $sessionTransparent
5756
* @param CartRepositoryInterface $quoteRepository
5857
* @param Transparent $transparent
@@ -77,36 +76,43 @@ public function __construct(
7776
}
7877

7978
/**
80-
* Returns gateway response data object
79+
* Returns gateway response data object.
8180
*
8281
* @param array $gatewayTransactionResponse
8382
* @return DataObject
8483
*/
8584
public function getResponseObject($gatewayTransactionResponse)
8685
{
8786
$response = new DataObject();
88-
$response = $this->transparent->mapGatewayResponse($gatewayTransactionResponse, $response);
87+
$response = $this->transparent->mapGatewayResponse((array) $gatewayTransactionResponse, $response);
88+
8989
$this->logger->debug(
90-
$gatewayTransactionResponse,
91-
(array)$this->transparent->getDebugReplacePrivateDataKeys(),
92-
(bool)$this->transparent->getDebugFlag()
90+
(array) $gatewayTransactionResponse,
91+
(array) $this->transparent->getDebugReplacePrivateDataKeys(),
92+
(bool) $this->transparent->getDebugFlag()
9393
);
94+
9495
return $response;
9596
}
9697

9798
/**
98-
* Saves payment information in quote
99+
* Saves payment information in quote.
99100
*
100-
* @param Object $response
101+
* @param DataObject $response
101102
* @return void
103+
* @throws \InvalidArgumentException
102104
*/
103105
public function savePaymentInQuote($response)
104106
{
105107
$quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId());
106108

107-
/** @var InfoInterface $payment */
108109
$payment = $this->paymentManagement->get($quote->getId());
109-
$payment->setAdditionalInformation(Transparent::PNREF, $response->getPnref());
110+
if (!$payment instanceof Payment) {
111+
throw new \InvalidArgumentException("Variable must contain instance of \\Quote\\Payment.");
112+
}
113+
114+
$payment->setData(OrderPaymentInterface::CC_TYPE, $response->getData(OrderPaymentInterface::CC_TYPE));
115+
$payment->setAdditionalInformation(Payflowpro::PNREF, $response->getData(Payflowpro::PNREF));
110116

111117
$this->errorHandler->handle($payment, $response);
112118

app/code/Magento/Paypal/Model/Payflow/Transparent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Paypal\Model\Payflow;
77

8-
use Magento\Framework\DataObject;
98
use Magento\Payment\Helper\Formatter;
109
use Magento\Payment\Model\InfoInterface;
1110
use Magento\Paypal\Model\Payflowpro;
@@ -42,7 +41,7 @@ class Transparent extends Payflowpro implements TransparentInterface
4241
/**
4342
* @var string
4443
*/
45-
protected $_infoBlockType = \Magento\Paypal\Block\Payflow\Info::class;
44+
protected $_infoBlockType = \Magento\Paypal\Block\Payment\Info::class;
4645

4746
/**
4847
* @var ResponseValidator

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Payflowadvanced extends \Magento\Paypal\Model\Payflowlink
3030
*
3131
* @var string
3232
*/
33-
protected $_infoBlockType = \Magento\Paypal\Block\Payflow\Advanced\Info::class;
33+
protected $_infoBlockType = \Magento\Paypal\Block\Payment\Info::class;
3434

3535
/**
3636
* Controller for callback urls

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Payment\Model\Method\AbstractMethod;
1212
use Magento\Payment\Model\Method\ConfigInterfaceFactory;
1313
use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface;
14+
use Magento\Sales\Api\Data\OrderPaymentInterface;
1415
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
1516

1617
/**
@@ -46,7 +47,7 @@ class Payflowlink extends \Magento\Paypal\Model\Payflowpro
4647
/**
4748
* @var string
4849
*/
49-
protected $_infoBlockType = \Magento\Paypal\Block\Payflow\Link\Info::class;
50+
protected $_infoBlockType = \Magento\Paypal\Block\Payment\Info::class;
5051

5152
/**
5253
* Availability option
@@ -308,8 +309,9 @@ protected function _processOrder(\Magento\Sales\Model\Order $order)
308309
$response = $this->getResponse();
309310
$payment = $order->getPayment();
310311
$payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0);
311-
$canSendNewOrderEmail = true;
312+
$payment->setCcType($response->getData(OrderPaymentInterface::CC_TYPE));
312313

314+
$canSendNewOrderEmail = true;
313315
if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER ||
314316
$response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER
315317
) {

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

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Paypal\Model\Payflow\Service\Gateway;
1616
use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface;
1717
use Magento\Quote\Model\Quote;
18+
use Magento\Sales\Api\Data\OrderPaymentInterface;
1819
use Magento\Sales\Model\Order;
1920
use Magento\Sales\Model\Order\Payment;
2021
use Magento\Store\Model\ScopeInterface;
@@ -120,7 +121,23 @@ class Payflowpro extends \Magento\Payment\Model\Method\Cc implements GatewayInte
120121
'securetokenid' => 'securetokenid',
121122
'authcode' => 'authcode',
122123
'hostcode' => 'hostcode',
123-
'pnref' => 'pnref'
124+
'pnref' => 'pnref',
125+
'cc_type' => 'cardtype'
126+
];
127+
128+
/**
129+
* PayPal credit card type map.
130+
* @see https://developer.paypal.com/docs/classic/payflow/integration-guide/#credit-card-transaction-responses
131+
*
132+
* @var array
133+
*/
134+
private $ccTypeMap = [
135+
'0' => 'VI',
136+
'1' => 'MC',
137+
'2' => 'DI',
138+
'3' => 'AE',
139+
'4' => 'DN',
140+
'5' => 'JCB'
124141
];
125142

126143
/**
@@ -766,24 +783,36 @@ public function setShipping($request, $shipping)
766783
public function mapGatewayResponse(array $postData, DataObject $response)
767784
{
768785
$response->setData(array_change_key_case($postData));
786+
769787
foreach ($this->_responseParamsMappings as $originKey => $key) {
770-
$data = $response->getData($key);
771-
if (isset($data)) {
772-
$response->setData($originKey, $data);
788+
if ($response->getData($key) !== null) {
789+
$response->setData($originKey, $response->getData($key));
773790
}
774791
}
775-
// process AVS data separately
776-
$avsAddr = $response->getData('avsaddr');
777-
$avsZip = $response->getData('avszip');
778-
if (isset($avsAddr) && isset($avsZip)) {
779-
$response->setData('avsdata', $avsAddr . $avsZip);
780-
}
781-
// process Name separately
782-
$firstnameParameter = $response->getData('billtofirstname');
783-
$lastnameParameter = $response->getData('billtolastname');
784-
if (isset($firstnameParameter) && isset($lastnameParameter)) {
785-
$response->setData('name', $firstnameParameter . ' ' . $lastnameParameter);
786-
}
792+
793+
$response->setData(
794+
'avsdata',
795+
$this->mapResponseAvsData(
796+
$response->getData('avsaddr'),
797+
$response->getData('avszip')
798+
)
799+
);
800+
801+
$response->setData(
802+
'name',
803+
$this->mapResponseBillToName(
804+
$response->getData('billtofirstname'),
805+
$response->getData('billtolastname')
806+
)
807+
);
808+
809+
$response->setData(
810+
OrderPaymentInterface::CC_TYPE,
811+
$this->mapResponseCreditCardType(
812+
$response->getData(OrderPaymentInterface::CC_TYPE)
813+
)
814+
);
815+
787816
return $response;
788817
}
789818

@@ -905,4 +934,41 @@ protected function transactionInquiryRequest(InfoInterface $payment, $transactio
905934

906935
return $response;
907936
}
937+
938+
/**
939+
* Maps PayPal `avsdata` field.
940+
*
941+
* @param string|null $avsAddr
942+
* @param string|null $avsZip
943+
* @return string|null
944+
*/
945+
private function mapResponseAvsData($avsAddr, $avsZip)
946+
{
947+
return isset($avsAddr, $avsZip) ? $avsAddr . $avsZip : null;
948+
}
949+
950+
/**
951+
* Maps PayPal `name` field.
952+
*
953+
* @param string|null $billToFirstName
954+
* @param string|null $billToLastName
955+
* @return string|null
956+
*/
957+
private function mapResponseBillToName($billToFirstName, $billToLastName)
958+
{
959+
return isset($billToFirstName, $billToLastName)
960+
? implode(' ', [$billToFirstName, $billToLastName])
961+
: null;
962+
}
963+
964+
/**
965+
* Map PayPal transaction response credit card type to Magento values if possible.
966+
*
967+
* @param string|null $ccType
968+
* @return string|null
969+
*/
970+
private function mapResponseCreditCardType($ccType)
971+
{
972+
return isset($this->ccTypeMap[$ccType]) ? $this->ccTypeMap[$ccType] : $ccType;
973+
}
908974
}

0 commit comments

Comments
 (0)