Passed
Push — main ( 04fe06...de114a )
by
unknown
10:00
created

Zarinpal::verify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Dizatech\Transaction\Drivers;
4
5
use Dizatech\Transaction\Abstracts\Driver;
6
use Dizatech\Transaction\Models\Transaction;
7
use Dizatech\ZarinpalIpg\ZarinpalIpg;
0 ignored issues
show
Bug introduced by
The type Dizatech\ZarinpalIpg\ZarinpalIpg was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class Zarinpal extends Driver
10
{
11
    public function init($amount, $orderId, $callbackUrl, $detail = [])
12
    {
13
        // Create new transaction
14
        $transaction = $this->createNewTransaction($orderId, $amount);
15
16
        // Create object from Parsian Driver
17
        $class = new ZarinpalIpg($this->getInformation());
18
        $result = $class->getToken($amount, $transaction->id, $callbackUrl);
19
20
        if(isset($detail['auto_redirect']) && $detail['auto_redirect'] == false && $result->status == 'success') {
21
            $result->token  = $result->token;
22
            $result->url    = 'Location: https://www.zarinpal.com/pg/StartPay/' . $result->token;
23
            return $result;
24
25
        } elseif($result->status == 'success') {
26
            $this->updateTransactionData($transaction->id, ['token' => $result->token]);
27
            header( 'Location: https://www.zarinpal.com/pg/StartPay/' . $result->token );
28
            die();
29
        }
30
31
        return $result;
32
    }
33
34
    public function verify($request)
35
    {
36
        $class = new ZarinpalIpg($this->getInformation());
37
38
        $transaction = Transaction::whereToken( $request['Authority'] )->first();
39
        $result = $class->verifyRequest( intval($transaction->amount), $transaction->token );
40
41
        if ($result->status == 'success') {
42
            $this->updateTransactionData($transaction->id, ['status' => 'successful', 'ref_no' => $result->ref_id]);
43
        } else {
44
            $this->updateTransactionData($transaction->id, ['status' => 'failed']);
45
        }
46
47
        return $result;
48
    }
49
}
50