Skip to content

Commit 3884167

Browse files
committed
Revision of the code and new PHPUnit tests
1 parent 56313f1 commit 3884167

15 files changed

+205
-254
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
}
2525
},
2626
"require": {
27+
"ext-SimpleXML": "*",
2728
"omnipay/common": "~2.0"
2829
},
2930
"require-dev": {

src/Omnipay/Ukash/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ public function completePurchase(array $parameters = array())
131131

132132
public function fetchTransaction(array $parameters = array())
133133
{
134-
return $this->createRequest('\Omnipay\Ukash\Message\FetchTransactionRequest', $parameters);
134+
return $this->createRequest('\Omnipay\Ukash\Message\CompletePurchaseRequest', $parameters);
135135
}
136136
}

src/Omnipay/Ukash/Message/AbstractRequest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace Omnipay\Ukash\Message;
33

4+
use SimpleXMLElement;
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
47
/**
58
* Ukash Abstract Request
69
*
@@ -137,6 +140,20 @@ public function sendRequest($method, $action, $data = null)
137140
$httpRequest = $this->httpClient->createRequest($method, $this->getEndpoint().$action, null, $data);
138141
$httpResponse = $httpRequest->send();
139142

140-
return $httpResponse->getBody(true);
143+
$xml = new SimpleXMLElement(htmlspecialchars_decode($httpResponse->getBody(true)), LIBXML_NONET);
144+
145+
if (isset($xml->UKashRPP)) {
146+
throw new InvalidResponseException('Missing "UKashRPP" element in XML response');
147+
}
148+
149+
if (!isset($xml->UKashRPP->SecurityToken)) {
150+
throw new InvalidResponseException('Missing "UKashRPP/SecurityToken" element in XML response');
151+
}
152+
153+
if ($xml->UKashRPP->SecurityToken != $this->getResponseSecurityToken()) {
154+
throw new InvalidResponseException('Invalid SecurityToken in XML response');
155+
}
156+
157+
return $xml->UKashRPP;
141158
}
142159
}

src/Omnipay/Ukash/Message/CompletePurchaseRequest.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,73 @@
22
namespace Omnipay\Ukash\Message;
33

44
/**
5-
* Ukash Complete Purchase Request
5+
* Ukash TransactionStatus Request
66
*
7-
* Once the consumer has completed his transaction, the system will notify the merchant
8-
* by doing an HTTP POST to the notification URL.
9-
* The following values will be sent to the merchant, via HTTP POST.
7+
* The merchant can verify the transaction status by making a HTTP POST Request to the Transaction status web method.
8+
* The method will return a string value containing a URL encoded XML string. The XML tags returned are listed below.
109
*
1110
* @author Alexander Fedra <[email protected]>
1211
* @copyright 2014 DerCoder
1312
* @license http://opensource.org/licenses/mit-license.php MIT
1413
* @version 1.0.0
1514
*/
16-
class CompletePurchaseRequest extends FetchTransactionRequest
15+
class CompletePurchaseRequest extends AbstractRequest
1716
{
17+
/**
18+
* Get the Response Security Token
19+
*
20+
* 20-Character alphanumeric unique Request-Token provided by Ukash.
21+
* The token is used to validate the merchant account.
22+
*
23+
* @return string response security token
24+
*/
25+
public function getUtid()
26+
{
27+
return $this->getParameter('utId');
28+
}
1829

30+
/**
31+
* Set the Response Security Token
32+
*
33+
* 20-Character alphanumeric unique Response-Token provided by Ukash.
34+
* The token is used to validate the merchant account.
35+
*
36+
* @param string $value response security token
37+
* @return self
38+
*/
39+
public function setUtid($value)
40+
{
41+
return $this->setParameter('utId', $value);
42+
}
43+
44+
/**
45+
* Get the data for this request.
46+
*
47+
* @return array request data
48+
*/
49+
public function getData()
50+
{
51+
$data = parent::getData();
52+
53+
$this->validate(
54+
'utId'
55+
);
56+
57+
$data['UTID'] = $this->getUtid();
58+
59+
return $data;
60+
}
61+
62+
/**
63+
* Send the request with specified data
64+
*
65+
* @param mixed $data The data to send
66+
* @return FetchTransactionResponse
67+
*/
68+
public function sendData($data)
69+
{
70+
$response = $this->sendRequest('POST', 'RPPGateway/process.asmx/GetTransactionStatus', $data);
71+
72+
return new FetchTransactionResponse($this, $response);
73+
}
1974
}

src/Omnipay/Ukash/Message/FetchTransactionRequest.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/Omnipay/Ukash/Message/FetchTransactionResponse.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Omnipay/Ukash/Message/PurchaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ public function sendData($data)
207207
{
208208
$response = $this->sendRequest('POST', 'RPPGateway/process.asmx/GetUniqueTransactionID', $data);
209209

210-
return new PurchaseResponse($this, $response);
210+
return new Response($this, $response);
211211
}
212212
}

src/Omnipay/Ukash/Message/PurchaseResponse.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)