-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update coding standards, fix phpstan errors
- Loading branch information
1 parent
005452c
commit 5ef801f
Showing
21 changed files
with
909 additions
and
950 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
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,12 @@ | ||
parameters: | ||
level: 7 | ||
paths: | ||
- src | ||
- tests/PayPal | ||
ignoreErrors: | ||
- '#Cannot call method getParameter\(\) on Nette\\Application\\UI\\Presenter|null#' | ||
# - '#Cannot call method redirectUrl\(\) on Nette\\Application\\UI\\Presenter|null#' | ||
|
||
includes: | ||
- vendor/phpstan/phpstan-nette/extension.neon | ||
- vendor/phpstan/phpstan-nette/rules.neon |
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 |
---|---|---|
@@ -1,61 +1,71 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace MetisFW\PayPal\DI; | ||
|
||
use Nette\Configurator; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\DI\Config\Helpers; | ||
use Nette\Utils\Validators; | ||
|
||
class PayPalExtension extends CompilerExtension { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $defaults = array( | ||
'currency' => 'CZK', | ||
'gaTrackingEnabled' => true | ||
); | ||
|
||
public function loadConfiguration() { | ||
$builder = $this->getContainerBuilder(); | ||
$config = Helpers::merge($this->getConfig(), $this->defaults); | ||
|
||
Validators::assertField($config, 'clientId'); | ||
Validators::assertField($config, 'secret'); | ||
Validators::assertField($config, 'sdkConfig', 'array'); | ||
|
||
$builder->addFactoryDefinition($this->prefix('simplePaymentOperationFactory')) | ||
->setImplement('MetisFW\PayPal\Payment\SimplePaymentOperationFactory'); | ||
|
||
$builder->addFactoryDefinition($this->prefix('plainPaymentOperationFactory')) | ||
->setImplement('MetisFW\PayPal\Payment\PlainPaymentOperationFactory'); | ||
|
||
$builder->addDefinition($this->prefix('credentials')) | ||
->setType('PayPal\Auth\OAuthTokenCredential') | ||
->setArguments(array($config['clientId'], $config['secret'])); | ||
|
||
$builder->addDefinition($this->prefix('apiContext')) | ||
->setType('PayPal\Rest\ApiContext') | ||
->setArguments(array($this->prefix('@credentials'))); | ||
|
||
$paypal = $builder->addDefinition($this->prefix('PayPal')) | ||
->setType('MetisFW\PayPal\PayPalContext') | ||
->setArguments(array($this->prefix('@apiContext'))) | ||
->addSetup('setConfig', array($config['sdkConfig'])) | ||
->addSetup('setCurrency', array($config['currency'])) | ||
->addSetup('setGaTrackingEnabled', array($config['gaTrackingEnabled'])); | ||
|
||
if (isset($config['experienceProfileId'])) { | ||
$paypal->addSetup('setExperienceProfileId', array($config['experienceProfileId'])); | ||
} | ||
} | ||
|
||
public static function register(Configurator $configurator) { | ||
$configurator->onCompile[] = function ($config, Compiler $compiler) { | ||
$compiler->addExtension('payPal', new PayPalExtension()); | ||
}; | ||
} | ||
use Nette\Schema\Expect; | ||
use Nette\Schema\Schema; | ||
|
||
class PayPalExtension extends CompilerExtension | ||
{ | ||
|
||
public function loadConfiguration() | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
$config = (array) $this->getConfig(); | ||
|
||
$builder->addFactoryDefinition($this->prefix('simplePaymentOperationFactory')) | ||
->setImplement('MetisFW\PayPal\Payment\SimplePaymentOperationFactory'); | ||
|
||
$builder->addFactoryDefinition($this->prefix('plainPaymentOperationFactory')) | ||
->setImplement('MetisFW\PayPal\Payment\PlainPaymentOperationFactory'); | ||
|
||
$builder->addDefinition($this->prefix('credentials')) | ||
->setType('PayPal\Auth\OAuthTokenCredential') | ||
->setArguments([$config['clientId'], $config['secret']]); | ||
|
||
$builder->addDefinition($this->prefix('apiContext')) | ||
->setType('PayPal\Rest\ApiContext') | ||
->setArguments([$this->prefix('@credentials')]); | ||
|
||
$paypal = $builder->addDefinition($this->prefix('PayPal')) | ||
->setType('MetisFW\PayPal\PayPalContext') | ||
->setArguments([$this->prefix('@apiContext')]) | ||
->addSetup('setConfig', [(array) $config['sdkConfig']]) | ||
->addSetup('setCurrency', [$config['currency']]) | ||
->addSetup('setGaTrackingEnabled', [$config['gaTrackingEnabled']]); | ||
|
||
if ($config['experienceProfileId'] !== null) { | ||
$paypal->addSetup('setExperienceProfileId', [$config['experienceProfileId']]); | ||
} | ||
} | ||
|
||
public static function register(Configurator $configurator) | ||
{ | ||
$configurator->onCompile[] = function ($config, Compiler $compiler) { | ||
$compiler->addExtension('payPal', new PayPalExtension()); | ||
}; | ||
} | ||
|
||
public function getConfigSchema(): Schema | ||
{ | ||
return Expect::structure([ | ||
'currency' => Expect::string('CZK'), | ||
'gaTrackingEnabled' => Expect::bool(true), | ||
'experienceProfileId' => Expect::string(), | ||
'clientId' => Expect::string()->required(), | ||
'secret' => Expect::string()->required(), | ||
'sdkConfig' => Expect::structure([ | ||
'mode' => Expect::anyOf('sandbox', 'live')->required(), | ||
'log.LogEnabled' => Expect::bool(), | ||
'log.FileName' => Expect::string(), | ||
'log.LogLevel' => Expect::anyOf('emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'), | ||
'cache.enabled' => Expect::bool(true), | ||
'cache.FileName' => Expect::string(), | ||
]), | ||
]); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace MetisFW\PayPal\Helpers; | ||
|
||
use Nette\Http\Url; | ||
use PayPal\Api\Payment; | ||
|
||
class GaTracking { | ||
class GaTracking | ||
{ | ||
|
||
private function __construct() { | ||
// nothing | ||
} | ||
private function __construct() | ||
{ | ||
// nothing | ||
} | ||
|
||
public static function addTrackingParameters(Payment $payment) { | ||
$redirectUrls = $payment->getRedirectUrls(); | ||
public static function addTrackingParameters(Payment $payment): Payment | ||
{ | ||
$redirectUrls = $payment->getRedirectUrls(); | ||
|
||
$url = new Url($redirectUrls->getReturnUrl()); | ||
$url->setQueryParameter('utm_nooverride', 1); | ||
$url = new Url($redirectUrls->getReturnUrl()); | ||
$url->setQueryParameter('utm_nooverride', 1); | ||
|
||
$redirectUrls->setReturnUrl($url->getAbsoluteUrl()); | ||
$payment->setRedirectUrls($redirectUrls); | ||
$redirectUrls->setReturnUrl($url->getAbsoluteUrl()); | ||
$payment->setRedirectUrls($redirectUrls); | ||
|
||
return $payment; | ||
} | ||
return $payment; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,85 +1,67 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace MetisFW\PayPal; | ||
|
||
use PayPal\Rest\ApiContext; | ||
|
||
class PayPalContext { | ||
|
||
/** @var ApiContext */ | ||
private $apiContext; | ||
|
||
/** @var string */ | ||
private $currency; | ||
|
||
/** @var bool */ | ||
private $gaTrackingEnabled; | ||
|
||
/** @var string */ | ||
private $experienceProfileId; | ||
|
||
/** | ||
* @param string $clientId | ||
* @param string $secret | ||
*/ | ||
public function __construct(ApiContext $apiContext) { | ||
$this->apiContext = $apiContext; | ||
} | ||
|
||
/** | ||
* @param array $config | ||
*/ | ||
public function setConfig(array $config) { | ||
$this->apiContext->setConfig($config); | ||
} | ||
|
||
/** | ||
* @param string $currency | ||
*/ | ||
public function setCurrency($currency) { | ||
$this->currency = $currency; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurrency() { | ||
return $this->currency; | ||
} | ||
|
||
/** | ||
* @return ApiContext | ||
*/ | ||
public function getApiContext() { | ||
return $this->apiContext; | ||
} | ||
|
||
/** | ||
* @param bool $value | ||
*/ | ||
public function setGaTrackingEnabled($value) { | ||
$this->gaTrackingEnabled = $value; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isGaTrackingEnabled() { | ||
return $this->gaTrackingEnabled; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getExperienceProfileId() { | ||
return $this->experienceProfileId; | ||
} | ||
|
||
/** | ||
* @param string $experienceProfileId | ||
*/ | ||
public function setExperienceProfileId($experienceProfileId) { | ||
$this->experienceProfileId = $experienceProfileId; | ||
} | ||
class PayPalContext | ||
{ | ||
|
||
/** @var ApiContext */ | ||
private $apiContext; | ||
|
||
/** @var string */ | ||
private $currency; | ||
|
||
/** @var bool */ | ||
private $gaTrackingEnabled = false; | ||
|
||
/** @var string|null */ | ||
private $experienceProfileId; | ||
|
||
public function __construct(ApiContext $apiContext) | ||
{ | ||
$this->apiContext = $apiContext; | ||
} | ||
|
||
public function setConfig(array $config): void | ||
{ | ||
$this->apiContext->setConfig($config); | ||
} | ||
|
||
public function setCurrency(string $currency): void | ||
{ | ||
$this->currency = $currency; | ||
} | ||
|
||
public function getCurrency(): string | ||
{ | ||
return $this->currency; | ||
} | ||
|
||
public function getApiContext(): ApiContext | ||
{ | ||
return $this->apiContext; | ||
} | ||
|
||
public function setGaTrackingEnabled(bool $value): void | ||
{ | ||
$this->gaTrackingEnabled = $value; | ||
} | ||
|
||
public function isGaTrackingEnabled(): bool | ||
{ | ||
return $this->gaTrackingEnabled; | ||
} | ||
|
||
public function getExperienceProfileId(): ?string | ||
{ | ||
return $this->experienceProfileId; | ||
} | ||
|
||
public function setExperienceProfileId(string $experienceProfileId): void | ||
{ | ||
$this->experienceProfileId = $experienceProfileId; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace MetisFW\PayPal; | ||
|
||
class PayPalException extends \RuntimeException { | ||
class PayPalException extends \RuntimeException | ||
{ | ||
|
||
} | ||
} |
Oops, something went wrong.