forked from thephpleague/omnipay-mollie
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from MyOnlineStore/void
Implement void method for order API
- Loading branch information
Showing
6 changed files
with
168 additions
and
1 deletion.
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,35 @@ | ||
<?php | ||
|
||
namespace Omnipay\Mollie\Message\Request; | ||
|
||
use Omnipay\Mollie\Message\Response\CancelOrderResponse; | ||
|
||
/** | ||
* Cancel an order with the Mollie API. | ||
* | ||
* @see https://docs.mollie.com/reference/v2/orders-api/cancel-order | ||
* @method CancelOrderResponse send() | ||
*/ | ||
final class CancelOrderRequest extends AbstractMollieRequest | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getData() | ||
{ | ||
$this->validate('apiKey', 'transactionReference'); | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function sendData($data) | ||
{ | ||
return $this->response = new CancelOrderResponse( | ||
$this, | ||
$this->sendRequest(self::DELETE, '/orders/'.$this->getTransactionReference(), $data) | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Omnipay\Mollie\Message\Response; | ||
|
||
/** | ||
* @see https://docs.mollie.com/reference/v2/orders-api/cancel-order | ||
*/ | ||
final class CancelOrderResponse extends FetchOrderResponse | ||
{ | ||
/** | ||
* @return bool | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
if (!isset($this->data['status'])) { | ||
return false; | ||
} | ||
|
||
return 'canceled' === $this->data['status']; | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
|
||
namespace Omnipay\Mollie\Test\Message; | ||
|
||
use Omnipay\Common\Http\ClientInterface; | ||
use Omnipay\Mollie\Message\Request\CancelOrderRequest; | ||
use Omnipay\Mollie\Message\Response\CancelOrderResponse; | ||
use Omnipay\Tests\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
final class CancelOrderRequestTest extends TestCase | ||
{ | ||
/** | ||
* @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $httpClient; | ||
|
||
/** | ||
* @var CancelOrderRequest | ||
*/ | ||
private $request; | ||
|
||
public function setUp() | ||
{ | ||
$this->httpClient = $this->createMock(ClientInterface::class); | ||
$this->request = new CancelOrderRequest($this->httpClient, $this->getHttpRequest()); | ||
} | ||
|
||
public function insufficientDataProvider() | ||
{ | ||
return [ | ||
[['apiKey' => 'mykey']], | ||
[['transactionReference' => 'myref']], | ||
]; | ||
} | ||
|
||
public function responseDataProvider() | ||
{ | ||
return [ | ||
[['id' => 'ord_kEn1PlbGa'], false], | ||
[['status' => 'paid', 'id' => 'ord_kEn1PlbGa'], false], | ||
[['status' => 'canceled', 'id' => 'ord_kEn1PlbGa'], true], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider insufficientDataProvider | ||
* | ||
* @expectedException \Omnipay\Common\Exception\InvalidRequestException | ||
* | ||
* @param array $input | ||
*/ | ||
public function testGetDataWillValidateRequiredData(array $input) | ||
{ | ||
$this->request->initialize($input); | ||
$this->request->getData(); | ||
} | ||
|
||
public function testGetDataWillReturnEmptyArray() | ||
{ | ||
$this->request->initialize(['apiKey' => 'mykey', 'transactionReference' => 'myref']); | ||
self::assertEquals([], $this->request->getData()); | ||
} | ||
|
||
/** | ||
* @dataProvider responseDataProvider | ||
*/ | ||
public function testSendData(array $responseData, $success) | ||
{ | ||
$response = $this->createMock(ResponseInterface::class); | ||
$response->expects(self::once()) | ||
->method('getBody') | ||
->willReturn(\json_encode($responseData)); | ||
|
||
$this->httpClient->expects(self::once()) | ||
->method('request') | ||
->with( | ||
'DELETE', | ||
'https://api.mollie.com/v2/orders/ord_kEn1PlbGa', | ||
['Authorization' => 'Bearer mykey'] | ||
)->willReturn($response); | ||
|
||
$this->request->initialize(['apiKey' => 'mykey', 'transactionReference' => 'ord_kEn1PlbGa']); | ||
$voidResponse = $this->request->sendData([]); | ||
|
||
$this->assertInstanceOf(CancelOrderResponse::class, $voidResponse); | ||
$this->assertEquals($success, $voidResponse->isSuccessful()); | ||
$this->assertSame('ord_kEn1PlbGa', $voidResponse->getTransactionReference()); | ||
} | ||
} |