Skip to content

Commit 550f63e

Browse files
author
has.well
committed
add validation to test cases, fixed synchronous capture validation
1 parent e92adf8 commit 550f63e

File tree

6 files changed

+27
-20
lines changed

6 files changed

+27
-20
lines changed

lib/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ public static function getRequestType()
181181
{
182182
return self::$RequestType;
183183
}
184-
}
184+
}

lib/Helper/ResultHelper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ResultHelper
1212
* @param $result
1313
* @param string $secretKey
1414
* @param string $ver
15-
* @return bool|string
15+
* @return bool
1616
*/
1717
public static function isPaymentValid($result, $secretKey = '', $ver = '')
1818
{
@@ -26,7 +26,8 @@ public static function isPaymentValid($result, $secretKey = '', $ver = '')
2626
if ($ver == '') {
2727
$ver = Configuration::getApiVersion();
2828
}
29-
if (!array_key_exists('signature', $result)) return 'Nothing to validate';
29+
if (!array_key_exists('signature', $result))
30+
return false;
3031
$signature = $result['signature'];
3132
if ($ver === '2.0') {
3233
$encoded = $result['encodedData'];
@@ -74,7 +75,7 @@ public static function isActiveMerchant(Array $result)
7475
public static function isPaymentApproved($data, $secretKey = '', $ver = '')
7576
{
7677
if (!isset($data['order_status']))
77-
return 'Nothing to check';
78+
return false;
7879
$valid = self::isPaymentValid($data, $secretKey, $ver);
7980
if ($valid && $data['order_status'] === 'approved')
8081
return true;
@@ -95,4 +96,4 @@ public function getVerifyStatus($data)
9596

9697
return false;
9798
}
98-
}
99+
}

lib/Response/OrderResponse.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ public function isReversed()
3030
{
3131
$data = $this->buildVerifyData();
3232
if (!isset($data['reverse_status']))
33-
return 'Nothing to check';
34-
$valid = $this->isValid();
33+
return false;
34+
$valid = $this->isValid($data);
3535
if ($valid && $data['reverse_status'] === 'approved')
3636
return true;
3737

3838
return false;
3939
}
4040

4141
/**
42-
* @return bool|string
43-
* @throws \Exception
42+
* @param bool $direct if synchronous call
43+
* @return bool
4444
*/
45-
public function isCaptured()
45+
public function isCaptured($direct = false)
4646
{
4747
$data = $this->buildVerifyData();
4848
if (!isset($data['capture_status']))
49-
return 'Nothing to check';
50-
$valid = $this->isValid();
49+
return false;
50+
$valid = $direct ? $direct : $this->isValid($data);
5151
if ($valid && $data['capture_status'] === 'captured')
5252
return true;
5353

@@ -85,4 +85,4 @@ private function getCapturedTransAction()
8585
}
8686
return false;
8787
}
88-
}
88+
}

lib/Response/Response.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ public function isApproved()
155155

156156
/**
157157
* Checking if order signature is valid
158+
* @param null $data
158159
* @return bool
159160
*/
160-
public function isValid()
161+
public function isValid($data = null)
161162
{
162-
$data = $this->buildVerifyData();
163+
if ($data == null)
164+
$data = $this->buildVerifyData();
163165
return ResultHelper::isPaymentValid($data, $this->paymentKey, $this->apiVersion);
164166
}
165167

@@ -175,4 +177,4 @@ protected function setKeyByOperationType($type = '')
175177
$this->paymentKey = Configuration::getSecretKey();
176178
}
177179
}
178-
}
180+
}

lib/Result/Result.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function isProcessing()
137137
{
138138
$data = $this->getData();
139139
if (!isset($data['order_status']))
140-
return 'Nothing to check';
140+
return false;
141141
$valid = $this->isValid();
142142
if ($valid && $data['order_status'] === 'processing')
143143
return true;
@@ -153,7 +153,7 @@ public function isDeclined()
153153
{
154154
$data = $this->getData();
155155
if (!isset($data['order_status']))
156-
return 'Nothing to check';
156+
return false;
157157
$valid = $this->isValid();
158158
if ($valid && $data['order_status'] === 'declined')
159159
return true;
@@ -169,12 +169,12 @@ public function isExpired()
169169
{
170170
$data = $this->getData();
171171
if (!isset($data['order_status']))
172-
return 'Nothing to check';
172+
return false;
173173
$valid = $this->isValid();
174174
if ($valid && $data['order_status'] === 'expired')
175175
return true;
176176

177177
return false;
178178

179179
}
180-
}
180+
}

tests/OrderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function testStatus()
5353
$this->assertNotEmpty($result['order_id'], 'order_id is empty');
5454
$this->assertNotEmpty($result['order_status'], 'order_status is empty');
5555
$this->assertEquals($result['response_status'], 'success');
56+
$this->assertEquals( true, $data->isApproved());
57+
$this->assertEquals( true, $data->isValid());
5658

5759
}
5860

@@ -71,6 +73,7 @@ public function testCapture()
7173
$result = $data->getData();
7274
$this->assertIsMyArray($result);
7375
$this->assertEquals($result['capture_status'], 'captured');
76+
$this->assertEquals(true, $data->isCaptured(true));
7477
}
7578

7679
/**
@@ -89,6 +92,7 @@ public function testReverse()
8992
$this->assertNotEmpty($result['order_id'], 'order_id is empty');
9093
$this->assertEquals($result['response_status'], 'success');
9194
$this->assertEquals($result['reverse_status'], 'approved');
95+
$this->assertEquals(true, $data->isReversed());
9296
}
9397

9498
/**

0 commit comments

Comments
 (0)