Skip to content

Commit

Permalink
Merge pull request #49 from sloory/master
Browse files Browse the repository at this point in the history
offer add AbstractRequest::getRequestId()
  • Loading branch information
delatbabel committed May 16, 2016
2 parents 0ea7a64 + 1efe887 commit 88badbd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ function ($event) {
$httpResponse = $httpRequest
->setHeader('Authorization', 'Basic '.base64_encode($this->getApiKey().':'))
->send();

$this->response = new Response($this, $httpResponse->json());

if ($httpResponse->hasHeader('Request-Id')) {
$this->response->setRequestId((string) $httpResponse->getHeader('Request-Id'));
}

return $this->response = new Response($this, $httpResponse->json());
return $this->response;
}

/**
Expand All @@ -167,6 +173,7 @@ public function setSource($value)
return $this->setParameter('source', $value);
}


/**
* Get the card data.
*
Expand Down
25 changes: 25 additions & 0 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
class Response extends AbstractResponse
{
/**
* Request id
*
* @var string URL
*/
protected $requestId = null;

/**
* Is the transaction successful?
*
Expand Down Expand Up @@ -301,4 +308,22 @@ public function getCode()

return null;
}

/**
* @return string
*/
public function getRequestId()
{
return $this->requestId;
}

/**
* Set request id
*
* @return AbstractRequest provides a fluent interface.
*/
public function setRequestId($requestId)
{
$this->requestId = $requestId;
}
}
1 change: 1 addition & 0 deletions tests/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function testSendSuccess()
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference());
$this->assertSame('req_8PDHeZazN2LwML', $response->getRequestId());
$this->assertNull($response->getMessage());
}

Expand Down
1 change: 1 addition & 0 deletions tests/Mock/PurchaseSuccess.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Content-Type: application/json;charset=utf-8
Content-Length: 995
Connection: keep-alive
Cache-Control: no-cache, no-store
Request-Id: req_8PDHeZazN2LwML
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 300

Expand Down

0 comments on commit 88badbd

Please sign in to comment.