1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Generalization over Omnipay and Payum |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/php-merchant |
6
|
|
|
* @package php-merchant |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\php\merchant; |
12
|
|
|
|
13
|
|
|
abstract class AbstractMerchant implements MerchantInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string Unique merchant identification. E.g. paypal, webmoney_usd, webmoney_rub. |
17
|
|
|
*/ |
18
|
|
|
public $id; |
19
|
|
|
|
20
|
|
|
public $library; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string gateway name, corresponding to namespace, e.g.: paypal, webmoney |
24
|
|
|
*/ |
25
|
|
|
public $gateway; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array Data that will be passed to Request |
29
|
|
|
* @see request |
30
|
|
|
*/ |
31
|
|
|
public $data = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string gateway label that should be used to display the merchant, e.g.: PayPal, WebMoney |
35
|
|
|
*/ |
36
|
|
|
public $label; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string request class name |
40
|
|
|
*/ |
41
|
|
|
public $requestClass; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string response class name |
45
|
|
|
*/ |
46
|
|
|
public $responseClass; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getLabel() |
52
|
|
|
{ |
53
|
|
|
return $this->label; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getGateway() |
60
|
|
|
{ |
61
|
|
|
return $this->gateway; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
abstract public function getGatewayNamespacePart(); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
* @return AbstractRequest |
72
|
|
|
*/ |
73
|
1 |
|
public function request($type, array $data) |
74
|
|
|
{ |
75
|
1 |
|
return Helper::createObject([ |
76
|
1 |
|
'class' => $this->getRequestClass(), |
77
|
1 |
|
'merchant' => $this, |
78
|
1 |
|
'type' => $type, |
79
|
1 |
|
'data' => array_merge((array) $this->data, (array) $data), |
80
|
1 |
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param RequestInterface $request |
85
|
|
|
* @return AbstractResponse |
86
|
|
|
*/ |
87
|
1 |
|
public function response(RequestInterface $request) |
88
|
|
|
{ |
89
|
1 |
|
return Helper::createObject([ |
90
|
1 |
|
'class' => $this->getResponseClass(), |
91
|
1 |
|
'merchant' => $this, |
92
|
1 |
|
'request' => $request, |
93
|
1 |
|
]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
1 |
|
public function getRequestClass() |
100
|
|
|
{ |
101
|
1 |
|
return $this->requestClass ?: Helper::findClass($this->gateway, $this->library, 'Request'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
1 |
|
public function getResponseClass() |
108
|
|
|
{ |
109
|
1 |
|
return $this->responseClass ?: Helper::findClass($this->gateway, $this->library, 'Response'); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|