Skip to content

Commit 46dfec8

Browse files
committed
Merge branch 'PR-MPI-S76' of github.corp.magento.com:magento-mpi/magento2ce into MAGETWO-48463
2 parents d23618b + e315d8e commit 46dfec8

Some content is hidden

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

47 files changed

+1015
-1110
lines changed

app/code/Magento/BraintreeTwo/Gateway/Command/CaptureStrategyCommand.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,18 @@ public function execute(array $commandSubject)
113113
private function getCommand(OrderPaymentInterface $payment)
114114
{
115115
// if auth transaction is not exists execute authorize&capture command
116-
if (!$payment->getAuthorizationTransaction()) {
116+
$existsCapture = $this->isExistsCaptureTransaction($payment);
117+
if (!$payment->getAuthorizationTransaction() && !$existsCapture) {
117118
return self::SALE;
118119
}
119120

120121
// do capture for authorization transaction
121-
if (!$this->isExistsCaptureTransaction($payment)) {
122+
if (!$existsCapture) {
122123
return self::CAPTURE;
123124
}
124125

125126
// process capture for payment via Vault
126-
if ($this->isExistsVaultToken($payment)) {
127-
return self::VAULT_CAPTURE;
128-
}
129-
130-
return self::CLONE_TRANSACTION;
127+
return self::VAULT_CAPTURE;
131128
}
132129

133130
/**
@@ -152,16 +149,4 @@ private function isExistsCaptureTransaction(OrderPaymentInterface $payment)
152149
$count = $this->transactionRepository->getList($searchCriteria)->getTotalCount();
153150
return (boolean) $count;
154151
}
155-
156-
/**
157-
* Check if payment was used vault token
158-
*
159-
* @param OrderPaymentInterface $payment
160-
* @return bool
161-
*/
162-
private function isExistsVaultToken(OrderPaymentInterface $payment)
163-
{
164-
$extensionAttributes = $payment->getExtensionAttributes();
165-
return (boolean) $extensionAttributes->getVaultPaymentToken();
166-
}
167152
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Config;
7+
8+
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader;
9+
use Magento\Payment\Gateway\Config\ValueHandlerInterface;
10+
use Magento\Sales\Model\Order\Payment;
11+
12+
class CanVoidHandler implements ValueHandlerInterface
13+
{
14+
/**
15+
* @var SubjectReader
16+
*/
17+
private $subjectReader;
18+
19+
/**
20+
* CanVoidHandler constructor.
21+
* @param SubjectReader $subjectReader
22+
*/
23+
public function __construct(
24+
SubjectReader $subjectReader
25+
) {
26+
$this->subjectReader = $subjectReader;
27+
}
28+
29+
/**
30+
* Retrieve method configured value
31+
*
32+
* @param array $subject
33+
* @param int|null $storeId
34+
*
35+
* @return mixed
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
37+
*/
38+
public function handle(array $subject, $storeId = null)
39+
{
40+
$paymentDO = $this->subjectReader->readPayment($subject);
41+
42+
$payment = $paymentDO->getPayment();
43+
return $payment instanceof Payment && !(bool)$payment->getAmountPaid();
44+
}
45+
}

app/code/Magento/BraintreeTwo/Gateway/Http/Client/TransactionClone.php

Lines changed: 0 additions & 25 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 © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Http\Client;
7+
8+
use Magento\BraintreeTwo\Gateway\Request\PaymentDataBuilder;
9+
10+
class TransactionRefund extends AbstractTransaction
11+
{
12+
/**
13+
* Process http request
14+
* @param array $data
15+
* @return \Braintree\Result\Error|\Braintree\Result\Successful
16+
*/
17+
protected function process(array $data)
18+
{
19+
return $this->adapter->refund(
20+
$data['transaction_id'],
21+
$data[PaymentDataBuilder::AMOUNT]
22+
);
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Http\Client;
7+
8+
class TransactionVoid extends AbstractTransaction
9+
{
10+
/**
11+
* Process http request
12+
* @param array $data
13+
* @return \Braintree\Result\Error|\Braintree\Result\Successful
14+
*/
15+
protected function process(array $data)
16+
{
17+
return $this->adapter->void($data['transaction_id']);
18+
}
19+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Request;
7+
8+
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader;
9+
use Magento\Payment\Gateway\Request\BuilderInterface;
10+
use Magento\Payment\Helper\Formatter;
11+
use Magento\Sales\Model\Order\Payment;
12+
13+
class RefundDataBuilder implements BuilderInterface
14+
{
15+
use Formatter;
16+
17+
/**
18+
* @var SubjectReader
19+
*/
20+
private $subjectReader;
21+
22+
/**
23+
* Constructor
24+
*
25+
* @param SubjectReader $subjectReader
26+
*/
27+
public function __construct(SubjectReader $subjectReader)
28+
{
29+
$this->subjectReader = $subjectReader;
30+
}
31+
32+
/**
33+
* Builds ENV request
34+
*
35+
* @param array $buildSubject
36+
* @return array
37+
*/
38+
public function build(array $buildSubject)
39+
{
40+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
41+
42+
/** @var Payment $payment */
43+
$payment = $paymentDO->getPayment();
44+
45+
$amount = null;
46+
try {
47+
$amount = $this->formatPrice($this->subjectReader->readAmount($buildSubject));
48+
} catch (\InvalidArgumentException $e) {
49+
// pass
50+
}
51+
52+
/*
53+
* we should remember that Payment sets Capture txn id of current Invoice into ParentTransactionId Field
54+
*/
55+
$txnId = $payment->getParentTransactionId();
56+
57+
return [
58+
'transaction_id' => $txnId,
59+
PaymentDataBuilder::AMOUNT => $amount
60+
];
61+
}
62+
}

app/code/Magento/BraintreeTwo/Gateway/Request/VaultDataBuilder.php

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
*/
66
namespace Magento\BraintreeTwo\Gateway\Request;
77

8-
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader;
9-
use Magento\BraintreeTwo\Model\Ui\ConfigProvider;
108
use Magento\Payment\Gateway\Request\BuilderInterface;
11-
use Magento\Vault\Gateway\Config\Config;
12-
use Magento\Vault\Model\VaultPaymentInterface;
139

1410
/**
1511
* Vault Data Builder
@@ -21,49 +17,22 @@ class VaultDataBuilder implements BuilderInterface
2117
*/
2218
const OPTIONS = 'options';
2319

24-
/**
25-
* The option that determines whether the payment method
26-
* associated with the successful transaction should be stored in the Vault.
27-
*/
28-
const STORE_IN_VAULT = 'storeInVault';
29-
3020
/**
3121
* The option that determines whether the shipping address information
3222
* provided with the transaction should be associated with the customer ID specified.
3323
* When passed, the payment method will always be stored in the Vault.
3424
*/
3525
const STORE_IN_VAULT_ON_SUCCESS = 'storeInVaultOnSuccess';
3626

37-
/**
38-
* "Is active" vault module config option name
39-
*/
40-
const CONFIG_PAYMENT_VAULT_ACTIVE = 'active';
41-
42-
/**
43-
* @var VaultPaymentInterface
44-
*/
45-
protected $vaultPayment;
46-
47-
/**
48-
* @param VaultPaymentInterface $vaultPayment
49-
*/
50-
public function __construct(VaultPaymentInterface $vaultPayment)
51-
{
52-
$this->vaultPayment = $vaultPayment;
53-
}
54-
5527
/**
5628
* @inheritdoc
5729
*/
5830
public function build(array $buildSubject)
5931
{
60-
$result = [];
61-
62-
$isActiveVaultModule = $this->vaultPayment->isActiveForPayment(ConfigProvider::CODE);
63-
if ($isActiveVaultModule) {
64-
$result[self::OPTIONS][self::STORE_IN_VAULT_ON_SUCCESS] = true;
65-
}
66-
67-
return $result;
32+
return [
33+
self::OPTIONS => [
34+
self::STORE_IN_VAULT_ON_SUCCESS => true
35+
]
36+
];
6837
}
6938
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Request;
7+
8+
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader;
9+
use Magento\Payment\Gateway\Request\BuilderInterface;
10+
use Magento\Sales\Model\Order\Payment;
11+
12+
class VoidDataBuilder implements BuilderInterface
13+
{
14+
/**
15+
* @var SubjectReader
16+
*/
17+
private $subjectReader;
18+
19+
/**
20+
* Constructor
21+
*
22+
* @param SubjectReader $subjectReader
23+
*/
24+
public function __construct(SubjectReader $subjectReader)
25+
{
26+
$this->subjectReader = $subjectReader;
27+
}
28+
29+
/**
30+
* Builds ENV request
31+
*
32+
* @param array $buildSubject
33+
* @return array
34+
*/
35+
public function build(array $buildSubject)
36+
{
37+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
38+
39+
/** @var Payment $payment */
40+
$payment = $paymentDO->getPayment();
41+
42+
return [
43+
'transaction_id' => $payment->getParentTransactionId()
44+
?: $payment->getLastTransId()
45+
];
46+
}
47+
}

app/code/Magento/BraintreeTwo/Gateway/Response/CaptureDetailsHandler.php

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

0 commit comments

Comments
 (0)