-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'mainlinec/develop' into MAGETWO-47054
- Loading branch information
Showing
348 changed files
with
13,058 additions
and
3,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
|
||
/** | ||
* Class Form | ||
* @package Magento\BraintreeTwo\Block | ||
*/ | ||
class Form extends Cc | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
|
||
/** | ||
* Class Info | ||
* @package Magento\BraintreeTwo\Block | ||
*/ | ||
class Info extends ConfigurableInfo | ||
{ | ||
|
89 changes: 89 additions & 0 deletions
89
app/code/Magento/BraintreeTwo/Controller/Payment/GetNonce.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Controller\Payment; | ||
|
||
use Magento\BraintreeTwo\Gateway\Command\GetPaymentNonceCommand; | ||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Framework\Webapi\Exception; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Class GetNonce | ||
*/ | ||
class GetNonce extends Action | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @var GetPaymentNonceCommand | ||
*/ | ||
private $command; | ||
|
||
/** | ||
* @param Context $context | ||
* @param LoggerInterface $logger | ||
* @param Session $session | ||
* @param GetPaymentNonceCommand $command | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
LoggerInterface $logger, | ||
Session $session, | ||
GetPaymentNonceCommand $command | ||
) { | ||
parent::__construct($context); | ||
$this->logger = $logger; | ||
$this->session = $session; | ||
$this->command = $command; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$response = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
|
||
try { | ||
$publicHash = $this->getRequest()->getParam('public_hash'); | ||
$customerId = $this->session->getCustomerId(); | ||
$result = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]) | ||
->get(); | ||
$response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]); | ||
|
||
} catch (\Exception $e) { | ||
$this->logger->critical($e); | ||
return $this->processBadRequest($response); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Return response for bad request | ||
* @param ResultInterface $response | ||
* @return ResultInterface | ||
*/ | ||
private function processBadRequest(ResultInterface $response) | ||
{ | ||
$response->setHttpResponseCode(Exception::HTTP_BAD_REQUEST); | ||
$response->setData(['message' => __('Sorry, but something went wrong')]); | ||
|
||
return $response; | ||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
app/code/Magento/BraintreeTwo/Controller/Token/GetClientToken.php
This file was deleted.
Oops, something went wrong.
144 changes: 144 additions & 0 deletions
144
app/code/Magento/BraintreeTwo/Gateway/Command/CaptureStrategyCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Gateway\Command; | ||
|
||
use Magento\Framework\Api\FilterBuilder; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Payment\Gateway\Command; | ||
use Magento\Payment\Gateway\Command\CommandPoolInterface; | ||
use Magento\Payment\Gateway\CommandInterface; | ||
use Magento\Payment\Gateway\Helper\ContextHelper; | ||
use Magento\BraintreeTwo\Gateway\Helper\SubjectReader; | ||
use Magento\Sales\Api\Data\OrderPaymentInterface; | ||
use Magento\Sales\Api\TransactionRepositoryInterface; | ||
use Magento\Sales\Api\Data\TransactionInterface; | ||
|
||
/** | ||
* Class CaptureStrategyCommand | ||
*/ | ||
class CaptureStrategyCommand implements CommandInterface | ||
{ | ||
/** | ||
* Braintree authorize and capture command | ||
*/ | ||
const SALE = 'sale'; | ||
|
||
/** | ||
* Braintree capture command | ||
*/ | ||
const CAPTURE = 'settlement'; | ||
|
||
/** | ||
* Braintree clone transaction command | ||
*/ | ||
const CLONE_TRANSACTION = 'clone'; | ||
|
||
/** | ||
* @var CommandPoolInterface | ||
*/ | ||
private $commandPool; | ||
|
||
/** | ||
* @var TransactionRepositoryInterface | ||
*/ | ||
private $transactionRepository; | ||
|
||
/** | ||
* @var FilterBuilder | ||
*/ | ||
private $filterBuilder; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var SubjectReader | ||
*/ | ||
private $subjectReader; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param CommandPoolInterface $commandPool | ||
* @param TransactionRepositoryInterface $repository | ||
* @param FilterBuilder $filterBuilder | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param SubjectReader $subjectReader | ||
*/ | ||
public function __construct( | ||
CommandPoolInterface $commandPool, | ||
TransactionRepositoryInterface $repository, | ||
FilterBuilder $filterBuilder, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
SubjectReader $subjectReader | ||
) { | ||
$this->commandPool = $commandPool; | ||
$this->transactionRepository = $repository; | ||
$this->filterBuilder = $filterBuilder; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->subjectReader = $subjectReader; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(array $commandSubject) | ||
{ | ||
/** @var \Magento\Payment\Gateway\Data\PaymentDataObjectInterface $paymentDO */ | ||
$paymentDO = $this->subjectReader->readPayment($commandSubject); | ||
|
||
/** @var \Magento\Sales\Api\Data\OrderPaymentInterface $paymentInfo */ | ||
$paymentInfo = $paymentDO->getPayment(); | ||
ContextHelper::assertOrderPayment($paymentInfo); | ||
|
||
$command = $this->getCommand($paymentInfo); | ||
return $this->commandPool->get($command)->execute($commandSubject); | ||
} | ||
|
||
/** | ||
* Get execution command name | ||
* @param OrderPaymentInterface $payment | ||
* @return string | ||
*/ | ||
private function getCommand(OrderPaymentInterface $payment) | ||
{ | ||
// if auth transaction is not exists execute authorize&capture command | ||
if (!$payment->getAuthorizationTransaction()) { | ||
return self::SALE; | ||
} | ||
|
||
if (!$this->isExistsCaptureTransaction($payment)) { | ||
return self::CAPTURE; | ||
} | ||
|
||
return self::CLONE_TRANSACTION; | ||
} | ||
|
||
/** | ||
* Check if capture transaction already exists | ||
* | ||
* @param OrderPaymentInterface $payment | ||
* @return bool | ||
*/ | ||
private function isExistsCaptureTransaction(OrderPaymentInterface $payment) | ||
{ | ||
$filters[] = $this->filterBuilder->setField('payment_id') | ||
->setValue($payment->getId()) | ||
->create(); | ||
|
||
$filters[] = $this->filterBuilder->setField('txn_type') | ||
->setValue(TransactionInterface::TYPE_CAPTURE) | ||
->create(); | ||
|
||
$searchCriteria = $this->searchCriteriaBuilder->addFilters($filters) | ||
->create(); | ||
|
||
$count = $this->transactionRepository->getList($searchCriteria)->getTotalCount(); | ||
return (boolean) $count; | ||
} | ||
} |
Oops, something went wrong.