Skip to content

Commit bbfff31

Browse files
author
Yaroslav Onischenko
authored
Merge pull request #589 from magento-mpi/PR-11082016
[MPI] Bugfixes, updating Zephyr tickets id and ApiAnnotationTest removing
2 parents d491a45 + eeb13d7 commit bbfff31

File tree

10 files changed

+321
-52
lines changed

10 files changed

+321
-52
lines changed

app/code/Magento/Authorizenet/Model/Authorizenet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ protected function buildRequest(\Magento\Framework\DataObject $payment)
332332
->setXCity($billing->getCity())
333333
->setXState($billing->getRegion())
334334
->setXZip($billing->getPostcode())
335-
->setXCountry($billing->getCountry())
335+
->setXCountry($billing->getCountryId())
336336
->setXPhone($billing->getTelephone())
337337
->setXFax($billing->getFax())
338338
->setXCustId($order->getCustomerId())
@@ -352,7 +352,7 @@ protected function buildRequest(\Magento\Framework\DataObject $payment)
352352
->setXShipToCity($shipping->getCity())
353353
->setXShipToState($shipping->getRegion())
354354
->setXShipToZip($shipping->getPostcode())
355-
->setXShipToCountry($shipping->getCountry());
355+
->setXShipToCountry($shipping->getCountryId());
356356
}
357357

358358
$request->setXPoNum($payment->getPoNumber())

app/code/Magento/Authorizenet/Model/Directpost/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function setDataFromOrder(
123123
->setXCity(strval($billing->getCity()))
124124
->setXState(strval($billing->getRegion()))
125125
->setXZip(strval($billing->getPostcode()))
126-
->setXCountry(strval($billing->getCountry()))
126+
->setXCountry(strval($billing->getCountryId()))
127127
->setXPhone(strval($billing->getTelephone()))
128128
->setXFax(strval($billing->getFax()))
129129
->setXCustId(strval($billing->getCustomerId()))
@@ -151,7 +151,7 @@ public function setDataFromOrder(
151151
)->setXShipToZip(
152152
strval($shipping->getPostcode())
153153
)->setXShipToCountry(
154-
strval($shipping->getCountry())
154+
strval($shipping->getCountryId())
155155
);
156156
}
157157

app/code/Magento/Braintree/view/adminhtml/web/js/vault.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ define([
2828
self.$selector = $('#' + self.selector);
2929
self.$container = $('#' + self.container);
3030
self.$selector.on(
31-
'setVaultNotActive',
31+
'setVaultNotActive.' + self.getCode(),
3232
function () {
3333
self.$selector.off('submitOrder.' + self.getCode());
3434
}

app/code/Magento/Vault/view/adminhtml/web/js/vault.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ define([
3333
.observe(['active']);
3434

3535
// re-init payment method events
36-
self.$selector.off('changePaymentMethod.' + this.code)
37-
.on('changePaymentMethod.' + this.code, this.changePaymentMethod.bind(this));
36+
self.$selector.off('changePaymentMethod.' + this.getCode())
37+
.on('changePaymentMethod.' + this.getCode(), this.changePaymentMethod.bind(this));
3838

3939
if (this.active()) {
4040
$('#' + this.fieldset + ' input:radio:first').trigger('click');
@@ -50,7 +50,7 @@ define([
5050
* @returns {exports.changePaymentMethod}
5151
*/
5252
changePaymentMethod: function (event, method) {
53-
this.active(method === this.code);
53+
this.active(method === this.getCode());
5454

5555
return this;
5656
},
@@ -61,13 +61,21 @@ define([
6161
*/
6262
onActiveChange: function (isActive) {
6363
if (!isActive) {
64-
this.$selector.trigger('setVaultNotActive');
64+
this.$selector.trigger('setVaultNotActive.' + this.getCode());
6565

6666
return;
6767
}
6868

6969
$('#' + this.fieldset + ' input:radio:first').trigger('click');
70-
window.order.addExcludedPaymentMethod(this.code);
70+
window.order.addExcludedPaymentMethod(this.getCode());
71+
},
72+
73+
/**
74+
* Get payment method code
75+
* @returns {String}
76+
*/
77+
getCode: function () {
78+
return this.code;
7179
}
7280
});
7381
});

dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/ReorderUsingVaultTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Vault\Test\TestCase\ReorderUsingVaultTest" summary="Reorder from Admin with saved within Braintree credit card">
10-
<variation name="ReorderUsingVaultBraintreeTestVariation1" summary="Reorder from Admin with saved within Braintree credit card for Guest Customer" ticketId="MAGETWO-54870">
10+
<variation name="ReorderUsingVaultBraintreeTestVariation1" summary="Reorder from Admin with saved within Braintree credit card for Guest Customer" ticketId="MAGETWO-54869, MAGETWO-54870">
1111
<data name="description" xsi:type="string">Reorder from Admin with saved within Braintree credit card for Guest Customer</data>
1212
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
1313
<data name="customer/dataset" xsi:type="string">default</data>

dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/ReorderUsingVaultTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Vault\Test\TestCase\ReorderUsingVaultTest" summary="Reorder from Admin with saved within PayPal Payflow Pro credit card">
10-
<variation name="ReorderUsingVaultPayflowProTestVariation1" summary="Reorder from Admin with saved within PayPal Payflow Pro credit card for Guest Customer" ticketId="MAGETWO-54872">
10+
<variation name="ReorderUsingVaultPayflowProTestVariation1" summary="Reorder from Admin with saved within PayPal Payflow Pro credit card for Guest Customer" ticketId="MAGETWO-34217, MAGETWO-54872">
1111
<data name="description" xsi:type="string">Reorder from Admin with saved within PayPal Payflow Pro credit card for Guest Customer</data>
1212
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
1313
<data name="customer/dataset" xsi:type="string">default</data>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Authorizenet\Model\Directpost;
7+
8+
use Magento\Authorizenet\Model\Directpost;
9+
use Magento\Framework\Api\FilterBuilder;
10+
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
14+
use Magento\Sales\Model\Order;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
17+
18+
/**
19+
* Class contains tests for Authorize.net Direct Post request handler
20+
*/
21+
class RequestTest extends \PHPUnit_Framework_TestCase
22+
{
23+
/**
24+
* @var Order
25+
*/
26+
private $order;
27+
28+
/**
29+
* @var Request
30+
*/
31+
private $request;
32+
33+
/**
34+
* @var ObjectManager
35+
*/
36+
private $objectManager;
37+
38+
protected function setUp()
39+
{
40+
$this->objectManager = Bootstrap::getObjectManager();
41+
42+
$this->order = $this->getOrder();
43+
$this->request = $this->objectManager->get(Request::class);
44+
}
45+
46+
/**
47+
* @covers \Magento\Authorizenet\Model\Directpost\Request::setDataFromOrder
48+
* @magentoDataFixture Magento/Authorizenet/_files/order.php
49+
*/
50+
public function testSetDataFromOrder()
51+
{
52+
$customerEmail = '[email protected]';
53+
$merchantEmail = '[email protected]';
54+
55+
/** @var Directpost|MockObject $payment */
56+
$payment = $this->getMockBuilder(Directpost::class)
57+
->disableOriginalConstructor()
58+
->setMethods(['getConfigData'])
59+
->getMock();
60+
61+
$payment->expects(static::exactly(2))
62+
->method('getConfigData')
63+
->willReturnMap([
64+
['email_customer', null, $customerEmail],
65+
['merchant_email', null, $merchantEmail]
66+
]);
67+
68+
$result = $this->request->setDataFromOrder($this->order, $payment);
69+
70+
static::assertEquals('US', $result->getXCountry());
71+
static::assertEquals('UK', $result->getXShipToCountry());
72+
static::assertEquals($customerEmail, $result->getXEmailCustomer());
73+
static::assertEquals($merchantEmail, $result->getXMerchantEmail());
74+
}
75+
76+
/**
77+
* Get stored order
78+
* @return Order
79+
*/
80+
private function getOrder()
81+
{
82+
/** @var FilterBuilder $filterBuilder */
83+
$filterBuilder = $this->objectManager->get(FilterBuilder::class);
84+
$filters = [
85+
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
86+
->setValue('100000002')
87+
->create()
88+
];
89+
90+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
91+
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
92+
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
93+
->create();
94+
95+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
96+
$orders = $orderRepository->getList($searchCriteria)
97+
->getItems();
98+
99+
/** @var OrderInterface $order */
100+
return array_pop($orders);
101+
}
102+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Authorizenet\Model;
7+
8+
use Magento\Framework\Api\FilterBuilder;
9+
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\HTTP\ZendClient;
12+
use Magento\Framework\HTTP\ZendClientFactory;
13+
use Magento\Sales\Api\Data\OrderInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Model\Order\Payment;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
18+
use Zend_Http_Response;
19+
20+
/**
21+
* Class contains tests for Direct Post integration
22+
*/
23+
class DirectpostTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* @var ObjectManager
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @var ZendClientFactory|MockObject
32+
*/
33+
private $httpClientFactory;
34+
35+
/**
36+
* @var Directpost
37+
*/
38+
private $directPost;
39+
40+
protected function setUp()
41+
{
42+
$this->objectManager = Bootstrap::getObjectManager();
43+
44+
$this->httpClientFactory = $this->getMockBuilder(ZendClientFactory::class)
45+
->disableOriginalConstructor()
46+
->setMethods(['create'])
47+
->getMock();
48+
49+
$this->directPost = $this->objectManager->create(Directpost::class, [
50+
'httpClientFactory' => $this->httpClientFactory
51+
]);
52+
}
53+
54+
/**
55+
* @covers \Magento\Authorizenet\Model\Directpost::capture
56+
* @magentoDataFixture Magento/Authorizenet/_files/order.php
57+
*/
58+
public function testCapture()
59+
{
60+
$amount = 120.15;
61+
/** @var Payment $payment */
62+
$payment = $this->getPayment();
63+
$transactionId = '106235225';
64+
65+
/** @var ZendClient|MockObject $httpClient */
66+
$httpClient = $this->getMockBuilder(ZendClient::class)
67+
->disableOriginalConstructor()
68+
->setMethods(['setUri', 'setConfig', 'setParameterPost', 'setMethod', 'request'])
69+
->getMock();
70+
71+
$this->httpClientFactory->expects(static::once())
72+
->method('create')
73+
->willReturn($httpClient);
74+
75+
$response = $this->getMockBuilder(Zend_Http_Response::class)
76+
->disableOriginalConstructor()
77+
->setMethods(['getBody'])
78+
->getMock();
79+
$response->expects(static::once())
80+
->method('getBody')
81+
->willReturn(
82+
"1(~)1(~)1(~)This transaction has been approved.(~)AWZFTG(~)P(~){$transactionId}(~)100000002(~)
83+
(~)120.15(~)CC(~)prior_auth_capture(~)(~)Anthony(~)Nealy(~)(~)Pearl St(~)Los Angeles(~)California
84+
(~)10020(~)US(~)22-333-44(~)(~)[email protected](~)John(~)Doe(~)
85+
(~)Bourne St(~)London(~)(~)DW23W(~)UK(~)0.00(~)(~){$amount}(~)(~)
86+
(~)74B5D54ADFE98093A0FF6446(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)XXXX1111(~)Visa(~)(~)(~)(~)(~)
87+
(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)(~)"
88+
);
89+
90+
$httpClient->expects(static::once())
91+
->method('request')
92+
->willReturn($response);
93+
94+
$this->directPost->capture($payment, $amount);
95+
96+
static::assertEquals($transactionId, $payment->getTransactionId());
97+
static::assertFalse($payment->getIsTransactionClosed());
98+
static::assertEquals('US', $payment->getOrder()->getBillingAddress()->getCountryId());
99+
static::assertEquals('UK', $payment->getOrder()->getShippingAddress()->getCountryId());
100+
}
101+
102+
/**
103+
* Get order payment
104+
* @return Payment
105+
*/
106+
private function getPayment()
107+
{
108+
/** @var FilterBuilder $filterBuilder */
109+
$filterBuilder = $this->objectManager->get(FilterBuilder::class);
110+
$filters = [
111+
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
112+
->setValue('100000002')
113+
->create()
114+
];
115+
116+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
117+
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
118+
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
119+
->create();
120+
121+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
122+
$orders = $orderRepository->getList($searchCriteria)
123+
->getItems();
124+
125+
/** @var OrderInterface $order */
126+
$order = array_pop($orders);
127+
return $order->getPayment();
128+
}
129+
}

0 commit comments

Comments
 (0)