|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PTS\Paysera\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\Model\PaymentInterface; |
|
11
|
|
|
use Payum\Core\Request\Convert; |
|
12
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareInterface; |
|
13
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareTrait; |
|
14
|
|
|
|
|
15
|
|
|
class ConvertPaymentAction implements ActionInterface, GenericTokenFactoryAwareInterface, GatewayAwareInterface |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
use GatewayAwareTrait; |
|
19
|
|
|
|
|
20
|
|
|
use GenericTokenFactoryAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritDoc} |
|
24
|
|
|
* |
|
25
|
|
|
* @param Convert $request |
|
26
|
|
|
*/ |
|
27
|
5 |
|
public function execute($request) |
|
28
|
|
|
{ |
|
29
|
5 |
|
RequestNotSupportedException::assertSupports($this, $request); |
|
30
|
|
|
/** |
|
31
|
|
|
* @var $order PaymentInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
$order = $request->getSource(); |
|
34
|
|
|
|
|
35
|
|
|
$details = ArrayObject::ensureArrayObject($order->getDetails()); |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$details['amount'] = $order->getTotalAmount(); |
|
39
|
|
|
$details['currency'] = $order->getCurrencyCode(); |
|
40
|
|
|
$details['orderid'] = $order->getNumber(); |
|
41
|
|
|
$details['description'] = $order->getDescription(); |
|
42
|
|
|
$details['p_email'] = $order->getClientEmail(); |
|
43
|
|
|
$details['personcode'] = $order->getClientId(); |
|
44
|
|
|
$details['customerIp'] = array_key_exists('REMOTE_ADDR', $_SERVER) ? $_SERVER['REMOTE_ADDR'] : null; |
|
45
|
|
|
|
|
46
|
|
|
$token = $request->getToken(); |
|
47
|
|
|
|
|
48
|
|
|
$details['accepturl'] = $token->getTargetUrl(); |
|
49
|
|
|
$details['cancelurl'] = $token->getTargetUrl() . '?cancel=true'; |
|
50
|
|
|
|
|
51
|
|
|
$notifyToken = $this->tokenFactory->createNotifyToken( |
|
52
|
|
|
$token->getGatewayName(), |
|
53
|
|
|
$token->getDetails() |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$details['callbackurl'] = $notifyToken->getTargetUrl(); |
|
57
|
|
|
|
|
58
|
|
|
$request->setResult((array)$details); |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritDoc} |
|
64
|
|
|
*/ |
|
65
|
13 |
|
public function supports($request) |
|
66
|
|
|
{ |
|
67
|
|
|
return |
|
68
|
13 |
|
$request instanceof Convert && |
|
69
|
5 |
|
$request->getSource() instanceof PaymentInterface && |
|
70
|
13 |
|
$request->getTo() == 'array'; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|