Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server-to-server password support #9

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}