Skip to content

Commit 04a46ca

Browse files
committed
[PayumPayzen] Initial commit.
0 parents  commit 04a46ca

17 files changed

+1116
-0
lines changed

.gitattributes

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Standard to msysgit
5+
*.doc diff=astextplain
6+
*.DOC diff=astextplain
7+
*.docx diff=astextplain
8+
*.DOCX diff=astextplain
9+
*.dot diff=astextplain
10+
*.DOT diff=astextplain
11+
*.pdf diff=astextplain
12+
*.PDF diff=astextplain
13+
*.rtf diff=astextplain
14+
*.RTF diff=astextplain

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Thumbs.db
2+
ehthumbs.db
3+
.DS_Store
4+
vendor
5+
composer.lock

Action/Api/AbstractApiAction.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action\Api;
4+
5+
use Ekyna\Component\Payum\Payzen\Api\Api;
6+
use Payum\Core\Action\ActionInterface;
7+
use Payum\Core\ApiAwareInterface;
8+
use Payum\Core\Exception\UnsupportedApiException;
9+
use Payum\Core\GatewayAwareInterface;
10+
use Payum\Core\GatewayAwareTrait;
11+
12+
/**
13+
* Class AbstractApiAction
14+
* @package Ekyna\Component\Payum\Payzen\Action\Api
15+
* @author Etienne Dauvergne <contact@ekyna.com>
16+
*/
17+
abstract class AbstractApiAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface
18+
{
19+
use GatewayAwareTrait;
20+
21+
/**
22+
* @var Api
23+
*/
24+
protected $api;
25+
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function setApi($api)
31+
{
32+
if (false == $api instanceof Api) {
33+
throw new UnsupportedApiException('Not supported.');
34+
}
35+
36+
$this->api = $api;
37+
}
38+
}

Action/Api/ApiRequestAction.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action\Api;
4+
5+
use Ekyna\Component\Payum\Payzen\Request\Request;
6+
use Payum\Core\Bridge\Spl\ArrayObject;
7+
use Payum\Core\Exception\RequestNotSupportedException;
8+
use Payum\Core\Reply\HttpRedirect;
9+
10+
/**
11+
* Class RequestAction
12+
* @package Ekyna\Component\Payum\Payzen\Action\Api
13+
* @author Etienne Dauvergne <contact@ekyna.com>
14+
*/
15+
class ApiRequestAction extends AbstractApiAction
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @throws \Payum\Core\Reply\HttpRedirect
21+
*/
22+
public function execute($request)
23+
{
24+
/** @var Request $request */
25+
RequestNotSupportedException::assertSupports($this, $request);
26+
27+
$model = ArrayObject::ensureArrayObject($request->getModel());
28+
29+
if ($model['vads_trans_id']) {
30+
return;
31+
}
32+
33+
$model['vads_trans_id'] = $this->api->getTransactionId();
34+
$model['vads_trans_date'] = date('YmdHis');
35+
36+
$url = $this->api->createRequestUrl($model->getArrayCopy());
37+
38+
throw new HttpRedirect($url);
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function supports($request)
45+
{
46+
return $request instanceof Request
47+
&& $request->getModel() instanceof \ArrayAccess;
48+
}
49+
}

Action/Api/ApiResponseAction.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action\Api;
4+
5+
use Ekyna\Component\Payum\Payzen\Request\Response;
6+
use Payum\Core\Bridge\Spl\ArrayObject;
7+
use Payum\Core\Exception\RequestNotSupportedException;
8+
use Payum\Core\Request\GetHttpRequest;
9+
/**
10+
* Class ResponseAction
11+
* @package Ekyna\Component\Payum\Payzen\Action\Api
12+
* @author Etienne Dauvergne <contact@ekyna.com>
13+
*/
14+
class ApiResponseAction extends AbstractApiAction
15+
{
16+
/**
17+
* @inheritdoc
18+
*/
19+
public function execute($request)
20+
{
21+
/** @var Response $request */
22+
RequestNotSupportedException::assertSupports($this, $request);
23+
24+
$model = ArrayObject::ensureArrayObject($request->getModel());
25+
26+
$this->gateway->execute($httpRequest = new GetHttpRequest());
27+
28+
if (isset($httpRequest->request['vads_result'])) {
29+
$data = $httpRequest->request;
30+
} elseif (isset($httpRequest->query['vads_result'])) {
31+
$data = $httpRequest->query;
32+
} else {
33+
return;
34+
}
35+
36+
// Check amount
37+
if ($model['vads_amount'] != $data['vads_amount']) {
38+
return;
39+
}
40+
41+
// Check the response signature
42+
if ($this->api->checkResponseSignature($data)) {
43+
// Update the payment details
44+
$model->replace($data);
45+
$request->setModel($model);
46+
}
47+
}
48+
49+
/**
50+
* @inheritdec
51+
*/
52+
public function supports($request)
53+
{
54+
return $request instanceof Response
55+
&& $request->getModel() instanceof \ArrayAccess;
56+
}
57+
}

Action/CaptureAction.php

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action;
4+
5+
use Ekyna\Component\Payum\Payzen\Request\Request;
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\Capture;
12+
use Payum\Core\Request\GetHttpRequest;
13+
use Payum\Core\Request\Sync;
14+
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
15+
use Payum\Core\Security\GenericTokenFactoryAwareTrait;
16+
17+
/**
18+
* Class CaptureAction
19+
* @package Ekyna\Component\Payum\Payzen\Action
20+
* @author Etienne Dauvergne <contact@ekyna.com>
21+
*/
22+
class CaptureAction implements ActionInterface, GatewayAwareInterface, GenericTokenFactoryAwareInterface
23+
{
24+
use GatewayAwareTrait;
25+
use GenericTokenFactoryAwareTrait;
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function execute($request)
31+
{
32+
RequestNotSupportedException::assertSupports($this, $request);
33+
34+
$model = ArrayObject::ensureArrayObject($request->getModel());
35+
36+
37+
if ($request->getToken()) {
38+
// Done redirections
39+
$targetUrl = $request->getToken()->getTargetUrl();
40+
$doneUrlFields = [
41+
'vads_url_cancel', // Annuler et retourner à la boutique
42+
'vads_url_error', // Erreur de traitement interne
43+
'vads_url_referral', // 02 contacter l'émetteur de la carte
44+
'vads_url_refused', // Refus autre que 02
45+
'vads_url_success', // 00 Success
46+
'vads_url_return', // Retour à la boutique
47+
];
48+
foreach ($doneUrlFields as $field) {
49+
if (false == $model[$field]) {
50+
$model[$field] = $targetUrl;
51+
}
52+
}
53+
54+
// Notify url
55+
if (empty($model['vads_url_check']) && $this->tokenFactory) {
56+
$notifyToken = $this->tokenFactory->createNotifyToken(
57+
$request->getToken()->getGatewayName(),
58+
$request->getToken()->getDetails()
59+
);
60+
$model['vads_url_check'] = $notifyToken->getTargetUrl();
61+
}
62+
}
63+
64+
if (false == $model['vads_trans_id']) {
65+
$this->gateway->execute(new Request($model));
66+
}
67+
68+
$this->gateway->execute(new Sync($model));
69+
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function supports($request)
75+
{
76+
return $request instanceof Capture
77+
&& $request->getModel() instanceof \ArrayAccess;
78+
}
79+
}

Action/ConvertPaymentAction.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Ekyna\Component\Payum\Payzen\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\Bridge\Spl\ArrayObject;
7+
use Payum\Core\Exception\RequestNotSupportedException;
8+
use Payum\Core\Exception\RuntimeException;
9+
use Payum\Core\GatewayAwareInterface;
10+
use Payum\Core\GatewayAwareTrait;
11+
use Payum\Core\Model\PaymentInterface;
12+
use Payum\Core\Request\Convert;
13+
use Payum\Core\Request\GetCurrency;
14+
15+
/**
16+
* Class ConvertPaymentAction
17+
* @package Ekyna\Component\Payum\Payzen\Action
18+
* @author Etienne Dauvergne <contact@ekyna.com>
19+
*/
20+
class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface
21+
{
22+
use GatewayAwareTrait;
23+
24+
/**
25+
* {@inheritDoc}
26+
*
27+
* @param Convert $request
28+
*/
29+
public function execute($request)
30+
{
31+
RequestNotSupportedException::assertSupports($this, $request);
32+
33+
/** @var PaymentInterface $payment */
34+
$payment = $request->getSource();
35+
36+
$model = ArrayObject::ensureArrayObject($payment->getDetails());
37+
38+
if (false == $model['vads_amount']) {
39+
$this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode()));
40+
if (2 < $currency->exp) {
41+
throw new RuntimeException('Unexpected currency exp.');
42+
}
43+
$divisor = pow(10, 2 - $currency->exp);
44+
45+
$model['vads_currency'] = $currency->numeric;
46+
$model['vads_amount'] = abs($payment->getTotalAmount() / $divisor);
47+
}
48+
49+
if (false == $model['vads_order_id']) {
50+
$model['vads_order_id'] = $payment->getNumber();
51+
}
52+
if (false == $model['vads_cust_id']) {
53+
$model['vads_cust_id'] = $payment->getClientId();
54+
}
55+
if (false == $model['vads_cust_email']) {
56+
$model['vads_cust_email'] = $payment->getClientEmail();
57+
}
58+
59+
$request->setResult((array)$model);
60+
}
61+
62+
/**
63+
* {@inheritDoc}
64+
*/
65+
public function supports($request)
66+
{
67+
return $request instanceof Convert
68+
&& $request->getSource() instanceof PaymentInterface
69+
&& $request->getTo() == 'array';
70+
}
71+
}

Action/NotifyAction.php

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

0 commit comments

Comments
 (0)