Skip to content

Commit 9854667

Browse files
committed
Added cancel action.
1 parent 1cf06a5 commit 9854667

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

Action/CancelAction.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action;
4+
5+
use Ekyna\Component\Commerce\Bridge\Payum\Request\GetHumanStatus;
6+
use Payum\Core\Action\ActionInterface;
7+
use Payum\Core\Bridge\Spl\ArrayObject;
8+
use Payum\Core\Exception\RequestNotSupportedException;
9+
use Payum\Core\GatewayAwareInterface;
10+
use Payum\Core\GatewayAwareTrait;
11+
use Payum\Core\Request\Cancel;
12+
13+
/**
14+
* Class CancelAction
15+
* @package Ekyna\Component\Payum\Payzen\Action
16+
* @author Etienne Dauvergne <contact@ekyna.com>
17+
*/
18+
class CancelAction implements ActionInterface, GatewayAwareInterface
19+
{
20+
use GatewayAwareTrait;
21+
22+
/**
23+
* {@inheritdoc}
24+
*
25+
* @param Cancel $request
26+
*/
27+
public function execute($request)
28+
{
29+
RequestNotSupportedException::assertSupports($this, $request);
30+
31+
$model = ArrayObject::ensureArrayObject($request->getModel());
32+
33+
$this->gateway->execute($status = new GetHumanStatus($model));
34+
35+
if ($status->isNew()) {
36+
$model['state_override'] = 'canceled';
37+
}
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function supports($request)
44+
{
45+
return $request instanceof Cancel
46+
&& $request->getModel() instanceof \ArrayAccess;
47+
}
48+
}

Action/RefundAction.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function execute($request)
3131
$model = ArrayObject::ensureArrayObject($request->getModel());
3232

3333
$this->gateway->execute($status = new GetHumanStatus($model));
34+
3435
if ($status->isCaptured()) {
3536
$model['state_override'] = 'refunded';
3637
}

Action/StatusAction.php

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public function execute($request)
9090
return;
9191
}
9292

93+
if (false != $code = $model['state_override']) {
94+
if ($code == 'canceled') {
95+
$request->markCanceled();
96+
97+
return;
98+
}
99+
}
100+
93101
$request->markNew();
94102
}
95103

PayzenGatewayFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function populateConfig(ArrayObject $config)
3838
'payum.action.capture' => new Action\CaptureAction(),
3939
'payum.action.convert_payment' => new Action\ConvertPaymentAction(),
4040
'payum.action.sync' => new Action\SyncAction(),
41+
'payum.action.cancel' => new Action\CancelAction(),
4142
'payum.action.refund' => new Action\RefundAction(),
4243
'payum.action.status' => new Action\StatusAction(),
4344
'payum.action.notify' => new Action\NotifyAction(),

0 commit comments

Comments
 (0)