From a87b270b0a5a859229b8695323d9d315c7e9b392 Mon Sep 17 00:00:00 2001 From: John C Date: Sat, 11 Aug 2018 14:06:16 +1000 Subject: [PATCH] Add auth to Rapid requests --- src/Message/RapidCaptureRequest.php | 7 +++++-- src/Message/RapidDirectAbstractRequest.php | 6 +++++- src/Message/RapidDirectCreateCardRequest.php | 6 +++++- src/Message/RapidDirectUpdateCardRequest.php | 6 +++++- src/Message/RapidDirectVoidRequest.php | 7 +++++-- src/Message/RapidPurchaseRequest.php | 6 +++++- src/Message/RapidSharedPurchaseRequest.php | 6 +++++- 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/Message/RapidCaptureRequest.php b/src/Message/RapidCaptureRequest.php index d876340..843d7be 100644 --- a/src/Message/RapidCaptureRequest.php +++ b/src/Message/RapidCaptureRequest.php @@ -54,9 +54,12 @@ public function getEndpoint() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [ + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()), 'content-type' => 'application/json', - ], json_encode($data)); + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidResponse($this, json_decode((string) $httpResponse->getBody(), true)); } diff --git a/src/Message/RapidDirectAbstractRequest.php b/src/Message/RapidDirectAbstractRequest.php index 18e5811..3222cbd 100644 --- a/src/Message/RapidDirectAbstractRequest.php +++ b/src/Message/RapidDirectAbstractRequest.php @@ -101,7 +101,11 @@ protected function getBaseData() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], json_encode($data)); + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()) + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidResponse($this, json_decode((string) $httpResponse->getBody(), true)); } diff --git a/src/Message/RapidDirectCreateCardRequest.php b/src/Message/RapidDirectCreateCardRequest.php index 0eaff37..f4ca766 100644 --- a/src/Message/RapidDirectCreateCardRequest.php +++ b/src/Message/RapidDirectCreateCardRequest.php @@ -76,7 +76,11 @@ protected function getEndpoint() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], json_encode($data)); + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()) + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); $this->response = new RapidDirectCreateCardResponse( $this, diff --git a/src/Message/RapidDirectUpdateCardRequest.php b/src/Message/RapidDirectUpdateCardRequest.php index 3448d63..a3ec454 100644 --- a/src/Message/RapidDirectUpdateCardRequest.php +++ b/src/Message/RapidDirectUpdateCardRequest.php @@ -81,7 +81,11 @@ protected function getEndpoint() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], json_encode($data)); + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()) + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidDirectCreateCardResponse( $this, diff --git a/src/Message/RapidDirectVoidRequest.php b/src/Message/RapidDirectVoidRequest.php index d50969b..883993d 100644 --- a/src/Message/RapidDirectVoidRequest.php +++ b/src/Message/RapidDirectVoidRequest.php @@ -24,9 +24,12 @@ protected function getEndpoint() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [ + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()), 'content-type' => 'application/json', - ], json_encode($data)); + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidResponse($this, json_decode((string) $httpResponse->getBody(), true)); } diff --git a/src/Message/RapidPurchaseRequest.php b/src/Message/RapidPurchaseRequest.php index f7c53d1..80d1682 100644 --- a/src/Message/RapidPurchaseRequest.php +++ b/src/Message/RapidPurchaseRequest.php @@ -39,7 +39,11 @@ public function getData() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], json_encode($data)); + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()) + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidResponse($this, json_decode((string) $httpResponse->getBody(), true)); } diff --git a/src/Message/RapidSharedPurchaseRequest.php b/src/Message/RapidSharedPurchaseRequest.php index c9120e5..d7f2822 100644 --- a/src/Message/RapidSharedPurchaseRequest.php +++ b/src/Message/RapidSharedPurchaseRequest.php @@ -49,7 +49,11 @@ public function getData() public function sendData($data) { - $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], json_encode($data)); + $headers = [ + 'Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':' . $this->getPassword()) + ]; + + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, json_encode($data)); return $this->response = new RapidSharedResponse($this, json_decode((string) $httpResponse->getBody(), true)); }