Skip to content

Commit

Permalink
Merge pull request #8 from incarnate/eway_rapid_direct
Browse files Browse the repository at this point in the history
Add eWAY Rapid Direct Connection
  • Loading branch information
greydnls committed Mar 30, 2015
2 parents 983e44b + 96fb1ea commit 0dcf285
Show file tree
Hide file tree
Showing 36 changed files with 1,684 additions and 33 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Omnipay: eWay
# Omnipay: eWAY

**eWay driver for the Omnipay PHP payment processing library**
**eWAY driver for the Omnipay PHP payment processing library**

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

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

## Installation

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

* Eway_Rapid
* Eway_RapidShared
* Eway_RapidDirect
* Eway_Direct

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

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

Expand Down
13 changes: 11 additions & 2 deletions src/DirectGateway.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?php

/**
* eWAY Legacy Direct XML Payments Gateway
*/

namespace Omnipay\Eway;

use Omnipay\Common\AbstractGateway;

/**
* eWAY Direct Payments Gateway
* eWAY Legacy Direct XML Payments Gateway
*
* This class forms the gateway class for eWAY Legacy Direct XML requests.
*
* NOTE: The APIs called by this gateway are older legacy APIs, new integrations should instead
* use eWAY Rapid.
*
*/
class DirectGateway extends AbstractGateway
{
Expand Down
20 changes: 15 additions & 5 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

/**
* eWAY Rapid Abstract Request
*/

namespace Omnipay\Eway\Message;

/**
* eWAY Abstract Request
*
*/
* eWAY Rapid Abstract Request
*
* This class forms the base class for eWAY Rapid requests
*
* @link https://eway.io/api-v3/#api-reference
*/
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
protected $liveEndpoint = 'https://api.ewaypayments.com';
Expand Down Expand Up @@ -43,7 +49,10 @@ public function setPartnerId($value)

public function getTransactionType()
{
return $this->getParameter('transactionType');
if ($this->getParameter('transactionType')) {
return $this->getParameter('transactionType');
}
return 'Purchase';
}

/**
Expand Down Expand Up @@ -86,6 +95,7 @@ protected function getBaseData()
$data['Customer'] = array();
$card = $this->getCard();
if ($card) {
$data['Customer']['Title'] = $card->getTitle();
$data['Customer']['FirstName'] = $card->getFirstName();
$data['Customer']['LastName'] = $card->getLastName();
$data['Customer']['CompanyName'] = $card->getCompany();
Expand Down
18 changes: 14 additions & 4 deletions src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<?php

/**
* eWAY Rapid Abstract Response
*/

namespace Omnipay\Eway\Message;

/**
* eWAY Abstract Response
*
*/
* eWAY Rapid Abstract Response
*
* This is the base response class for all eWAY requests.
*
*/
abstract class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
{
/**
* Translation of eWAY response codes to English
*
* @link https://eway.io/api-v3/#response-amp-error-codes
*/
public static $MESSAGES = array(
'A2000' => 'Transaction Approved',
'A2008' => 'Honour With Identification',
Expand Down
68 changes: 68 additions & 0 deletions src/Message/RapidCaptureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* eWAY Rapid Capture Request
*/

namespace Omnipay\Eway\Message;

/**
* eWAY Rapid Capture Request
*
* This is a request to capture and process a previously created authorisation.
*
* Example - note this example assumes that the authorisation has been successful
* and that the Transaction ID returned from the authorisation is held in $txn_id.
* See RapidDirectAuthorizeRequest for the first part of this example.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->capture(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* ));
* $transaction->setTransactionReference($txn_id);
* $response = $transaction->send();
* </code>
*
* @link https://eway.io/api-v3/#pre-auth
* @see RapidDirectAuthorizeRequest
*/
class RapidCaptureRequest extends AbstractRequest
{
public function getData()
{
$this->validate('amount', 'transactionReference');

$data = array();

$data['Payment'] = array();
$data['Payment']['TotalAmount'] = $this->getAmountInteger();
$data['Payment']['InvoiceNumber'] = $this->getTransactionId();
$data['Payment']['InvoiceDescription'] = $this->getDescription();
$data['Payment']['CurrencyCode'] = $this->getCurrency();
$data['Payment']['InvoiceReference'] = $this->getInvoiceReference();

$data['TransactionId'] = $this->getTransactionReference();

return $data;
}

public function getEndpoint()
{
return $this->getEndpointBase().'/CapturePayment';
}

public function sendData($data)
{
// This request uses the REST endpoint and requires the JSON content type header
$httpResponse = $this->httpClient->post(
$this->getEndpoint(),
array('content-type' => 'application/json'),
json_encode($data)
)
->setAuth($this->getApiKey(), $this->getPassword())
->send();

return $this->response = new RapidResponse($this, $httpResponse->json());
}
}
11 changes: 8 additions & 3 deletions src/Message/RapidCompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

/**
* eWAY Rapid Complete Purchase Request
*/

namespace Omnipay\Eway\Message;

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

public function getEndpoint()
protected function getEndpoint()
{
return $this->getEndpointBase().'/GetAccessCodeResult.json';
}
Expand Down
107 changes: 107 additions & 0 deletions src/Message/RapidDirectAbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* eWAY Rapid Direct Abstract Request
*/

namespace Omnipay\Eway\Message;

/**
* eWAY Rapid Direct Abstract Request
*
* This class forms the base class for eWAY Rapid Direct requests.
*
* @link https://eway.io/api-v3/#direct-connection
*/
abstract class RapidDirectAbstractRequest extends AbstractRequest
{
public function getEncryptedCardNumber()
{
return $this->getParameter('encryptedCardNumber');
}

/**
* Sets the encrypted card number, for use when submitting card data
* encrypted using eWAY's client side encryption.
*
* @param string $value
* @return RapidDirectAbstractRequest
*/
public function setEncryptedCardNumber($value)
{
return $this->setParameter('encryptedCardNumber', $value);
}

public function getEncryptedCardCvv()
{
return $this->getParameter('encryptedCardCvv');
}

/**
* Sets the encrypted card cvv, for use when submitting card data
* encrypted using eWAY's client side encryption.
*
* @param string $value
* @return RapidDirectAbstractRequest
*/
public function setEncryptedCardCvv($value)
{
return $this->setParameter('encryptedCardCvv', $value);
}

protected function getBaseData()
{

$data = parent::getBaseData();
$data['TransactionType'] = $this->getTransactionType();

if ($this->getCardReference()) {
$data['Customer']['TokenCustomerID'] = $this->getCardReference();
} else {
$this->validate('card');
}

if ($this->getCard()) {
$data['Customer']['CardDetails'] = array();
$data['Customer']['CardDetails']['Name'] = $this->getCard()->getName();
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();

if ($this->getEncryptedCardNumber()) {
$data['Customer']['CardDetails']['Number'] = $this->getEncryptedCardNumber();
} else {
$data['Customer']['CardDetails']['Number'] = $this->getCard()->getNumber();
}

if ($this->getEncryptedCardCvv()) {
$data['Customer']['CardDetails']['CVN'] = $this->getEncryptedCardCvv();
} else {
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();
}

if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) {
$data['Customer']['CardDetails']['StartMonth'] = $this->getCard()->getStartDate('m');
$data['Customer']['CardDetails']['StartYear'] = $this->getCard()->getStartDate('y');
}

if ($this->getCard()->getIssueNumber()) {
$data['Customer']['CardDetails']['IssueNumber'] = $this->getCard()->getIssueNumber();
}
}

if ($this->getItems()) {
$data['Items'] = $this->getItemData();
}

return $data;
}

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

return $this->response = new RapidResponse($this, $httpResponse->json());
}
}
Loading

0 comments on commit 0dcf285

Please sign in to comment.