-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
15 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,36 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action\Api; | ||
|
||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\CancelTransaction; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class CancelTransactionAction extends BaseApiAwareAction | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param $request RefundTransaction | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$details->validateNotEmpty(['uid', 'key']); | ||
|
||
$details->replace($this->api->cancelTransaction((array) $details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof CancelTransaction && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action\Api; | ||
|
||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\RefundTransaction; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class RefundTransactionAction extends BaseApiAwareAction | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param $request RefundTransaction | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$details->validateNotEmpty(['uid', 'key', 'cost']); | ||
|
||
$details->replace($this->api->refundTransaction((array) $details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof RefundTransaction && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action; | ||
|
||
use Payum\Core\Request\Cancel; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\CancelTransaction; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class CancelAction implements ActionInterface, GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param Cancel $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$this->gateway->execute(new CancelTransaction($details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Cancel && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action; | ||
|
||
use Payum\Core\Request\Refund; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\RefundTransaction; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class RefundAction implements ActionInterface, GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param Refund $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$this->gateway->execute(new RefundTransaction($details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Refund && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Request\Api; | ||
|
||
use Payum\Core\Request\Generic; | ||
|
||
class CancelTransaction extends Generic | ||
{ | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Request\Api; | ||
|
||
use Payum\Core\Request\Generic; | ||
|
||
class RefundTransaction extends Generic | ||
{ | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Tests\Action\Api; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\CancelTransaction; | ||
use PayumTW\Mypay\Action\Api\CancelTransactionAction; | ||
|
||
class CancelTransactionActionTest extends TestCase | ||
{ | ||
protected function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$action = new CancelTransactionAction(); | ||
$request = new CancelTransaction(new ArrayObject(['uid' => 'foo', 'key' => 'foo'])); | ||
|
||
$action->setApi( | ||
$api = m::mock('PayumTW\Mypay\Api') | ||
); | ||
|
||
$api->shouldReceive('cancelTransaction')->once()->with((array) $request->getModel())->andReturn($params = ['foo' => 'bar']); | ||
|
||
$action->execute($request); | ||
|
||
$this->assertSame(array_merge(['uid' => 'foo', 'key' => 'foo'], $params), (array) $request->getModel()); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Tests\Action\Api; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\RefundTransaction; | ||
use PayumTW\Mypay\Action\Api\RefundTransactionAction; | ||
|
||
class RefundTransactionActionTest extends TestCase | ||
{ | ||
protected function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$action = new RefundTransactionAction(); | ||
$request = new RefundTransaction(new ArrayObject(['uid' => 'foo_uid', 'key' => 'foo_key', 'cost' => 'foo_cost'])); | ||
|
||
$action->setApi( | ||
$api = m::mock('PayumTW\Mypay\Api') | ||
); | ||
|
||
$api->shouldReceive('refundTransaction')->once()->with((array) $request->getModel())->andReturn($params = ['foo' => 'bar']); | ||
|
||
$action->execute($request); | ||
|
||
$this->assertSame(array_merge(['uid' => 'foo_uid', 'key' => 'foo_key', 'cost' => 'foo_cost'], $params), (array) $request->getModel()); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Tests\Action; | ||
|
||
use Mockery as m; | ||
use Payum\Core\Request\Cancel; | ||
use PHPUnit\Framework\TestCase; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Action\CancelAction; | ||
|
||
class CancelActionTest extends TestCase | ||
{ | ||
protected function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$action = new CancelAction(); | ||
$request = new Cancel(new ArrayObject([])); | ||
|
||
$action->setGateway( | ||
$gateway = m::mock('Payum\Core\GatewayInterface') | ||
); | ||
|
||
$gateway->shouldReceive('execute')->once()->with('PayumTW\Mypay\Request\Api\CancelTransaction'); | ||
|
||
$this->assertNull($action->execute($request)); | ||
} | ||
} |
Oops, something went wrong.