Skip to content

Commit 855b0e7

Browse files
committed
[Payzen] Fix transactionId generation. Added refund action.
1 parent b34a365 commit 855b0e7

5 files changed

+56
-6
lines changed

Action/CaptureAction.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Payum\Core\GatewayAwareInterface;
1010
use Payum\Core\GatewayAwareTrait;
1111
use Payum\Core\Request\Capture;
12-
use Payum\Core\Request\GetHttpRequest;
1312
use Payum\Core\Request\Sync;
1413
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
1514
use Payum\Core\Security\GenericTokenFactoryAwareTrait;

Action/RefundAction.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\Refund;
12+
13+
/**
14+
* Class CaptureAction
15+
* @package Ekyna\Component\Payum\Payzen\Action
16+
* @author Etienne Dauvergne <contact@ekyna.com>
17+
*/
18+
class RefundAction implements ActionInterface, GatewayAwareInterface
19+
{
20+
use GatewayAwareTrait;
21+
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function execute($request)
26+
{
27+
RequestNotSupportedException::assertSupports($this, $request);
28+
29+
$model = ArrayObject::ensureArrayObject($request->getModel());
30+
31+
$this->gateway->execute($status = new GetHumanStatus($model));
32+
if ($status->isCaptured()) {
33+
$model['state_override'] = 'refunded';
34+
}
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function supports($request)
41+
{
42+
return $request instanceof Refund
43+
&& $request->getModel() instanceof \ArrayAccess;
44+
}
45+
}

Action/StatusAction.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function execute($request)
3131
return;
3232
}
3333

34-
35-
36-
if (false != $responseCode = $model['vads_auth_result']) {
37-
switch ($responseCode) {
34+
if (false != $code = $model['vads_auth_result']) {
35+
switch ($code) {
3836
case "00" : // transaction approuvée ou traitée avec succès
3937
$request->markCaptured();
4038
break;
@@ -81,6 +79,12 @@ public function execute($request)
8179
$request->markUnknown();
8280
}
8381

82+
if ($request->isCaptured() && false != $code = $model['state_override']) {
83+
if ($code == 'refunded') {
84+
$request->markRefunded();
85+
}
86+
}
87+
8488
return;
8589
}
8690

Api/Api.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function getTransactionId()
8080

8181
$id = 1;
8282
$date = (new \DateTime())->format('Ymd');
83-
$isDailyFirstAccess = ($date != date('Ymd', fileatime($path)));
83+
$fileDate = date('Ymd', filemtime($path));
84+
$isDailyFirstAccess = ($date != $fileDate);
8485

8586
// Open file
8687
$handle = fopen($this->config['trans_id_file_path'], 'r+');

PayzenGatewayFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected function populateConfig(ArrayObject $config)
4444
'payum.action.api_request' => new Action\Api\ApiRequestAction(),
4545
'payum.action.api_response' => new Action\Api\ApiResponseAction(),
4646
'payum.action.sync' => new Action\SyncAction(),
47+
'payum.action.refund' => new Action\RefundAction(),
4748
'payum.action.status' => new Action\StatusAction(),
4849
]);
4950

0 commit comments

Comments
 (0)