Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 4, 2015
2 parents 61dcd86 + 983e44b commit 8d09f94
Show file tree
Hide file tree
Showing 20 changed files with 714 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following gateways are provided by this package:

* Eway_Rapid
* Eway_RapidShared
* Eway_Direct

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.
Expand Down
59 changes: 59 additions & 0 deletions src/DirectGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Omnipay\Eway;

use Omnipay\Common\AbstractGateway;

/**
* eWAY Direct Payments Gateway
*/
class DirectGateway extends AbstractGateway
{
public function getName()
{
return 'eWAY Direct';
}

public function getDefaultParameters()
{
return array(
'customerId' => '',
'testMode' => false,
);
}

public function getCustomerId()
{
return $this->getParameter('customerId');
}

public function setCustomerId($value)
{
return $this->setParameter('customerId', $value);
}

public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\Eway\Message\DirectAuthorizeRequest', $parameters);
}

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

public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Eway\Message\DirectPurchaseRequest', $parameters);
}

public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\Eway\Message\DirectRefundRequest', $parameters);
}

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

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractRequest;

/**
* eWAY Direct Abstract Request
*/
abstract class DirectAbstractRequest extends AbstractRequest
{

public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data->asXML())->send();

return $this->response = new DirectResponse($this, $httpResponse->xml());
}

public function getCustomerId()
{
return $this->getParameter('customerId');
}

public function setCustomerId($value)
{
return $this->setParameter('customerId', $value);
}

public function setOption1($value)
{
return $this->setParameter('option1', $value);
}

public function getOption1()
{
return $this->getParameter('option1');
}

public function setOption2($value)
{
return $this->setParameter('option2', $value);
}

public function getOption2()
{
return $this->getParameter('option2');
}

public function setOption3($value)
{
return $this->setParameter('option3', $value);
}

public function getOption3()
{
return $this->getParameter('option3');
}

/**
* Get End Point
*
* Depends on Test or Live environment
*
* @return string
*/
public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}
}
53 changes: 53 additions & 0 deletions src/Message/DirectAuthorizeRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractRequest;

/**
* eWAY Direct Authorize Request
*/
class DirectAuthorizeRequest extends DirectAbstractRequest
{
protected $liveEndpoint = 'https://www.eway.com.au/gateway_cvn/xmlauth.asp';
protected $testEndpoint = 'https://www.eway.com.au/gateway_cvn/xmltest/authtestpage.asp';

public function getData()
{
$this->validate('card');

$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
$sxml = new \SimpleXMLElement($xml);

/* eWAY Customer Id */
$sxml->addChild('ewayCustomerID', $this->getCustomerId());

/* eWAY Transaction Details */
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
$sxml->addChild('ewayTrxnNumber', $this->getTransactionId());

/* Card Holder Details */
$card = $this->getCard();
$sxml->addChild('ewayCardHoldersName', $card->getName());
$sxml->addChild('ewayCardNumber', $card->getNumber());
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));
$sxml->addChild('ewayCVN', $card->getCVV());

/* Customer Details */
$sxml->addChild('ewayCustomerFirstName', $card->getFirstName());
$sxml->addChild('ewayCustomerLastName', $card->getLastName());
$sxml->addChild('ewayCustomerEmail', $card->getEmail());
$sxml->addChild('ewayCustomerAddress', $card->getAddress1().' '.$card->getAddress2());
$sxml->addChild('ewayCustomerPostcode', $card->getPostCode());

$sxml->addChild('ewayOption1', $this->getOption1());
$sxml->addChild('ewayOption2', $this->getOption2());
$sxml->addChild('ewayOption3', $this->getOption3());

$sxml->addChild('ewayCustomerInvoiceDescription', $this->getDescription());
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());

return $sxml;
}
}
38 changes: 38 additions & 0 deletions src/Message/DirectCaptureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractRequest;

/**
* eWAY Direct Capture Request
*/
class DirectCaptureRequest extends DirectAbstractRequest
{
protected $liveEndpoint = 'https://www.eway.com.au/gateway/xmlauthcomplete.asp';
protected $testEndpoint = 'https://www.eway.com.au/gateway/xmltest/authcompletetestpage.asp';

public function getData()
{
$this->validate('transactionId');

$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
$sxml = new \SimpleXMLElement($xml);

/* eWAY Customer Id */
$sxml->addChild('ewayCustomerID', $this->getCustomerId());

/* eWAY Transaction Details */
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
$sxml->addChild('ewayAuthTrxnNumber', $this->getTransactionId());

$sxml->addChild('ewayCardExpiryMonth', null); // optional field
$sxml->addChild('ewayCardExpiryYear', null); // optional field

$sxml->addChild('ewayOption1', $this->getOption1());
$sxml->addChild('ewayOption2', $this->getOption2());
$sxml->addChild('ewayOption3', $this->getOption3());

return $sxml;
}
}
53 changes: 53 additions & 0 deletions src/Message/DirectPurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractRequest;

/**
* eWAY Direct Purchase Request
*/
class DirectPurchaseRequest extends DirectAbstractRequest
{
protected $liveEndpoint = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp';
protected $testEndpoint = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp';

public function getData()
{
$this->validate('card');

$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
$sxml = new \SimpleXMLElement($xml);

/* eWAY Customer Id */
$sxml->addChild('ewayCustomerID', $this->getCustomerId());

/* eWAY Transaction Details */
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
$sxml->addChild('ewayTrxnNumber', $this->getTransactionId());

/* Card Holder Details */
$card = $this->getCard();
$sxml->addChild('ewayCardHoldersName', $card->getName());
$sxml->addChild('ewayCardNumber', $card->getNumber());
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));
$sxml->addChild('ewayCVN', $card->getCVV());

/* Customer Details */
$sxml->addChild('ewayCustomerFirstName', $card->getFirstName());
$sxml->addChild('ewayCustomerLastName', $card->getLastName());
$sxml->addChild('ewayCustomerEmail', $card->getEmail());
$sxml->addChild('ewayCustomerAddress', $card->getAddress1().' '.$card->getAddress2());
$sxml->addChild('ewayCustomerPostcode', $card->getPostCode());

$sxml->addChild('ewayOption1', $this->getOption1());
$sxml->addChild('ewayOption2', $this->getOption2());
$sxml->addChild('ewayOption3', $this->getOption3());

$sxml->addChild('ewayCustomerInvoiceDescription', $this->getDescription());
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());

return $sxml;
}
}
53 changes: 53 additions & 0 deletions src/Message/DirectRefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractRequest;

/**
* eWAY Direct Refund Request
*/
class DirectRefundRequest extends DirectAbstractRequest
{
protected $liveEndpoint = 'https://www.eway.com.au/gateway/xmlpaymentrefund.asp';
protected $testEndpoint = 'https://www.eway.com.au/gateway/xmltest/refund_test.asp';

public function setRefundPassword($value)
{
return $this->setParameter('refundPassword', $value);
}

public function getRefundPassword()
{
return $this->getParameter('refundPassword');
}

public function getData()
{
$this->validate('refundPassword', 'transactionId');

$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
$sxml = new \SimpleXMLElement($xml);

/* eWAY Customer Id */
$sxml->addChild('ewayCustomerID', $this->getCustomerId());

/* eWAY Transaction Details */
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
$sxml->addChild('ewayOriginalTrxnNumber', $this->getTransactionId());

/* Card Holder Details */
$card = $this->getCard();
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));

$sxml->addChild('ewayOption1', $this->getOption1());
$sxml->addChild('ewayOption2', $this->getOption2());
$sxml->addChild('ewayOption3', $this->getOption3());

$sxml->addChild('ewayRefundPassword', $this->getRefundPassword());
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());

return $sxml;
}
}
37 changes: 37 additions & 0 deletions src/Message/DirectResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Omnipay\Eway\Message;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RequestInterface;
use Omnipay\Common\Exception\InvalidResponseException;

/**
* eWAY Direct Response
*/
class DirectResponse extends AbstractResponse
{
public function isSuccessful()
{
return "True" === (string) $this->data->ewayTrxnStatus;
}

public function isRedirect()
{
return false;
}

public function getTransactionReference()
{
if (empty($this->data->ewayTrxnNumber)) {
return null;
}

return (int) $this->data->ewayTrxnNumber;
}

public function getMessage()
{
return (string) $this->data->ewayTrxnError;
}
}
Loading

0 comments on commit 8d09f94

Please sign in to comment.