-
Notifications
You must be signed in to change notification settings - Fork 1
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
Erkin Çakar
committed
Oct 28, 2015
0 parents
commit 370b5db
Showing
42 changed files
with
3,026 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,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
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.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: 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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Erkin Cakar (https://github.com/travijuu) | ||
|
||
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,3 @@ | ||
# BKM Express PHP Payment Library | ||
|
||
Documentation is preparing. |
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 @@ | ||
{ | ||
"name": "travijuu/bkm-express", | ||
"type": "library", | ||
"description": "BKM Express Payment Library", | ||
"keywords": ["bkm express", "payment", "e-commerce"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Erkin Cakar", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "5.0.*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Travijuu\\BkmExpress": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,18 @@ | ||
<?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="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</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,141 @@ | ||
<?php | ||
namespace Travijuu\BkmExpress; | ||
|
||
use Travijuu\BkmExpress\Common\IncomingResult; | ||
use Travijuu\BkmExpress\Common\Result; | ||
use Travijuu\BkmExpress\Exception\VerificationException; | ||
use Travijuu\BkmExpress\Payment\InitializePayment\BKMSoapClient; | ||
use Travijuu\BkmExpress\Payment\InitializePayment\InitializePayment; | ||
use Travijuu\BkmExpress\Payment\InitializePayment\InitializePaymentWSRequest; | ||
use Travijuu\BkmExpress\Payment\InitializePayment\RedirectRequest; | ||
use Travijuu\BkmExpress\Payment\RequestMerchInfo\RequestMerchInfoServer; | ||
use Travijuu\BkmExpress\Utility\Calculate; | ||
use Travijuu\BkmExpress\Utility\Certificate; | ||
use Travijuu\BkmExpress\Exception\ClassNotFoundException; | ||
use SoapServer; | ||
use Closure; | ||
|
||
class BkmExpress | ||
{ | ||
public $mid; | ||
|
||
public $successUrl; | ||
|
||
public $cancelUrl; | ||
|
||
public $privateKeyPath; | ||
|
||
public $publicKeyPath; | ||
|
||
public $bkmPublicKeyPath; | ||
|
||
public $bankList = []; | ||
|
||
public $virtualPosList = []; | ||
|
||
|
||
public function __construct($mid, $successUrl, $cancelUrl, $privateKeyPath, $publicKeyPath, $bkmPublicKeyPath) | ||
{ | ||
$this->mid = $mid; | ||
$this->successUrl = $successUrl; | ||
$this->cancelUrl = $cancelUrl; | ||
$this->privateKeyPath = $privateKeyPath; | ||
$this->publicKeyPath = $publicKeyPath; | ||
$this->bkmPublicKeyPath = $bkmPublicKeyPath; | ||
|
||
$this->bankList = include('Config/BkmBankList.php'); | ||
} | ||
|
||
public function initPayment($wsdl, $sAmount, $cAmount, $banks) | ||
{ | ||
$bkmClient = new BKMSoapClient($wsdl, ['trace' => 1]); | ||
$initPayment = new InitializePayment(); | ||
$initPaymentRequest = new InitializePaymentWSRequest(); | ||
|
||
$initPaymentRequest->setMerchantId($this->mid) | ||
->setSuccessUrl($this->successUrl) | ||
->setCancelUrl($this->cancelUrl) | ||
->setSaleAmount($sAmount) | ||
->setCargoAmount($cAmount) | ||
->setBanks($banks) | ||
->setTimestamp(date('Ymd-H:i:s')); | ||
|
||
$dataToBeHashed = $initPaymentRequest->getDataToBeHashed(); | ||
$signature = Certificate::sign($dataToBeHashed, $this->privateKeyPath); | ||
$verified = Certificate::verify($signature, $dataToBeHashed, $this->publicKeyPath); | ||
|
||
if (! $verified) { | ||
throw new VerificationException("Private / Public key does not match!"); | ||
} | ||
|
||
$initPaymentRequest->setSignature(base64_encode($signature)); | ||
$initPayment->setRequest($initPaymentRequest); | ||
$bkmClient->setParams($initPayment); | ||
|
||
$response = $bkmClient->initializePayment(); | ||
|
||
$verified = $response->verify($this->bkmPublicKeyPath); | ||
|
||
if (! $verified) { | ||
throw new VerificationException("Response can not be verified!"); | ||
} | ||
|
||
if ($response->success()) { | ||
return new RedirectRequest($response, $this->privateKeyPath); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function requestMerchInfo($wsdl, $virtualPosList, Closure $saveTokenCallback = null) | ||
{ | ||
$this->virtualPosList = $virtualPosList; | ||
|
||
$server = new SoapServer($wsdl, ['classmap' => RequestMerchInfoServer::$classmap]); | ||
$server->setClass( | ||
'Travijuu\BkmExpress\Payment\RequestMerchInfo\RequestMerchInfoServer', | ||
$this->publicKeyPath, | ||
$this->privateKeyPath, | ||
$virtualPosList, | ||
$saveTokenCallback | ||
); | ||
$server->handle(); | ||
} | ||
|
||
public function confirm($data) | ||
{ | ||
$incomingResult = new IncomingResult($data); | ||
$verified = $incomingResult->verify($this->bkmPublicKeyPath); | ||
|
||
if (Calculate::timeDiff($incomingResult->getTs()) > 30) { | ||
return Result::build('REQUEST_NOT_SYNCHRONIZED'); | ||
} | ||
|
||
if (! $verified) { | ||
return Result::build('MAC_VERIFICATION_FAILED'); | ||
} | ||
|
||
return $incomingResult; | ||
} | ||
|
||
public function getBank($bankId) | ||
{ | ||
foreach ($this->bankList as $bank) { | ||
if ($bank['id'] == $bankId) { | ||
return $bank; | ||
} | ||
} | ||
} | ||
|
||
public function getPosResponse($bankId, $data) | ||
{ | ||
$bank = $this->getBank($bankId); | ||
$class = 'PosResponse\Response' . $bank['system']; | ||
|
||
if (! class_exists($class)) { | ||
throw new ClassNotFoundException("{$class} not found!"); | ||
} | ||
|
||
return new $class($data); | ||
} | ||
} |
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 Travijuu\BkmExpress; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class BkmExpressServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return []; | ||
} | ||
|
||
} |
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,106 @@ | ||
<?php | ||
namespace Travijuu\BkmExpress\Common; | ||
|
||
use Travijuu\BkmExpress\Exception\UnexpectedDataType; | ||
use Travijuu\BkmExpress\Exception\UnexpectedInstance; | ||
|
||
class Bank | ||
{ | ||
|
||
/** | ||
* @access private | ||
* @var string | ||
*/ | ||
private $id; | ||
/** | ||
* @access private | ||
* @var string | ||
*/ | ||
private $name; | ||
/** | ||
* @access private | ||
* @var string | ||
*/ | ||
private $expBank; | ||
/** | ||
* @access private | ||
* @var Bin | ||
*/ | ||
private $bins = []; | ||
/** | ||
* @access private | ||
* @var bin[] | ||
*/ | ||
private $bin; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDescription() | ||
{ | ||
return $this->expBank; | ||
} | ||
|
||
public function setDescription($description) | ||
{ | ||
$this->expBank = $description; | ||
|
||
return $this; | ||
} | ||
|
||
public function getBins() | ||
{ | ||
return $this->bins; | ||
} | ||
|
||
public function setBins($bins) | ||
{ | ||
if (! is_array($bins)) { | ||
|
||
throw new UnexpectedDataType("Bins should be array"); | ||
} | ||
|
||
$this->bins = []; | ||
|
||
foreach ($bins as $bin) { | ||
|
||
$this->addBin($bin); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function addBin($bin) | ||
{ | ||
if (! $bin instanceof Bin) { | ||
|
||
throw new UnexpectedInstance("Should be instance of Bin"); | ||
} | ||
|
||
array_push($this->bins, $bin); | ||
|
||
return $this; | ||
} | ||
} | ||
|
Oops, something went wrong.