-
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
Recca Tsai
committed
Jan 23, 2017
1 parent
65d4832
commit 2eb327f
Showing
10 changed files
with
250 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action\Api; | ||
|
||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\GetTransactionData; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class GetTransactionDataAction extends BaseApiAwareAction | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param $request GetTransactionData | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$details->replace($this->api->getTransactionData((array) $details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof GetTransactionData && | ||
$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,40 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Action; | ||
|
||
use Payum\Core\Request\Sync; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\GetTransactionData; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class SyncAction 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 GetTransactionData($details)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Sync && | ||
$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
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 GetTransactionData 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,54 @@ | ||
<?php | ||
|
||
use Mockery as m; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Action\Api\GetTransactionDataAction; | ||
|
||
class GetTransactionDataActionTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function test_get_transaction_data() | ||
{ | ||
/* | ||
|------------------------------------------------------------ | ||
| Arrange | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$api = m::spy('PayumTW\Mypay\Api'); | ||
$request = m::spy('PayumTW\Mypay\Request\Api\GetTransactionData'); | ||
$details = m::mock(new ArrayObject([])); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Act | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request | ||
->shouldReceive('getModel')->andReturn($details); | ||
|
||
$api | ||
->shouldReceive('getTransactionData')->andReturn([ | ||
'RspCode' => '1', | ||
]); | ||
|
||
$action = new GetTransactionDataAction(); | ||
$action->setApi($api); | ||
$action->execute($request); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Assert | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request->shouldHaveReceived('getModel')->twice(); | ||
$api->shouldHaveReceived('getTransactionData')->once(); | ||
$details->shouldHaveReceived('replace')->once(); | ||
} | ||
} |
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
Oops, something went wrong.