Skip to content

Commit

Permalink
Merge pull request #9 from gallib/master
Browse files Browse the repository at this point in the history
Add server-to-server password support
  • Loading branch information
judgej authored Aug 23, 2022
2 parents 7654e30 + df5c0f8 commit 98fd453
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Message/AbstractXmlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ protected function getHttpMethod()
*/
public function sendData($data)
{
$headers = [
'Accept' => 'application/xml',
'Content-type' => 'application/xml',
];

if ($this->getAuthorization()) {
$headers['Authorization'] = $this->getAuthorization();
}

$httpResponse = $this->httpClient->request(
$this->getHttpMethod(),
$this->getEndpoint(),
[
'Accept' => 'application/xml',
'Content-type' => 'application/xml',
],
$headers,
$this->getRequestXml()->asXML()
);

Expand Down Expand Up @@ -209,4 +215,16 @@ public function getApiEndpoint()
{
return $this->apiEndpoint;
}

/**
* @return string|null
*/
public function getAuthorization()
{
if ($this->getPassword()) {
return 'Basic ' . base64_encode($this->getMerchantId() . ':' . $this->getPassword());
}

return null;
}
}
17 changes: 17 additions & 0 deletions src/Traits/HasGatewayParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,4 +777,21 @@ public function getHmacKey()
{
return $this->getParameter('hmacKey2') ?: $this->getParameter('hmacKey1');
}

/**
* @param string password for server-to-server services
* @return $this
*/
public function setPassword($value)
{
return $this->setParameter('password', $value);
}

/**
* @return string
*/
public function getPassword()
{
return $this->getParameter('password');
}
}

0 comments on commit 98fd453

Please sign in to comment.