|
1
|
|
|
<?php |
|
2
|
|
|
namespace PTS\Paysera; |
|
3
|
|
|
|
|
4
|
|
|
use function League\Uri\create; |
|
5
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
|
6
|
|
|
use Payum\Core\Reply\HttpPostRedirect; |
|
7
|
|
|
use WebToPay; |
|
8
|
|
|
|
|
9
|
|
|
class Api |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var mixed |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $options = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Api constructor. |
|
18
|
|
|
* @param array $options |
|
19
|
|
|
*/ |
|
20
|
4 |
|
public function __construct(array $options) |
|
21
|
|
|
{ |
|
22
|
4 |
|
$options = ArrayObject::ensureArrayObject($options); |
|
23
|
4 |
|
$options->defaults($this->options); |
|
24
|
4 |
|
$this->options = $options; |
|
25
|
4 |
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
public function doPayment(array $fields) |
|
28
|
|
|
{ |
|
29
|
2 |
|
$fields['projectid'] = $this->options['projectid']; |
|
30
|
2 |
|
$fields['sign_password'] = $this->options['sign_password']; |
|
31
|
2 |
|
$this->options['test'] ? $fields['test'] = 1 : $fields['test'] = 0; |
|
32
|
2 |
|
$authorizeTokenUrl = $this->getApiEndpoint(); |
|
33
|
2 |
|
$data = WebToPay::buildRequest($fields); |
|
34
|
1 |
|
throw new HttpPostRedirect($authorizeTokenUrl, $data); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function doNotify(array $fields) |
|
38
|
|
|
{ |
|
39
|
1 |
|
return WebToPay::validateAndParseData($fields, $this->options['projectid'], $this->options['sign_password']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
2 |
|
protected function getApiEndpoint() |
|
46
|
|
|
{ |
|
47
|
2 |
|
return WebToPay::PAY_URL; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getApiOptions() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->options; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|