1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\GoCardless\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* GoCardless Purchase Response |
9
|
|
|
*/ |
10
|
|
|
class PurchaseResponse extends AbstractResponse |
11
|
|
|
{ |
12
|
|
|
public function isSuccessful() |
13
|
|
|
{ |
14
|
|
|
$status = $this->getStatus(); |
15
|
|
|
return !$this->isError() && isset($this->data['payments']) |
16
|
|
|
&& ($status == 'confirmed' || $status == 'paid_out'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function isPending() |
20
|
|
|
{ |
21
|
|
|
$status = $this->getStatus(); |
22
|
|
|
return $status == 'pending_customer_approval' || $status == 'pending_submission' || $status == 'submitted'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function isCancelled() |
26
|
|
|
{ |
27
|
|
|
return $this->getStatus() == 'cancelled'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function isRedirect() |
31
|
|
|
{ |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function isError() |
36
|
|
|
{ |
37
|
|
|
return isset($this->data['error']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getTransactionReference() |
41
|
|
|
{ |
42
|
|
|
if (!$this->isError()) { |
43
|
|
|
return $this->data['payments']['id']; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getMessage() |
48
|
|
|
{ |
49
|
|
|
if ($this->isError()) { |
50
|
|
|
return $this->data['error']['message']; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getMandateId() |
55
|
|
|
{ |
56
|
|
|
if ($this->isSuccessful() || $this->isPending()) { |
57
|
|
|
return $this->data['payments']['links']['mandate']; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Treat mandate as a 'card' to support createCard pattern |
63
|
|
|
*/ |
64
|
|
|
public function getCardReference() |
65
|
|
|
{ |
66
|
|
|
return $this->getMandateId(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getMetaData() |
70
|
|
|
{ |
71
|
|
|
if ($this->isSuccessful() || $this->isPending()) { |
72
|
|
|
return $this->data['payments']['metadata']; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getCode() |
77
|
|
|
{ |
78
|
|
|
return $this->isError() ? $this->data['error']['code'] : $this->getStatus(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getStatus() |
82
|
|
|
{ |
83
|
|
|
return $this->isError() ? $this->data['error']['type'] : $this->data['payments']['status']; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|