diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 72b9e10..8e9bbff 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -39,7 +39,7 @@ public function setSecureHash($value) { return $this->setParameter('secureHash', $value); } - + public function getLocaleCode() { return $this->getParameter('localeCode'); @@ -50,18 +50,51 @@ public function setLocaleCode($value) return $this->setParameter('localeCode', $value); } + public function getTransactionNo() + { + return $this->getParameter('transactionNo'); + } + + public function setTransactionNo($value) + { + return $this->setParameter('transactionNo', $value); + } + + public function getUser() + { + return $this->getParameter('user'); + } + + public function setUser($value) + { + return $this->setParameter('user', $value); + } + + public function getPassword() + { + return $this->getParameter('password'); + } + + public function setPassword($value) + { + return $this->setParameter('password', $value); + } + protected function getBaseData() { $data = array(); $data['vpc_Merchant'] = $this->getMerchantId(); $data['vpc_AccessCode'] = $this->getMerchantAccessCode(); $data['vpc_Version'] = '1'; - $data['vpc_Locale'] = $this->getLocaleCode(); $data['vpc_Command'] = $this->action; $data['vpc_Amount'] = $this->getAmountInteger(); $data['vpc_MerchTxnRef'] = $this->getTransactionId(); - $data['vpc_OrderInfo'] = $this->getDescription(); - $data['vpc_ReturnURL'] = $this->getReturnUrl(); + + if ($this->action != 'refund') { + $data['vpc_Locale'] = $this->getLocaleCode() != null ? $this->getLocaleCode() : 'en'; + $data['vpc_OrderInfo'] = $this->getDescription(); + $data['vpc_ReturnURL'] = $this->getReturnUrl(); + } return $data; } diff --git a/src/Message/Response.php b/src/Message/Response.php index 10431f7..bde9c0f 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -21,7 +21,7 @@ public function __construct(RequestInterface $request, $data) public function isSuccessful() { - return isset($this->data['vpc_TxnResponseCode']) && "0" === $this->data['vpc_TxnResponseCode']; + return "0" === $this->getCode(); } public function getTransactionReference() @@ -33,4 +33,9 @@ public function getMessage() { return isset($this->data['vpc_Message']) ? $this->data['vpc_Message'] : null; } + + public function getCode() + { + return isset($this->data['vpc_TxnResponseCode']) ? $this->data['vpc_TxnResponseCode'] : null; + } } diff --git a/src/Message/ThreePartyRefundRequest.php b/src/Message/ThreePartyRefundRequest.php index b724e76..e183d55 100644 --- a/src/Message/ThreePartyRefundRequest.php +++ b/src/Message/ThreePartyRefundRequest.php @@ -2,8 +2,6 @@ namespace Omnipay\Migs\Message; -use Omnipay\Common\Exception\InvalidRequestException; - /** * Migs Complete Purchase Request */ @@ -12,10 +10,10 @@ class ThreePartyRefundRequest extends AbstractRequest protected $action = 'refund'; public function getData() { - $this->validate('amount', 'returnUrl', 'transactionId'); + $this->validate('amount', 'transactionId', 'user', 'password'); $data = $this->getBaseData(); $data['vpc_SecureHash'] = $this->calculateHash($data); - $data['vpc_TransNo'] = $this->getParameter('transactionNo'); + $data['vpc_TransNo'] = $this->getTransactionNo(); $data['vpc_User'] = $this->getUser(); $data['vpc_Password'] = $this->getPassword(); return $data; diff --git a/tests/Message/ThreePartyCompletePurchaseRequestTest.php b/tests/Message/ThreePartyCompletePurchaseRequestTest.php index 79ea430..3fef90d 100644 --- a/tests/Message/ThreePartyCompletePurchaseRequestTest.php +++ b/tests/Message/ThreePartyCompletePurchaseRequestTest.php @@ -27,7 +27,7 @@ public function testThreePartyCompletePurchaseSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); - $this->assertNull($response->getCode()); + $this->assertSame('0', $response->getCode()); } public function testThreePartyCompletePurchaseFailure() @@ -46,6 +46,6 @@ public function testThreePartyCompletePurchaseFailure() $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertNotSame('Approved', $response->getMessage()); - $this->assertNull($response->getCode()); + $this->assertSame('1', $response->getCode()); } } diff --git a/tests/Message/ThreePartyRefundRequestTest.php b/tests/Message/ThreePartyRefundRequestTest.php index e69de29..77dee61 100644 --- a/tests/Message/ThreePartyRefundRequestTest.php +++ b/tests/Message/ThreePartyRefundRequestTest.php @@ -0,0 +1,68 @@ +request = new ThreePartyRefundRequest($this->getHttpClient(), $this->getHttpRequest()); + } + + public function testSignature() + { + $this->request->initialize( + array( + 'amount' => '12.00', + 'transactionId' => 123, + + 'merchantId' => '123', + 'merchantAccessCode' => '123', + 'secureHash' => '123', + + 'transactionNo' => '1112', + + 'user' => 'amauser', + 'password' => 'amapassword' + ) + ); + + $data = $this->request->getData(); + + $this->assertSame('80E8AD6C582431F9C8A55C9645EE2F05BA70D178EB0A85E7394331DC09B61875', $data['vpc_SecureHash']); + } + + /** + * @depends testSignature + */ + public function testRefund() + { + $this->request->initialize( + array( + 'amount' => '12.00', + 'transactionId' => 123, + + 'merchantId' => '123', + 'merchantAccessCode' => '123', + 'secureHash' => '123', + + 'transactionNo' => '1112', + + 'user' => 'amauser', + 'password' => 'amapassword' + ) + ); + + $response = $this->request->send(); + $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('7', $response->getCode()); + $this->assertSame( + 'E5000: Merchant [123] does not have the required privilege to use the VirtualPaymentClient API.', + $response->getMessage() + ); + } +} diff --git a/tests/Message/TwoPartyPurchaseRequestTest.php b/tests/Message/TwoPartyPurchaseRequestTest.php index 467702a..fbd8b14 100644 --- a/tests/Message/TwoPartyPurchaseRequestTest.php +++ b/tests/Message/TwoPartyPurchaseRequestTest.php @@ -58,7 +58,7 @@ public function testPurchase() $this->assertFalse($response->isRedirect()); $this->assertEquals('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); - $this->assertNull($response->getCode()); + $this->assertSame('0', $response->getCode()); $this->assertArrayHasKey('vpc_SecureHash', $response->getData()); } } diff --git a/tests/Message/TwoPartyPurchaseResponseTest.php b/tests/Message/TwoPartyPurchaseResponseTest.php index 54b4529..8438591 100644 --- a/tests/Message/TwoPartyPurchaseResponseTest.php +++ b/tests/Message/TwoPartyPurchaseResponseTest.php @@ -16,7 +16,7 @@ public function testTwoPartyPurchaseSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); - $this->assertNull($response->getCode()); + $this->assertSame('0', $response->getCode()); } public function testTwoPartyPurchaseFailure() @@ -29,6 +29,6 @@ public function testTwoPartyPurchaseFailure() $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Declined', $response->getMessage()); - $this->assertNull($response->getCode()); + $this->assertSame('2', $response->getCode()); } } diff --git a/tests/ThreePartyGatewayTest.php b/tests/ThreePartyGatewayTest.php index 4e8c847..03d10a8 100644 --- a/tests/ThreePartyGatewayTest.php +++ b/tests/ThreePartyGatewayTest.php @@ -39,11 +39,21 @@ public function testCompletePurchase() public function testRefund() { - $request = $this->gateway->refund(array('amount' => '10.00', 'transactionNo' => '1112')); + $request = $this->gateway->refund(array( + 'amount' => '10.00', + 'transactionNo' => '1112', + 'user' => 'amauser', + 'password' =>'amapassword' + )); $this->assertInstanceOf('\Omnipay\Migs\Message\ThreePartyRefundRequest', $request); $this->assertSame('10.00', $request->getAmount()); - } + $this->assertSame('1112', $request->getTransactionNo()); + + $this->assertSame('amauser', $request->getUser()); + + $this->assertSame('amapassword', $request->getPassword()); + } }