Skip to content

Commit

Permalink
Merge pull request #5 from bileto/fix-transation-id
Browse files Browse the repository at this point in the history
Fixed TransactionId and TransactionReference to refer for right meaning
  • Loading branch information
stekycz authored Nov 24, 2016
2 parents dc5a13c + 2dad794 commit b34bfa2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
7 changes: 4 additions & 3 deletions examples/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
try {
$orderNo = uniqid();
$returnUrl = 'http://localhost:8000/gateway-return.php';
$notifyUrl = 'http://127.0.0.1/online-payments/uuid/notify';
$notifyUrl = 'http://127.0.0.1/uuid/notify';
$description = 'Shopping at myStore.com';

$purchaseRequest = [
Expand Down Expand Up @@ -56,8 +56,9 @@
$response = $gateway->purchase($purchaseRequest);

echo "TransactionId: " . $response->getTransactionId() . PHP_EOL;
echo 'Is Successful: ' . (bool) $response->isSuccessful() . PHP_EOL;
echo 'Is redirect: ' . (bool) $response->isRedirect() . PHP_EOL;
echo "TransactionReference: " . $response->getTransactionReference() . PHP_EOL;
echo 'Is Successful: ' . (bool)$response->isSuccessful() . PHP_EOL;
echo 'Is redirect: ' . (bool)$response->isRedirect() . PHP_EOL;

// Payment init OK, redirect to the payment gateway
echo $response->getRedirectUrl() . PHP_EOL;
Expand Down
23 changes: 13 additions & 10 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ public function getName()
public function getAccessToken()
{
$request = parent::createRequest(AccessTokenRequest::class, [
'clientId' => $this->getParameter('posId'),
'clientId' => $this->getParameter('posId'),
'clientSecret' => $this->getParameter('clientSecret'),
'apiUrl' => $this->getApiUrl()
'apiUrl' => $this->getApiUrl()
]);
$response = $request->send();

return $response;
}

/**
* @param array $parameters
* @return PurchaseResponse
*/
public function purchase(array $parameters = array())
public function purchase(array $parameters = [])
{
$this->setAccessToken($this->getAccessToken()->getAccessToken());
$request = parent::createRequest(PurchaseRequest::class, $parameters);
Expand All @@ -55,7 +56,7 @@ public function purchase(array $parameters = array())
* @param array $parameters
* @return CompletePurchaseResponse
*/
public function completePurchase(array $parameters = array())
public function completePurchase(array $parameters = [])
{
$this->setAccessToken($this->getAccessToken()->getAccessToken());
$request = self::createRequest(CompletePurchaseRequest::class, $parameters);
Expand Down Expand Up @@ -84,11 +85,11 @@ private function getApiUrl()
public function getDefaultParameters()
{
return [
'posId' => '',
'secondKey' => '',
'posId' => '',
'secondKey' => '',
'clientSecret' => '',
'testMode' => true,
'posAuthKey' => null,
'testMode' => true,
'posAuthKey' => null,
];
}

Expand Down Expand Up @@ -119,14 +120,16 @@ public function setClientSecret($clientSecret)
/**
* @param string|null $posAuthKey
*/
public function setPosAuthKey($posAuthKey = null) {
public function setPosAuthKey($posAuthKey = null)
{
$this->setParameter('posAuthKey', $posAuthKey);
}

public function initialize(array $parameters = array())
public function initialize(array $parameters = [])
{
parent::initialize($parameters);
$this->setApiUrl($this->getApiUrl());

return $this;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Messages/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public function isSuccessful()
public function getTransactionId()
{
if (isset($this->data['orders'][0]['extOrderId'])) {
return (string) $this->data['orders'][0]['extOrderId'];
return (string)$this->data['orders'][0]['extOrderId'];
}

return null;
}

Expand All @@ -37,8 +38,9 @@ public function isCancelled()
public function getTransactionReference()
{
if (isset($this->data['orders'][0]['orderId'])) {
return (string) $this->data['orders'][0]['orderId'];
return (string)$this->data['orders'][0]['orderId'];
}

return null;
}

Expand All @@ -62,7 +64,7 @@ public function isPending()
*/
public function getPaymentReference()
{
if(isset($this->data['properties'])) {
if (isset($this->data['properties'])) {
$properties = $this->data['properties'];
$paymentIdProperty = array_filter($properties, function ($item) {
return $item['name'] === 'PAYMENT_ID';
Expand Down
3 changes: 3 additions & 0 deletions src/Messages/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function sendData($data)
'Authorization' => $data['accessToken']
];
$apiUrl = $data['apiUrl'] . '/api/v2_1/orders';
if (isset($data['purchaseData']['extOrderId'])) {
$this->setTransactionId($data['purchaseData']['extOrderId']);
}
$httpRequest = $this->httpClient->post($apiUrl, $headers, json_encode($data['purchaseData']));
$httpRequest->configureRedirects(true, 0);
$httpResponse = $httpRequest->send();
Expand Down
20 changes: 12 additions & 8 deletions src/Messages/PurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,27 @@ public function getRedirectData()
}

/**
* PayU orderId
* @return string
* @return string|null
*/
public function getTransactionId()
{
return (string)$this->data['orderId'];
if (isset($this->data['extOrderId'])) {
return (string)$this->data['extOrderId'];
}
if (isset($this->request->getParameters()['transactionId'])) {
return $this->request->getParameters()['transactionId'];
}

return null;
}

/**
* @return string|null
* PayU orderId
* @return string
*/
public function getTransactionReference()
{
if (isset($this->data['extOrderId'])) {
return (string)$this->data['extOrderId'];
}
return null;
return (string)$this->data['orderId'];
}

public function isRedirect()
Expand Down

0 comments on commit b34bfa2

Please sign in to comment.