Skip to content

Commit 0dcf285

Browse files
committed
Merge pull request #8 from incarnate/eway_rapid_direct
Add eWAY Rapid Direct Connection
2 parents 983e44b + 96fb1ea commit 0dcf285

36 files changed

+1684
-33
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Omnipay: eWay
1+
# Omnipay: eWAY
22

3-
**eWay driver for the Omnipay PHP payment processing library**
3+
**eWAY driver for the Omnipay PHP payment processing library**
44

55
[![Build Status](https://travis-ci.org/thephpleague/omnipay-eway.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-eway)
66
[![Latest Stable Version](https://poser.pugx.org/omnipay/eway/version.png)](https://packagist.org/packages/omnipay/eway)
77
[![Total Downloads](https://poser.pugx.org/omnipay/eway/d/total.png)](https://packagist.org/packages/omnipay/eway)
88

99
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
10-
processing library for PHP 5.3+. This package implements eWay support for Omnipay.
10+
processing library for PHP 5.3+. This package implements eWAY support for Omnipay.
1111

1212
## Installation
1313

@@ -33,6 +33,7 @@ The following gateways are provided by this package:
3333

3434
* Eway_Rapid
3535
* Eway_RapidShared
36+
* Eway_RapidDirect
3637
* Eway_Direct
3738

3839
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
@@ -44,7 +45,7 @@ If you are having general issues with Omnipay, we suggest posting on
4445
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
4546
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
4647

47-
If you want to keep up to date with release anouncements, discuss ideas for the project,
48+
If you want to keep up to date with release announcements, discuss ideas for the project,
4849
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
4950
you can subscribe to.
5051

src/DirectGateway.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<?php
2-
2+
/**
3+
* eWAY Legacy Direct XML Payments Gateway
4+
*/
5+
36
namespace Omnipay\Eway;
47

58
use Omnipay\Common\AbstractGateway;
69

710
/**
8-
* eWAY Direct Payments Gateway
11+
* eWAY Legacy Direct XML Payments Gateway
12+
*
13+
* This class forms the gateway class for eWAY Legacy Direct XML requests.
14+
*
15+
* NOTE: The APIs called by this gateway are older legacy APIs, new integrations should instead
16+
* use eWAY Rapid.
17+
*
918
*/
1019
class DirectGateway extends AbstractGateway
1120
{

src/Message/AbstractRequest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
2-
2+
/**
3+
* eWAY Rapid Abstract Request
4+
*/
5+
36
namespace Omnipay\Eway\Message;
47

58
/**
6-
* eWAY Abstract Request
7-
*
8-
*/
9+
* eWAY Rapid Abstract Request
10+
*
11+
* This class forms the base class for eWAY Rapid requests
12+
*
13+
* @link https://eway.io/api-v3/#api-reference
14+
*/
915
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1016
{
1117
protected $liveEndpoint = 'https://api.ewaypayments.com';
@@ -43,7 +49,10 @@ public function setPartnerId($value)
4349

4450
public function getTransactionType()
4551
{
46-
return $this->getParameter('transactionType');
52+
if ($this->getParameter('transactionType')) {
53+
return $this->getParameter('transactionType');
54+
}
55+
return 'Purchase';
4756
}
4857

4958
/**
@@ -86,6 +95,7 @@ protected function getBaseData()
8695
$data['Customer'] = array();
8796
$card = $this->getCard();
8897
if ($card) {
98+
$data['Customer']['Title'] = $card->getTitle();
8999
$data['Customer']['FirstName'] = $card->getFirstName();
90100
$data['Customer']['LastName'] = $card->getLastName();
91101
$data['Customer']['CompanyName'] = $card->getCompany();

src/Message/AbstractResponse.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
<?php
2-
2+
/**
3+
* eWAY Rapid Abstract Response
4+
*/
5+
36
namespace Omnipay\Eway\Message;
47

58
/**
6-
* eWAY Abstract Response
7-
*
8-
*/
9+
* eWAY Rapid Abstract Response
10+
*
11+
* This is the base response class for all eWAY requests.
12+
*
13+
*/
914
abstract class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
1015
{
16+
/**
17+
* Translation of eWAY response codes to English
18+
*
19+
* @link https://eway.io/api-v3/#response-amp-error-codes
20+
*/
1121
public static $MESSAGES = array(
1222
'A2000' => 'Transaction Approved',
1323
'A2008' => 'Honour With Identification',

src/Message/RapidCaptureRequest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Capture Request
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
/**
9+
* eWAY Rapid Capture Request
10+
*
11+
* This is a request to capture and process a previously created authorisation.
12+
*
13+
* Example - note this example assumes that the authorisation has been successful
14+
* and that the Transaction ID returned from the authorisation is held in $txn_id.
15+
* See RapidDirectAuthorizeRequest for the first part of this example.
16+
*
17+
* <code>
18+
* // Once the transaction has been authorized, we can capture it for final payment.
19+
* $transaction = $gateway->capture(array(
20+
* 'amount' => '10.00',
21+
* 'currency' => 'AUD',
22+
* ));
23+
* $transaction->setTransactionReference($txn_id);
24+
* $response = $transaction->send();
25+
* </code>
26+
*
27+
* @link https://eway.io/api-v3/#pre-auth
28+
* @see RapidDirectAuthorizeRequest
29+
*/
30+
class RapidCaptureRequest extends AbstractRequest
31+
{
32+
public function getData()
33+
{
34+
$this->validate('amount', 'transactionReference');
35+
36+
$data = array();
37+
38+
$data['Payment'] = array();
39+
$data['Payment']['TotalAmount'] = $this->getAmountInteger();
40+
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
41+
$data['Payment']['InvoiceDescription'] = $this->getDescription();
42+
$data['Payment']['CurrencyCode'] = $this->getCurrency();
43+
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();
44+
45+
$data['TransactionId'] = $this->getTransactionReference();
46+
47+
return $data;
48+
}
49+
50+
public function getEndpoint()
51+
{
52+
return $this->getEndpointBase().'/CapturePayment';
53+
}
54+
55+
public function sendData($data)
56+
{
57+
// This request uses the REST endpoint and requires the JSON content type header
58+
$httpResponse = $this->httpClient->post(
59+
$this->getEndpoint(),
60+
array('content-type' => 'application/json'),
61+
json_encode($data)
62+
)
63+
->setAuth($this->getApiKey(), $this->getPassword())
64+
->send();
65+
66+
return $this->response = new RapidResponse($this, $httpResponse->json());
67+
}
68+
}

src/Message/RapidCompletePurchaseRequest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
2-
2+
/**
3+
* eWAY Rapid Complete Purchase Request
4+
*/
5+
36
namespace Omnipay\Eway\Message;
47

58
/**
6-
* eWAY Rapid 3.0 Complete Purchase Request
9+
* eWAY Rapid Complete Purchase Request
10+
*
11+
* @link https://eway.io/api-v3/#step-3-request-the-results
712
*/
813
class RapidCompletePurchaseRequest extends RapidPurchaseRequest
914
{
@@ -12,7 +17,7 @@ public function getData()
1217
return array('AccessCode' => $this->httpRequest->query->get('AccessCode'));
1318
}
1419

15-
public function getEndpoint()
20+
protected function getEndpoint()
1621
{
1722
return $this->getEndpointBase().'/GetAccessCodeResult.json';
1823
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* eWAY Rapid Direct Abstract Request
4+
*/
5+
6+
namespace Omnipay\Eway\Message;
7+
8+
/**
9+
* eWAY Rapid Direct Abstract Request
10+
*
11+
* This class forms the base class for eWAY Rapid Direct requests.
12+
*
13+
* @link https://eway.io/api-v3/#direct-connection
14+
*/
15+
abstract class RapidDirectAbstractRequest extends AbstractRequest
16+
{
17+
public function getEncryptedCardNumber()
18+
{
19+
return $this->getParameter('encryptedCardNumber');
20+
}
21+
22+
/**
23+
* Sets the encrypted card number, for use when submitting card data
24+
* encrypted using eWAY's client side encryption.
25+
*
26+
* @param string $value
27+
* @return RapidDirectAbstractRequest
28+
*/
29+
public function setEncryptedCardNumber($value)
30+
{
31+
return $this->setParameter('encryptedCardNumber', $value);
32+
}
33+
34+
public function getEncryptedCardCvv()
35+
{
36+
return $this->getParameter('encryptedCardCvv');
37+
}
38+
39+
/**
40+
* Sets the encrypted card cvv, for use when submitting card data
41+
* encrypted using eWAY's client side encryption.
42+
*
43+
* @param string $value
44+
* @return RapidDirectAbstractRequest
45+
*/
46+
public function setEncryptedCardCvv($value)
47+
{
48+
return $this->setParameter('encryptedCardCvv', $value);
49+
}
50+
51+
protected function getBaseData()
52+
{
53+
54+
$data = parent::getBaseData();
55+
$data['TransactionType'] = $this->getTransactionType();
56+
57+
if ($this->getCardReference()) {
58+
$data['Customer']['TokenCustomerID'] = $this->getCardReference();
59+
} else {
60+
$this->validate('card');
61+
}
62+
63+
if ($this->getCard()) {
64+
$data['Customer']['CardDetails'] = array();
65+
$data['Customer']['CardDetails']['Name'] = $this->getCard()->getName();
66+
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
67+
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
68+
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();
69+
70+
if ($this->getEncryptedCardNumber()) {
71+
$data['Customer']['CardDetails']['Number'] = $this->getEncryptedCardNumber();
72+
} else {
73+
$data['Customer']['CardDetails']['Number'] = $this->getCard()->getNumber();
74+
}
75+
76+
if ($this->getEncryptedCardCvv()) {
77+
$data['Customer']['CardDetails']['CVN'] = $this->getEncryptedCardCvv();
78+
} else {
79+
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();
80+
}
81+
82+
if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) {
83+
$data['Customer']['CardDetails']['StartMonth'] = $this->getCard()->getStartDate('m');
84+
$data['Customer']['CardDetails']['StartYear'] = $this->getCard()->getStartDate('y');
85+
}
86+
87+
if ($this->getCard()->getIssueNumber()) {
88+
$data['Customer']['CardDetails']['IssueNumber'] = $this->getCard()->getIssueNumber();
89+
}
90+
}
91+
92+
if ($this->getItems()) {
93+
$data['Items'] = $this->getItemData();
94+
}
95+
96+
return $data;
97+
}
98+
99+
public function sendData($data)
100+
{
101+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($data))
102+
->setAuth($this->getApiKey(), $this->getPassword())
103+
->send();
104+
105+
return $this->response = new RapidResponse($this, $httpResponse->json());
106+
}
107+
}

0 commit comments

Comments
 (0)