Skip to content

Commit

Permalink
Merge pull request #4 from antonioperic/master
Browse files Browse the repository at this point in the history
Adding capture option
  • Loading branch information
greydnls committed May 8, 2015
2 parents a661c21 + 3a16cb5 commit a15ab75
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,19 @@ public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Netaxept\Message\CompletePurchaseRequest', $parameters);
}

public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\Netaxept\Message\CaptureRequest', $parameters);
}

public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\Netaxept\Message\AnnulRequest', $parameters);
}

public function credit(array $parameters = array())
{
return $this->createRequest('\Omnipay\Netaxept\Message\CreditRequest', $parameters);
}
}
38 changes: 38 additions & 0 deletions src/Message/AnnulRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;

/**
* Netaxept Annul Request
*
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class AnnulRequest extends PurchaseRequest
{
public function getData()
{
$data = array();
$data['transactionAmount'] = $this->getAmountInteger();
$data['transactionId'] = $this->getTransactionId();
$data['merchantId'] = $this->getMerchantId();
$data['token'] = $this->getPassword();
$data['operation'] = 'ANNUL';

if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
throw new InvalidResponseException;
}

return $data;
}

public function sendData($data)
{
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();

return $this->response = new Response($this, $httpResponse->xml());
}
}
37 changes: 37 additions & 0 deletions src/Message/CaptureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Common\Exception\InvalidResponseException;

/**
* Netaxept Capture Request
*
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class CaptureRequest extends PurchaseRequest
{
public function getData()
{
$data = array();
$data['transactionAmount'] = $this->getAmountInteger();
$data['transactionId'] = $this->getTransactionId();
$data['merchantId'] = $this->getMerchantId();
$data['token'] = $this->getPassword();
$data['operation'] = 'CAPTURE';

if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
throw new InvalidResponseException;
}

return $data;
}

public function sendData($data)
{
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();

return $this->response = new Response($this, $httpResponse->xml());
}
}
38 changes: 38 additions & 0 deletions src/Message/CreditRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;

/**
* Netaxept Credit Request
*
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class CreditRequest extends PurchaseRequest
{
public function getData()
{
$data = array();
$data['transactionAmount'] = $this->getAmountInteger();
$data['transactionId'] = $this->getTransactionId();
$data['merchantId'] = $this->getMerchantId();
$data['token'] = $this->getPassword();
$data['operation'] = 'CREDIT';

if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
throw new InvalidResponseException;
}

return $data;
}

public function sendData($data)
{
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();

return $this->response = new Response($this, $httpResponse->xml());
}
}
75 changes: 75 additions & 0 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,81 @@ public function testCompletePurchaseFailure()

$response = $this->gateway->completePurchase($this->options)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());

var_dump($response->getMessage());

$this->assertSame('Unable to find transaction', $response->getMessage());
}

public function testCaptureSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('cc497f37603678c61a09fd5645959812', $response->getTransactionReference());
$this->assertSame('OK', $response->getMessage());
}

public function testCaptureFailure()
{
$this->setMockHttpResponse('CaptureFailure.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('Unable to find transaction', $response->getMessage());
}

public function testAnnulSuccess()
{
$this->setMockHttpResponse('AnnulSuccess.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('3fece3574598c6ae3932fae5f38bc8af', $response->getTransactionReference());
$this->assertSame('OK', $response->getMessage());
}

public function testAnnulFailure()
{
$this->setMockHttpResponse('AnnulFailure.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('Unable to find transaction', $response->getMessage());
}

public function testCreditSuccess()
{
$this->setMockHttpResponse('CreditSuccess.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('3fece3574598c6ae3932fae5f38bc8af', $response->getTransactionReference());
$this->assertSame('OK', $response->getMessage());
}

public function testCreditFailure()
{
$this->setMockHttpResponse('CreditFailure.txt');

$response = $this->gateway->capture($this->options)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
Expand Down
49 changes: 49 additions & 0 deletions tests/Message/AnnulRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Tests\TestCase;

/**
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class AnnulRequestTest extends TestCase
{
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
private $httpRequest;

/**
* @var \Omnipay\Netaxept\Message\AnnulRequest
*/
private $request;

public function setUp()
{
$client = $this->getHttpClient();
$this->httpRequest = $this->getHttpRequest();

$this->request = new AnnulRequest($client, $this->httpRequest);
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionAmount()
{
$this->httpRequest->query->set('transactionId', 'TRANS-123');

$this->request->getData();
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionId()
{
$this->httpRequest->query->set('transactionAmount', 'ABC-123');

$this->request->getData();
}
}
49 changes: 49 additions & 0 deletions tests/Message/CaptureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Tests\TestCase;

/**
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class CaptureRequestTest extends TestCase
{
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
private $httpRequest;

/**
* @var \Omnipay\Netaxept\Message\CaptureRequest
*/
private $request;

public function setUp()
{
$client = $this->getHttpClient();
$this->httpRequest = $this->getHttpRequest();

$this->request = new CaptureRequest($client, $this->httpRequest);
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionAmount()
{
$this->httpRequest->query->set('transactionId', 'TRANS-123');

$this->request->getData();
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionId()
{
$this->httpRequest->query->set('transactionAmount', 'ABC-123');

$this->request->getData();
}
}
49 changes: 49 additions & 0 deletions tests/Message/CreditRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Omnipay\Netaxept\Message;

use Omnipay\Tests\TestCase;

/**
* @author Antonio Peric-Mazar <antonio@locastic.com>
*/
class CreditRequestTest extends TestCase
{
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
private $httpRequest;

/**
* @var \Omnipay\Netaxept\Message\CreditRequest
*/
private $request;

public function setUp()
{
$client = $this->getHttpClient();
$this->httpRequest = $this->getHttpRequest();

$this->request = new CreditRequest($client, $this->httpRequest);
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionAmount()
{
$this->httpRequest->query->set('transactionId', 'TRANS-123');

$this->request->getData();
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
*/
public function testGetDataThrowsExceptionWithoutTransactionId()
{
$this->httpRequest->query->set('transactionAmount', 'ABC-123');

$this->request->getData();
}
}
Loading

0 comments on commit a15ab75

Please sign in to comment.