-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Linus Larsson
committed
Jan 24, 2016
0 parents
commit 1a7a3e5
Showing
16 changed files
with
564 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/vendor | ||
composer.lock | ||
composer.phar | ||
phpunit.xml | ||
.idea/ | ||
|
||
.directory | ||
dirlist.app | ||
dirlist.vendor | ||
dirlist.cache | ||
documents/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- composer install -n --dev --prefer-source | ||
|
||
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Nessla AB | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Omnipay: Swish | ||
|
||
**Swish driver for the Omnipay PHP payment processing library** | ||
|
||
[![Build Status](https://travis-ci.org/nessla/omnipay-swish.svg?branch=master)](https://travis-ci.org/nessla/omnipay-swish) | ||
[![Latest Stable Version](https://poser.pugx.org/nessla/omnipay-swish/version.svg)](https://packagist.org/packages/nessla/omnipay-swish) | ||
[![Total Downloads](https://poser.pugx.org/nessla/omnipay-swish/d/total.png)](https://packagist.org/packages/nessla/omnipay-swish) | ||
|
||
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment | ||
processing library for PHP 5.3+. This package implements Swish support for Omnipay. | ||
|
||
## Installation | ||
|
||
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it | ||
to your `composer.json` file: | ||
|
||
```json | ||
{ | ||
"require": { | ||
"nessla/omnipay-swish": "~1.0" | ||
} | ||
} | ||
``` | ||
|
||
And run composer to update your dependencies: | ||
|
||
$ curl -s http://getcomposer.org/installer | php | ||
$ php composer.phar update | ||
|
||
## Basic Usage | ||
|
||
The following gateways are provided by this package: | ||
|
||
* [Swish](https://www.getswish.se) | ||
|
||
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) | ||
repository. | ||
|
||
|
||
|
||
## Support | ||
|
||
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 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. | ||
|
||
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/nessla/omnipay-swish/issues), | ||
or better yet, fork the library and submit a pull request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "nessla/omnipay-swish", | ||
"type": "library", | ||
"description": "Swish gateway for Omnipay payment processing library", | ||
"keywords": [ | ||
"gateway", | ||
"merchant", | ||
"omnipay", | ||
"pay", | ||
"payment", | ||
"swish", | ||
"purchase" | ||
], | ||
"homepage": "https://github.com/nessla/omnipay-swish", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Linus Larsson", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { "Omnipay\\Swish\\" : "src/" } | ||
}, | ||
"require": { | ||
"omnipay/common": "~2.0" | ||
}, | ||
"require-dev": { | ||
"omnipay/tests": "~2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false"> | ||
<testsuites> | ||
<testsuite name="Omnipay Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<listeners> | ||
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" /> | ||
</listeners> | ||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Omnipay\Swish; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
|
||
class Gateway extends AbstractGateway | ||
{ | ||
|
||
public function getName() | ||
{ | ||
return 'Swish'; | ||
} | ||
|
||
public function getDefaultParameters() | ||
{ | ||
return array( | ||
'cert' => null, | ||
'privateKey' => null, | ||
'caCert' => null, | ||
'testMode' => false | ||
); | ||
} | ||
|
||
public function getCert() | ||
{ | ||
return $this->getParameter('cert'); | ||
} | ||
|
||
public function setCert($value) | ||
{ | ||
return $this->setParameter('cert', $value); | ||
} | ||
|
||
public function getPrivateKey() | ||
{ | ||
return $this->getParameter('privateKey'); | ||
} | ||
|
||
public function setPrivateKey($value) | ||
{ | ||
return $this->setParameter('privateKey', $value); | ||
} | ||
|
||
public function getCaCert() | ||
{ | ||
return $this->getParameter('caCert'); | ||
} | ||
|
||
public function setCaCert($value) | ||
{ | ||
return $this->setParameter('caCert', $value); | ||
} | ||
|
||
public function purchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\Swish\Message\PurchaseRequest', $parameters); | ||
} | ||
|
||
public function fetchTransaction(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\Swish\Message\FetchTransactionRequest', $parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
|
||
namespace Omnipay\Swish\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
|
||
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest | ||
{ | ||
|
||
const API_VERSION = 'v1'; | ||
|
||
protected $liveEndpoint = 'https://swicpc.bankgirot.se/swishcpcapi/api'; | ||
protected $testEndpoint = 'https://mss.swicpc.bankgirot.se/swish-cpcapi/api'; | ||
|
||
|
||
public function getCert() | ||
{ | ||
return $this->getParameter('cert'); | ||
} | ||
|
||
public function setCert($value) | ||
{ | ||
return $this->setParameter('cert', $value); | ||
} | ||
|
||
public function getPrivateKey() | ||
{ | ||
return $this->getParameter('privateKey'); | ||
} | ||
|
||
public function setPrivateKey($value) | ||
{ | ||
return $this->setParameter('privateKey', $value); | ||
} | ||
|
||
public function getCaCert() | ||
{ | ||
return $this->getParameter('caCert'); | ||
} | ||
|
||
public function setCaCert($value) | ||
{ | ||
return $this->setParameter('caCert', $value); | ||
} | ||
|
||
public function getPayeePaymentReference() | ||
{ | ||
return $this->getParameter('payeePaymentReference'); | ||
} | ||
|
||
public function setPayeePaymentReference($value) | ||
{ | ||
return $this->setParameter('payeePaymentReference', $value); | ||
} | ||
|
||
public function getPayerAlias() | ||
{ | ||
return $this->getParameter('payerAlias'); | ||
} | ||
|
||
public function setPayerAlias($value) | ||
{ | ||
return $this->setParameter('payerAlias', $value); | ||
} | ||
|
||
public function getPayeeAlias() | ||
{ | ||
return $this->getParameter('payeeAlias'); | ||
} | ||
|
||
public function setPayeeAlias($value) | ||
{ | ||
return $this->setParameter('payeeAlias', $value); | ||
} | ||
|
||
protected function getHttpMethod() | ||
{ | ||
return 'POST'; | ||
} | ||
|
||
protected function getEndpoint() | ||
{ | ||
$url = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; | ||
return $url . '/' . self::API_VERSION; | ||
} | ||
|
||
public function getData() | ||
{ | ||
$this->validate('notifyUrl', 'amount', 'currency', 'payeeAlias'); | ||
|
||
$data = array( | ||
'callbackUrl' => $this->getNotifyUrl(), | ||
'amount' => $this->getAmount(), | ||
'currency' => $this->getCurrency(), | ||
'payerAlias' => $this->getPayerAlias(), | ||
'payeeAlias' => $this->getPayeeAlias() | ||
); | ||
|
||
return $data; | ||
} | ||
|
||
public function sendData($data) | ||
{ | ||
// don't throw exceptions for 4xx errors | ||
$this->httpClient->getEventDispatcher()->addListener( | ||
'request.error', | ||
function ($event) { | ||
if ($event['response']->isClientError()) { | ||
$event->stopPropagation(); | ||
} | ||
} | ||
); | ||
|
||
// Guzzle HTTP Client createRequest does funny things when a GET request | ||
// has attached data, so don't send the data if the method is GET. | ||
if ($this->getHttpMethod() == 'GET') { | ||
$httpRequest = $this->httpClient->createRequest( | ||
$this->getHttpMethod(), | ||
$this->getEndpoint() . '?' . http_build_query($data), | ||
array( | ||
'Content-type' => 'application/json' | ||
), | ||
null, | ||
array( | ||
'cert' => $this->getCert(), | ||
'ssl_key' => $this->getPrivateKey(), | ||
'verify' => $this->getCaCert() | ||
) | ||
); | ||
} else { | ||
$httpRequest = $this->httpClient->createRequest( | ||
$this->getHttpMethod(), | ||
$this->getEndpoint(), | ||
array( | ||
'Content-type' => 'application/json', | ||
), | ||
json_encode($data), | ||
array( | ||
'cert' => $this->getCert(), | ||
'ssl_key' => $this->getPrivateKey(), | ||
'verify' => $this->getCaCert() | ||
) | ||
); | ||
} | ||
|
||
try { | ||
$httpResponse = $httpRequest->send(); | ||
return $this->response = $this->createResponse($httpResponse); | ||
} catch (\Exception $e) { | ||
throw new InvalidResponseException( | ||
'Error communicating with payment gateway: ' . $e->getMessage(), | ||
$e->getCode() | ||
); | ||
} | ||
} | ||
|
||
|
||
protected function createResponse($response) | ||
{ | ||
$data = $response->json(); | ||
$statusCode = $response->getStatusCode(); | ||
|
||
return $this->response = new PurchaseResponse($this, $response, $data, $statusCode); | ||
} | ||
} |
Oops, something went wrong.