Skip to content

Commit 98fd453

Browse files
authored
Merge pull request #9 from gallib/master
Add server-to-server password support
2 parents 7654e30 + df5c0f8 commit 98fd453

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/Message/AbstractXmlRequest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,19 @@ protected function getHttpMethod()
149149
*/
150150
public function sendData($data)
151151
{
152+
$headers = [
153+
'Accept' => 'application/xml',
154+
'Content-type' => 'application/xml',
155+
];
156+
157+
if ($this->getAuthorization()) {
158+
$headers['Authorization'] = $this->getAuthorization();
159+
}
160+
152161
$httpResponse = $this->httpClient->request(
153162
$this->getHttpMethod(),
154163
$this->getEndpoint(),
155-
[
156-
'Accept' => 'application/xml',
157-
'Content-type' => 'application/xml',
158-
],
164+
$headers,
159165
$this->getRequestXml()->asXML()
160166
);
161167

@@ -209,4 +215,16 @@ public function getApiEndpoint()
209215
{
210216
return $this->apiEndpoint;
211217
}
218+
219+
/**
220+
* @return string|null
221+
*/
222+
public function getAuthorization()
223+
{
224+
if ($this->getPassword()) {
225+
return 'Basic ' . base64_encode($this->getMerchantId() . ':' . $this->getPassword());
226+
}
227+
228+
return null;
229+
}
212230
}

src/Traits/HasGatewayParameters.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,21 @@ public function getHmacKey()
777777
{
778778
return $this->getParameter('hmacKey2') ?: $this->getParameter('hmacKey1');
779779
}
780+
781+
/**
782+
* @param string password for server-to-server services
783+
* @return $this
784+
*/
785+
public function setPassword($value)
786+
{
787+
return $this->setParameter('password', $value);
788+
}
789+
790+
/**
791+
* @return string
792+
*/
793+
public function getPassword()
794+
{
795+
return $this->getParameter('password');
796+
}
780797
}

0 commit comments

Comments
 (0)