1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2017 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Service\Decorator; |
12
|
|
|
|
13
|
|
|
use \Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
use \Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base for service frontend controller decorators |
19
|
|
|
* |
20
|
|
|
* @package Controller |
21
|
|
|
* @subpackage Frontend |
22
|
|
|
*/ |
23
|
|
|
abstract class Base |
24
|
|
|
extends \Aimeos\Controller\Frontend\Base |
25
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Service\Iface |
26
|
|
|
{ |
27
|
|
|
private $controller; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes the controller decorator. |
32
|
|
|
* |
33
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
34
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
35
|
|
|
*/ |
36
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
37
|
|
|
{ |
38
|
|
|
$iface = '\Aimeos\Controller\Frontend\Service\Iface'; |
39
|
|
|
if( !( $controller instanceof $iface ) ) |
40
|
|
|
{ |
41
|
|
|
$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface ); |
42
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( $msg ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->controller = $controller; |
46
|
|
|
|
47
|
|
|
parent::__construct( $context ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Passes unknown methods to wrapped objects. |
53
|
|
|
* |
54
|
|
|
* @param string $name Name of the method |
55
|
|
|
* @param array $param List of method parameter |
56
|
|
|
* @return mixed Returns the value of the called method |
57
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
58
|
|
|
*/ |
59
|
|
|
public function __call( $name, array $param ) |
60
|
|
|
{ |
61
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns a list of attributes that are invalid |
67
|
|
|
* |
68
|
|
|
* @param string $serviceId Unique service ID |
69
|
|
|
* @param string[] $attributes List of attribute codes as keys and strings entered by the customer as value |
70
|
|
|
* @return string[] List of attributes codes as keys and error messages as values for invalid or missing values |
71
|
|
|
*/ |
72
|
|
|
public function checkAttributes( $serviceId, array $attributes ) |
73
|
|
|
{ |
74
|
|
|
return $this->controller->checkAttributes( $serviceId, $attributes ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the service item for the given ID |
80
|
|
|
* |
81
|
|
|
* @param string $serviceId Unique service ID |
82
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
83
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface Service provider object |
84
|
|
|
*/ |
85
|
|
|
public function getProvider( $serviceId, $ref = ['media', 'price', 'text'] ) |
86
|
|
|
{ |
87
|
|
|
return $this->controller->getProvider( $serviceId, $ref ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the service providers for the given type |
93
|
|
|
* |
94
|
|
|
* @param string|null $type Service type, e.g. "delivery" (shipping related), "payment" (payment related) or null for all |
95
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
96
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values |
97
|
|
|
*/ |
98
|
|
|
public function getProviders( $type = null, $ref = ['media', 'price', 'text'] ) |
99
|
|
|
{ |
100
|
|
|
return $this->controller->getProviders( $type, $ref ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Processes the service for the given order, e.g. payment and delivery services |
106
|
|
|
* |
107
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order which should be processed |
108
|
|
|
* @param string $serviceId Unique service item ID |
109
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
110
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
111
|
|
|
* @param array $params Request parameters and order service attributes |
112
|
|
|
* @return \Aimeos\MShop\Common\Item\Helper\Form\Iface|null Form object with URL, parameters, etc. |
113
|
|
|
* or null if no form data is required |
114
|
|
|
*/ |
115
|
|
|
public function process( \Aimeos\MShop\Order\Item\Iface $orderItem, $serviceId, array $urls, array $params ) |
116
|
|
|
{ |
117
|
|
|
return $this->controller->process( $orderItem, $serviceId, $urls, $params ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Updates the order status sent by payment gateway notifications |
123
|
|
|
* |
124
|
|
|
* @param ServerRequestInterface $request Request object |
125
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
126
|
|
|
* @param string $code Unique code of the service used for the current order |
127
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object |
128
|
|
|
*/ |
129
|
|
|
public function updatePush( ServerRequestInterface $request, ResponseInterface $response, $code ) |
130
|
|
|
{ |
131
|
|
|
return $this->controller->updatePush( $request, $response, $code ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Updates the payment or delivery status for the given request |
137
|
|
|
* |
138
|
|
|
* @param ServerRequestInterface $request Request object with parameters and request body |
139
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
140
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
141
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
142
|
|
|
* @param string $code Unique code of the service used for the current order |
143
|
|
|
* @param string $orderid Unique ID of the order whose payment status should be updated |
144
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated |
145
|
|
|
*/ |
146
|
|
|
public function updateSync( ServerRequestInterface $request, ResponseInterface $response, array $urls, $code, $orderid ) |
147
|
|
|
{ |
148
|
|
|
return $this->controller->updateSync( $request, $response, $urls, $code, $orderid ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the frontend controller |
154
|
|
|
* |
155
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Frontend controller object |
156
|
|
|
*/ |
157
|
|
|
protected function getController() |
158
|
|
|
{ |
159
|
|
|
return $this->controller; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|