-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWebserviceGateway.php
413 lines (394 loc) · 14.3 KB
/
WebserviceGateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php
/**
* First Data Webservice Gateway
*/
namespace Omnipay\FirstData;
use Omnipay\Common\AbstractGateway;
/**
* First Data Webservice Gateway
*
* The Webservice Gateway was originally called the LinkPoint Gateway but since First Data's
* acquisition of LinkPoint it is now known as the First Data Global Gateway Web Service API.
* As of this writing the Global Gateway Web Service API version 9.0 is supported. It is
* referred to here as the "First Data Webservice" gateway.
*
* ### Quirks
*
* #### WSDL
*
* There is currently a roadblock with the implementation of this gateway in that the
* WSDL is not recognised as valid by PHP's SOAP client.
*
* See this bug: https://bugs.php.net/bug.php?id=43868
*
* PHP Fatal error: SOAP-ERROR: Parsing Schema: element
* 'http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi:FDGGWSApiOrderRequest'
* already defined in omnipay-firstdata/src/Soap/BaseSoapClient.php on line 121
*
* In this gateway code we have ignored the SOAP thing completely and just constructed XML
* messages to send to the gateway POST URL directly, using templates and lots of string
* substitution.
*
* https://ws.firstdataglobalgateway.com:443/fdggwsapi/services
*
* Neither the native PHP SOAP client nor the BeSimple SOAP client work at all dealing
* with the WSDL.
*
* In addition, sending a properly formed SOAP message with an XML header (of
* the type <?xml ... ?>) throws an error message. The XML header must be
* omitted.
*
* To be honest I have better things to spend my time on than dealing with such
* nonsense. If people can't drag themselves out of the 19th century and use
* REST APIs instead of SOAP then they can at least have the good grace and
* common courtesy to get their XML handling and formatting correct.
*
* #### Transaction ID
*
* A user supplied transaction ID (transactionId parameter) must be supplied for each
* purchase() or authorize() request. This is known as "OrderId" in the Webservice Gateway.
*
* The First Data Webservice Gateway Web Service API only accepts ASCII characters. The Order
* ID cannot contain the following characters: &, %, /, or exceed 100 characters in length.
* The Order ID will be restricted in such a way so that it can only accepts alpha numeric
* (a-z, A-Z, 0-9) and some special characters for merchants convenience.
*
* #### Voids and Refunds
*
* Voids and Refunds require both the transactionId and the TDATE parameter returned
* from the purchase (or capture) call. To make things cleaner for calling applicatons,
* the transactionReference returned by getTransactionReference() after the purhcase
* or capture call is the transactionId and the TDATE concatenated together and
* separated by '::'.
*
* Refunds require an amount parameter. The amount parameter is ignored by the void
* call.
*
* ### Authentication
*
* Within the SSL connection (see below), authentication is done via HTTP Basic Auth.
*
* First Data should provide you, as part of the connection package, a username and a
* password. The username will be of the form WS*******._.1 and the password will be
* a string containing letters and numbers. Provide these as the userName and password
* parameters when initializing the gateway.
*
* ### SSL Connection Security
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* First Data should provide you, as part of the connection package, at least the
* following files:
*
* * WS____.pem (certificate file)
* * WS____.key (key file)
* * WS____.key.pw.txt (text file containing the password for the key)
*
* ... where WS___ is your username also provided by First Data (see above).
*
* You need to store the certificate file and the key file on disk somewhere and
* pass the following parameters when initializing the gateway:
*
* * sslCertificate -- on disk location of the .pem certificate file.
* * sslKey -- on disk location of the .key file.
* * sslKeyPassword -- the password for the key (not the file name)
*
* In case First Data provide you with a .p12 (PKCS-12) file for the certificate
* instead of a PEM file, you will need to convert the .p12 file to a .pem file
* using this command:
*
* ```
* openssl pkcs12 -in WS____.p12 -out WS____.1.pem -clcerts -nokeys
* ```
*
* ### Test Accounts
*
* To obtain a test account, use this form:
* http://www.firstdata.com/gg/apply_test_account.htm
*
* ### Example
*
* This is an example of a purchase request.
*
* <code>
* // Create a gateway for the First Data Webservice Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('FirstData_Webservice');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'sslCertificate' => 'WS9999999._.1.pem',
* 'sslKey' => 'WS9999999._.1.key',
* 'sslKeyPassword' => 'sslKEYpassWORD',
* 'userName' => 'WS9999999._.1',
* 'password' => 'passWORD',
* 'testMode' => true,
* ));
*
* // Create a credit card object
* $card = new CreditCard(array(
* 'firstName' => 'Example',
* 'lastName' => 'Customer',
* 'number' => '4222222222222222',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '123',
* 'email' => 'customer@example.com',
* 'billingAddress1' => '1 Scrubby Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Scrubby Creek',
* 'billingPostcode' => '4999',
* 'billingState' => 'QLD',
* ));
*
* // Do a purchase transaction on the gateway
* $transaction = $gateway->purchase(array(
* 'accountId' => '12345',
* 'amount' => '10.00',
* 'currency' => 'USD',
* 'description' => 'Super Deluxe Excellent Discount Package',
* 'transactionId' => 12345,
* 'clientIp' => $_SERVER['REMOTE_ADDR'],
* 'card' => $card,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Purchase transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*
* @link https://www.firstdata.com/downloads/pdf/FDGG_Web_Service_API_v9.0.pdf
*/
class WebserviceGateway extends AbstractGateway
{
public function getName()
{
return 'First Data Webservice';
}
public function getDefaultParameters()
{
return array(
'sslCertificate' => '',
'sslKey' => '',
'sslKeyPassword' => '',
'userName' => '',
'password' => '',
'testMode' => false,
);
}
/**
* Get SSL Certificate file name
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Webservice Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @return string
*/
public function getSslCertificate()
{
return $this->getParameter('sslCertificate');
}
/**
* Set SSL Certificate file name
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Webservice Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @param string $value
* @return WebserviceGateway provides a fluent interface.
*/
public function setSslCertificate($value)
{
return $this->setParameter('sslCertificate', $value);
}
/**
* Get SSL Key file name
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Webservice Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @return string
*/
public function getSslKey()
{
return $this->getParameter('sslKey');
}
/**
* Set SSL Key file name
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Webservice Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @param string $value
* @return WebserviceGateway provides a fluent interface.
*/
public function setSslKey($value)
{
return $this->setParameter('sslKey', $value);
}
/**
* Get SSL Key password
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Global Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @return string
*/
public function getSslKeyPassword()
{
return $this->getParameter('sslKeyPassword');
}
/**
* Set SSL Key password
*
* You must establish a secure communication channel to send the HTTP request.
* This ensures that the data sent between your client application and the First
* Data Global Gateway Web Service API is encrypted and that both parties can
* be sure they are communicating with each other and no one else.
*
* The Web Service API requires an SSL connection with client and server exchanging
* certificates to guarantee this level of security. The client and server certificates
* each uniquely identify the party.
*
* @param string $value
* @return WebserviceGateway provides a fluent interface.
*/
public function setSslKeyPassword($value)
{
return $this->setParameter('sslKeyPassword', $value);
}
/**
* Get Username
*
* Calls to the Global Gateway API are secured with a username and
* password sent via HTTP Basic Authentication.
*
* @return string
*/
public function getUserName()
{
return $this->getParameter('userName');
}
/**
* Set Username
*
* Calls to the Global Gateway API are secured with a username and
* password sent via HTTP Basic Authentication.
*
* @param string $value
* @return WebserviceGateway provides a fluent interface.
*/
public function setUserName($value)
{
return $this->setParameter('userName', $value);
}
/**
* Get Password
*
* Calls to the Global Gateway API are secured with a username and
* password sent via HTTP Basic Authentication.
*
* @return string
*/
public function getPassword()
{
return $this->getParameter('password');
}
/**
* Set Password
*
* Calls to the Global Gateway API are secured with a username and
* password sent via HTTP Basic Authentication.
*
* @param string $value
* @return WebserviceGateway provides a fluent interface.
*/
public function setPassword($value)
{
return $this->setParameter('password', $value);
}
/**
* Create a purchase request.
*
* @param array $parameters
* @return \Omnipay\FirstData\Message\WebservicePurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\WebservicePurchaseRequest', $parameters);
}
/**
* Create an authorize request.
*
* @param array $parameters
* @return \Omnipay\FirstData\Message\WebserviceAuthorizeRequest
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\WebserviceAuthorizeRequest', $parameters);
}
/**
* Create a capture request.
*
* @param array $parameters
* @return \Omnipay\FirstData\Message\WebserviceCaptureRequest
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\WebserviceCaptureRequest', $parameters);
}
/**
* Create a void request.
*
* @param array $parameters
* @return \Omnipay\FirstData\Message\WebserviceVoidRequest
*/
public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\WebserviceVoidRequest', $parameters);
}
/**
* Create a refund request.
*
* @param array $parameters
* @return \Omnipay\FirstData\Message\WebserviceRefundRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\WebserviceRefundRequest', $parameters);
}
}