-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8c5131
commit e79a54f
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob\Message; | ||
|
||
use Guzzle\Http\Message\RequestInterface; | ||
use Omnipay\Common\Message\ResponseInterface; | ||
|
||
class EchoRequest extends AbstractRequest | ||
{ | ||
public function setMerchantId($value) | ||
{ | ||
$this->setParameter('merchantId', $value); | ||
} | ||
|
||
public function setDttm($value) | ||
{ | ||
$this->setParameter('dttm', $value); | ||
} | ||
|
||
/** | ||
* Get the raw data array for this message. The format of this varies from gateway to | ||
* gateway, but will usually be either an associative array, or a SimpleXMLElement. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
$data = [ | ||
"merchantId" => $this->getParameter('merchantId'), | ||
"dttm" => $this->getParameter('dttm'), | ||
]; | ||
$data['signature'] = $this->signData($data); | ||
return $data; | ||
} | ||
|
||
private function signData($data) | ||
{ | ||
$arrayKeys = [ | ||
'merchantId', 'dttm', | ||
]; | ||
return $this->getSignator()->sign($data, $arrayKeys); | ||
} | ||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* @return ResponseInterface | ||
*/ | ||
public function sendData($data) | ||
{ | ||
return $this->sendViaPost(); | ||
} | ||
|
||
public function sendViaPost() | ||
{ | ||
$apiUrl = $this->getApiUrl() . '/echo'; | ||
$data = json_encode($this->getData()); | ||
|
||
$httpRequest = $this->httpClient->createRequest( | ||
RequestInterface::POST, | ||
$apiUrl, | ||
['Content-Type' => 'application/json'], | ||
$data | ||
); | ||
|
||
return $this->response = $this->sendAndProcessResponse($httpRequest); | ||
} | ||
|
||
public function sendViaGet() | ||
{ | ||
$data = $this->getData(); | ||
$apiUrl = implode('/', [ | ||
$this->getApiUrl(), | ||
'echo', | ||
$data['merchantId'], | ||
$data['dttm'], | ||
urlencode($data['signature']), | ||
]); | ||
|
||
$httpRequest = $this->httpClient->createRequest( | ||
RequestInterface::GET, | ||
$apiUrl | ||
); | ||
|
||
return $this->response = $this->sendAndProcessResponse($httpRequest); | ||
} | ||
|
||
/** | ||
* @param RequestInterface $httpRequest | ||
* @return EchoResponse | ||
*/ | ||
private function sendAndProcessResponse(RequestInterface $httpRequest) | ||
{ | ||
$httpResponse = $httpRequest->send(); | ||
$data = $httpResponse->json(); | ||
|
||
$response = new EchoResponse($this, $data); | ||
$response->setVerifier($this->getVerifier()); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob\Message; | ||
|
||
class EchoResponse extends AbstractResponse | ||
{ | ||
|
||
} |