1 <?php
2
3 namespace Omnipay\Pagarme\Message;
4
5 use Omnipay\Common\Message\AbstractResponse;
6
7 8 9 10 11 12 13
14 class Response extends AbstractResponse
15 {
16 17 18 19 20
21 public function isSuccessful()
22 {
23 if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
24 return !($this->data['status'] == 'refused');
25 }
26 return !isset($this->data['errors']);
27 }
28
29 30 31 32 33
34 public function getTransactionReference()
35 {
36 if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
37 return $this->data['id'];
38 }
39
40 return null;
41 }
42
43 44 45 46 47
48 public function getCardReference()
49 {
50 if (isset($this->data['object']) && 'card' === $this->data['object']) {
51 if (! empty($this->data['id'])) {
52 return $this->data['id'];
53 }
54 } elseif (isset($this->data['object']) && 'transaction' === $this->data['object']) {
55 return $this->data['card']['id'];
56 }
57
58 return null;
59 }
60
61 62 63 64 65
66 public function getCustomerReference()
67 {
68 if (isset($this->data['object']) && 'customer' === $this->data['object']) {
69 return $this->data['id'];
70 }
71 if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
72 if (! empty($this->data['customer'])) {
73 return $this->data['customer']['id'];
74 }
75 }
76 if (isset($this->data['object']) && 'card' === $this->data['object']) {
77 if (! empty($this->data['customer'])) {
78 return $this->data['customer']['id'];
79 }
80 }
81
82 return null;
83 }
84
85 86 87 88 89 90 91
92 public function getMessage()
93 {
94 if (!$this->isSuccessful()) {
95 if (isset($this->data['errors'])) {
96 return $this->data['errors'][0]['message'];
97 } else {
98 return $this->data['refuse_reason'];
99 }
100 }
101
102 return null;
103 }
104
105 106 107 108 109 110
111 public function getBoleto()
112 {
113 if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
114 if ( $this->data['boleto_url'] ) {
115 $data = array(
116 'boleto_url' => $this->data['boleto_url'],
117 'boleto_barcode' => $this->data['boleto_barcode'],
118 'boleto_expiration_date' => $this->data['boleto_expiration_date'],
119 );
120 return $data;
121 } else {
122 return null;
123 }
124 }
125
126 return null;
127 }
128
129 130 131 132 133
134 public function getCalculatedInstallments()
135 {
136 if (isset($this->data['installments'])) {
137 $data = $this->data['installments'];
138 return $data;
139 } else {
140 return null;
141 }
142 }
143 }