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