Skip to content

Commit 85dabe3

Browse files
committed
MAGETWO-38191: Contribute payment service API to mainline
- Added getUri method to TransferInterface
1 parent eddd8cd commit 85dabe3

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

app/code/Magento/Payment/Gateway/Http/Client/Zend.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,21 @@ public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $tr
4343

4444
$client->setConfig($transferObject->getClientConfig());
4545
$client->setMethod($transferObject->getMethod());
46-
$client->setParameterPost($transferObject->getBody());
46+
47+
switch($transferObject->getMethod()) {
48+
case \Zend_Http_Client::GET:
49+
$client->setParameterGet($transferObject->getBody());
50+
break;
51+
case \Zend_Http_Client::POST:
52+
$client->setParameterPost($transferObject->getBody());
53+
break;
54+
default:
55+
throw new \LogicException(sprintf('Unsupported HTTP method %s', $transferObject->getMethod()));
56+
}
57+
4758
$client->setHeaders($transferObject->getHeaders());
4859
$client->setUrlEncodeBody($transferObject->shouldEncode());
60+
$client->setUri($transferObject->getUri());
4961

5062
try {
5163
$response = $client->request();

app/code/Magento/Payment/Gateway/Http/TransferInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ public function shouldEncode();
4141
* @return string
4242
*/
4343
public function getBody();
44+
45+
/**
46+
* Returns URI
47+
*
48+
* @return string
49+
*/
50+
public function getUri();
4451
}

app/code/Magento/Payment/Test/Unit/Gateway/Http/Client/ZendTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,24 @@ public function testPlaceRequestConvertResponseFail()
127127
private function setClientTransferObjects()
128128
{
129129
$config = ['key1' => 'value1', 'key2' => 'value2'];
130-
$method = 'methodName';
130+
$method = \Zend_Http_Client::POST;
131131
$headers = ['key1' => 'value1', 'key2' => 'value2'];
132132
$body = 'Body content';
133+
$uri = 'https://example.com/listener';
133134
$shouldEncode = true;
134135

135136
$this->transferObjectMock->expects($this->once())->method('getClientConfig')->willReturn($config);
136-
$this->transferObjectMock->expects($this->once())->method('getMethod')->willReturn($method);
137+
$this->transferObjectMock->expects($this->atLeastOnce())->method('getMethod')->willReturn($method);
137138
$this->transferObjectMock->expects($this->once())->method('getHeaders')->willReturn($headers);
138139
$this->transferObjectMock->expects($this->once())->method('getBody')->willReturn($body);
139140
$this->transferObjectMock->expects($this->once())->method('shouldEncode')->willReturn($shouldEncode);
141+
$this->transferObjectMock->expects($this->once())->method('getUri')->willReturn($uri);
140142

141143
$this->clientMock->expects($this->once())->method('setConfig')->with($config)->willReturnSelf();
142144
$this->clientMock->expects($this->once())->method('setMethod')->with($method)->willReturnSelf();
143145
$this->clientMock->expects($this->once())->method('setParameterPost')->with($body)->willReturnSelf();
144146
$this->clientMock->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
145147
$this->clientMock->expects($this->once())->method('setUrlEncodeBody')->with($shouldEncode)->willReturnSelf();
148+
$this->clientMock->expects($this->once())->method('setUri')->with($uri)->willReturnSelf();
146149
}
147150
}

0 commit comments

Comments
 (0)