-
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.
Merge pull request #11 from superbrave/splits-transaction-status-to-c…
…omplete-authorise-and-capture Splits transaction status to complete authorise and capture
- Loading branch information
Showing
28 changed files
with
654 additions
and
87 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
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,58 @@ | ||
<?php | ||
|
||
namespace Omnipay\IcepayPayments\Message; | ||
|
||
use Omnipay\Common\Message\ResponseInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* The request for retrieving the payment transaction status when the CompleteAuthorise and Capture happens. | ||
* The payment transaction status can be different from what we get back as data from Icepay. | ||
*/ | ||
class CompleteAuthoriseAndCaptureRequest extends AbstractRequest | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getData(): array | ||
{ | ||
$data = parent::getData(); | ||
|
||
$data['ContractProfileId'] = $this->getContractProfileId(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sendData($data): ResponseInterface | ||
{ | ||
$this->sendRequest( | ||
Request::METHOD_POST, | ||
sprintf( | ||
'/transaction/%s', | ||
$this->getTransactionReference() | ||
), | ||
$data | ||
); | ||
|
||
return new CompleteAuthoriseAndCaptureResponse( | ||
$this, | ||
$this->getResponseBody() | ||
); | ||
} | ||
|
||
/** | ||
* Get the HttpRequest. | ||
* Note: this is not an API request. | ||
* | ||
* @see Omnipay\Common\Message\AbstractRequest::$httpRequest | ||
* | ||
* @return Request | ||
*/ | ||
public function getHttpRequest(): Request | ||
{ | ||
return $this->httpRequest; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Omnipay\IcepayPayments\Message; | ||
|
||
/** | ||
* The response after complete authorise and capture request. | ||
* For this response, we explicitly check what the status is of the payment transaction at Icepay. | ||
*/ | ||
class CompleteAuthoriseAndCaptureResponse extends AbstractResponse | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isSuccessful(): bool | ||
{ | ||
return isset($this->data['status']) && in_array($this->data['status'], [ | ||
self::RESPONSE_STATUS_COMPLETED, | ||
self::RESPONSE_STATUS_SETTLED, | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* In case there is no status 'cancelled' available in the response (yet), check if there is statusCode in the | ||
* queryString. Icepay calls a postback to the completeUrl with data of the payment transaction as queryString. | ||
*/ | ||
public function isCancelled(): bool | ||
{ | ||
return isset($this->data['status']) && $this->data['status'] === self::RESPONSE_STATUS_CANCELLED | ||
|| $this->request->getHttpRequest()->get('statusCode') === self::RESPONSE_STATUS_CANCELLED; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransactionReference(): ?string | ||
{ | ||
return $this->request->getTransactionReference(); | ||
} | ||
} |
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
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
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,78 @@ | ||
<?php | ||
|
||
namespace Omnipay\IcepayPayments\Tests\Message; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use Omnipay\IcepayPayments\Message\CompleteAuthoriseAndCaptureRequest; | ||
use Omnipay\IcepayPayments\Message\CompleteAuthoriseAndCaptureResponse; | ||
use Omnipay\IcepayPayments\Tests\AbstractTestCase; | ||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; | ||
|
||
/** | ||
* Class CompleteAuthoriseAndCaptureRequestTest. | ||
*/ | ||
class CompleteAuthoriseAndCaptureRequestTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @var CompleteAuthoriseAndCaptureRequest | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* Creates a new CompleteAuthoriseAndCaptureRequestTest instance. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->request = new CompleteAuthoriseAndCaptureRequest($this->httpClient, $this->httpRequest); | ||
$this->request->setBaseUrl('https://www.superbrave.nl'); | ||
$this->request->setSecretKey('NjRlYjM3MTctOGI1ZC00MDg4LTgxMDgtOTMyMjQ2NzVlNTM4'); | ||
$this->request->setContractProfileId('64eb3717-8b5d-4088-8108-93224675e538'); | ||
$this->request->setTransactionReference('e7ca29c8-f1f4-4a4c-a968-0f9667d0519d'); | ||
} | ||
|
||
/** | ||
* Tests if CompleteAuthoriseAndCaptureRequest::getData validates the basic keys and returns an array of data. | ||
*/ | ||
public function testGetData(): void | ||
{ | ||
$expectedData = [ | ||
'ContractProfileId' => '64eb3717-8b5d-4088-8108-93224675e538', | ||
]; | ||
$this->assertEquals($expectedData, $this->request->getData()); | ||
} | ||
|
||
/** | ||
* Tests if CompleteAuthoriseAndCaptureRequest::sendData returns a CompleteAuthoriseAndCaptureResponse. | ||
*/ | ||
public function testSendData(): void | ||
{ | ||
$data = [ | ||
'AmountInCents' => 1337, | ||
'CurrencyCode' => 'EUR', | ||
'Reference' => '2fad9b1b-a2d3-455c-bc29-b79516fd3257', | ||
'Timestamp' => '2019-03-09T12:00:00Z', | ||
]; | ||
$response = $this->request->sendData($data); | ||
|
||
$this->assertInstanceOf(CompleteAuthoriseAndCaptureResponse::class, $response); | ||
|
||
$expectedRequest = new Request( | ||
SymfonyRequest::METHOD_POST, | ||
'https://www.superbrave.nl/transaction/e7ca29c8-f1f4-4a4c-a968-0f9667d0519d' | ||
); | ||
|
||
$this->assertEquals($expectedRequest->getMethod(), $this->clientMock->getLastRequest()->getMethod()); | ||
$this->assertEquals($expectedRequest->getUri(), $this->clientMock->getLastRequest()->getUri()); | ||
} | ||
|
||
/** | ||
* Tests if CompleteAuthoriseAndCaptureRequest getRequest function will return a Symfony HttpRequest object. | ||
*/ | ||
public function testGetHttpRequest(): void | ||
{ | ||
$this->assertSame($this->httpRequest, $this->request->getHttpRequest()); | ||
$this->assertInstanceOf(SymfonyRequest::class, $this->request->getHttpRequest()); | ||
} | ||
} |
Oops, something went wrong.