Skip to content

Commit 59d576e

Browse files
committed
Merge pull request #260 from magento-mpi/MAGETWO-43491
[MPI] Sprint 73
2 parents eee63de + c142089 commit 59d576e

File tree

210 files changed

+9029
-1951
lines changed

Some content is hidden

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

210 files changed

+9029
-1951
lines changed

app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/Cctypes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/**
1313
* Class Cctypes
14-
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
1514
*/
1615
class Cctypes extends Select
1716
{

app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/Countries.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/**
1313
* Class Countries
14-
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
1514
*/
1615
class Countries extends Select
1716
{

app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/CountryCreditCard.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
/**
1212
* Class CountryCreditCard
13-
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
1413
*/
1514
class CountryCreditCard extends AbstractFieldArray
1615
{

app/code/Magento/BraintreeTwo/Block/Form.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Class Form
17-
* @package Magento\BraintreeTwo\Block
1817
*/
1918
class Form extends Cc
2019
{

app/code/Magento/BraintreeTwo/Block/Info.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
/**
1212
* Class Info
13-
* @package Magento\BraintreeTwo\Block
1413
*/
1514
class Info extends ConfigurableInfo
1615
{
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Controller\Payment;
7+
8+
use Magento\BraintreeTwo\Gateway\Command\GetPaymentNonceCommand;
9+
use Magento\Customer\Model\Session;
10+
use Magento\Framework\App\Action\Action;
11+
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\Controller\ResultInterface;
14+
use Magento\Framework\Webapi\Exception;
15+
use Psr\Log\LoggerInterface;
16+
17+
/**
18+
* Class GetNonce
19+
*/
20+
class GetNonce extends Action
21+
{
22+
/**
23+
* @var LoggerInterface
24+
*/
25+
private $logger;
26+
27+
/**
28+
* @var Session
29+
*/
30+
private $session;
31+
32+
/**
33+
* @var GetPaymentNonceCommand
34+
*/
35+
private $command;
36+
37+
/**
38+
* @param Context $context
39+
* @param LoggerInterface $logger
40+
* @param Session $session
41+
* @param GetPaymentNonceCommand $command
42+
*/
43+
public function __construct(
44+
Context $context,
45+
LoggerInterface $logger,
46+
Session $session,
47+
GetPaymentNonceCommand $command
48+
) {
49+
parent::__construct($context);
50+
$this->logger = $logger;
51+
$this->session = $session;
52+
$this->command = $command;
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function execute()
59+
{
60+
$response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
61+
62+
try {
63+
$publicHash = $this->getRequest()->getParam('public_hash');
64+
$customerId = $this->session->getCustomerId();
65+
$result = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId])
66+
->get();
67+
$response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]);
68+
69+
} catch (\Exception $e) {
70+
$this->logger->critical($e);
71+
return $this->processBadRequest($response);
72+
}
73+
74+
return $response;
75+
}
76+
77+
/**
78+
* Return response for bad request
79+
* @param ResultInterface $response
80+
* @return ResultInterface
81+
*/
82+
private function processBadRequest(ResultInterface $response)
83+
{
84+
$response->setHttpResponseCode(Exception::HTTP_BAD_REQUEST);
85+
$response->setData(['message' => __('Sorry, but something went wrong')]);
86+
87+
return $response;
88+
}
89+
}

app/code/Magento/BraintreeTwo/Controller/Token/GetClientToken.php

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BraintreeTwo\Gateway\Command;
7+
8+
use Magento\Framework\Api\FilterBuilder;
9+
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Payment\Gateway\Command;
11+
use Magento\Payment\Gateway\Command\CommandPoolInterface;
12+
use Magento\Payment\Gateway\CommandInterface;
13+
use Magento\Payment\Gateway\Helper\ContextHelper;
14+
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader;
15+
use Magento\Sales\Api\Data\OrderPaymentInterface;
16+
use Magento\Sales\Api\TransactionRepositoryInterface;
17+
use Magento\Sales\Api\Data\TransactionInterface;
18+
19+
/**
20+
* Class CaptureStrategyCommand
21+
*/
22+
class CaptureStrategyCommand implements CommandInterface
23+
{
24+
/**
25+
* Braintree authorize and capture command
26+
*/
27+
const SALE = 'sale';
28+
29+
/**
30+
* Braintree capture command
31+
*/
32+
const CAPTURE = 'settlement';
33+
34+
/**
35+
* Braintree clone transaction command
36+
*/
37+
const CLONE_TRANSACTION = 'clone';
38+
39+
/**
40+
* @var CommandPoolInterface
41+
*/
42+
private $commandPool;
43+
44+
/**
45+
* @var TransactionRepositoryInterface
46+
*/
47+
private $transactionRepository;
48+
49+
/**
50+
* @var FilterBuilder
51+
*/
52+
private $filterBuilder;
53+
54+
/**
55+
* @var SearchCriteriaBuilder
56+
*/
57+
private $searchCriteriaBuilder;
58+
59+
/**
60+
* @var SubjectReader
61+
*/
62+
private $subjectReader;
63+
64+
/**
65+
* Constructor
66+
*
67+
* @param CommandPoolInterface $commandPool
68+
* @param TransactionRepositoryInterface $repository
69+
* @param FilterBuilder $filterBuilder
70+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
71+
* @param SubjectReader $subjectReader
72+
*/
73+
public function __construct(
74+
CommandPoolInterface $commandPool,
75+
TransactionRepositoryInterface $repository,
76+
FilterBuilder $filterBuilder,
77+
SearchCriteriaBuilder $searchCriteriaBuilder,
78+
SubjectReader $subjectReader
79+
) {
80+
$this->commandPool = $commandPool;
81+
$this->transactionRepository = $repository;
82+
$this->filterBuilder = $filterBuilder;
83+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
84+
$this->subjectReader = $subjectReader;
85+
}
86+
87+
/**
88+
* @inheritdoc
89+
*/
90+
public function execute(array $commandSubject)
91+
{
92+
/** @var \Magento\Payment\Gateway\Data\PaymentDataObjectInterface $paymentDO */
93+
$paymentDO = $this->subjectReader->readPayment($commandSubject);
94+
95+
/** @var \Magento\Sales\Api\Data\OrderPaymentInterface $paymentInfo */
96+
$paymentInfo = $paymentDO->getPayment();
97+
ContextHelper::assertOrderPayment($paymentInfo);
98+
99+
$command = $this->getCommand($paymentInfo);
100+
return $this->commandPool->get($command)->execute($commandSubject);
101+
}
102+
103+
/**
104+
* Get execution command name
105+
* @param OrderPaymentInterface $payment
106+
* @return string
107+
*/
108+
private function getCommand(OrderPaymentInterface $payment)
109+
{
110+
// if auth transaction is not exists execute authorize&capture command
111+
if (!$payment->getAuthorizationTransaction()) {
112+
return self::SALE;
113+
}
114+
115+
if (!$this->isExistsCaptureTransaction($payment)) {
116+
return self::CAPTURE;
117+
}
118+
119+
return self::CLONE_TRANSACTION;
120+
}
121+
122+
/**
123+
* Check if capture transaction already exists
124+
*
125+
* @param OrderPaymentInterface $payment
126+
* @return bool
127+
*/
128+
private function isExistsCaptureTransaction(OrderPaymentInterface $payment)
129+
{
130+
$filters[] = $this->filterBuilder->setField('payment_id')
131+
->setValue($payment->getId())
132+
->create();
133+
134+
$filters[] = $this->filterBuilder->setField('txn_type')
135+
->setValue(TransactionInterface::TYPE_CAPTURE)
136+
->create();
137+
138+
$searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)
139+
->create();
140+
141+
$count = $this->transactionRepository->getList($searchCriteria)->getTotalCount();
142+
return (boolean) $count;
143+
}
144+
}

0 commit comments

Comments
 (0)