diff --git a/src/Message/NoiDiaCompletePurchaseResponse.php b/src/Message/NoiDiaCompletePurchaseResponse.php index ab2cc78..06ab05a 100644 --- a/src/Message/NoiDiaCompletePurchaseResponse.php +++ b/src/Message/NoiDiaCompletePurchaseResponse.php @@ -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() @@ -89,4 +88,9 @@ public function getTransactionId() return null; } + + private function isHashMatch() + { + return (strtoupper($this->data['vpc_SecureHash']) == strtoupper($this->data['computed_hash_value'])); + } } \ No newline at end of file diff --git a/tests/Message/NoiDiaCompletePurchaseResponseTest.php b/tests/Message/NoiDiaCompletePurchaseResponseTest.php index be61b75..ade623e 100755 --- a/tests/Message/NoiDiaCompletePurchaseResponseTest.php +++ b/tests/Message/NoiDiaCompletePurchaseResponseTest.php @@ -11,7 +11,7 @@ class NoiDiaCompletePurchaseResponseTest extends TestCase */ public $response; - public function testIsSuccessReturnTrue() + public function testIsSuccessCheckHash() { $data = [ 'vpc_AdditionData' => 970436, @@ -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 = [