NotificationResponse   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 78
ccs 0
cts 48
cp 0
rs 10
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A success() 0 3 1
A getMessage() 0 3 1
A getTransactionId() 0 3 1
A isSuccessful() 0 3 1
A getTransactionStatus() 0 3 1
A setToken() 0 3 1
A accept() 0 3 1
A getTransactionReference() 0 3 1
A confirm() 0 20 3
1
<?php
2
3
namespace Omnipay\MyCard\Message;
4
5
6
use Omnipay\Common\Message\AbstractResponse;
7
use Omnipay\Common\Message\NotificationInterface;
8
9
class NotificationResponse extends AbstractResponse implements NotificationInterface
10
{
11
12
13
    protected $token;
14
15
16
    protected $status;
17
18
19
    public function setToken($value)
20
    {
21
        $this->token = $value;
22
    }
23
24
25
    public function isSuccessful()
26
    {
27
        return $this->status == static::STATUS_COMPLETED;
28
    }
29
30
31
    public function getTransactionId()
32
    {
33
        return $this->getData()['transactionId'];
34
    }
35
36
37
    public function getTransactionReference()
38
    {
39
        return null;
40
    }
41
42
43
    public function getTransactionStatus()
44
    {
45
        return $this->status;
46
    }
47
48
49
    public function getMessage()
50
    {
51
        return $this->getData()['message'];
52
    }
53
54
55
    public function accept()
56
    {
57
        return $this->confirm();
58
    }
59
60
61
    public function success()
62
    {
63
        return $this->confirm();
64
    }
65
66
67
    public function confirm()
68
    {
69
        // 查询
70
        $fetchResponse = $this->request->fetchTransaction($this->token);
0 ignored issues
show
Bug introduced by
The method fetchTransaction() does not exist on Omnipay\Common\Message\RequestInterface. It seems like you code against a sub-type of Omnipay\Common\Message\RequestInterface such as Omnipay\MyCard\Message\NotificationRequest. ( Ignorable by Annotation )

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

70
        /** @scrutinizer ignore-call */ 
71
        $fetchResponse = $this->request->fetchTransaction($this->token);
Loading history...
71
        $this->data['confirmData'] = $fetchResponse->getData();
72
73
        $this->status = static::STATUS_FAILED;
74
        if ($fetchResponse->getData()['PayResult'] == 3) {  // 交易成功為3; 交易失敗為0;
75
            $this->status = static::STATUS_COMPLETED;
76
        }
77
78
        // TODO :: 二次确认会失败
79
        $confirmResponse = $this->request->confirmTransaction();
0 ignored issues
show
Bug introduced by
The method confirmTransaction() does not exist on Omnipay\Common\Message\RequestInterface. It seems like you code against a sub-type of Omnipay\Common\Message\RequestInterface such as Omnipay\MyCard\Message\NotificationRequest. ( Ignorable by Annotation )

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

79
        /** @scrutinizer ignore-call */ 
80
        $confirmResponse = $this->request->confirmTransaction();
Loading history...
80
        if ($confirmResponse->getData()['ReturnCode'] == 1) {
81
            $this->data['confirmData']['confirm'] = true;
82
        }
83
        else {
84
            $this->data['confirmData']['confirm'] = false;
85
        }
86
        return $this;
87
    }
88
89
90
}