Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainlinec/develop' into MAGETWO-47054
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Korablov committed Dec 25, 2015
2 parents a0da1d4 + 6ca1cf3 commit 4794293
Show file tree
Hide file tree
Showing 348 changed files with 13,058 additions and 3,025 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sudo: required
dist: trusty

language: php
php:
- 5.5
Expand Down Expand Up @@ -44,12 +47,10 @@ before_script:
# Install MySQL 5.6, create DB for integration tests
- >
sh -c "if [ '$TEST_SUITE' = 'integration_part_1' ] || [ '$TEST_SUITE' = 'integration_part_2' ] || [ '$TEST_SUITE' = 'integration_integrity' ]; then
sudo apt-get remove --purge mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5;
sudo apt-get autoremove;
sudo apt-get autoclean;
sudo apt-add-repository ppa:ondrej/mysql-5.6 -y;
sudo apt-get update;
sudo apt-get install mysql-server-5.6 mysql-client-5.6;
sudo apt-get remove -y -qq --purge mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5;
sudo apt-get -y -qq autoremove;
sudo apt-get -y -qq autoclean;
sudo apt-get install -y -qq mysql-server-5.6 mysql-client-5.6;
mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magento_integration_tests;';
mv dev/tests/integration/etc/install-config-mysql.travis.php.dist dev/tests/integration/etc/install-config-mysql.php;
fi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

/**
* Class Cctypes
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
*/
class Cctypes extends Select
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

/**
* Class Countries
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
*/
class Countries extends Select
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

/**
* Class CountryCreditCard
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field
*/
class CountryCreditCard extends AbstractFieldArray
{
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/BraintreeTwo/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

/**
* Class Form
* @package Magento\BraintreeTwo\Block
*/
class Form extends Cc
{
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/BraintreeTwo/Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

/**
* Class Info
* @package Magento\BraintreeTwo\Block
*/
class Info extends ConfigurableInfo
{
Expand Down
89 changes: 89 additions & 0 deletions app/code/Magento/BraintreeTwo/Controller/Payment/GetNonce.php
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 app/code/Magento/BraintreeTwo/Controller/Token/GetClientToken.php

This file was deleted.

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;
}
}
Loading

0 comments on commit 4794293

Please sign in to comment.