Skip to content

Commit

Permalink
Merge pull request #11 from igorkosteski/master
Browse files Browse the repository at this point in the history
- Complete the ThreePartyRefundRequest
  • Loading branch information
delatbabel authored Jun 7, 2017
2 parents 2d74ff3 + 4b62be8 commit 0f79c81
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 16 deletions.
41 changes: 37 additions & 4 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setSecureHash($value)
{
return $this->setParameter('secureHash', $value);
}

public function getLocaleCode()
{
return $this->getParameter('localeCode');
Expand All @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
}
6 changes: 2 additions & 4 deletions src/Message/ThreePartyRefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\Migs\Message;

use Omnipay\Common\Exception\InvalidRequestException;

/**
* Migs Complete Purchase Request
*/
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/ThreePartyCompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
}
}
68 changes: 68 additions & 0 deletions tests/Message/ThreePartyRefundRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Omnipay\Migs\Message;

use Omnipay\Tests\TestCase;

class ThreePartyRefundRequestTest extends TestCase
{
public function setUp()
{
$this->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()
);
}
}
2 changes: 1 addition & 1 deletion tests/Message/TwoPartyPurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions tests/Message/TwoPartyPurchaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
}
}
14 changes: 12 additions & 2 deletions tests/ThreePartyGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 0f79c81

Please sign in to comment.