-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added NotifyAction #28
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,19 +2,26 @@ | |
|
||
namespace Payum\OmnipayBridge\Action; | ||
|
||
use Omnipay\Common\GatewayInterface; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\ApiAwareInterface; | ||
use Payum\Core\ApiAwareTrait; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Reply\HttpResponse; | ||
use Payum\Core\Request\Notify; | ||
|
||
/** | ||
* @author Steffen Brem <[email protected]> | ||
*/ | ||
class NotifyAction extends BaseApiAwareAction implements GatewayAwareInterface | ||
class NotifyAction implements ApiAwareInterface, ActionInterface | ||
{ | ||
use GatewayAwareTrait; | ||
use ApiAwareTrait; | ||
|
||
public function __construct() | ||
{ | ||
$this->apiClass = GatewayInterface::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
|
@@ -25,7 +32,11 @@ public function execute($request) | |
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$response = $this->omnipayGateway->fetchTransaction($details->toUnsafeArray())->send(); | ||
if (method_exists($this->api, 'fetchTransaction')) { | ||
$response = $this->api->fetchTransaction($details->toUnsafeArray())->send(); | ||
} else if (method_exists($this->api, 'acceptNotification')) { | ||
$response = $this->api->acceptNotification($details->toUnsafeArray())->send(); | ||
} | ||
|
||
$details->replace((array)$response->getData()); | ||
|
||
|
@@ -43,8 +54,10 @@ public function supports($request) | |
{ | ||
return | ||
$request instanceof Notify && | ||
$request->getModel() instanceof \ArrayAccess && | ||
method_exists($this->omnipayGateway, 'fetchTransaction') | ||
$request->getModel() instanceof \ArrayAccess && ( | ||
method_exists($this->api, 'fetchTransaction') || | ||
method_exists($this->api, 'acceptNotification') | ||
) | ||
; | ||
} | ||
} |
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,100 @@ | ||
<?php | ||
|
||
namespace Payum\OmnipayBridge\Tests\Action; | ||
|
||
use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface as OmnipayRequestInterface; | ||
use Omnipay\Common\Message\ResponseInterface as OmnipayResponseInterface; | ||
use Payum\Core\Reply\HttpResponse; | ||
use Payum\Core\Request\Notify; | ||
use Payum\Core\Tests\GenericActionTest; | ||
use Payum\OmnipayBridge\Action\NotifyAction; | ||
use Payum\OmnipayBridge\Tests\MollieGateway; | ||
|
||
/** | ||
* @author Steffen Brem <[email protected]> | ||
*/ | ||
class NotifyActionTest extends GenericActionTest | ||
{ | ||
protected $actionClass = NotifyAction::class; | ||
|
||
protected function setUp() | ||
{ | ||
$this->action = new $this->actionClass(); | ||
$this->action->setApi(new MollieGateway()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSetStatusCapturedWhenSuccessful() | ||
{ | ||
$model = new \ArrayObject([]); | ||
|
||
$responseMock = $this->getMock(OmnipayResponseInterface::class); | ||
$responseMock | ||
->method('isSuccessful') | ||
->willReturn(true) | ||
; | ||
|
||
$requestMock = $this->getMock(OmnipayRequestInterface::class); | ||
$requestMock | ||
->expects($this->once()) | ||
->method('send') | ||
->willReturn($responseMock) | ||
; | ||
|
||
$action = new NotifyAction(); | ||
|
||
$gateway = new MollieGateway(); | ||
$gateway->returnFetchTransaction = $requestMock; | ||
$action->setApi($gateway); | ||
|
||
try { | ||
$action->execute(new Notify($model)); | ||
} catch (HttpResponse $e) { | ||
$this->assertEquals(200, $e->getStatusCode()); | ||
} | ||
|
||
$details = iterator_to_array($model); | ||
|
||
$this->assertEquals('captured', $details['_status']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSetStatusFailedWhenNotSuccessful() | ||
{ | ||
$model = new \ArrayObject([]); | ||
|
||
$responseMock = $this->getMock(OmnipayResponseInterface::class); | ||
$responseMock | ||
->method('isSuccessful') | ||
->willReturn(false) | ||
; | ||
|
||
$requestMock = $this->getMock(OmnipayRequestInterface::class); | ||
$requestMock | ||
->expects($this->once()) | ||
->method('send') | ||
->willReturn($responseMock) | ||
; | ||
|
||
$action = new NotifyAction(); | ||
|
||
$gateway = new MollieGateway(); | ||
$gateway->returnFetchTransaction = $requestMock; | ||
$action->setApi($gateway); | ||
|
||
try { | ||
$action->execute(new Notify($model)); | ||
} catch (HttpResponse $e) { | ||
$this->assertEquals(200, $e->getStatusCode()); | ||
} | ||
|
||
$details = iterator_to_array($model); | ||
|
||
$this->assertEquals('failed', $details['_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Payum\OmnipayBridge\Tests; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
|
||
/** | ||
* @author Steffen Brem <[email protected]> | ||
*/ | ||
class MollieGateway extends AbstractGateway | ||
{ | ||
public $returnFetchTransaction; | ||
|
||
public function getName() {} | ||
|
||
public function fetchTransaction() | ||
{ | ||
return $this->returnFetchTransaction; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not we try call acceptNotification first?