Skip to content

Commit d4223c5

Browse files
committed
MAGETWO-63910: Create infrastructure for mapper in Payment module
- Reimplemented API interfaces - Updated purchase builder
1 parent 9f9cc31 commit d4223c5

File tree

9 files changed

+93
-174
lines changed

9 files changed

+93
-174
lines changed

app/code/Magento/Braintree/Model/CodeVerification.php renamed to app/code/Magento/Braintree/Model/AvsPaymentVerification.php

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,18 @@
66
namespace Magento\Braintree\Model;
77

88
use Magento\Braintree\Gateway\Response\PaymentDetailsHandler;
9-
use Magento\Payment\Api\CodeVerificationInterface;
9+
use Magento\Payment\Api\PaymentVerificationInterface;
1010
use Magento\Sales\Api\Data\OrderPaymentInterface;
1111

1212
/**
13-
* Processes AVS and CVV codes mapping from Braintree transaction to
13+
* Processes AVS codes mapping from Braintree transaction to
1414
* electronic merchant systems standard.
1515
*
1616
* @see https://developers.braintreepayments.com/reference/response/transaction
1717
* @see http://www.emsecommerce.net/avs_cvv2_response_codes.htm
1818
*/
19-
class CodeVerification implements CodeVerificationInterface
19+
class AvsPaymentVerification implements PaymentVerificationInterface
2020
{
21-
/**
22-
* List of mapping CVV codes
23-
*
24-
* @var array
25-
*/
26-
private static $cvvMap = [
27-
'M' => 'M',
28-
'N' => 'N',
29-
'U' => 'P',
30-
'I' => 'P',
31-
'S' => 'S',
32-
'A' => ''
33-
];
34-
3521
/**
3622
* List of mapping AVS codes
3723
*
@@ -48,24 +34,14 @@ class CodeVerification implements CodeVerificationInterface
4834
];
4935

5036
/**
51-
* @var OrderPaymentInterface
52-
*/
53-
private $orderPayment;
54-
55-
/**
56-
* @param OrderPaymentInterface $orderPayment
57-
*/
58-
public function __construct(OrderPaymentInterface $orderPayment)
59-
{
60-
$this->orderPayment = $orderPayment;
61-
}
62-
63-
/**
64-
* @inheritdoc
37+
* Gets payment AVS verification code.
38+
* Returns null if payment does not contain any AVS details.
39+
*
40+
* @return string|null
6541
*/
66-
public function getAvsCode()
42+
public function getCode(OrderPaymentInterface $orderPayment)
6743
{
68-
$additionalInfo = $this->orderPayment->getAdditionalInformation();
44+
$additionalInfo = $orderPayment->getAdditionalInformation();
6945
if (empty($additionalInfo[PaymentDetailsHandler::AVS_POSTAL_RESPONSE_CODE]) ||
7046
empty($additionalInfo[PaymentDetailsHandler::AVS_STREET_ADDRESS_RESPONSE_CODE])
7147
) {
@@ -74,20 +50,6 @@ public function getAvsCode()
7450
$streetCode = $additionalInfo[PaymentDetailsHandler::AVS_STREET_ADDRESS_RESPONSE_CODE];
7551
$zipCode = $additionalInfo[PaymentDetailsHandler::AVS_POSTAL_RESPONSE_CODE];
7652
$key = $zipCode . $streetCode;
77-
return isset(self::$avsMap[$key]) ? self::$avsMap[$key] : 'U';
78-
}
79-
80-
/**
81-
* @inheritdoc
82-
*/
83-
public function getCvvCode()
84-
{
85-
$additionalInfo = $this->orderPayment->getAdditionalInformation();
86-
if (empty($additionalInfo[PaymentDetailsHandler::CVV_RESPONSE_CODE])) {
87-
return null;
88-
}
89-
90-
$cvv = $additionalInfo[PaymentDetailsHandler::CVV_RESPONSE_CODE];
91-
return self::$cvvMap[$cvv];
53+
return isset(self::$avsMap[$key]) ? self::$avsMap[$key] : null;
9254
}
9355
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Model;
7+
8+
use Magento\Braintree\Gateway\Response\PaymentDetailsHandler;
9+
use Magento\Payment\Api\PaymentVerificationInterface;
10+
use Magento\Sales\Api\Data\OrderPaymentInterface;
11+
12+
/**
13+
* Processes CVV codes mapping from Braintree transaction to
14+
* electronic merchant systems standard.
15+
*
16+
* @see https://developers.braintreepayments.com/reference/response/transaction
17+
* @see http://www.emsecommerce.net/avs_cvv2_response_codes.htm
18+
*/
19+
class CvvPaymentVerification implements PaymentVerificationInterface
20+
{
21+
/**
22+
* List of mapping CVV codes
23+
*
24+
* @var array
25+
*/
26+
private static $cvvMap = [
27+
'M' => 'M',
28+
'N' => 'N',
29+
'U' => 'P',
30+
'I' => 'P',
31+
'S' => 'S',
32+
'A' => ''
33+
];
34+
35+
/**
36+
* Gets payment CVV verification code.
37+
* Returns null if payment does not contain any CVV details.
38+
*
39+
* @return string|null
40+
*/
41+
public function getCode(OrderPaymentInterface $orderPayment)
42+
{
43+
$additionalInfo = $orderPayment->getAdditionalInformation();
44+
if (empty($additionalInfo[PaymentDetailsHandler::CVV_RESPONSE_CODE])) {
45+
return null;
46+
}
47+
48+
$cvv = $additionalInfo[PaymentDetailsHandler::CVV_RESPONSE_CODE];
49+
return isset(self::$cvvMap[$cvv]) ? self::$cvvMap[$cvv] : null;
50+
}
51+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<masked_fields>cvv,number</masked_fields>
4141
<privateInfoKeys>avsPostalCodeResponseCode,avsStreetAddressResponseCode,cvvResponseCode,processorAuthorizationCode,processorResponseCode,processorResponseText,liabilityShifted,liabilityShiftPossible,riskDataId,riskDataDecision</privateInfoKeys>
4242
<paymentInfoKeys>cc_type,cc_number,avsPostalCodeResponseCode,avsStreetAddressResponseCode,cvvResponseCode,processorAuthorizationCode,processorResponseCode,processorResponseText,liabilityShifted,liabilityShiftPossible,riskDataId,riskDataDecision</paymentInfoKeys>
43-
<code_verification>Magento\Braintree\Model\CodeVerification</code_verification>
43+
<avs_ems_adapter>Magento\Braintree\Model\AvsPaymentVerification</avs_ems_adapter>
44+
<cvv_ems_adapter>Magento\Braintree\Model\CvvPaymentVerification</cvv_ems_adapter>
4445
</braintree>
4546
<braintree_paypal>
4647
<model>BraintreePayPalFacade</model>

app/code/Magento/Payment/Api/CodeVerificationInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/code/Magento/Payment/Api/Data/CodeVerificationInterfaceFactory.php

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Api;
7+
8+
use Magento\Sales\Api\Data\OrderPaymentInterface;
9+
10+
/**
11+
* Payment provider codes verification interface.
12+
*
13+
* @api
14+
*/
15+
interface PaymentVerificationInterface
16+
{
17+
/**
18+
* Gets payment provider verification code.
19+
* Returns null if payment method does not support verification.
20+
*
21+
* @return string|null
22+
*/
23+
public function getCode(OrderPaymentInterface $orderPayment);
24+
}

app/code/Magento/Payment/Model/CodeVerificationFactory.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

app/code/Magento/Payment/Model/NullCodeVerification.php renamed to app/code/Magento/Payment/Model/NullPaymentVerification.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@
55
*/
66
namespace Magento\Payment\Model;
77

8-
use Magento\Payment\Api\CodeVerificationInterface;
8+
use Magento\Payment\Api\PaymentVerificationInterface;
9+
use Magento\Sales\Api\Data\OrderPaymentInterface;
910

1011
/**
11-
* Default implementation of code verification interface.
12+
* Default implementation of codes verification interfaces.
1213
* Provides AVS, CVV codes matching for payment methods which are not support AVS, CVV verification.
1314
*/
14-
class NullCodeVerification implements CodeVerificationInterface
15+
class NullPaymentVerification implements PaymentVerificationInterface
1516
{
1617
/**
1718
* @inheritdoc
1819
*/
19-
public function getAvsCode()
20-
{
21-
return null;
22-
}
23-
24-
/**
25-
* @inheritdoc
26-
*/
27-
public function getCvvCode()
20+
public function getCode(OrderPaymentInterface $orderPayment)
2821
{
2922
return null;
3023
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<preference for="Magento\Payment\Gateway\ConfigFactoryInterface" type="Magento\Payment\Gateway\Config\ConfigFactory" />
1313
<preference for="Magento\Payment\Gateway\Command\CommandManagerPoolInterface" type="Magento\Payment\Gateway\Command\CommandManagerPool" />
1414
<preference for="Magento\Payment\Gateway\Data\PaymentDataObjectFactoryInterface" type="Magento\Payment\Gateway\Data\PaymentDataObjectFactory" />
15-
<preference for="Magento\Payment\Api\CodeVerificationInterface" type="Magento\Payment\Model\NullCodeVerification" />
16-
<preference for="Magento\Payment\Api\Data\CodeVerificationInterfaceFactory" type="Magento\Payment\Model\CodeVerificationFactory" />
15+
<preference for="Magento\Payment\Api\PaymentVerificationInterface" type="Magento\Payment\Model\NullPaymentVerification" />
1716

1817
<type name="Magento\Payment\Model\Config\Reader">
1918
<arguments>

0 commit comments

Comments
 (0)