Poolam   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 10
eloc 39
c 3
b 0
f 1
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check_payment() 0 9 1
A payment_request() 0 9 1
A verify() 0 14 3
A init() 0 21 5
1
<?php
2
3
namespace Sinarajabpour1998\Gateway\Drivers;
4
5
use Sinarajabpour1998\Gateway\Abstracts\Driver;
6
7
class Poolam extends Driver
8
{
9
    public function init($amount, $orderId, $callbackUrl, $detail = [])
10
    {
11
        // Create new transaction
12
        $transaction = $this->createNewTransaction($orderId, $amount);
13
14
        $result = $this->payment_request($amount, $callbackUrl);
15
16
        if(isset($detail['auto_redirect']) && $detail['auto_redirect'] == false && $result['status'] == 1) {
17
            $result['token'] = $result['invoice_key'];
18
            $this->updateTransactionData($transaction->id, ['token' => $result['invoice_key']]);
19
            $result['url'] = config('gateway.information')['poolam']['constructor']['api_url'] . "pay/" . $result['token'];
20
            return $result;
21
22
        } elseif($result['status'] == 1) {
23
            $this->updateTransactionData($transaction->id, ['token' => $result['invoice_key']]);
24
            header( 'Location: ' . config('gateway.information')['poolam']['constructor']['api_url'] . "pay/" . $result['invoice_key']);
25
            die();
26
27
        }
28
29
        return $result;
30
    }
31
32
    public function verify($request)
33
    {
34
        $check = $this->check_payment($request['invoice_key']);
35
        $transaction = $this->getTransactionByToken($request['invoice_key']);
36
        $check['order'] = null;
37
        if (!is_null($transaction)) {
38
            $check['order'] = $transaction->parent;
0 ignored issues
show
Bug introduced by
The property parent does not seem to exist on Sinarajabpour1998\Gateway\Models\Transaction. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
39
            if ($check['status'] == 1) {
40
                $this->updateTransactionData($transaction->id, ['status' => 'successful', 'ref_no' => $check['bank_code']]);
41
            }else {
42
                $this->updateTransactionData($transaction->id, ['status' => 'failed', 'ref_no' => $check['errorCode'], 'description' => $check['errorDescription']]);
43
            }
44
        }
45
        return $check;
46
    }
47
48
    protected function check_payment($inv_key){
49
        $ch = curl_init();
50
        curl_setopt($ch,CURLOPT_URL,config('gateway.information')['poolam']['constructor']['api_url'] . 'check/'.$inv_key);
51
        curl_setopt($ch,CURLOPT_POSTFIELDS,"api_key=" . config('gateway.information')['poolam']['constructor']['api_key']);
52
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
53
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
54
        $res = curl_exec($ch);
55
        curl_close($ch);
56
        return json_decode($res,1);
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        return json_decode(/** @scrutinizer ignore-type */ $res,1);
Loading history...
57
    }
58
59
    protected function payment_request($amount,$redirect){
60
        $ch = curl_init();
61
        curl_setopt($ch,CURLOPT_URL,config('gateway.information')['poolam']['constructor']['api_url'] . 'request');
62
        curl_setopt($ch,CURLOPT_POSTFIELDS,"api_key=" . config('gateway.information')['poolam']['constructor']['api_key'] . "&amount=$amount&return_url=$redirect");
63
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
64
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
65
        $res = curl_exec($ch);
66
        curl_close($ch);
67
        return json_decode($res,1);
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        return json_decode(/** @scrutinizer ignore-type */ $res,1);
Loading history...
68
    }
69
}
70