1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Gateway; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Validator; |
6
|
|
|
use Illuminate\Validation\ValidationException; |
7
|
|
|
use Tzsk\Payu\Actions\Actionable; |
8
|
|
|
use Tzsk\Payu\Actions\VerifyPayuBiz; |
9
|
|
|
|
10
|
|
|
class PayuBiz extends Gateway |
11
|
|
|
{ |
12
|
|
|
public ?string $key; |
|
|
|
|
13
|
|
|
public ?string $salt; |
14
|
|
|
public ?string $base; |
15
|
|
|
|
16
|
|
|
protected array $processUrls = [ |
17
|
|
|
self::TEST_MODE => 'https://test.%s/_payment', |
18
|
|
|
self::LIVE_MODE => 'https://secure.%s/_payment', |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
public function __construct(array $config) |
22
|
|
|
{ |
23
|
|
|
$this->key = data_get($config, 'key'); |
24
|
|
|
$this->salt = data_get($config, 'salt'); |
25
|
|
|
$this->base = data_get($config, 'base', 'payu.in'); |
26
|
|
|
$this->mode = data_get($config, 'mode', self::TEST_MODE); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function salt(): ?string |
30
|
|
|
{ |
31
|
|
|
return $this->salt; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function endpoint(): ?string |
35
|
|
|
{ |
36
|
|
|
$url = data_get($this->processUrls, $this->mode); |
37
|
|
|
throw_unless($url, ValidationException::withMessages([ |
38
|
|
|
'mode' => __('Invalid mode supplied for PayuBiz'), |
39
|
|
|
])); |
40
|
|
|
|
41
|
|
|
return sprintf($url, $this->base); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function auth(): ?string |
45
|
|
|
{ |
46
|
|
|
return null; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function verifier(): Actionable |
50
|
|
|
{ |
51
|
|
|
return new VerifyPayuBiz(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function toArray(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
'key' => $this->key, |
58
|
|
|
'salt' => $this->salt, |
59
|
|
|
'endpoint' => $this->endpoint(), |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @throws ValidationException |
65
|
|
|
*/ |
66
|
|
|
public function validate(): array |
67
|
|
|
{ |
68
|
|
|
return Validator::make($this->toArray(), [ |
69
|
|
|
'key' => 'required|string', |
70
|
|
|
'salt' => 'required|string', |
71
|
|
|
'endpoint' => 'required|url', |
72
|
|
|
])->validate(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function fields(): array |
76
|
|
|
{ |
77
|
|
|
return collect($this->toArray()) |
78
|
|
|
->except(['endpoint', 'salt']) |
79
|
|
|
->all(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|