|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\Common\Payments\Gateways\Providers\Mobilpay\Message; |
|
4
|
|
|
|
|
5
|
|
|
use ByTIC\Common\Payments\Gateways\Providers\AbstractGateway\Message\ServerCompletePurchaseResponse as AbstractResponse; |
|
6
|
|
|
use ByTIC\Common\Payments\Gateways\Providers\Mobilpay\Api\Request; |
|
7
|
|
|
use ByTIC\Common\Payments\Gateways\Providers\Mobilpay\Api\Request\Notify; |
|
8
|
|
|
use DateTime; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class PurchaseResponse |
|
12
|
|
|
* @package ByTIC\Common\Payments\Gateways\Providers\AbstractGateway\Messages |
|
13
|
|
|
*/ |
|
14
|
|
|
class ServerCompletePurchaseResponse extends AbstractResponse |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Is the response successful? |
|
19
|
|
|
* |
|
20
|
|
|
* @return boolean |
|
21
|
|
|
*/ |
|
22
|
5 |
|
public function isSuccessful() |
|
23
|
|
|
{ |
|
24
|
5 |
|
return $this->getCode() == 0 && in_array($this->getAction(), ['confirmed']); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Response code |
|
29
|
|
|
* |
|
30
|
|
|
* @return null|string A response code from the payment gateway |
|
31
|
|
|
*/ |
|
32
|
5 |
|
public function getCode() |
|
33
|
|
|
{ |
|
34
|
5 |
|
return $this->getDataProperty('code'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function getAction() |
|
41
|
|
|
{ |
|
42
|
2 |
|
return $this->getRequestNotify()->action; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return Notify |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function getRequestNotify() |
|
49
|
|
|
{ |
|
50
|
2 |
|
return $this->getRequestData()->objPmNotify; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return Request\Card |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function getRequestData() |
|
57
|
|
|
{ |
|
58
|
2 |
|
return $this->data['requestData']; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Is the transaction cancelled by the user? |
|
63
|
|
|
* |
|
64
|
|
|
* @return boolean |
|
65
|
|
|
*/ |
|
66
|
4 |
|
public function isPending() |
|
67
|
|
|
{ |
|
68
|
4 |
|
if ($this->getCode() == 0) { |
|
69
|
|
|
return in_array($this->getAction(), ['paid', 'paid_pending', 'confirmed_pending']); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
4 |
|
return parent::isCancelled(); // TODO: Change the autogenerated stub |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Is the transaction cancelled by the user? |
|
77
|
|
|
* |
|
78
|
|
|
* @return boolean |
|
79
|
|
|
*/ |
|
80
|
4 |
|
public function isCancelled() |
|
81
|
|
|
{ |
|
82
|
4 |
|
if ($this->getCode() == 0) { |
|
83
|
|
|
return in_array($this->getAction(), ['credit', 'canceled']); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
4 |
|
return parent::isCancelled(); // TODO: Change the autogenerated stub |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function send() |
|
90
|
|
|
{ |
|
91
|
|
|
header('Content-type: application/xml'); |
|
92
|
|
|
parent::send(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
4 |
|
public function getContent() |
|
99
|
|
|
{ |
|
100
|
4 |
|
$content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
|
101
|
|
|
|
|
102
|
4 |
|
if ($this->getCodeType() == 0) { |
|
103
|
4 |
|
$content .= "<crc>{$this->getDataProperty('notificationCrc')}</crc>"; |
|
104
|
|
|
} else { |
|
105
|
|
|
$content .= "<crc error_type=\"{$this->getCodeType()}\" error_code=\"{$this->getCode()}\">"; |
|
106
|
|
|
$content .= $this->getMessage(); |
|
107
|
|
|
$content .= "</crc>"; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
4 |
|
return $content; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Response code |
|
115
|
|
|
* |
|
116
|
|
|
* @return null|string A response code from the payment gateway |
|
117
|
|
|
*/ |
|
118
|
4 |
|
public function getCodeType() |
|
119
|
|
|
{ |
|
120
|
4 |
|
return $this->getDataProperty('codeType'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Response Message |
|
125
|
|
|
* |
|
126
|
|
|
* @return null|string A response message from the payment gateway |
|
127
|
|
|
*/ |
|
128
|
3 |
|
public function getMessage() |
|
129
|
|
|
{ |
|
130
|
3 |
|
return $this->getDataProperty('message'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return false|string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getTransactionDate() |
|
137
|
|
|
{ |
|
138
|
|
|
$timestamp = $this->getRequestNotify()->timestamp; |
|
139
|
|
|
$dateTime = DateTime::createFromFormat('YmdHis', $timestamp); |
|
140
|
|
|
|
|
141
|
|
|
return $dateTime->format('Y-m-d H:i:s'); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection |
|
145
|
|
|
* Gateway Reference |
|
146
|
|
|
* |
|
147
|
|
|
* @return null|string A reference provided by the gateway to represent this transaction |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getTransactionReference() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->getRequestNotify()->purchaseId; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection |
|
155
|
|
|
* @return bool |
|
156
|
|
|
*/ |
|
157
|
|
|
protected function canProcessModel() |
|
158
|
|
|
{ |
|
159
|
|
|
return true; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.