Skip to content

Commit

Permalink
Merge branch '2.2-develop' into 2.2-develop-PR-port-16537
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Aug 8, 2018
2 parents 0fc1574 + b62b78b commit 11feca4
Show file tree
Hide file tree
Showing 114 changed files with 943 additions and 210 deletions.
52 changes: 26 additions & 26 deletions app/code/Magento/Authorizenet/Model/Directpost/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,50 @@ public function setDataFromOrder(
sprintf('%.2F', $order->getBaseShippingAmount())
);

//need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript,
//need to use (string) because NULL values IE6-8 decodes as "null" in JSON in JavaScript,
//but we need "" for null values.
$billing = $order->getBillingAddress();
if (!empty($billing)) {
$this->setXFirstName(strval($billing->getFirstname()))
->setXLastName(strval($billing->getLastname()))
->setXCompany(strval($billing->getCompany()))
->setXAddress(strval($billing->getStreetLine(1)))
->setXCity(strval($billing->getCity()))
->setXState(strval($billing->getRegion()))
->setXZip(strval($billing->getPostcode()))
->setXCountry(strval($billing->getCountryId()))
->setXPhone(strval($billing->getTelephone()))
->setXFax(strval($billing->getFax()))
->setXCustId(strval($billing->getCustomerId()))
->setXCustomerIp(strval($order->getRemoteIp()))
->setXCustomerTaxId(strval($billing->getTaxId()))
->setXEmail(strval($order->getCustomerEmail()))
->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))
->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email')));
$this->setXFirstName((string)$billing->getFirstname())
->setXLastName((string)$billing->getLastname())
->setXCompany((string)$billing->getCompany())
->setXAddress((string)$billing->getStreetLine(1))
->setXCity((string)$billing->getCity())
->setXState((string)$billing->getRegion())
->setXZip((string)$billing->getPostcode())
->setXCountry((string)$billing->getCountryId())
->setXPhone((string)$billing->getTelephone())
->setXFax((string)$billing->getFax())
->setXCustId((string)$billing->getCustomerId())
->setXCustomerIp((string)$order->getRemoteIp())
->setXCustomerTaxId((string)$billing->getTaxId())
->setXEmail((string)$order->getCustomerEmail())
->setXEmailCustomer((string)$paymentMethod->getConfigData('email_customer'))
->setXMerchantEmail((string)$paymentMethod->getConfigData('merchant_email'));
}

$shipping = $order->getShippingAddress();
if (!empty($shipping)) {
$this->setXShipToFirstName(
strval($shipping->getFirstname())
(string)$shipping->getFirstname()
)->setXShipToLastName(
strval($shipping->getLastname())
(string)$shipping->getLastname()
)->setXShipToCompany(
strval($shipping->getCompany())
(string)$shipping->getCompany()
)->setXShipToAddress(
strval($shipping->getStreetLine(1))
(string)$shipping->getStreetLine(1)
)->setXShipToCity(
strval($shipping->getCity())
(string)$shipping->getCity()
)->setXShipToState(
strval($shipping->getRegion())
(string)$shipping->getRegion()
)->setXShipToZip(
strval($shipping->getPostcode())
(string)$shipping->getPostcode()
)->setXShipToCountry(
strval($shipping->getCountryId())
(string)$shipping->getCountryId()
);
}

$this->setXPoNum(strval($payment->getPoNumber()));
$this->setXPoNum((string)$payment->getPoNumber());

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
var config = {
map: {
'*': {
transparent: 'Magento_Payment/transparent'
transparent: 'Magento_Payment/js/transparent',
'Magento_Payment/transparent': 'Magento_Payment/js/transparent'
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function render(\Magento\Framework\DataObject $row)
{
if ($data = (string)$this->_getValue($row)) {
$currency_code = $this->_getCurrencyCode($row);
$data = floatval($data) * $this->_getRate($row);
$data = (float)$data * $this->_getRate($row);
$sign = (bool)(int)$this->getColumn()->getShowNumberSign() && $data > 0 ? '+' : '';
$data = sprintf("%f", $data);
$data = $this->_localeCurrency->getCurrency($currency_code)->toCurrency($data);
Expand Down Expand Up @@ -118,10 +118,10 @@ protected function _getCurrencyCode($row)
protected function _getRate($row)
{
if ($rate = $this->getColumn()->getRate()) {
return floatval($rate);
return (float)$rate;
}
if ($rate = $row->getData($this->getColumn()->getRateField())) {
return floatval($rate);
return (float)$rate;
}
return $this->_defaultBaseCurrency->getRate($this->_getCurrencyCode($row));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function render(\Magento\Framework\DataObject $row)
return $data;
}

$data = floatval($data) * $this->_getRate($row);
$data = (float)$data * $this->_getRate($row);
$data = sprintf("%f", $data);
$data = $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
return $data;
Expand Down Expand Up @@ -94,10 +94,10 @@ protected function _getCurrencyCode($row)
protected function _getRate($row)
{
if ($rate = $this->getColumn()->getRate()) {
return floatval($rate);
return (float)$rate;
}
if ($rate = $row->getData($this->getColumn()->getRateField())) {
return floatval($rate);
return (float)$rate;
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Gateway\Http\Client;

use Braintree\Result\Successful;
use Magento\Braintree\Gateway\Http\Client\TransactionRefund;
use Magento\Braintree\Model\Adapter\BraintreeAdapter;
use Magento\Braintree\Model\Adapter\BraintreeAdapterFactory;
use Magento\Payment\Gateway\Http\ClientException;
use Magento\Payment\Gateway\Http\ConverterException;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Braintree\Gateway\Request\PaymentDataBuilder;
use Magento\Payment\Model\Method\Logger;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Log\LoggerInterface;

/**
* Class TransactionRefundTest
*/
class TransactionRefundTest extends \PHPUnit\Framework\TestCase
{
/**
* @var TransactionRefund
*/
private $transactionRefundModel;

/**
* @var BraintreeAdapter|\PHPUnit_Framework_MockObject_MockObject
*/
private $adapterMock;

/**
* @inheritdoc
*/
protected function setUp()
{
/** @var LoggerInterface|MockObject $criticalLoggerMock */
$criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
/** @var Logger|\PHPUnit_Framework_MockObject_MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();
$this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
->disableOriginalConstructor()
->getMock();
/** @var BraintreeAdapterFactory|MockObject $adapterFactoryMock */
$adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
->disableOriginalConstructor()
->getMock();
$adapterFactoryMock->method('create')
->willReturn($this->adapterMock);

$this->transactionRefundModel = new TransactionRefund($criticalLoggerMock, $loggerMock, $adapterFactoryMock);
}

/**
* @throws ClientException
* @throws ConverterException
*/
public function testRefundRequestWithStoreId()
{
$transactionId = '11223344';
$refundAmount = 10;
$data = [
'store_id' => 0,
'transaction_id' => $transactionId,
PaymentDataBuilder::AMOUNT => $refundAmount
];
$successfulResponse = new Successful();

/** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObjectMock */
$transferObjectMock = $this->createMock(TransferInterface::class);
$transferObjectMock->method('getBody')
->willReturn($data);
$this->adapterMock->expects($this->once())
->method('refund')
->with($transactionId, $refundAmount)
->willReturn($successfulResponse);

$response = $this->transactionRefundModel->placeRequest($transferObjectMock);

self::assertEquals($successfulResponse, $response['object']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Gateway\Http\Client;

use Braintree\Result\Successful;
use Magento\Braintree\Gateway\Http\Client\TransactionVoid;
use Magento\Braintree\Model\Adapter\BraintreeAdapter;
use Magento\Braintree\Model\Adapter\BraintreeAdapterFactory;
use Magento\Payment\Gateway\Http\ClientException;
use Magento\Payment\Gateway\Http\ConverterException;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Payment\Model\Method\Logger;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Log\LoggerInterface;

/**
* Class TransactionVoidTest
*/
class TransactionVoidTest extends \PHPUnit\Framework\TestCase
{
/**
* @var TransactionVoid
*/
private $transactionVoidModel;

/**
* @var BraintreeAdapter|\PHPUnit_Framework_MockObject_MockObject
*/
private $adapterMock;

/**
* @inheritdoc
*/
protected function setUp()
{
/** @var LoggerInterface|MockObject $criticalLoggerMock */
$criticalLoggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
/** @var Logger|\PHPUnit_Framework_MockObject_MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();
$this->adapterMock = $this->getMockBuilder(BraintreeAdapter::class)
->disableOriginalConstructor()
->getMock();
/** @var BraintreeAdapterFactory|MockObject $adapterFactoryMock */
$adapterFactoryMock = $this->getMockBuilder(BraintreeAdapterFactory::class)
->disableOriginalConstructor()
->getMock();
$adapterFactoryMock->method('create')
->willReturn($this->adapterMock);

$this->transactionVoidModel = new TransactionVoid($criticalLoggerMock, $loggerMock, $adapterFactoryMock);
}

/**
* @throws ClientException
* @throws ConverterException
*/
public function testVoidRequestWithStoreId()
{
$transactionId = '11223344';
$data = [
'store_id' => 0,
'transaction_id' => $transactionId
];
$successfulResponse = new Successful();

/** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObjectMock */
$transferObjectMock = $this->createMock(TransferInterface::class);
$transferObjectMock->method('getBody')
->willReturn($data);
$this->adapterMock->expects($this->once())
->method('void')
->with($transactionId)
->willReturn($successfulResponse);

$response = $this->transactionVoidModel->placeRequest($transferObjectMock);

self::assertEquals($successfulResponse, $response['object']);
}
}
Loading

0 comments on commit 11feca4

Please sign in to comment.