Skip to content

Commit

Permalink
Merge pull request #12 from delatbabel/code-tidy-1
Browse files Browse the repository at this point in the history
Code tidy 1
  • Loading branch information
delatbabel committed Mar 22, 2016
2 parents 0dcf285 + 8010523 commit 1c95363
Show file tree
Hide file tree
Showing 25 changed files with 314 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
composer.lock
composer.phar
phpunit.xml
/.idea
/documents
.directory
dirlist.app
dirlist.cache
dirlist.vendor
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[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.

[eWay](https://eway.io/about-eway) was launched in Australia in 1998 and now operates payment gateways
in 8 countries.

## Installation

Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
Expand All @@ -31,10 +34,19 @@ And run composer to update your dependencies:

The following gateways are provided by this package:

* Eway_Rapid
* Eway_RapidShared
* Eway_RapidDirect
* Eway_Direct
* Eway_Direct -- This gateway is deprecated. If you have existing code that uses it you can continue
to do so but you should consider migrating to Eway_RapidDirect
* Eway_RapidDirect -- This is the primary gateway used for direct card processing, i.e. where you collect the
card details from the customer and pass them to eWay yourself via the API.
* Eway_Rapid -- This is used for eWAY Rapid Transparent Redirect requests. The gateway is just
called Eway_Rapid as it was the first implemented. Like other redirect gateways the purchase() call
will return a redirect response and then requires you to redirect the customer to the eWay site for
the actual purchase.
* Eway_RapidShared -- This provides a hosted form for entering payment information, other than that
it is similar to the Eway_Rapid gateway in functionality.

See the docblocks within the gateway classes for further information and links to the eWay gateway on
line.

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.
Expand Down
146 changes: 146 additions & 0 deletions makedoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/sh

#
# Smart little documentation generator.
# GPL/LGPL
# (c) Del 2015 http://www.babel.com.au/
#

APPNAME='Omnipay eWay Gateway Module'
CMDFILE=apigen.cmd.$$
DESTDIR=./documents

#
# Find apigen, either in the path or as a local phar file
#
if [ -f apigen.phar ]; then
APIGEN="php apigen.phar"

else
APIGEN=`which apigen`
if [ ! -f "$APIGEN" ]; then

# Search for phpdoc if apigen is not found.
if [ -f phpDocumentor.phar ]; then
PHPDOC="php phpDocumentor.phar"

else
PHPDOC=`which phpdoc`
if [ ! -f "$PHPDOC" ]; then
echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them"
echo "see http://www.apigen.org/ or http://www.phpdoc.org/"
exit 1
fi
fi
fi
fi

#
# As of version 4 of apigen need to use the generate subcommand
#
if [ ! -z "$APIGEN" ]; then
APIGEN="$APIGEN generate"
fi

#
# Without any arguments this builds the entire system documentation,
# making the cache file first if required.
#
if [ -z "$1" ]; then
#
# Check to see that the cache has been made.
#
if [ ! -f dirlist.cache ]; then
echo "Making dirlist.cache file"
$0 makecache
fi

#
# Build the apigen/phpdoc command in a file.
#
if [ ! -z "$APIGEN" ]; then
echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE
cat dirlist.cache | while read dir; do
echo "--source $dir \\" >> $CMDFILE
done
echo "" >> $CMDFILE

elif [ ! -z "$PHPDOC" ]; then
echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE
cat dirlist.cache | while read dir; do
echo "${dir},\\" >> $CMDFILE
done
echo "" >> $CMDFILE

else
"Neither apigen nor phpdoc are found, how did I get here?"
exit 1
fi

#
# Run the apigen command
#
rm -rf $DESTDIR/main
mkdir -p $DESTDIR/main
. ./$CMDFILE

/bin/rm -f ./$CMDFILE

#
# The "makecache" argument causes the script to just make the cache file
#
elif [ "$1" = "makecache" ]; then
echo "Find application source directories"
find src -name \*.php -print | \
(
while read file; do
grep -q 'class' $file && dirname $file
done
) | sort -u | \
grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app

echo "Find vendor source directories"
find vendor -name \*.php -print | \
(
while read file; do
grep -q 'class' $file && dirname $file
done
) | sort -u | \
grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor

#
# Filter out any vendor directories for which apigen fails
#
echo "Filter source directories"
mkdir -p $DESTDIR/tmp
cat dirlist.app dirlist.vendor | while read dir; do
if [ ! -z "$APIGEN" ]; then
$APIGEN --quiet --title "Test please ignore" \
--source $dir \
--destination $DESTDIR/tmp && (
echo "Including $dir"
echo $dir >> dirlist.cache
) || (
echo "Excluding $dir"
)

elif [ ! -z "$PHPDOC" ]; then
$PHPDOC --quiet --title "Test please ignore" \
--directory $dir \
--target $DESTDIR/tmp && (
echo "Including $dir"
echo $dir >> dirlist.cache
) || (
echo "Excluding $dir"
)

fi
done
echo "Documentation cache dirlist.cache built OK"

#
# Clean up
#
/bin/rm -rf $DESTDIR/tmp

fi
25 changes: 25 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

#
# Command line runner for unit tests for composer projects
# (c) Del 2015 http://www.babel.com.au/
# No Rights Reserved
#

#
# Clean up after any previous test runs
#
mkdir -p documents
rm -rf documents/coverage-html-new
rm -f documents/coverage.xml

#
# Run phpunit
#
vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml

if [ -d documents/coverage-html-new ]; then
rm -rf documents/coverage-html
mv documents/coverage-html-new documents/coverage-html
fi

5 changes: 2 additions & 3 deletions src/DirectGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Legacy Direct XML Payments Gateway
*/

namespace Omnipay\Eway;

use Omnipay\Common\AbstractGateway;
Expand All @@ -14,7 +14,6 @@
*
* NOTE: The APIs called by this gateway are older legacy APIs, new integrations should instead
* use eWAY Rapid.
*
*/
class DirectGateway extends AbstractGateway
{
Expand All @@ -27,7 +26,7 @@ public function getDefaultParameters()
{
return array(
'customerId' => '',
'testMode' => false,
'testMode' => false,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Rapid Abstract Request
*/

namespace Omnipay\Eway\Message;

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ public function setInvoiceReference($value)
{
return $this->setParameter('invoiceReference', $value);
}

protected function getBaseData()
{
$data = array();
Expand Down
2 changes: 1 addition & 1 deletion src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Rapid Abstract Response
*/

namespace Omnipay\Eway\Message;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Message/DirectCaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DirectCaptureRequest extends DirectAbstractRequest
public function getData()
{
$this->validate('transactionId');

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

Expand Down
2 changes: 1 addition & 1 deletion src/Message/DirectRefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getRefundPassword()
public function getData()
{
$this->validate('refundPassword', 'transactionId');

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

Expand Down
2 changes: 1 addition & 1 deletion src/Message/DirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getTransactionReference()
if (empty($this->data->ewayTrxnNumber)) {
return null;
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/Message/RapidCaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Rapid Capture Request
*/

namespace Omnipay\Eway\Message;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public function getEndpoint()
{
return $this->getEndpointBase().'/CapturePayment';
}

public function sendData($data)
{
// This request uses the REST endpoint and requires the JSON content type header
Expand Down
2 changes: 1 addition & 1 deletion src/Message/RapidCompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Rapid Complete Purchase Request
*/

namespace Omnipay\Eway\Message;

/**
Expand Down
19 changes: 9 additions & 10 deletions src/Message/RapidDirectAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* eWAY Rapid Direct Abstract Request
*/

namespace Omnipay\Eway\Message;

/**
Expand All @@ -18,7 +18,7 @@ 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.
Expand All @@ -30,7 +30,7 @@ public function setEncryptedCardNumber($value)
{
return $this->setParameter('encryptedCardNumber', $value);
}

public function getEncryptedCardCvv()
{
return $this->getParameter('encryptedCardCvv');
Expand All @@ -47,32 +47,31 @@ 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 {
Expand All @@ -83,7 +82,7 @@ protected function getBaseData()
$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();
}
Expand Down
Loading

0 comments on commit 1c95363

Please sign in to comment.