Skip to content

Commit

Permalink
check responsecode
Browse files Browse the repository at this point in the history
  • Loading branch information
dilab committed Apr 9, 2018
1 parent 4e87410 commit dd9863f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Message/NoiDiaCompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class NoiDiaCompletePurchaseResponse extends AbstractResponse
{
public function isSuccessful()
{
return strtoupper($this->data['vpc_SecureHash']) ==
strtoupper($this->data['computed_hash_value']);
return $this->isHashMatch() && $this->data['vpc_TxnResponseCode'] == '0';
}

public function getMessage()
Expand Down Expand Up @@ -89,4 +88,9 @@ public function getTransactionId()

return null;
}

private function isHashMatch()
{
return (strtoupper($this->data['vpc_SecureHash']) == strtoupper($this->data['computed_hash_value']));
}
}
29 changes: 28 additions & 1 deletion tests/Message/NoiDiaCompletePurchaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NoiDiaCompletePurchaseResponseTest extends TestCase
*/
public $response;

public function testIsSuccessReturnTrue()
public function testIsSuccessCheckHash()
{
$data = [
'vpc_AdditionData' => 970436,
Expand All @@ -38,6 +38,33 @@ public function testIsSuccessReturnTrue()
$this->assertEquals('JSECURETEST01',$this->response->getTransactionId());
}

public function testIsSuccessCheckResponseCode()
{
$data = [
'vpc_AdditionData' => 970436,
'vpc_Amount' => 100,
'vpc_Command' => 'pay',
'vpc_CurrencyCode' => 'VND',
'vpc_Locale' => 'vn',
'vpc_MerchTxnRef' => '201803210919102006754784',
'vpc_Merchant' => 'ONEPAY',
'vpc_OrderInfo' => 'JSECURETEST01',
'vpc_TransactionNo' => '1625746',
'vpc_TxnResponseCode' => 8,
'vpc_Version' => 2,
'vpc_SecureHash' => '0331F9D8E0CD9A6BC581B74721658DFD9A5A219145F92DED700C13E4843BB3B0',
'computed_hash_value' => '0331f9d8e0cd9a6bc581b74721658dfd9a5a219145f92ded700c13e4843bb3b0'
];

$this->response = new NoiDiaCompletePurchaseResponse($this->getMockRequest(), $data);

$this->assertFalse($this->response->isSuccessful());
$this->assertFalse($this->response->isPending());
$this->assertFalse($this->response->isRedirect());
$this->assertEquals('1625746',$this->response->getTransactionReference());
$this->assertEquals('JSECURETEST01',$this->response->getTransactionId());
}

public function testGetMessage()
{
$data = [
Expand Down

0 comments on commit dd9863f

Please sign in to comment.