1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sinarajabpour1998\Gateway\Drivers; |
4
|
|
|
|
5
|
|
|
use Vandar\Laravel\Facade\Vandar as VandarFacade; |
6
|
|
|
use Sinarajabpour1998\Gateway\Abstracts\Driver; |
7
|
|
|
|
8
|
|
|
class Vandar extends Driver |
9
|
|
|
{ |
10
|
|
|
public function init($amount, $orderId, $callbackUrl, $detail = []) |
11
|
|
|
{ |
12
|
|
|
// Create new transaction |
13
|
|
|
$transaction = $this->createNewTransaction($orderId, $amount); |
14
|
|
|
|
15
|
|
|
$result = VandarFacade::request($amount, $callbackUrl, null, $orderId, null); |
16
|
|
|
|
17
|
|
|
$given_result = (object) array('token' => '', 'url' => ''); |
18
|
|
|
|
19
|
|
|
if ($result['status'] == 1){ |
20
|
|
|
$this->updateTransactionData($transaction->id, ['token' => $result['token']]); |
21
|
|
|
if(isset($detail['auto_redirect']) && $detail['auto_redirect'] == false) { |
22
|
|
|
$given_result->token = $result['token']; |
23
|
|
|
$given_result->url = 'https://ipg.vandar.io/v3/' . $result['token']; |
24
|
|
|
return $given_result; |
25
|
|
|
|
26
|
|
|
} else { |
27
|
|
|
header( 'Location: https://ipg.vandar.io/v3/' . $result['token']); |
28
|
|
|
die(); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $result; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function verify($request) |
36
|
|
|
{ |
37
|
|
|
$result = VandarFacade::verify($request['token']); |
38
|
|
|
|
39
|
|
|
if ($result['status'] == 1) { |
40
|
|
|
if ($result['message'] == 'ok') { |
41
|
|
|
$this->updateTransactionData($result['factorNumber'], ['status' => 'successful', 'ref_no' => $result['transId']]); |
42
|
|
|
} else { |
43
|
|
|
$this->updateTransactionData($result['factorNumber'], ['status' => 'failed', 'ref_no' => $result['transId']]); |
44
|
|
|
} |
45
|
|
|
return $result; |
46
|
|
|
|
47
|
|
|
}elseif ($result['status'] == 0){ |
48
|
|
|
$this->updateTransactionData($request['transId'], ['status' => 'failed', 'description' => $result['error']]); |
49
|
|
|
}elseif ($result['status'] == 3){ |
50
|
|
|
$this->updateTransactionData($request['transId'], ['status' => 'failed', 'description' => $result['errors'][0]]); |
51
|
|
|
} |
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|