├── .gitignore ├── .php_cs.dist ├── .travis.yml ├── LICENSE.md ├── README.md ├── UPGRADE.md ├── composer.json ├── phpunit.xml.dist ├── psalm.xml ├── src ├── Common │ ├── AbstractGateway.php │ ├── AbstractModel.php │ ├── AbstractRequest.php │ ├── AbstractResponse.php │ ├── BaseUrl.php │ ├── CreditCard.php │ ├── CurrencyInterface.php │ ├── Exception │ │ ├── InvalidArgumentException.php │ │ ├── NotFoundClassException.php │ │ ├── NotSupportedMethodException.php │ │ ├── PayconnException.php │ │ └── RuntimeException.php │ ├── GatewayInterface.php │ ├── HttpClient.php │ ├── HttpClientInterface.php │ ├── Model │ │ ├── AuthorizeInterface.php │ │ ├── CancelInterface.php │ │ ├── CompleteInterface.php │ │ ├── PurchaseInterface.php │ │ ├── QueryInterface.php │ │ └── RefundInterface.php │ ├── ModelInterface.php │ ├── RequestInterface.php │ ├── ResponseInterface.php │ ├── TokenInterface.php │ └── Traits │ │ ├── Amount.php │ │ ├── CreditCard.php │ │ ├── Currency.php │ │ ├── Installment.php │ │ ├── OrderId.php │ │ └── ReturnUrl.php └── Payconn.php └── tests └── Common ├── Sample ├── Authorize.php ├── AuthorizeRequest.php ├── AuthorizeResponse.php ├── Gateway.php └── Token.php └── SampleGatewayTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor/ 3 | composer.lock 4 | .DS_Store 5 | .php_cs.cache 6 | -------------------------------------------------------------------------------- /.php_cs.dist: -------------------------------------------------------------------------------- 1 | in(__DIR__) 4 | ->ignoreDotFiles(true) 5 | ->ignoreVCS(true) 6 | ->exclude([ 7 | 'vendor', 8 | ]) 9 | ->files() 10 | ->name('*.php'); 11 | return PhpCsFixer\Config::create() 12 | ->setUsingCache(true) 13 | ->setRiskyAllowed(true) 14 | ->setFinder($finder) 15 | ->setRules([ 16 | '@Symfony' => true, 17 | 'array_syntax' => ['syntax' => 'short'], 18 | 'binary_operator_spaces' => ['align_double_arrow' => false], 19 | 'combine_consecutive_unsets' => true, 20 | 'no_useless_else' => true, 21 | 'no_useless_return' => true, 22 | 'ordered_imports' => true, 23 | 'ordered_class_elements' => true, 24 | 'strict_comparison' => false, 25 | 'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'package']], 26 | 'mb_str_functions' => true, 27 | ]); -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - '7.1.3' 5 | 6 | cache: 7 | directories: 8 | - $HOME/.composer/cache/files 9 | 10 | before_install: 11 | - phpenv config-rm xdebug.ini 12 | - composer self-update 13 | 14 | install: 15 | - composer install 16 | - composer global require friendsofphp/php-cs-fixer 17 | - export PATH="$PATH:$HOME/.composer/vendor/bin" 18 | 19 | script: 20 | # php CS check 21 | - CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE) 22 | - if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then IFS=$'\n' PHP_CS_EXTRA_ARGS=('--path-mode=intersection' '--' ${CHANGED_FILES[@]}); fi 23 | - echo "PHP CS FIXER extra args -> ${PHP_CS_EXTRA_ARGS}" 24 | - php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no "${PHP_CS_EXTRA_ARGS[@]}" || travis_terminate 1 25 | # static analyze 26 | - ./vendor/bin/phpstan analyze src/ -l max || travis_terminate 1 27 | - ./vendor/bin/psalm || travis_terminate 1 28 | # unit tests 29 | - ./vendor/bin/phpunit --stop-on-failure --stop-on-error 30 | 31 | git: 32 | submodules: false -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2019-2021 Murat Saç 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Payconn Common 2 | 3 | **Core components for the Payconn PHP payment processing library** 4 | 5 | [![Build Status](https://travis-ci.com/payconn/common.svg?branch=master)](https://travis-ci.com/payconn/common) 6 | 7 | [Payconn](https://github.com/payconn/common) is a framework agnostic, multi-gateway payment 8 | processing library for PHP. This package implements common classes required by Payconn. 9 | 10 | ## Installation 11 | 12 | composer require payconn/common 13 | 14 | ## Change log 15 | 16 | Please see [UPGRADE](UPGRADE.md) for more information on how to upgrade to the latest version. 17 | 18 | ## Support 19 | 20 | If you are having general issues with Payconn, we suggest posting on 21 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 22 | 23 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/payconn/common/issues), 24 | or better yet, fork the library and submit a pull request. 25 | 26 | 27 | ## Security 28 | 29 | If you discover any security related issues, please email muratsac@mail.com instead of using the issue tracker. 30 | 31 | 32 | ## License 33 | 34 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 35 | -------------------------------------------------------------------------------- /UPGRADE.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/payconn/common/fb9ffff6b8c2615fd42a9d74441d02ac8731b840/UPGRADE.md -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "payconn/common", 3 | "description": "Payconn payment processing library for PHP", 4 | "keywords": [ 5 | "payconn", 6 | "gateway", 7 | "payment", 8 | "purchase", 9 | "3d", 10 | "turkey" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Murat SAC", 16 | "email": "muratsac@mail.com" 17 | } 18 | ], 19 | "type": "library", 20 | "require": { 21 | "php": ">=7.1.3", 22 | "guzzlehttp/guzzle": "^6.5|^7.0.1", 23 | "symfony/http-foundation": "^4.4|^5.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Payconn\\Common\\": "src/Common" 28 | }, 29 | "classmap": ["src/Payconn.php"] 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Payconn\\Tests\\Common\\": "tests/Common" 34 | } 35 | }, 36 | "require-dev": { 37 | "phpunit/phpunit": "^7.3", 38 | "phpstan/phpstan": "^0.11.2", 39 | "vimeo/psalm": "^3.9" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | tests/ 17 | 18 | 19 | -------------------------------------------------------------------------------- /psalm.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Common/AbstractGateway.php: -------------------------------------------------------------------------------- 1 | httpClient = $httpClient; 22 | $this->token = $token; 23 | $this->baseUrl = new BaseUrl(); 24 | } 25 | 26 | public function setBaseUrl(BaseUrl $baseUrl): self 27 | { 28 | $this->baseUrl = $baseUrl; 29 | 30 | return $this; 31 | } 32 | 33 | public function createRequest(string $class, ModelInterface $model): ResponseInterface 34 | { 35 | if (!class_exists($class)) { 36 | throw new NotFoundClassException('Method class not found'); 37 | } 38 | $this->initialize(); 39 | if ($model instanceof AuthorizeInterface) { 40 | $model->setBaseUrl($this->baseUrl->getSecureUrl($model->isTestMode())); 41 | } else { 42 | $model->setBaseUrl($this->baseUrl->getApiUrl($model->isTestMode())); 43 | } 44 | 45 | return (new $class($this->token, $this->httpClient, $model))->send(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Common/AbstractModel.php: -------------------------------------------------------------------------------- 1 | testMode = $testMode; 14 | 15 | return $this; 16 | } 17 | 18 | public function isTestMode(): bool 19 | { 20 | return $this->testMode; 21 | } 22 | 23 | public function getBaseUrl(): string 24 | { 25 | return $this->baseUrl; 26 | } 27 | 28 | public function setBaseUrl(string $baseUrl): ModelInterface 29 | { 30 | $this->baseUrl = $baseUrl; 31 | 32 | return $this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Common/AbstractRequest.php: -------------------------------------------------------------------------------- 1 | token = $token; 18 | $this->httpClient = $httpClient; 19 | $this->model = $model; 20 | } 21 | 22 | public function getHttpClient(): HttpClientInterface 23 | { 24 | return $this->httpClient; 25 | } 26 | 27 | public function getToken(): TokenInterface 28 | { 29 | return $this->token; 30 | } 31 | 32 | public function getIpAddress(): string 33 | { 34 | $clientIp = (Request::createFromGlobals())->getClientIp(); 35 | if (!$clientIp) { 36 | $clientIp = '127.0.0.1'; 37 | } 38 | 39 | return $clientIp; 40 | } 41 | 42 | public function getModel(): ModelInterface 43 | { 44 | return $this->model; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Common/AbstractResponse.php: -------------------------------------------------------------------------------- 1 | model = $model; 16 | $this->parameters = new ParameterBag($parameters); 17 | } 18 | 19 | public function getParameters(): ParameterBag 20 | { 21 | return $this->parameters; 22 | } 23 | 24 | public function getModel(): ModelInterface 25 | { 26 | return $this->model; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Common/BaseUrl.php: -------------------------------------------------------------------------------- 1 | urls = new ParameterBag([ 14 | 'prod' => [ 15 | 'api' => null, 16 | 'secure' => null, 17 | ], 18 | 'test' => [ 19 | 'api' => null, 20 | 'secure' => null, 21 | ], 22 | ]); 23 | } 24 | 25 | public function setProdUrls(string $api, string $secure): self 26 | { 27 | $this->urls->set('prod', [ 28 | 'api' => $api, 29 | 'secure' => $secure, 30 | ]); 31 | 32 | return $this; 33 | } 34 | 35 | public function setTestUrls(string $api, string $secure): self 36 | { 37 | $this->urls->set('test', [ 38 | 'api' => $api, 39 | 'secure' => $secure, 40 | ]); 41 | 42 | return $this; 43 | } 44 | 45 | public function getApiUrl(bool $testMode = false): string 46 | { 47 | if ($testMode) { 48 | return $this->urls->get('test')['api']; 49 | } 50 | 51 | return $this->urls->get('prod')['api']; 52 | } 53 | 54 | public function getSecureUrl(bool $testMode = false): string 55 | { 56 | if ($testMode) { 57 | return $this->urls->get('test')['secure']; 58 | } 59 | 60 | return $this->urls->get('prod')['secure']; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Common/CreditCard.php: -------------------------------------------------------------------------------- 1 | number = $number; 20 | $this->expireYear = \DateTime::createFromFormat('Y', $expireYear); 21 | $this->expireMonth = \DateTime::createFromFormat('!m', $expireMonth); 22 | $this->cvv = $cvv; 23 | } 24 | 25 | public function getNumber(): string 26 | { 27 | return $this->number; 28 | } 29 | 30 | public function getExpireYear(string $format = 'y'): string 31 | { 32 | return $this->expireYear->format($format); 33 | } 34 | 35 | public function getExpireMonth(string $format = 'm'): string 36 | { 37 | return $this->expireMonth->format($format); 38 | } 39 | 40 | public function getCvv(): string 41 | { 42 | return $this->cvv; 43 | } 44 | 45 | public function getHolderName(): string 46 | { 47 | return $this->holderName; 48 | } 49 | 50 | public function setHolderName(string $holderName): self 51 | { 52 | $this->holderName = $holderName; 53 | 54 | return $this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Common/CurrencyInterface.php: -------------------------------------------------------------------------------- 1 | amount = $amount; 12 | } 13 | 14 | public function getAmount(): float 15 | { 16 | return $this->amount; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Common/Traits/CreditCard.php: -------------------------------------------------------------------------------- 1 | creditCard; 12 | } 13 | 14 | public function setCreditCard(\Payconn\Common\CreditCard $creditCard): void 15 | { 16 | $this->creditCard = $creditCard; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Common/Traits/Currency.php: -------------------------------------------------------------------------------- 1 | currency; 12 | } 13 | 14 | public function setCurrency(string $currency): void 15 | { 16 | $this->currency = $currency; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Common/Traits/Installment.php: -------------------------------------------------------------------------------- 1 | installment; 12 | } 13 | 14 | public function setInstallment(int $installment): void 15 | { 16 | $this->installment = $installment; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Common/Traits/OrderId.php: -------------------------------------------------------------------------------- 1 | orderId; 12 | } 13 | 14 | public function setOrderId(string $orderId): void 15 | { 16 | $this->orderId = $orderId; 17 | } 18 | 19 | public function generateOrderId(): void 20 | { 21 | $this->setOrderId(md5(uniqid(mt_rand(), true)).time()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Common/Traits/ReturnUrl.php: -------------------------------------------------------------------------------- 1 | successfulUrl; 14 | } 15 | 16 | public function setSuccessfulUrl(string $successfulUrl): void 17 | { 18 | $this->successfulUrl = $successfulUrl; 19 | } 20 | 21 | public function getFailureUrl(): string 22 | { 23 | return $this->failureUrl; 24 | } 25 | 26 | public function setFailureUrl(string $failureUrl): void 27 | { 28 | $this->failureUrl = $failureUrl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Payconn.php: -------------------------------------------------------------------------------- 1 | '00', 14 | 'ReturnCode' => '00', 15 | 'ReturnMessage' => 'Successful', 16 | ]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Common/Sample/AuthorizeResponse.php: -------------------------------------------------------------------------------- 1 | getParameters()->get('StatusCode') ? true : false; 12 | } 13 | 14 | public function getResponseMessage(): string 15 | { 16 | return $this->getParameters()->get('ReturnMessage'); 17 | } 18 | 19 | public function getResponseCode(): string 20 | { 21 | return $this->getParameters()->get('ReturnCode'); 22 | } 23 | 24 | public function getResponseBody(): array 25 | { 26 | return $this->getParameters()->all(); 27 | } 28 | 29 | public function isRedirection(): bool 30 | { 31 | return false; 32 | } 33 | 34 | public function getRedirectForm(): ?string 35 | { 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Common/Sample/Gateway.php: -------------------------------------------------------------------------------- 1 | createRequest(AuthorizeRequest::class, $authorize); 19 | } 20 | 21 | public function purchase(PurchaseInterface $purchase): ResponseInterface 22 | { 23 | // TODO: Implement purchase() method. 24 | } 25 | 26 | public function complete(CompleteInterface $complete): ResponseInterface 27 | { 28 | // TODO: Implement purchaseComplete() method. 29 | } 30 | 31 | public function refund(RefundInterface $refund): ResponseInterface 32 | { 33 | // TODO: Implement refund() method. 34 | } 35 | 36 | public function cancel(CancelInterface $model): ResponseInterface 37 | { 38 | // TODO: Implement cancel() method. 39 | } 40 | 41 | public function initialize(): void 42 | { 43 | $this->setBaseUrl((new BaseUrl()) 44 | ->setProdUrls('API_URL', 'SECURE_URL') 45 | ->setTestUrls('API_URL', 'SECURE_URL')); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Common/Sample/Token.php: -------------------------------------------------------------------------------- 1 | username = $username; 16 | $this->password = $password; 17 | } 18 | 19 | public function getUsername(): string 20 | { 21 | return $this->username; 22 | } 23 | 24 | public function getPassword(): string 25 | { 26 | return $this->password; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Common/SampleGatewayTest.php: -------------------------------------------------------------------------------- 1 | setCreditCard($creditCard); 19 | $authorize->setCurrency('TRY'); 20 | $authorize->setAmount(100); 21 | $authorize->setTestMode(true); 22 | $response = (new Gateway($token))->authorize($authorize); 23 | $this->assertTrue($response->isSuccessful()); 24 | $this->assertFalse($response->isRedirection()); 25 | $this->assertEquals('Successful', $response->getResponseMessage()); 26 | $this->assertEquals('00', $response->getResponseCode()); 27 | $this->assertArrayHasKey('ReturnCode', $response->getResponseBody()); 28 | $this->assertArrayHasKey('ReturnMessage', $response->getResponseBody()); 29 | } 30 | } 31 | --------------------------------------------------------------------------------