-
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
0 parents
commit 5f2c8aa
Showing
27 changed files
with
1,152 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,3 @@ | ||
.idea | ||
vendor | ||
composer.lock |
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,8 @@ | ||
# Omnipay: ČSOB | ||
|
||
**ČSOB driver for the Omnipay PHP payment processing library** | ||
|
||
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment | ||
processing library for PHP 5.3+. This package implements PayPal support for Omnipay. | ||
|
||
ČSOB Online Payment Gateway [documentation](https://github.com/csob/paymentgateway/wiki) |
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,32 @@ | ||
{ | ||
"name": "bileto/omnipay-csob", | ||
"type": "library", | ||
"description": "ČSOB gateway for Omnipay payment processing library", | ||
"keywords": [ | ||
"gateway", | ||
"merchant", | ||
"omnipay", | ||
"pay", | ||
"payment", | ||
"csob", | ||
"purchase" | ||
], | ||
"homepage": "https://github.com/bileto/omnipay-csob", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Michal Sänger", | ||
"email": "michal.sanger@bileto.cz" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { "Omnipay\\Csob\\" : "src/" } | ||
}, | ||
"require": { | ||
"omnipay/common": "^2.3" | ||
}, | ||
"require-dev": { | ||
"omnipay/tests": "^2.0", | ||
"symfony/var-dumper": "^2.7" | ||
} | ||
} |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="QUEUE_DRIVER" value="sync"/> | ||
</php> | ||
</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,118 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\Csob\Message\CompletePurchaseRequest; | ||
use Omnipay\Csob\Message\InitPaymentRequest; | ||
use Omnipay\Csob\Message\ProcessPaymentRequest; | ||
use Omnipay\Csob\Message\PaymentResponse; | ||
use Omnipay\Csob\Sign\DataSignator; | ||
use Omnipay\Csob\Sign\DataVerifier; | ||
|
||
class Gateway extends AbstractGateway | ||
{ | ||
/** @var DataSignator */ | ||
private $signator; | ||
|
||
/** @var DataVerifier */ | ||
private $verifier; | ||
|
||
/** | ||
* Get gateway display name | ||
* | ||
* This can be used by carts to get the display name for each gateway. | ||
*/ | ||
public function getName() | ||
{ | ||
return 'ČSOB'; | ||
} | ||
|
||
/** | ||
* @param DataSignator $signator | ||
*/ | ||
public function setSignator(DataSignator $signator) | ||
{ | ||
$this->signator = $signator; | ||
} | ||
|
||
/** | ||
* @param DataVerifier $verifier | ||
*/ | ||
public function setVerifier(DataVerifier $verifier) | ||
{ | ||
$this->verifier = $verifier; | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return InitPaymentRequest | ||
* @throws \Exception | ||
*/ | ||
public function initPayment(array $parameters = array()) | ||
{ | ||
return $this->createRequest(InitPaymentRequest::class, $parameters); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return ProcessPaymentRequest | ||
* @throws \Exception | ||
*/ | ||
public function processPayment(array $parameters = array()) | ||
{ | ||
return $this->createRequest(ProcessPaymentRequest::class, $parameters); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return InitPaymentRequest | ||
* @throws \Exception | ||
*/ | ||
public function purchase(array $parameters = array()) | ||
{ | ||
$initRequest = $this->initPayment($parameters); | ||
/** @var PaymentResponse $initResponse */ | ||
$initResponse = $initRequest->send(); | ||
if (!$initResponse->isSuccessful()) { | ||
throw new InvalidResponseException($initResponse->getMessage(), $initResponse->getCode()); | ||
} | ||
$processRequest = $this->processPayment([ | ||
'merchantId' => $initRequest->getMerchantId(), | ||
'payId' => $initResponse->getTransactionReference(), | ||
'dttm' => $initResponse->getDttm(), | ||
]); | ||
return $processRequest; | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return CompletePurchaseRequest | ||
* @throws \Exception | ||
*/ | ||
public function completePurchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest(CompletePurchaseRequest::class, $parameters); | ||
} | ||
|
||
protected function createRequest($class, array $parameters) | ||
{ | ||
if (!($this->signator instanceof DataSignator)) { | ||
throw new \Exception('Cannot create request, Signator is not set'); | ||
} | ||
if (!($this->verifier instanceof DataVerifier)) { | ||
throw new \Exception('Cannot create request, Verifier is not set'); | ||
} | ||
|
||
/** @var \Omnipay\Csob\Message\AbstractRequest $request */ | ||
$request = parent::createRequest($class, $parameters); | ||
|
||
$request->setSignator($this->signator); | ||
$request->setVerifier($this->verifier); | ||
|
||
return $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,34 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob; | ||
|
||
use Omnipay\Csob\Sign\DataSignator; | ||
use Omnipay\Csob\Sign\DataVerifier; | ||
use Omnipay\Csob\Sign\Preparer; | ||
use Omnipay\Csob\Sign\Signator; | ||
use Omnipay\Csob\Sign\Verifier; | ||
use Omnipay\Omnipay; | ||
|
||
class GatewayFactory | ||
{ | ||
/** | ||
* @param string $publicKeyFilename | ||
* @param string $privateKeyFilename | ||
* @param string $privateKeyPassword | ||
* @return Gateway | ||
*/ | ||
public static function createInstance($publicKeyFilename, $privateKeyFilename, $privateKeyPassword = null) | ||
{ | ||
$preparer = new Preparer(); | ||
$signator = new Signator($privateKeyFilename, $privateKeyPassword); | ||
$verifier = new Verifier($publicKeyFilename); | ||
$dataSignator = new DataSignator($preparer, $signator); | ||
$dataVerifier = new DataVerifier($preparer, $verifier); | ||
|
||
/** @var \Omnipay\Csob\Gateway $gateway */ | ||
$gateway = Omnipay::create('Csob'); | ||
$gateway->setSignator($dataSignator); | ||
$gateway->setVerifier($dataVerifier); | ||
return $gateway; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob\Message; | ||
|
||
use Omnipay\Csob\Sign\DataSignator; | ||
use Omnipay\Csob\Sign\DataVerifier; | ||
|
||
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest | ||
{ | ||
/** @var DataSignator */ | ||
private $signator; | ||
|
||
/** @var DataVerifier */ | ||
private $verifier; | ||
|
||
/** | ||
* @param DataSignator $signator | ||
*/ | ||
public function setSignator(DataSignator $signator) | ||
{ | ||
$this->signator = $signator; | ||
} | ||
|
||
/** | ||
* @return DataSignator | ||
*/ | ||
public function getSignator() | ||
{ | ||
return $this->signator; | ||
} | ||
|
||
/** | ||
* @return DataVerifier | ||
*/ | ||
public function getVerifier() | ||
{ | ||
return $this->verifier; | ||
} | ||
|
||
/** | ||
* @param DataVerifier $verifier | ||
*/ | ||
public function setVerifier(DataVerifier $verifier) | ||
{ | ||
$this->verifier = $verifier; | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Omnipay\Csob\Message; | ||
|
||
use Omnipay\Csob\Sign\DataVerifier; | ||
|
||
class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse | ||
{ | ||
/** @var DataVerifier */ | ||
private $verifier; | ||
|
||
/** @var boolean */ | ||
private $isVerified; | ||
|
||
/** | ||
* @param DataVerifier $verifier | ||
*/ | ||
public function setVerifier(DataVerifier $verifier) | ||
{ | ||
$this->verifier = $verifier; | ||
} | ||
|
||
public function isVerified() | ||
{ | ||
if ($this->isVerified === null) { | ||
$data = $this->getData(); | ||
$arrayKeys = ['payId', 'dttm', 'resultCode', 'resultMessage', 'paymentStatus', 'authCode', 'merchantData']; | ||
$signature = $this->getSignature(); | ||
$this->isVerified = $this->verifier->verify($data, $arrayKeys, $signature); | ||
} | ||
return $this->isVerified; | ||
} | ||
|
||
/** | ||
* Is the response successful? | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
if (!$this->isVerified()) { | ||
return false; | ||
} | ||
return $this->getCode() === 0 || $this->getCode() === "0"; | ||
} | ||
|
||
public function getSignature() | ||
{ | ||
if (isset($this->data['signature'])) { | ||
return $this->data['signature']; | ||
} | ||
} | ||
|
||
public function getDttm() | ||
{ | ||
if (isset($this->data['dttm'])) { | ||
return $this->data['dttm']; | ||
} | ||
} | ||
|
||
public function getCode() | ||
{ | ||
if (isset($this->data['resultCode'])) { | ||
return $this->data['resultCode']; | ||
} | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
if (!$this->isVerified()) { | ||
return 'Verification error, the signature cannot be verified with given public key.'; | ||
} | ||
if (isset($this->data['resultMessage'])) { | ||
return $this->data['resultMessage']; | ||
} | ||
} | ||
} |
Oops, something went wrong.