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\PayuMoney; |
9
|
|
|
use Tzsk\Payu\Models\PayuTransaction; |
10
|
|
|
|
11
|
|
|
class VerifyPayuMoney implements Actionable |
12
|
|
|
{ |
13
|
|
|
use Verifier; |
14
|
|
|
|
15
|
|
|
protected PayuMoney $gateway; |
|
|
|
|
16
|
|
|
protected string $transactionId; |
17
|
|
|
protected array $partMap = [ |
18
|
|
|
Gateway::TEST_MODE => 'sandbox/', |
19
|
|
|
Gateway::LIVE_MODE => '', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
public function handle(PayuTransaction $transaction) |
23
|
|
|
{ |
24
|
|
|
if (! $transaction->shouldVerify()) { |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->initialize($transaction); |
29
|
|
|
|
30
|
|
|
$response = Http::withHeaders(['Authorization' => $this->gateway->auth()])->post($this->url()); |
31
|
|
|
$data = collect(data_get($response->json(), 'result', []))->first(); |
32
|
|
|
|
33
|
|
|
$this->verify($transaction, $data); |
34
|
|
|
|
35
|
|
|
return true; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function initialize(PayuTransaction $transaction) |
39
|
|
|
{ |
40
|
|
|
$this->gateway = $transaction->gateway; |
41
|
|
|
$this->transactionId = data_get($transaction, 'transaction_id'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function url(): string |
45
|
|
|
{ |
46
|
|
|
$part = data_get($this->partMap, $this->gateway->mode); |
47
|
|
|
throw_unless($part, ValidationException::withMessages([ |
48
|
|
|
'mode' => __('Invalid mode supplied for PayuBiz'), |
49
|
|
|
])); |
50
|
|
|
|
51
|
|
|
return sprintf('https://www.payumoney.com/%spayment/op/getPaymentResponse?%s', $part, $this->getQuery()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getQuery(): string |
55
|
|
|
{ |
56
|
|
|
return http_build_query([ |
57
|
|
|
'merchantKey' => $this->gateway->key, |
58
|
|
|
'merchantTransactionIds' => $this->transactionId, |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|