Skip to content

Commit 3cd3b23

Browse files
committed
Merge pull request #2 from alexw23/eway-direct
Added eWay Direct
2 parents 1fe8af0 + fac24ac commit 3cd3b23

19 files changed

+713
-0
lines changed

src/DirectGateway.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Omnipay\Eway;
4+
5+
use Omnipay\Common\AbstractGateway;
6+
7+
/**
8+
* eWAY Direct Payments Gateway
9+
*/
10+
class DirectGateway extends AbstractGateway
11+
{
12+
public function getName()
13+
{
14+
return 'eWAY Direct';
15+
}
16+
17+
public function getDefaultParameters()
18+
{
19+
return array(
20+
'customerId' => '',
21+
'testMode' => false,
22+
);
23+
}
24+
25+
public function getCustomerId()
26+
{
27+
return $this->getParameter('customerId');
28+
}
29+
30+
public function setCustomerId($value)
31+
{
32+
return $this->setParameter('customerId', $value);
33+
}
34+
35+
public function authorize(array $parameters = array())
36+
{
37+
return $this->createRequest('\Omnipay\Eway\Message\DirectAuthorizeRequest', $parameters);
38+
}
39+
40+
public function capture(array $parameters = array())
41+
{
42+
return $this->createRequest('\Omnipay\Eway\Message\DirectCaptureRequest', $parameters);
43+
}
44+
45+
public function purchase(array $parameters = array())
46+
{
47+
return $this->createRequest('\Omnipay\Eway\Message\DirectPurchaseRequest', $parameters);
48+
}
49+
50+
public function refund(array $parameters = array())
51+
{
52+
return $this->createRequest('\Omnipay\Eway\Message\DirectRefundRequest', $parameters);
53+
}
54+
55+
public function void(array $parameters = array())
56+
{
57+
return $this->createRequest('\Omnipay\Eway\Message\DirectVoidRequest', $parameters);
58+
}
59+
}

src/Message/DirectAbstractRequest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
7+
/**
8+
* eWAY Direct Abstract Request
9+
*/
10+
abstract class DirectAbstractRequest extends AbstractRequest
11+
{
12+
13+
public function sendData($data)
14+
{
15+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data->asXML())->send();
16+
17+
return $this->response = new DirectResponse($this, $httpResponse->xml());
18+
}
19+
20+
public function getCustomerId()
21+
{
22+
return $this->getParameter('customerId');
23+
}
24+
25+
public function setCustomerId($value)
26+
{
27+
return $this->setParameter('customerId', $value);
28+
}
29+
30+
public function setOption1($value)
31+
{
32+
return $this->setParameter('option1', $value);
33+
}
34+
35+
public function getOption1()
36+
{
37+
return $this->getParameter('option1');
38+
}
39+
40+
public function setOption2($value)
41+
{
42+
return $this->setParameter('option2', $value);
43+
}
44+
45+
public function getOption2()
46+
{
47+
return $this->getParameter('option2');
48+
}
49+
50+
public function setOption3($value)
51+
{
52+
return $this->setParameter('option3', $value);
53+
}
54+
55+
public function getOption3()
56+
{
57+
return $this->getParameter('option3');
58+
}
59+
60+
/**
61+
* Get End Point
62+
*
63+
* Depends on Test or Live environment
64+
*
65+
* @return string
66+
*/
67+
public function getEndpoint()
68+
{
69+
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
70+
}
71+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
7+
/**
8+
* eWAY Direct Authorize Request
9+
*/
10+
class DirectAuthorizeRequest extends DirectAbstractRequest
11+
{
12+
protected $liveEndpoint = 'https://www.eway.com.au/gateway_cvn/xmlauth.asp';
13+
protected $testEndpoint = 'https://www.eway.com.au/gateway_cvn/xmltest/authtestpage.asp';
14+
15+
public function getData()
16+
{
17+
$this->validate('card');
18+
19+
$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
20+
$sxml = new \SimpleXMLElement($xml);
21+
22+
/* eWAY Customer Id */
23+
$sxml->addChild('ewayCustomerID', $this->getCustomerId());
24+
25+
/* eWAY Transaction Details */
26+
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
27+
$sxml->addChild('ewayTrxnNumber', $this->getTransactionId());
28+
29+
/* Card Holder Details */
30+
$card = $this->getCard();
31+
$sxml->addChild('ewayCardHoldersName', $card->getName());
32+
$sxml->addChild('ewayCardNumber', $card->getNumber());
33+
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
34+
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));
35+
$sxml->addChild('ewayCVN', $card->getCVV());
36+
37+
/* Customer Details */
38+
$sxml->addChild('ewayCustomerFirstName', $card->getFirstName());
39+
$sxml->addChild('ewayCustomerLastName', $card->getLastName());
40+
$sxml->addChild('ewayCustomerEmail', $card->getEmail());
41+
$sxml->addChild('ewayCustomerAddress', $card->getAddress1().' '.$card->getAddress2());
42+
$sxml->addChild('ewayCustomerPostcode', $card->getPostCode());
43+
44+
$sxml->addChild('ewayOption1', $this->getOption1());
45+
$sxml->addChild('ewayOption2', $this->getOption2());
46+
$sxml->addChild('ewayOption3', $this->getOption3());
47+
48+
$sxml->addChild('ewayCustomerInvoiceDescription', $this->getDescription());
49+
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());
50+
51+
return $sxml;
52+
}
53+
}

src/Message/DirectCaptureRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
7+
/**
8+
* eWAY Direct Capture Request
9+
*/
10+
class DirectCaptureRequest extends DirectAbstractRequest
11+
{
12+
protected $liveEndpoint = 'https://www.eway.com.au/gateway/xmlauthcomplete.asp';
13+
protected $testEndpoint = 'https://www.eway.com.au/gateway/xmltest/authcompletetestpage.asp';
14+
15+
public function getData()
16+
{
17+
$this->validate('transactionId');
18+
19+
$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
20+
$sxml = new \SimpleXMLElement($xml);
21+
22+
/* eWAY Customer Id */
23+
$sxml->addChild('ewayCustomerID', $this->getCustomerId());
24+
25+
/* eWAY Transaction Details */
26+
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
27+
$sxml->addChild('ewayAuthTrxnNumber', $this->getTransactionId());
28+
29+
$sxml->addChild('ewayCardExpiryMonth', null); // optional field
30+
$sxml->addChild('ewayCardExpiryYear', null); // optional field
31+
32+
$sxml->addChild('ewayOption1', $this->getOption1());
33+
$sxml->addChild('ewayOption2', $this->getOption2());
34+
$sxml->addChild('ewayOption3', $this->getOption3());
35+
36+
return $sxml;
37+
}
38+
}

src/Message/DirectPurchaseRequest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
7+
/**
8+
* eWAY Direct Purchase Request
9+
*/
10+
class DirectPurchaseRequest extends DirectAbstractRequest
11+
{
12+
protected $liveEndpoint = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp';
13+
protected $testEndpoint = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp';
14+
15+
public function getData()
16+
{
17+
$this->validate('card');
18+
19+
$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
20+
$sxml = new \SimpleXMLElement($xml);
21+
22+
/* eWAY Customer Id */
23+
$sxml->addChild('ewayCustomerID', $this->getCustomerId());
24+
25+
/* eWAY Transaction Details */
26+
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
27+
$sxml->addChild('ewayTrxnNumber', $this->getTransactionId());
28+
29+
/* Card Holder Details */
30+
$card = $this->getCard();
31+
$sxml->addChild('ewayCardHoldersName', $card->getName());
32+
$sxml->addChild('ewayCardNumber', $card->getNumber());
33+
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
34+
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));
35+
$sxml->addChild('ewayCVN', $card->getCVV());
36+
37+
/* Customer Details */
38+
$sxml->addChild('ewayCustomerFirstName', $card->getFirstName());
39+
$sxml->addChild('ewayCustomerLastName', $card->getLastName());
40+
$sxml->addChild('ewayCustomerEmail', $card->getEmail());
41+
$sxml->addChild('ewayCustomerAddress', $card->getAddress1().' '.$card->getAddress2());
42+
$sxml->addChild('ewayCustomerPostcode', $card->getPostCode());
43+
44+
$sxml->addChild('ewayOption1', $this->getOption1());
45+
$sxml->addChild('ewayOption2', $this->getOption2());
46+
$sxml->addChild('ewayOption3', $this->getOption3());
47+
48+
$sxml->addChild('ewayCustomerInvoiceDescription', $this->getDescription());
49+
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());
50+
51+
return $sxml;
52+
}
53+
}

src/Message/DirectRefundRequest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
7+
/**
8+
* eWAY Direct Refund Request
9+
*/
10+
class DirectRefundRequest extends DirectAbstractRequest
11+
{
12+
protected $liveEndpoint = 'https://www.eway.com.au/gateway/xmlpaymentrefund.asp';
13+
protected $testEndpoint = 'https://www.eway.com.au/gateway/xmltest/refund_test.asp';
14+
15+
public function setRefundPassword($value)
16+
{
17+
return $this->setParameter('refundPassword', $value);
18+
}
19+
20+
public function getRefundPassword()
21+
{
22+
return $this->getParameter('refundPassword');
23+
}
24+
25+
public function getData()
26+
{
27+
$this->validate('refundPassword', 'transactionId');
28+
29+
$xml = '<?xml version="1.0"?><ewaygateway></ewaygateway>';
30+
$sxml = new \SimpleXMLElement($xml);
31+
32+
/* eWAY Customer Id */
33+
$sxml->addChild('ewayCustomerID', $this->getCustomerId());
34+
35+
/* eWAY Transaction Details */
36+
$sxml->addChild('ewayTotalAmount', $this->getAmountInteger());
37+
$sxml->addChild('ewayOriginalTrxnNumber', $this->getTransactionId());
38+
39+
/* Card Holder Details */
40+
$card = $this->getCard();
41+
$sxml->addChild('ewayCardExpiryMonth', $card->getExpiryDate('m'));
42+
$sxml->addChild('ewayCardExpiryYear', $card->getExpiryDate('y'));
43+
44+
$sxml->addChild('ewayOption1', $this->getOption1());
45+
$sxml->addChild('ewayOption2', $this->getOption2());
46+
$sxml->addChild('ewayOption3', $this->getOption3());
47+
48+
$sxml->addChild('ewayRefundPassword', $this->getRefundPassword());
49+
$sxml->addChild('ewayCustomerInvoiceRef', $this->getTransactionReference());
50+
51+
return $sxml;
52+
}
53+
}

src/Message/DirectResponse.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Omnipay\Eway\Message;
4+
5+
use Omnipay\Common\Message\AbstractResponse;
6+
use Omnipay\Common\Message\RequestInterface;
7+
use Omnipay\Common\Exception\InvalidResponseException;
8+
9+
/**
10+
* eWAY Direct Response
11+
*/
12+
class DirectResponse extends AbstractResponse
13+
{
14+
public function isSuccessful()
15+
{
16+
return "True" === (string) $this->data->ewayTrxnStatus;
17+
}
18+
19+
public function isRedirect()
20+
{
21+
return false;
22+
}
23+
24+
public function getTransactionReference()
25+
{
26+
if (empty($this->data->ewayTrxnNumber)) {
27+
return null;
28+
}
29+
30+
return (int) $this->data->ewayTrxnNumber;
31+
}
32+
33+
public function getMessage()
34+
{
35+
return (string) $this->data->ewayTrxnError;
36+
}
37+
}

0 commit comments

Comments
 (0)