From cba93b695a6a2f4ab7150ca53e6e5324ee856458 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Sat, 26 Nov 2016 11:35:20 +0545 Subject: [PATCH] Some test fixes --- .../DirectPostCompletePurchaseResponse.php | 10 ++- .../DirectPostAuthorizeRequestTest.php | 20 +++--- .../DirectPostCompletePurchaseRequestTest.php | 64 +++++++++---------- .../Message/DirectPostPurchaseRequestTest.php | 14 ++-- 4 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/Message/DirectPostCompletePurchaseResponse.php b/src/Message/DirectPostCompletePurchaseResponse.php index c59972b..3e52d59 100644 --- a/src/Message/DirectPostCompletePurchaseResponse.php +++ b/src/Message/DirectPostCompletePurchaseResponse.php @@ -9,9 +9,17 @@ */ class DirectPostCompletePurchaseResponse extends AbstractResponse { + /** + * @return mixed + */ public function isSuccessful() { - return isset($this->data['summarycode']) && $this->data['summarycode'] == 1; + return $this->summaryCode() && (int) $this->getCode() == 00; + } + + public function summaryCode() + { + return isset($this->data['summarycode']) && (int) $this->data['summarycode'] == 1; } /** diff --git a/tests/Message/DirectPostAuthorizeRequestTest.php b/tests/Message/DirectPostAuthorizeRequestTest.php index 6244b88..2ad9d1c 100644 --- a/tests/Message/DirectPostAuthorizeRequestTest.php +++ b/tests/Message/DirectPostAuthorizeRequestTest.php @@ -12,15 +12,15 @@ public function setUp() $this->request->initialize( array( - 'merchantId' => 'foo', - 'transactionPassword' => 'bar', - 'amount' => '12.00', - 'returnUrl' => 'https://www.abc.com/return', - 'card' => array( - 'number' => '4444333322221111', + 'merchantId' => 'XYZ0010', + 'transactionPassword' => 'abcd1234', + 'amount' => '12.00', + 'returnUrl' => 'https://www.abc.com/return', + 'card' => array( + 'number' => '4444333322221111', 'expiryMonth' => '6', - 'expiryYear' => '2030', - 'cvv' => '123', + 'expiryYear' => '2030', + 'cvv' => '123', ), ) ); @@ -29,9 +29,9 @@ public function setUp() public function testFingerprint() { $data = $this->request->getData(); - $data['EPS_TIMESTAMP'] = '20130416123332'; + $data['EPS_TIMESTAMP'] = '20161126053143'; - $this->assertSame('46b6a59173c9fea66f71b8679558837895f0bce8', $this->request->generateFingerprint($data)); + $this->assertSame('687bb11413254824e3f854be330b5b5f2efaaf6d', $this->request->generateFingerprint($data)); } public function testSend() diff --git a/tests/Message/DirectPostCompletePurchaseRequestTest.php b/tests/Message/DirectPostCompletePurchaseRequestTest.php index 987f2da..03a505e 100644 --- a/tests/Message/DirectPostCompletePurchaseRequestTest.php +++ b/tests/Message/DirectPostCompletePurchaseRequestTest.php @@ -15,15 +15,15 @@ public function testGenerateResponseFingerprint() { $this->request->initialize( array( - 'amount' => '465.18', + 'amount' => '465.18', 'transactionPassword' => 'abcd1234', ) ); $data = array( - 'timestamp' => '20161125123332', - 'merchant' => 'XYZ0010', - 'refid' => '222', + 'timestamp' => '20161125123332', + 'merchant' => 'XYZ0010', + 'refid' => '222', 'summarycode' => '2', ); @@ -35,26 +35,26 @@ public function testSuccess() { $this->request->initialize( array( - 'amount' => '12.00', + 'amount' => '12.00', 'transactionPassword' => 'abcd1234', - 'transactionId' => 'ORDER-ZYX8', + 'transactionId' => 'ORDER-ZYX8', ) ); $this->getHttpRequest()->query->replace( array( - 'timestamp' => '20161125130241', + 'timestamp' => '20161125130241', 'callback_status_code' => '-1', - 'fingerprint' => 'e30eb8381bc41201fbdf54a021d8228a3fbb6a6f', - 'txnid' => '271337', - 'merchant' => 'XYZ0010', - 'restext' => 'Approved', - 'rescode' => '00', - 'expirydate' => '20161126', - 'settdate' => '20161126', - 'refid' => 'ORDER-ZYX8', - 'pan' => '444433...111', - 'summarycode' => '1', + 'fingerprint' => 'e30eb8381bc41201fbdf54a021d8228a3fbb6a6f', + 'txnid' => '271337', + 'merchant' => 'XYZ0010', + 'restext' => 'Approved', + 'rescode' => '00', + 'expirydate' => '20161126', + 'settdate' => '20161126', + 'refid' => 'ORDER-ZYX8', + 'pan' => '444433...111', + 'summarycode' => '1', ) ); @@ -75,23 +75,23 @@ public function testSuccess() public function testFailure() { $this->request->initialize(array( - 'amount' => '465.18', - 'transactionPassword' => 'abc123', + 'amount' => '465.18', + 'transactionPassword' => 'abcd1234', )); $this->getHttpRequest()->query->replace(array( - 'timestamp' => '20130602102927', - 'callback_status_code' => '', - 'fingerprint' => '0516a31bf96ad89c354266afb9bd4be43aaf853f', - 'txnid' => '205833', - 'merchant' => 'ABC0030', - 'restext' => 'Customer Dispute', - 'rescode' => '18', - 'expirydate' => '052016', - 'settdate' => '20130602', - 'refid' => '222', - 'pan' => '444433...111', - 'summarycode' => '2', + 'timestamp' => '20161126051715', + 'callback_status_code' => '404', + 'fingerprint' => 'cd75e2ef38cf63a2fa390024539acc7691eebc1d', + 'txnid' => '274279', + 'merchant' => 'XYZ0010', + 'restext' => 'Customer Dispute', + 'rescode' => '18', + 'expirydate' => '102030', + 'settdate' => '20161126', + 'refid' => 'ORDER-ZYX8', + 'pan' => '444433...111', + 'summarycode' => '2', )); $response = $this->request->send(); @@ -100,7 +100,7 @@ public function testFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); - $this->assertSame('205833', $response->getTransactionReference()); + $this->assertSame('274279', $response->getTransactionReference()); $this->assertSame('Customer Dispute', $response->getMessage()); $this->assertSame('18', $response->getCode()); } diff --git a/tests/Message/DirectPostPurchaseRequestTest.php b/tests/Message/DirectPostPurchaseRequestTest.php index 1d0bab5..38898f2 100644 --- a/tests/Message/DirectPostPurchaseRequestTest.php +++ b/tests/Message/DirectPostPurchaseRequestTest.php @@ -12,15 +12,15 @@ public function setUp() $this->request->initialize( array( - 'merchantId' => 'XYZ0010', + 'merchantId' => 'XYZ0010', 'transactionPassword' => 'abcd1234', - 'amount' => '12.00', - 'returnUrl' => 'https://www.example.com/return', - 'card' => array( - 'number' => '4444333322221111', + 'amount' => '12.00', + 'returnUrl' => 'https://www.example.com/return', + 'card' => array( + 'number' => '4444333322221111', 'expiryMonth' => '06', - 'expiryYear' => '2020', - 'cvv' => '123', + 'expiryYear' => '2020', + 'cvv' => '123', ), ) );