1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sinarajabpour1998\Gateway\Drivers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Sinarajabpour1998\Gateway\Abstracts\Driver; |
7
|
|
|
|
8
|
|
|
class Poolam extends Driver |
9
|
|
|
{ |
10
|
|
|
public function init($amount, $orderId, $callbackUrl, $detail = []) |
11
|
|
|
{ |
12
|
|
|
// Create new transaction |
13
|
|
|
$transaction = $this->createNewTransaction($orderId, $amount); |
14
|
|
|
|
15
|
|
|
// $amount, $transaction->id, $transaction->created_at->format('Y/m/d H:i:s'), $callbackUrl |
16
|
|
|
$result = $this->payment_request($amount, $callbackUrl); |
17
|
|
|
|
18
|
|
|
if(isset($detail['auto_redirect']) && $detail['auto_redirect'] == false && $result['status'] == 1) { |
19
|
|
|
$result['token'] = $result['invoice_key']; |
20
|
|
|
$result['url'] = config('gateway.information')['poolam']['api_url'] . "pay/" . $result['token']; |
21
|
|
|
return $result; |
22
|
|
|
|
23
|
|
|
} elseif($result['status'] == 1) { |
24
|
|
|
$this->updateTransactionData($transaction->id, ['token' => $result['invoice_key']]); |
25
|
|
|
header( 'Location: ' . config('gateway.information')['poolam']['api_url'] . "pay/" . $result['invoice_key']); |
26
|
|
|
die(); |
27
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $result; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function verify($request) |
34
|
|
|
{ |
35
|
|
|
$check = $this->check_payment($request['invoice_key']); |
36
|
|
|
$transaction = $this->getTransaction($request['invoice_key']); |
37
|
|
|
|
38
|
|
|
if (!is_null($transaction)) { |
39
|
|
|
if ($check['status'] == 1 && $transaction->parent->user->id == Auth::user()->id) { |
|
|
|
|
40
|
|
|
$this->updateTransactionData($transaction->id, ['status' => 'successful', 'ref_no' => $check['bank_code']]); |
41
|
|
|
return $result; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->updateTransactionData($transaction->id, ['status' => 'failed', 'ref_no' => $result['errorCode'], 'description' => $result['errorDescription']]); |
45
|
|
|
} |
46
|
|
|
return $check; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function check_payment($inv_key){ |
50
|
|
|
$ch = curl_init(); |
51
|
|
|
curl_setopt($ch,CURLOPT_URL,config('gateway.information')['poolam']['api_url'] . 'check/'.$inv_key); |
52
|
|
|
curl_setopt($ch,CURLOPT_POSTFIELDS,"api_key=" . config('gateway.information')['poolam']['api_key']); |
53
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); |
54
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); |
55
|
|
|
$res = curl_exec($ch); |
56
|
|
|
curl_close($ch); |
57
|
|
|
return json_decode($res,1); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function payment_request($amount,$redirect){ |
61
|
|
|
$ch = curl_init(); |
62
|
|
|
curl_setopt($ch,CURLOPT_URL,config('gateway.information')['poolam']['api_url'] . 'request'); |
63
|
|
|
curl_setopt($ch,CURLOPT_POSTFIELDS,"api_key=" . config('gateway.information')['poolam']['api_key'] . "&amount=$amount&return_url=$redirect"); |
64
|
|
|
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); |
65
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); |
66
|
|
|
$res = curl_exec($ch); |
67
|
|
|
curl_close($ch); |
68
|
|
|
return json_decode($res,1); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.