1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\TargetPay; |
4
|
|
|
|
5
|
|
|
use Pronamic\WordPress\Pay\Core\Util; |
6
|
|
|
use Pronamic\WordPress\Pay\Core\XML\Security; |
7
|
|
|
use stdClass; |
8
|
|
|
use WP_Error; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Title: TargetPay gateway |
12
|
|
|
* Description: |
13
|
|
|
* Copyright: 2005-2019 Pronamic |
14
|
|
|
* Company: Pronamic |
15
|
|
|
* |
16
|
|
|
* @author Remco Tolsma |
17
|
|
|
* @version 2.0.0 |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
class Client { |
21
|
|
|
/** |
22
|
|
|
* URL for issuers in Dutch language |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
const URL_ISSUERS_NL = 'https://www.targetpay.com/ideal/issuers-nl.js'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* URL for issuers in English language |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
const URL_ISSUERS_EN = 'https://www.targetpay.com/ideal/issuers-en.js'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* URL for retrieving issuers in HTL format |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
const URL_ISSUERS_HTML = 'https://www.targetpay.com/ideal/getissuers.php?format=html'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* URL for retrieving issuers in XML format |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
const URL_ISSUERS_XML = 'https://www.targetpay.com/ideal/getissuers.php?format=xml'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* URL to start an transaction |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
const URL_START_TRANSACTION = 'https://www.targetpay.com/ideal/start'; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* URL to check an transaction |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
const URL_CHECK_TRANSACTION = 'https://www.targetpay.com/ideal/check'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Token used by TargetPay to separate some values |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
const TOKEN = ' |'; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Status indicator for 'Ok' |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
const STATUS_OK = '000000'; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Status indicator for 'No layout code' |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
const STATUS_NO_LAYOUT_CODE = 'TP0001'; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Error |
86
|
|
|
* |
87
|
|
|
* @var WP_Error |
88
|
|
|
*/ |
89
|
|
|
private $error; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Constructs and initializes an TargetPay client object |
93
|
|
|
*/ |
94
|
|
|
public function __construct() { |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get error. |
100
|
|
|
* |
101
|
|
|
* @return WP_Error |
102
|
|
|
*/ |
103
|
|
|
public function get_error() { |
104
|
|
|
return $this->error; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Remote get. |
109
|
|
|
* |
110
|
|
|
* @param string $url URL for GET request. |
111
|
|
|
* |
112
|
|
|
* @return string|WP_Error |
113
|
|
|
*/ |
114
|
|
|
private function remote_get( $url ) { |
115
|
|
|
return Util::remote_get_body( $url, 200 ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Start transaction |
120
|
|
|
* |
121
|
|
|
* @param IDealStartParameters $parameters Start parameters. |
122
|
|
|
* |
123
|
|
|
* @return stdClass |
124
|
|
|
*/ |
125
|
|
|
public function start_transaction( IDealStartParameters $parameters ) { |
126
|
|
|
$url = Util::build_url( self::URL_START_TRANSACTION, $parameters->get_array() ); |
127
|
|
|
|
128
|
|
|
$data = self::remote_get( $url ); |
|
|
|
|
129
|
|
|
|
130
|
|
|
if ( false !== $data ) { |
|
|
|
|
131
|
|
|
$status = strtok( $data, self::TOKEN ); |
|
|
|
|
132
|
|
|
|
133
|
|
|
if ( self::STATUS_OK === $status ) { |
134
|
|
|
$result = new stdClass(); |
135
|
|
|
|
136
|
|
|
$result->status = $status; |
137
|
|
|
$result->transaction_id = strtok( self::TOKEN ); |
138
|
|
|
$result->url = strtok( self::TOKEN ); |
139
|
|
|
|
140
|
|
|
return $result; |
141
|
|
|
} else { |
142
|
|
|
$code = $status; |
143
|
|
|
$description = substr( $data, 7 ); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$error = new Error( $code, $description ); |
146
|
|
|
|
147
|
|
|
$this->error = new WP_Error( 'targetpay_error', (string) $error, $error ); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Check status |
154
|
|
|
* |
155
|
|
|
* @param string $rtlo |
156
|
|
|
* @param string $transaction_id |
157
|
|
|
* @param string $once |
158
|
|
|
* @param string $test |
159
|
|
|
* |
160
|
|
|
* @return null|Status |
161
|
|
|
*/ |
162
|
|
|
public function check_status( $rtlo, $transaction_id, $once, $test ) { |
163
|
|
|
$result = null; |
164
|
|
|
|
165
|
|
|
$url = Util::build_url( |
166
|
|
|
self::URL_CHECK_TRANSACTION, |
167
|
|
|
array( |
168
|
|
|
'rtlo' => $rtlo, |
169
|
|
|
'trxid' => $transaction_id, |
170
|
|
|
'once' => Util::boolean_to_numeric( $once ), |
|
|
|
|
171
|
|
|
'test' => Util::boolean_to_numeric( $test ), |
172
|
|
|
) |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
$data = self::remote_get( $url ); |
|
|
|
|
176
|
|
|
|
177
|
|
|
if ( false !== $data ) { |
|
|
|
|
178
|
|
|
$result = StatusStringParser::parse( $data ); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $result; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get issuers |
186
|
|
|
* |
187
|
|
|
* @return array |
188
|
|
|
*/ |
189
|
|
|
public function get_issuers() { |
190
|
|
|
$issuers = false; |
191
|
|
|
|
192
|
|
|
$url = self::URL_ISSUERS_XML; |
193
|
|
|
|
194
|
|
|
$data = self::remote_get( $url ); |
|
|
|
|
195
|
|
|
|
196
|
|
|
if ( false !== $data ) { |
|
|
|
|
197
|
|
|
$xml = Util::simplexml_load_string( $data ); |
|
|
|
|
198
|
|
|
|
199
|
|
|
if ( is_wp_error( $xml ) ) { |
200
|
|
|
$this->error = $xml; |
|
|
|
|
201
|
|
|
} else { |
202
|
|
|
$issuers = array(); |
203
|
|
|
|
204
|
|
|
foreach ( $xml->issuer as $xml_issuer ) { |
205
|
|
|
$id = Security::filter( $xml_issuer['id'] ); |
206
|
|
|
$name = Security::filter( $xml_issuer ); |
207
|
|
|
|
208
|
|
|
$issuers[ $id ] = $name; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $issuers; |
|
|
|
|
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|