Skip to content

Commit b34bfa2

Browse files
authored
Merge pull request #5 from bileto/fix-transation-id
Fixed TransactionId and TransactionReference to refer for right meaning
2 parents dc5a13c + 2dad794 commit b34bfa2

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

examples/test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
try {
1919
$orderNo = uniqid();
2020
$returnUrl = 'http://localhost:8000/gateway-return.php';
21-
$notifyUrl = 'http://127.0.0.1/online-payments/uuid/notify';
21+
$notifyUrl = 'http://127.0.0.1/uuid/notify';
2222
$description = 'Shopping at myStore.com';
2323

2424
$purchaseRequest = [
@@ -56,8 +56,9 @@
5656
$response = $gateway->purchase($purchaseRequest);
5757

5858
echo "TransactionId: " . $response->getTransactionId() . PHP_EOL;
59-
echo 'Is Successful: ' . (bool) $response->isSuccessful() . PHP_EOL;
60-
echo 'Is redirect: ' . (bool) $response->isRedirect() . PHP_EOL;
59+
echo "TransactionReference: " . $response->getTransactionReference() . PHP_EOL;
60+
echo 'Is Successful: ' . (bool)$response->isSuccessful() . PHP_EOL;
61+
echo 'Is redirect: ' . (bool)$response->isRedirect() . PHP_EOL;
6162

6263
// Payment init OK, redirect to the payment gateway
6364
echo $response->getRedirectUrl() . PHP_EOL;

src/Gateway.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ public function getName()
3030
public function getAccessToken()
3131
{
3232
$request = parent::createRequest(AccessTokenRequest::class, [
33-
'clientId' => $this->getParameter('posId'),
33+
'clientId' => $this->getParameter('posId'),
3434
'clientSecret' => $this->getParameter('clientSecret'),
35-
'apiUrl' => $this->getApiUrl()
35+
'apiUrl' => $this->getApiUrl()
3636
]);
3737
$response = $request->send();
38+
3839
return $response;
3940
}
4041

4142
/**
4243
* @param array $parameters
4344
* @return PurchaseResponse
4445
*/
45-
public function purchase(array $parameters = array())
46+
public function purchase(array $parameters = [])
4647
{
4748
$this->setAccessToken($this->getAccessToken()->getAccessToken());
4849
$request = parent::createRequest(PurchaseRequest::class, $parameters);
@@ -55,7 +56,7 @@ public function purchase(array $parameters = array())
5556
* @param array $parameters
5657
* @return CompletePurchaseResponse
5758
*/
58-
public function completePurchase(array $parameters = array())
59+
public function completePurchase(array $parameters = [])
5960
{
6061
$this->setAccessToken($this->getAccessToken()->getAccessToken());
6162
$request = self::createRequest(CompletePurchaseRequest::class, $parameters);
@@ -84,11 +85,11 @@ private function getApiUrl()
8485
public function getDefaultParameters()
8586
{
8687
return [
87-
'posId' => '',
88-
'secondKey' => '',
88+
'posId' => '',
89+
'secondKey' => '',
8990
'clientSecret' => '',
90-
'testMode' => true,
91-
'posAuthKey' => null,
91+
'testMode' => true,
92+
'posAuthKey' => null,
9293
];
9394
}
9495

@@ -119,14 +120,16 @@ public function setClientSecret($clientSecret)
119120
/**
120121
* @param string|null $posAuthKey
121122
*/
122-
public function setPosAuthKey($posAuthKey = null) {
123+
public function setPosAuthKey($posAuthKey = null)
124+
{
123125
$this->setParameter('posAuthKey', $posAuthKey);
124126
}
125127

126-
public function initialize(array $parameters = array())
128+
public function initialize(array $parameters = [])
127129
{
128130
parent::initialize($parameters);
129131
$this->setApiUrl($this->getApiUrl());
132+
130133
return $this;
131134
}
132135

src/Messages/CompletePurchaseResponse.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public function isSuccessful()
2020
public function getTransactionId()
2121
{
2222
if (isset($this->data['orders'][0]['extOrderId'])) {
23-
return (string) $this->data['orders'][0]['extOrderId'];
23+
return (string)$this->data['orders'][0]['extOrderId'];
2424
}
25+
2526
return null;
2627
}
2728

@@ -37,8 +38,9 @@ public function isCancelled()
3738
public function getTransactionReference()
3839
{
3940
if (isset($this->data['orders'][0]['orderId'])) {
40-
return (string) $this->data['orders'][0]['orderId'];
41+
return (string)$this->data['orders'][0]['orderId'];
4142
}
43+
4244
return null;
4345
}
4446

@@ -62,7 +64,7 @@ public function isPending()
6264
*/
6365
public function getPaymentReference()
6466
{
65-
if(isset($this->data['properties'])) {
67+
if (isset($this->data['properties'])) {
6668
$properties = $this->data['properties'];
6769
$paymentIdProperty = array_filter($properties, function ($item) {
6870
return $item['name'] === 'PAYMENT_ID';

src/Messages/PurchaseRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function sendData($data)
2929
'Authorization' => $data['accessToken']
3030
];
3131
$apiUrl = $data['apiUrl'] . '/api/v2_1/orders';
32+
if (isset($data['purchaseData']['extOrderId'])) {
33+
$this->setTransactionId($data['purchaseData']['extOrderId']);
34+
}
3235
$httpRequest = $this->httpClient->post($apiUrl, $headers, json_encode($data['purchaseData']));
3336
$httpRequest->configureRedirects(true, 0);
3437
$httpResponse = $httpRequest->send();

src/Messages/PurchaseResponse.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,27 @@ public function getRedirectData()
4949
}
5050

5151
/**
52-
* PayU orderId
53-
* @return string
52+
* @return string|null
5453
*/
5554
public function getTransactionId()
5655
{
57-
return (string)$this->data['orderId'];
56+
if (isset($this->data['extOrderId'])) {
57+
return (string)$this->data['extOrderId'];
58+
}
59+
if (isset($this->request->getParameters()['transactionId'])) {
60+
return $this->request->getParameters()['transactionId'];
61+
}
62+
63+
return null;
5864
}
5965

6066
/**
61-
* @return string|null
67+
* PayU orderId
68+
* @return string
6269
*/
6370
public function getTransactionReference()
6471
{
65-
if (isset($this->data['extOrderId'])) {
66-
return (string)$this->data['extOrderId'];
67-
}
68-
return null;
72+
return (string)$this->data['orderId'];
6973
}
7074

7175
public function isRedirect()

0 commit comments

Comments
 (0)