1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Http; |
6
|
|
|
use Illuminate\Validation\ValidationException; |
7
|
|
|
use Tzsk\Payu\Gateway\Gateway; |
8
|
|
|
use Tzsk\Payu\Gateway\PayuBiz; |
9
|
|
|
use Tzsk\Payu\Models\PayuTransaction; |
10
|
|
|
|
11
|
|
|
class VerifyPayuBiz implements Actionable |
12
|
|
|
{ |
13
|
|
|
use Verifier; |
14
|
|
|
|
15
|
|
|
protected PayuBiz $gateway; |
|
|
|
|
16
|
|
|
protected string $transactionId; |
17
|
|
|
protected array $domainMap = [ |
18
|
|
|
Gateway::TEST_MODE => 'test', |
19
|
|
|
Gateway::LIVE_MODE => 'info', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
public function handle(PayuTransaction $transaction): bool |
23
|
|
|
{ |
24
|
|
|
if (! $transaction->shouldVerify()) { |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
$this->initialize($transaction); |
28
|
|
|
|
29
|
|
|
$response = Http::asForm()->post($this->url(), $this->payload())->json(); |
30
|
|
|
$data = data_get($response, 'transaction_details.'.$this->transactionId); |
31
|
|
|
|
32
|
|
|
$this->verify($transaction, $data); |
33
|
|
|
|
34
|
|
|
return true; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function initialize(PayuTransaction $transaction) |
38
|
|
|
{ |
39
|
|
|
$this->gateway = $transaction->gateway; |
40
|
|
|
$this->transactionId = data_get($transaction, 'transaction_id'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function url(): string |
44
|
|
|
{ |
45
|
|
|
$subdomain = data_get($this->domainMap, $this->gateway->mode); |
46
|
|
|
throw_unless($subdomain, ValidationException::withMessages([ |
47
|
|
|
'mode' => __('Invalid mode supplied for PayuBiz'), |
48
|
|
|
])); |
49
|
|
|
|
50
|
|
|
return sprintf('https://%s.payu.in/merchant/postservice?form=2', $subdomain); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function payload(): array |
54
|
|
|
{ |
55
|
|
|
$command = 'verify_payment'; |
56
|
|
|
$values = array_merge($this->gateway->toArray(), [ |
57
|
|
|
'id' => $this->transactionId, |
58
|
|
|
'command' => $command, |
59
|
|
|
]); |
60
|
|
|
$sequence = collect(['key', 'command', 'id', 'salt']) |
61
|
|
|
->map(fn ($key) => data_get($values, $key)) |
62
|
|
|
->join('|'); |
63
|
|
|
|
64
|
|
|
return [ |
65
|
|
|
'key' => $this->gateway->key, |
66
|
|
|
'hash' => hash('sha512', $sequence), |
67
|
|
|
'var1' => $this->transactionId, |
68
|
|
|
'command' => $command, |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|