File tree 4 files changed +58
-0
lines changed
4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public function execute($request)
31
31
$ model = ArrayObject::ensureArrayObject ($ request ->getModel ());
32
32
33
33
$ this ->gateway ->execute ($ status = new GetHumanStatus ($ model ));
34
+
34
35
if ($ status ->isCaptured ()) {
35
36
$ model ['state_override ' ] = 'refunded ' ;
36
37
}
Original file line number Diff line number Diff line change @@ -90,6 +90,14 @@ public function execute($request)
90
90
return ;
91
91
}
92
92
93
+ if (false != $ code = $ model ['state_override ' ]) {
94
+ if ($ code == 'canceled ' ) {
95
+ $ request ->markCanceled ();
96
+
97
+ return ;
98
+ }
99
+ }
100
+
93
101
$ request ->markNew ();
94
102
}
95
103
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ protected function populateConfig(ArrayObject $config)
38
38
'payum.action.capture ' => new Action \CaptureAction (),
39
39
'payum.action.convert_payment ' => new Action \ConvertPaymentAction (),
40
40
'payum.action.sync ' => new Action \SyncAction (),
41
+ 'payum.action.cancel ' => new Action \CancelAction (),
41
42
'payum.action.refund ' => new Action \RefundAction (),
42
43
'payum.action.status ' => new Action \StatusAction (),
43
44
'payum.action.notify ' => new Action \NotifyAction (),
You can’t perform that action at this time.
0 commit comments