Skip to content

Commit 012a703

Browse files
author
Andy Coates
committed
Initial commit
0 parents  commit 012a703

17 files changed

+571
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.lock
3+
composer.phar
4+
phpunit.xml

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
env:
9+
- SYMFONY_VERSION="2.1" GUZZLE_VERSION="3.1"
10+
- SYMFONY_VERSION="2.*" GUZZLE_VERSION="3.1"
11+
- SYMFONY_VERSION="2.1" GUZZLE_VERSION="3.*"
12+
- SYMFONY_VERSION="2.*" GUZZLE_VERSION="3.*"
13+
14+
before_script:
15+
- composer self-update
16+
- composer --version
17+
- composer require symfony/http-foundation:${SYMFONY_VERSION} --no-update
18+
- composer require guzzle/http:${GUZZLE_VERSION} --no-update
19+
- composer install -n --dev --prefer-source
20+
21+
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text

CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing Guidelines
2+
3+
* Fork the project.
4+
* Make your feature addition or bug fix.
5+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
6+
* Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files.
7+
* Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
8+
style and that all tests pass.
9+
* Send the pull request.
10+
* Check that the Travis CI build passed. If not, rinse and repeat.

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2012-2013 Adrian Macneil
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Omnipay: DataCash
2+
3+
**DataCash driver for the Omnipay PHP payment processing library**
4+
5+
[![Build Status](https://travis-ci.org/omnipay/datacash.png?branch=master)](https://travis-ci.org/omnipay/datacash)
6+
[![Latest Stable Version](https://poser.pugx.org/omnipay/datacash/version.png)](https://packagist.org/packages/omnipay/datacash)
7+
[![Total Downloads](https://poser.pugx.org/omnipay/datacash/d/total.png)](https://packagist.org/packages/omnipay/datacash)
8+
9+
[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment
10+
processing library for PHP 5.3+. This package implements DataCash support for Omnipay.
11+
12+
## Installation
13+
14+
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
15+
to your `composer.json` file:
16+
17+
```json
18+
{
19+
"require": {
20+
"omnipay/datacash": "~2.0"
21+
}
22+
}
23+
```
24+
25+
And run composer to update your dependencies:
26+
27+
$ curl -s http://getcomposer.org/installer | php
28+
$ php composer.phar update
29+
30+
## Basic Usage
31+
32+
The following gateways are provided by this package:
33+
34+
* DataCash
35+
36+
For general usage instructions, please see the main [Omnipay](https://github.com/omnipay/omnipay)
37+
repository.
38+
39+
## Support
40+
41+
If you are having general issues with Omnipay, we suggest posting on
42+
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
43+
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
44+
45+
If you want to keep up to date with release anouncements, discuss ideas for the project,
46+
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
47+
you can subscribe to.
48+
49+
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/omnipay/datacash/issues),
50+
or better yet, fork the library and submit a pull request.

composer.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "omnipay/datacash",
3+
"type": "library",
4+
"description": "DataCash driver for the Omnipay payment processing library",
5+
"keywords": [
6+
"datacash",
7+
"gateway",
8+
"merchant",
9+
"omnipay",
10+
"pay",
11+
"payment"
12+
],
13+
"homepage": "https://github.com/omnipay/datacash",
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Adrian Macneil",
18+
"email": "[email protected]"
19+
},
20+
{
21+
"name": "Omnipay Contributors",
22+
"homepage": "https://github.com/omnipay/datacash/contributors"
23+
}
24+
],
25+
"autoload": {
26+
"psr-0": { "Omnipay\\DataCash\\" : "src/" }
27+
},
28+
"require": {
29+
"omnipay/common": "2.*"
30+
},
31+
"require-dev": {
32+
"guzzle/plugin-mock": "~3.1",
33+
"mockery/mockery": "~0.8",
34+
"omnipay/tests": "2.*",
35+
"phpunit/phpunit": "~3.7.16",
36+
"squizlabs/php_codesniffer": "~1.4.4"
37+
},
38+
"extra": {
39+
"branch-alias": {
40+
"dev-master": "2.0.x-dev"
41+
}
42+
},
43+
"minimum-stability": "dev",
44+
"prefer-stable": true
45+
}

phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="Omnipay Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<listeners>
18+
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" />
19+
</listeners>
20+
<filter>
21+
<whitelist>
22+
<directory>./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/Omnipay/DataCash/Gateway.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Omnipay\DataCash;
4+
5+
use Omnipay\DataCash\Message\CompletePurchaseRequest;
6+
use Omnipay\DataCash\Message\PurchaseRequest;
7+
use Omnipay\Common\AbstractGateway;
8+
9+
/**
10+
* DataCash Gateway
11+
*
12+
* @link https://www.datacash.com/developersarea.php
13+
*/
14+
class Gateway extends AbstractGateway
15+
{
16+
public function getName()
17+
{
18+
return 'DataCash';
19+
}
20+
21+
public function getDefaultParameters()
22+
{
23+
return array(
24+
'merchantId' => '',
25+
'password' => '',
26+
'testMode' => false
27+
);
28+
}
29+
30+
public function getMerchantId()
31+
{
32+
return $this->getParameter('merchantId');
33+
}
34+
35+
public function setMerchantId($value)
36+
{
37+
return $this->setParameter('merchantId', $value);
38+
}
39+
40+
public function getPassword()
41+
{
42+
return $this->getParameter('password');
43+
}
44+
45+
public function setPassword($value)
46+
{
47+
return $this->setParameter('password', $value);
48+
}
49+
50+
public function purchase(array $parameters = array())
51+
{
52+
return $this->createRequest('\Omnipay\DataCash\Message\PurchaseRequest', $parameters);
53+
}
54+
55+
public function completePurchase(array $parameters = array())
56+
{
57+
return $this->createRequest('\Omnipay\DataCash\Message\CompletePurchaseRequest', $parameters);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Omnipay\DataCash\Message;
4+
5+
use SimpleXMLElement;
6+
use Omnipay\Common\Exception\InvalidResponseException;
7+
8+
/**
9+
* DataCash Complete Purchase Request
10+
*/
11+
class CompletePurchaseRequest extends PurchaseRequest
12+
{
13+
public function getData()
14+
{
15+
return $this->httpRequest->request->all();
16+
}
17+
18+
public function sendData($data)
19+
{
20+
return $this->response = new Response($this, $data);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Omnipay\DataCash\Message;
4+
5+
use DOMDocument;
6+
use SimpleXMLElement;
7+
use Omnipay\Common\Message\AbstractRequest;
8+
9+
/**
10+
* DataCash Purchase Request
11+
*/
12+
class PurchaseRequest extends AbstractRequest
13+
{
14+
protected $liveEndpoint = 'https://mars.transaction.datacash.com/Transaction';
15+
protected $testEndpoint = 'https://testserver.datacash.com/Transaction';
16+
17+
public function getMerchantId()
18+
{
19+
return $this->getParameter('merchantId');
20+
}
21+
22+
public function setMerchantId($value)
23+
{
24+
return $this->setParameter('merchantId', $value);
25+
}
26+
27+
public function getPassword()
28+
{
29+
return $this->getParameter('password');
30+
}
31+
32+
public function setPassword($value)
33+
{
34+
return $this->setParameter('password', $value);
35+
}
36+
37+
public function getData()
38+
{
39+
$this->validate('amount', 'card', 'transactionId');
40+
$this->getCard()->validate();
41+
42+
$data = new SimpleXMLElement('<Request/>');
43+
44+
$data->Authentication->client = $this->getMerchantId();
45+
$data->Authentication->password = $this->getPassword();
46+
47+
$data->Transaction->TxnDetails->amount = $this->getAmount();
48+
$data->Transaction->TxnDetails->amount->addAttribute('currency', $this->getCurrency());
49+
$data->Transaction->TxnDetails->merchantreference = $this->getTransactionId();
50+
51+
$data->Transaction->CardTxn->Card->pan = $this->getCard()->getNumber();
52+
$data->Transaction->CardTxn->Card->expirydate = $this->getCard()->getExpiryDate('m') . '/' . $this->getCard()->getExpiryDate('y');
53+
54+
$data->Transaction->CardTxn->method = 'auth';
55+
56+
return $data;
57+
}
58+
59+
public function getEndpoint()
60+
{
61+
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
62+
}
63+
64+
/**
65+
* @param SimpleXMLElement $data
66+
* @return \Omnipay\Common\Message\ResponseInterface|Response
67+
*/
68+
public function sendData($data)
69+
{
70+
// post to DataCash
71+
$xml = $data->saveXML();
72+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $xml)->send();
73+
74+
return $this->response = new Response($this, $httpResponse->getBody());
75+
}
76+
}

0 commit comments

Comments
 (0)