diff --git a/README.md b/README.md index 09f89be3d..cb789ec88 100644 --- a/README.md +++ b/README.md @@ -62,13 +62,15 @@ Extension Points ----------- #### Events -BraintreePaymentActionEvent (aligent_braintree.payment_action.{action}): +BraintreePaymentActionEvent (aligent_braintree.payment_action): This event is fired when a payment action executes but before the payload is sent to the payment gateway. It is used internally to build up the payment payload and can be extended with other listeners to add data to be sent to the payment gateway. -Currently supported events: -- aligent_braintree.payment_action.purchase +Use the `$this->getAction()` method to restrict Event Listener to a specific Braintree Action + +Currently supported actions: +- Purchase (`\Aligent\BraintreeBundle\Method\Action\PurchaseAction::ACTION`) #### Actions @@ -78,7 +80,7 @@ Custom payment actions can be added by implementing the BraintreeActionInterface Support ------- -If you have any issues with this bundle, please feel free to open [GitHub issue](https://github.com/aligent/braintree-orocommerce/issues) with version and steps to reproduce. +If you have any issues with this bundle, please feel free to open a [GitHub issue](https://github.com/aligent/braintree-orocommerce/issues) with version and detailed steps to reproduce. Contribution ------------ diff --git a/src/AligentBraintreeBundle.php b/src/AligentBraintreeBundle.php index ccc8d9bf3..fef678de1 100644 --- a/src/AligentBraintreeBundle.php +++ b/src/AligentBraintreeBundle.php @@ -17,10 +17,7 @@ class AligentBraintreeBundle extends Bundle { - /** - * @param ContainerBuilder $container - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $container ->addCompilerPass(new ActionPass()) diff --git a/src/Braintree/Gateway.php b/src/Braintree/Gateway.php index b32bee083..7484333e8 100644 --- a/src/Braintree/Gateway.php +++ b/src/Braintree/Gateway.php @@ -11,11 +11,11 @@ namespace Aligent\BraintreeBundle\Braintree; use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; -use Braintree\ClientToken; -use Braintree\Configuration; -use Braintree\Customer; use Braintree\Exception\NotFound; -use Braintree\Transaction; +use Braintree\Gateway as BraintreeGateway; +use Braintree\Result\Error as BraintreeErrorResult; +use Braintree\Result\Successful as BraintreeSuccessResult; +use Doctrine\ORM\ORMException; use Oro\Bundle\CustomerBundle\Entity\CustomerUser; use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; @@ -24,31 +24,15 @@ class Gateway const PRODUCTION = 'production'; const SANDBOX = 'sandbox'; - /** - * @var BraintreeConfigInterface - */ - public $config; - - /** - * @var \Braintree\Gateway - */ - protected $braintreeGateway; + protected BraintreeConfigInterface $config; + protected BraintreeGateway $braintreeGateway; + protected DoctrineHelper $doctrineHelper; - /** - * @var DoctrineHelper - */ - protected $doctrineHelper; - - /** - * Gateway constructor. - * @param BraintreeConfigInterface $config - * @param DoctrineHelper $doctrineHelper - */ public function __construct(BraintreeConfigInterface $config, DoctrineHelper $doctrineHelper) { $this->config = $config; $this->doctrineHelper = $doctrineHelper; - $this->braintreeGateway = new \Braintree\Gateway( + $this->braintreeGateway = new BraintreeGateway( [ 'environment' => $config->getEnvironment(), 'publicKey' => $config->getPublicKey(), @@ -60,13 +44,14 @@ public function __construct(BraintreeConfigInterface $config, DoctrineHelper $do /** * Generate Braintree Authentication Token for a customer user - * @param CustomerUser $customerUser - * @return string - * @throws \Doctrine\ORM\ORMException - * @throws \Doctrine\ORM\OptimisticLockException */ - public function getCustomerAuthToken(CustomerUser $customerUser) + public function getCustomerAuthToken(CustomerUser $customerUser): string { + if (!method_exists($customerUser, 'getBraintreeId')) { + // Schema Migrations most likely have not been run + return ''; + } + $braintreeId = $customerUser->getBraintreeId(); // if the customer doesn't already exist with braintree create it @@ -85,43 +70,44 @@ public function getCustomerAuthToken(CustomerUser $customerUser) try { $this->braintreeGateway->customer()->find($braintreeId); } catch (NotFound $exception) { - return $this->getAuthToken(); + return $this->getAuthToken(); } - return $this->braintreeGateway->clientToken()->generate( - [ - 'customerId' => $braintreeId - ] - ); + /** @phpstan-ignore-next-line BrainTree ClientTokenGateway is incorrectly type-hinted, it accepts an array */ + return $this->braintreeGateway->clientToken()->generate([ + 'customerId' => $braintreeId, + ]); } /** * Generate a generic auth token for braintree * @return string */ - public function getAuthToken() + public function getAuthToken(): string { return $this->braintreeGateway->clientToken()->generate(); } /** * Charge the payment nonce - * @param array $params - * @return \Braintree\Result\Error|\Braintree\Result\Successful + * @param array $params + * @return BraintreeErrorResult|BraintreeSuccessResult */ - public function sale(array $params) + public function sale(array $params): BraintreeErrorResult|BraintreeSuccessResult { return $this->braintreeGateway->transaction()->sale($params); } /** * @param CustomerUser $customerUser - * @return \Braintree\Result\Error|\Braintree\Result\Successful - * @throws \Doctrine\ORM\ORMException - * @throws \Doctrine\ORM\OptimisticLockException + * @return BraintreeErrorResult|BraintreeSuccessResult */ - public function createBraintreeCustomer(CustomerUser $customerUser) + public function createBraintreeCustomer(CustomerUser $customerUser): BraintreeErrorResult|BraintreeSuccessResult { + if (!method_exists($customerUser, 'setBraintreeId')) { + return new BraintreeErrorResult('Braintree Bundle not installed correctly'); + } + $result = $this->braintreeGateway->customer()->create( [ 'firstName' => $customerUser->getFirstName(), @@ -133,8 +119,14 @@ public function createBraintreeCustomer(CustomerUser $customerUser) if ($result->success) { $em = $this->doctrineHelper->getEntityManager(CustomerUser::class); + /* @phpstan-ignore-next-line The Braintree Result classes unfortunately use magic methods */ $customerUser->setBraintreeId($result->customer->id); - $em->flush($customerUser); + + try { + $em->flush($customerUser); + } catch (ORMException $e) { + return new BraintreeErrorResult($e->getMessage()); + } } return $result; diff --git a/src/Braintree/PaymentMethod/Settings/Builder/ApplePayConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/ApplePayConfigurationBuilder.php index b85cb243e..ae15eb46c 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/ApplePayConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/ApplePayConfigurationBuilder.php @@ -18,33 +18,24 @@ class ApplePayConfigurationBuilder implements ConfigurationBuilderInterface, FeatureToggleableInterface { use FeatureCheckerHolderTrait; - /** - * @var TotalProcessorProvider - */ - protected $totalsProvider; - /** - * PayPalCreditSettingsBuilder constructor. - * @param TotalProcessorProvider $totalsProvider - */ + protected TotalProcessorProvider $totalsProvider; + public function __construct(TotalProcessorProvider $totalsProvider) { $this->totalsProvider = $totalsProvider; } /** - * Build the settings object to pass to Dropin - * @param PaymentContextInterface $context - * @param array $configuration - * @return mixed + * {@inheritDoc} */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { if (!$this->isFeaturesEnabled()) { - return; + return []; } - // Strip Null values + // Strip null values $viewSettings = array_filter( $configuration, function ($value) { diff --git a/src/Braintree/PaymentMethod/Settings/Builder/ChainConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/ChainConfigurationBuilder.php index 5e096d8b9..afb940e5e 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/ChainConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/ChainConfigurationBuilder.php @@ -14,19 +14,13 @@ class ChainConfigurationBuilder implements ConfigurationBuilderInterface { + /** @var ConfigurationBuilderInterface[] */ + protected array $builders = []; /** - * @var ConfigurationBuilderInterface[] $builders + * {@inheritDoc} */ - protected $builders = []; - - /** - * Build the settings object to pass to the Drop-in UI - * @param PaymentContextInterface $context - * @param array $configuration - * @return mixed - */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { $config = []; foreach ($configuration as $paymentMethod => $paymentMethodConfig) { @@ -39,7 +33,7 @@ public function build(PaymentContextInterface $context, array $configuration) } $config[$paymentMethod] = $paymentMethodConfig; - } elseif (!$paymentMethodConfig['enabled'] && $paymentMethod === 'card') { + } elseif ($paymentMethod === 'card') { // handle the card special case, as card is the default it must be explicitly // set to false, so it doesn't display $config[$paymentMethod] = false; @@ -49,20 +43,12 @@ public function build(PaymentContextInterface $context, array $configuration) return $config; } - /** - * @param $method - * @return bool - */ - public function hasBuilder($method) + public function hasBuilder(string $method): bool { return isset($this->builders[$method]); } - /** - * @param $method - * @return ConfigurationBuilderInterface - */ - public function getBuilder($method) + public function getBuilder(string $method): ConfigurationBuilderInterface { if (!$this->hasBuilder($method)) { throw new \InvalidArgumentException("Builder for {$method} does not exist."); @@ -71,12 +57,7 @@ public function getBuilder($method) return $this->builders[$method]; } - /** - * @param $method - * @param ConfigurationBuilderInterface $builder - * @return $this - */ - public function addBuilder($method, ConfigurationBuilderInterface $builder) + public function addBuilder(string $method, ConfigurationBuilderInterface $builder): self { if ($this->hasBuilder($method)) { throw new \InvalidArgumentException("Builder for {$method} already exists"); diff --git a/src/Braintree/PaymentMethod/Settings/Builder/ConfigurationBuilderInterface.php b/src/Braintree/PaymentMethod/Settings/Builder/ConfigurationBuilderInterface.php index bc3de66bb..f15a50346 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/ConfigurationBuilderInterface.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/ConfigurationBuilderInterface.php @@ -14,12 +14,11 @@ interface ConfigurationBuilderInterface { - /** - * Build the settings object to pass to Dropin + * Build the settings object to pass to Drop-in * @param PaymentContextInterface $context - * @param array $configuration - * @return mixed + * @param array $configuration + * @return array */ - public function build(PaymentContextInterface $context, array $configuration); + public function build(PaymentContextInterface $context, array $configuration): array; } diff --git a/src/Braintree/PaymentMethod/Settings/Builder/GooglePayConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/GooglePayConfigurationBuilder.php index 46b85c529..36dea865e 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/GooglePayConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/GooglePayConfigurationBuilder.php @@ -19,30 +19,20 @@ class GooglePayConfigurationBuilder implements ConfigurationBuilderInterface, Fe { use FeatureCheckerHolderTrait; - /** - * @var TotalProcessorProvider - */ - protected $totalsProvider; + protected TotalProcessorProvider $totalsProvider; - /** - * PayPalCreditSettingsBuilder constructor. - * @param TotalProcessorProvider $totalsProvider - */ public function __construct(TotalProcessorProvider $totalsProvider) { $this->totalsProvider = $totalsProvider; } /** - * Build the settings object to pass to Dropin - * @param PaymentContextInterface $context - * @param array $configuration - * @return mixed + * {@inheritDoc} */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { if (!$this->isFeaturesEnabled()) { - return; + return []; } // Strip Null values diff --git a/src/Braintree/PaymentMethod/Settings/Builder/PayPalConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/PayPalConfigurationBuilder.php index 0dbbd4d31..cebfff0e7 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/PayPalConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/PayPalConfigurationBuilder.php @@ -15,25 +15,17 @@ class PayPalConfigurationBuilder implements ConfigurationBuilderInterface { + protected TotalProcessorProvider $totalsProvider; - /** - * @var TotalProcessorProvider - */ - protected $totalsProvider; - - /** - * PayPalCreditSettingsBuilder constructor. - * @param TotalProcessorProvider $totalsProvider - */ public function __construct(TotalProcessorProvider $totalsProvider) { $this->totalsProvider = $totalsProvider; } - /** - * @inheritdoc + /** + * {@inheritDoc} */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { // Strip Null values $viewSettings = array_filter( diff --git a/src/Braintree/PaymentMethod/Settings/Builder/PayPalCreditConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/PayPalCreditConfigurationBuilder.php index 8a607068b..0d2a4d0fc 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/PayPalCreditConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/PayPalCreditConfigurationBuilder.php @@ -19,27 +19,20 @@ class PayPalCreditConfigurationBuilder implements ConfigurationBuilderInterface, { use FeatureCheckerHolderTrait; - /** - * @var TotalProcessorProvider - */ - protected $totalsProvider; + protected TotalProcessorProvider $totalsProvider; - /** - * PayPalCreditSettingsBuilder constructor. - * @param TotalProcessorProvider $totalsProvider - */ public function __construct(TotalProcessorProvider $totalsProvider) { $this->totalsProvider = $totalsProvider; } /** - * @inheritdoc + * {@inheritDoc} */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { if (!$this->isFeaturesEnabled()) { - return; + return []; } // Strip Null values @@ -53,7 +46,7 @@ function ($value) { // Checkout flow requires an amount and total if ($viewSettings['flow'] === 'checkout') { $total = $this->totalsProvider->getTotal($context->getSourceEntity()); - $viewSettings['amount'] = $total->getValue(); + $viewSettings['amount'] = $total->getAmount(); $viewSettings['currency'] = $total->getCurrency(); } diff --git a/src/Braintree/PaymentMethod/Settings/Builder/VenmoConfigurationBuilder.php b/src/Braintree/PaymentMethod/Settings/Builder/VenmoConfigurationBuilder.php index 1fabf654a..4f72d9e1e 100644 --- a/src/Braintree/PaymentMethod/Settings/Builder/VenmoConfigurationBuilder.php +++ b/src/Braintree/PaymentMethod/Settings/Builder/VenmoConfigurationBuilder.php @@ -19,15 +19,12 @@ class VenmoConfigurationBuilder implements ConfigurationBuilderInterface, Featur use FeatureCheckerHolderTrait; /** - * Build the settings object to pass to Dropin - * @param PaymentContextInterface $context - * @param array $configuration - * @return mixed + * {@inheritdoc} */ - public function build(PaymentContextInterface $context, array $configuration) + public function build(PaymentContextInterface $context, array $configuration): array { if (!$this->isFeaturesEnabled()) { - return; + return []; } // Never allow new browser tab as it isn't supported by our checkout flow yet. diff --git a/src/DependencyInjection/AligentBraintreeExtension.php b/src/DependencyInjection/AligentBraintreeExtension.php index 0dc62da86..942e353ca 100644 --- a/src/DependencyInjection/AligentBraintreeExtension.php +++ b/src/DependencyInjection/AligentBraintreeExtension.php @@ -20,13 +20,11 @@ class AligentBraintreeExtension extends Extension const ALIAS = 'aligent_braintree'; /** - * Loads a specific configuration. - * - * @param array $configs + * @param array $configs * @param ContainerBuilder $container * @throws \Exception */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -40,7 +38,7 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('event_listeners.yml'); } - public function getAlias() + public function getAlias(): string { return self::ALIAS; } diff --git a/src/DependencyInjection/Compiler/ActionPass.php b/src/DependencyInjection/Compiler/ActionPass.php index 54a0e4972..e649c5dcd 100644 --- a/src/DependencyInjection/Compiler/ActionPass.php +++ b/src/DependencyInjection/Compiler/ActionPass.php @@ -20,10 +20,7 @@ class ActionPass implements CompilerPassInterface { const ALIGENT_BRAINTREE_ACTION_TAG = 'braintree.action'; - /** - * @param ContainerBuilder $container - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { // always first check if the primary service is defined if (!$container->has(BraintreeActionProvider::class)) { diff --git a/src/DependencyInjection/Compiler/PaymentMethodConfigurationPass.php b/src/DependencyInjection/Compiler/PaymentMethodConfigurationPass.php index 7e436ad39..2764926fe 100644 --- a/src/DependencyInjection/Compiler/PaymentMethodConfigurationPass.php +++ b/src/DependencyInjection/Compiler/PaymentMethodConfigurationPass.php @@ -21,10 +21,7 @@ class PaymentMethodConfigurationPass implements CompilerPassInterface { const ALIGENT_BRAINTREE_PAYMENT_METHOD_SETTINGS_TAG = 'braintree.payment_method_settings'; - /** - * @param ContainerBuilder $container - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { // always first check if the primary service is defined if (!$container->has(ChainConfigurationBuilder::class)) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 688a5ebac..a90ca270a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,22 +11,21 @@ namespace Aligent\BraintreeBundle\DependencyInjection; use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { - /** - * Generates the configuration tree builder. - * - * @return TreeBuilder - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder(AligentBraintreeExtension::ALIAS); + /** @var ArrayNodeDefinition $rootNode */ + $rootNode = $treeBuilder->getRootNode(); + SettingsBuilder::append( - $treeBuilder->getRootNode(), + $rootNode, [ 'experimental_payment_methods' => ['type' => 'boolean', 'value' => false] ] diff --git a/src/Entity/BraintreeIntegrationSettings.php b/src/Entity/BraintreeIntegrationSettings.php index 737a2206d..df812c471 100644 --- a/src/Entity/BraintreeIntegrationSettings.php +++ b/src/Entity/BraintreeIntegrationSettings.php @@ -10,140 +10,129 @@ namespace Aligent\BraintreeBundle\Entity; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfig; +use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Oro\Bundle\IntegrationBundle\Entity\Transport; use Doctrine\ORM\Mapping as ORM; +use Oro\Bundle\IntegrationBundle\Entity\Transport; use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue; use Symfony\Component\HttpFoundation\ParameterBag; /** - * Class BraintreeIntegrationSettings * @package Aligent\BraintreeBundle\Entity * @ORM\Entity(repositoryClass="Aligent\BraintreeBundle\Entity\Repository\BraintreeIntegrationSettingsRepository") */ class BraintreeIntegrationSettings extends Transport { /** - * - * @var Collection|LocalizedFallbackValue[] @ORM\ManyToMany( + * @ORM\ManyToMany( * targetEntity="Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue", * cascade={"ALL"}, * orphanRemoval=true - * ) + * ) * @ORM\JoinTable( * name="aligent_braintree_lbl", * joinColumns={ - * @ORM\JoinColumn(name="transport_id", referencedColumnName="id", onDelete="CASCADE") + * @ORM\JoinColumn(name="transport_id", referencedColumnName="id", onDelete="CASCADE") * }, * inverseJoinColumns={ - * @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true) + * @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true) * } - * ) + * ) + * @var Collection */ - protected $labels; + protected Collection $labels; /** - * - * @var Collection|LocalizedFallbackValue[] @ORM\ManyToMany( + * @ORM\ManyToMany( * targetEntity="Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue", * cascade={"ALL"}, * orphanRemoval=true - * ) + * ) * @ORM\JoinTable( * name="aligent_braintree_sh_lbl", * joinColumns={ - * @ORM\JoinColumn(name="transport_id", referencedColumnName="id", onDelete="CASCADE") + * @ORM\JoinColumn(name="transport_id", referencedColumnName="id", onDelete="CASCADE") * }, * inverseJoinColumns={ - * @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true) + * @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true) * } - * ) - */ - protected $shortLabels; - - /** - * - * @var string @ORM\Column(name="braintree_environment_type", type="string", length=255, nullable=false) + * ) + * @var Collection */ - protected $environment; + protected Collection $shortLabels; /** - * - * @var string @ORM\Column(name="braintree_merch_id", type="string", length=255, nullable=false) + * @var string + * @ORM\Column(name="braintree_environment_type", type="string", length=255, nullable=false) */ - protected $merchantId; + protected string $environment; /** - * - * @var string @ORM\Column(name="braintree_merch_account_id", type="string", length=255, nullable=false) + * @var string + * @ORM\Column(name="braintree_merch_id", type="string", length=255, nullable=false) */ - protected $merchantAccountId; + protected string $merchantId; /** - * - * @var string @ORM\Column(name="braintree_merch_public_key", type="string", length=255, nullable=false) + * @var string + * @ORM\Column(name="braintree_merch_account_id", type="string", length=255, nullable=false) */ - protected $publicKey; + protected string $merchantAccountId; /** - * - * @var string @ORM\Column(name="braintree_merch_private_key", type="string", length=255, nullable=false) + * @var string + * @ORM\Column(name="braintree_merch_public_key", type="string", length=255, nullable=false) */ - protected $privateKey; + protected string $publicKey; /** - * - * @var boolean @ORM\Column(name="braintree_vault", type="boolean", options={"default"=false}) + * @var string + * @ORM\Column(name="braintree_merch_private_key", type="string", length=255, nullable=false) */ - protected $vault = false; + protected string $privateKey; /** - * - * @var array @ORM\Column(name="braintree_settings", type="array") + * @var boolean + * @ORM\Column(name="braintree_vault", type="boolean", options={"default"=false}) */ - protected $paymentMethodSettings; + protected bool $vault = false; /** - * @var ParameterBag + * @var array + * @ORM\Column(name="braintree_settings", type="array") */ - protected $settings; + protected array $paymentMethodSettings; /** * Column name shortened to braintree_fraud_advanced due to max db name length 30 - * @var boolean @ORM\Column(name="braintree_fraud_advanced", type="boolean", options={"default"=false}) + * @var boolean + * @ORM\Column(name="braintree_fraud_advanced", type="boolean", options={"default"=false}) */ - protected $fraudProtectionAdvanced = false; + protected bool $fraudProtectionAdvanced = false; + + protected ?ParameterBag $settings = null; - /** - * BraintreeIntegrationSettings constructor. - */ public function __construct() { $this->labels = new ArrayCollection(); $this->shortLabels = new ArrayCollection(); $this->paymentMethodSettings = [ 'card' => [ - 'enabled' => true + 'enabled' => true, ] ]; } /** - * @return Collection|LocalizedFallbackValue[] + * @return Collection */ - public function getLabels() + public function getLabels(): Collection { return $this->labels; } - /** - * @param LocalizedFallbackValue $label - * - * @return $this - */ - public function addLabel(LocalizedFallbackValue $label) + public function addLabel(LocalizedFallbackValue $label): static { if (!$this->labels->contains($label)) { $this->labels->add($label); @@ -152,12 +141,7 @@ public function addLabel(LocalizedFallbackValue $label) return $this; } - /** - * @param LocalizedFallbackValue $label - * - * @return $this - */ - public function removeLabel(LocalizedFallbackValue $label) + public function removeLabel(LocalizedFallbackValue $label): static { if ($this->labels->contains($label)) { $this->labels->removeElement($label); @@ -167,19 +151,14 @@ public function removeLabel(LocalizedFallbackValue $label) } /** - * @return Collection|LocalizedFallbackValue[] + * @return Collection */ - public function getShortLabels() + public function getShortLabels(): Collection { return $this->shortLabels; } - /** - * @param LocalizedFallbackValue $label - * - * @return $this - */ - public function addShortLabel(LocalizedFallbackValue $label) + public function addShortLabel(LocalizedFallbackValue $label): static { if (!$this->shortLabels->contains($label)) { $this->shortLabels->add($label); @@ -188,12 +167,7 @@ public function addShortLabel(LocalizedFallbackValue $label) return $this; } - /** - * @param LocalizedFallbackValue $label - * - * @return $this - */ - public function removeShortLabel(LocalizedFallbackValue $label) + public function removeShortLabel(LocalizedFallbackValue $label): static { if ($this->shortLabels->contains($label)) { $this->shortLabels->removeElement($label); @@ -202,175 +176,130 @@ public function removeShortLabel(LocalizedFallbackValue $label) return $this; } - /** - * @return string - */ - public function getEnvironment() + public function getEnvironment(): string { return $this->environment; } - /** - * @param string $environment - */ - public function setEnvironment($environment) + public function setEnvironment(string $environment): static { $this->environment = $environment; + return $this; } - /** - * @return string - */ - public function getMerchantId() + public function getMerchantId(): string { return $this->merchantId; } - /** - * @param string $merchantId - */ - public function setMerchantId($merchantId) + public function setMerchantId(string $merchantId): static { $this->merchantId = $merchantId; + return $this; } - /** - * @return string - */ - public function getMerchantAccountId() + public function getMerchantAccountId(): string { return $this->merchantAccountId; } - /** - * @param string $merchantAccountId - */ - public function setMerchantAccountId($merchantAccountId) + public function setMerchantAccountId(string $merchantAccountId): static { $this->merchantAccountId = $merchantAccountId; + return $this; } /** * @return string */ - public function getPublicKey() + public function getPublicKey(): string { return $this->publicKey; } - /** - * @param string $publicKey - */ - public function setPublicKey($publicKey) + public function setPublicKey(string $publicKey): static { $this->publicKey = $publicKey; + return $this; } - /** - * @return string - */ - public function getPrivateKey() + public function getPrivateKey(): string { return $this->privateKey; } - /** - * @param string $privateKey - */ - public function setPrivateKey($privateKey) + public function setPrivateKey(string $privateKey): static { $this->privateKey = $privateKey; + return $this; } - /** - * @return bool - */ - public function isVaultModeActive() + public function isVaultModeActive(): bool { return $this->vault; } - /** - * @return void - */ - public function enableVaultMode() + public function enableVaultMode(): void { $this->vault = true; } - /** - * @return void - */ - public function disableVaultMode() + public function disableVaultMode(): void { $this->vault = false; } - /** - * @param bool $vault - */ - public function setVaultMode($vault) + public function setVaultMode(bool $vault): static { $this->vault = $vault; + return $this; } - /** - * @@return bool - */ - public function getVaultMode() + public function getVaultMode(): bool { return $this->vault; } /** - * @return array + * @return array */ - public function getPaymentMethodSettings() + public function getPaymentMethodSettings(): array { return $this->paymentMethodSettings; } /** - * @param array $paymentMethodSettings + * @param array $paymentMethodSettings */ - public function setPaymentMethodSettings(array $paymentMethodSettings) + public function setPaymentMethodSettings(array $paymentMethodSettings): static { $this->paymentMethodSettings = $paymentMethodSettings; + return $this; } - /** - * @return bool - */ - public function isFraudProtectionAdvanced() + public function isFraudProtectionAdvanced(): bool { return $this->fraudProtectionAdvanced; } - /** - * @param bool $fraudProtectionAdvanced - */ - public function setFraudProtectionAdvanced(bool $fraudProtectionAdvanced) + public function setFraudProtectionAdvanced(bool $fraudProtectionAdvanced): static { $this->fraudProtectionAdvanced = $fraudProtectionAdvanced; + return $this; } - - - /** - * @return ParameterBag - */ - public function getSettingsBag() + public function getSettingsBag(): ParameterBag { if (null === $this->settings) { $this->settings = new ParameterBag( [ - BraintreeConfig::LABELS_KEY => $this->getLabels(), - BraintreeConfig::SHORT_LABELS_KEY => $this->getShortLabels(), - BraintreeConfig::ENVIRONMENT_KEY => $this->getEnvironment(), - BraintreeConfig::MERCHANT_ACCOUNT_ID_KEY => $this->getMerchantAccountId(), - BraintreeConfig::MERCHANT_ID_KEY => $this->getMerchantId(), - BraintreeConfig::VAULT_KEY => $this->isVaultModeActive(), - BraintreeConfig::FRAUD_PROTECTION_ADVANCED_KEY => $this->isFraudProtectionAdvanced() + BraintreeConfigInterface::LABELS_KEY => $this->getLabels(), + BraintreeConfigInterface::SHORT_LABELS_KEY => $this->getShortLabels(), + BraintreeConfigInterface::ENVIRONMENT_KEY => $this->getEnvironment(), + BraintreeConfigInterface::MERCHANT_ACCOUNT_ID_KEY => $this->getMerchantAccountId(), + BraintreeConfigInterface::MERCHANT_ID_KEY => $this->getMerchantId(), + BraintreeConfigInterface::VAULT_KEY => $this->isVaultModeActive(), + BraintreeConfigInterface::FRAUD_PROTECTION_ADVANCED_KEY => $this->isFraudProtectionAdvanced() ] ); } diff --git a/src/Entity/Repository/BraintreeIntegrationSettingsRepository.php b/src/Entity/Repository/BraintreeIntegrationSettingsRepository.php index 70f8910a3..683a66cb4 100644 --- a/src/Entity/Repository/BraintreeIntegrationSettingsRepository.php +++ b/src/Entity/Repository/BraintreeIntegrationSettingsRepository.php @@ -13,12 +13,15 @@ use Aligent\BraintreeBundle\Entity\BraintreeIntegrationSettings; use Doctrine\ORM\EntityRepository; +/** + * @extends EntityRepository + */ class BraintreeIntegrationSettingsRepository extends EntityRepository { /** * @return BraintreeIntegrationSettings[] */ - public function getEnabledSettings() + public function getEnabledSettings(): array { return $this->createQueryBuilder('settings') ->innerJoin('settings.channel', 'channel') diff --git a/src/Event/BraintreePaymentActionEvent.php b/src/Event/BraintreePaymentActionEvent.php index 6d6885ba1..37a4c39a6 100644 --- a/src/Event/BraintreePaymentActionEvent.php +++ b/src/Event/BraintreePaymentActionEvent.php @@ -12,69 +12,68 @@ use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Oro\Bundle\PaymentBundle\Entity\PaymentTransaction; -use Symfony\Component\EventDispatcher\Event; -class BraintreePaymentActionEvent extends Event +class BraintreePaymentActionEvent { const NAME = 'aligent_braintree.payment_action'; - const ACTION_EVENT_NAME = 'aligent_braintree.payment_action.%s'; - /** - * @var array - */ - protected $data; - - /** - * @var PaymentTransaction - */ - protected $paymentTransaction; + protected string $action; + /** @var array */ + protected array $data; + protected PaymentTransaction $paymentTransaction; + protected BraintreeConfigInterface $config; /** - * @var BraintreeConfigInterface - */ - protected $config; - - /** - * BraintreePaymentActionEvent constructor. - * @param array $data + * @param string $action + * @param array $data * @param PaymentTransaction $paymentTransaction * @param BraintreeConfigInterface $config */ - public function __construct(array $data, PaymentTransaction $paymentTransaction, BraintreeConfigInterface $config) - { + public function __construct( + string $action, + array $data, + PaymentTransaction $paymentTransaction, + BraintreeConfigInterface $config, + ) { + $this->action = $action; $this->data = $data; $this->paymentTransaction = $paymentTransaction; $this->config = $config; } + public function getAction(): string + { + return $this->action; + } + + public function setAction(string $action): void + { + $this->action = $action; + } + /** - * @return array + * @return array */ - public function getData() + public function getData(): array { return $this->data; } /** - * @param array $data + * @param array $data + * @return void */ - public function setData($data) + public function setData(array $data): void { $this->data = $data; } - /** - * @return BraintreeConfigInterface - */ - public function getConfig() + public function getConfig(): BraintreeConfigInterface { return $this->config; } - /** - * @return PaymentTransaction - */ - public function getPaymentTransaction() + public function getPaymentTransaction(): PaymentTransaction { return $this->paymentTransaction; } diff --git a/src/EventListener/AdvancedFraudEventListener.php b/src/EventListener/AdvancedFraudEventListener.php index ed59742c7..8d84ec1ce 100644 --- a/src/EventListener/AdvancedFraudEventListener.php +++ b/src/EventListener/AdvancedFraudEventListener.php @@ -11,46 +11,47 @@ namespace Aligent\BraintreeBundle\EventListener; use Aligent\BraintreeBundle\Event\BraintreePaymentActionEvent; -use InvalidArgumentException; +use Aligent\BraintreeBundle\Method\Action\PurchaseAction; use Oro\Bundle\PaymentBundle\Entity\PaymentTransaction; class AdvancedFraudEventListener { - /** - * Add deviceData to payload as required for abraintree advanced fraud detection + * Add deviceData to payload as required for a braintree advanced fraud detection * https://developer.paypal.com/braintree/docs/guides/premium-fraud-management-tools/server-side - * @param BraintreePaymentActionEvent $actionEvent */ - public function onPurchase(BraintreePaymentActionEvent $actionEvent) + public function onPurchase(BraintreePaymentActionEvent $event): void { - if ($actionEvent->getConfig()->isFraudProtectionAdvancedEnabled()) { - $data = $actionEvent->getData(); + if ($event->getAction() !== PurchaseAction::ACTION) { + // Ignore other action types + return; + } + + if ($event->getConfig()->isFraudProtectionAdvancedEnabled()) { + $data = $event->getData(); - $paymentTransaction = $actionEvent->getPaymentTransaction(); + $paymentTransaction = $event->getPaymentTransaction(); $data['deviceData'] = $this->getDeviceData($paymentTransaction); - $actionEvent->setData($data); + $event->setData($data); } } /** * Extracts the device data out of the additional data array - * @param PaymentTransaction $paymentTransaction - * @return string */ - protected function getDeviceData(PaymentTransaction $paymentTransaction) + protected function getDeviceData(PaymentTransaction $paymentTransaction): string { $transactionOptions = $paymentTransaction->getTransactionOptions(); if (!isset($transactionOptions['additionalData'])) { - throw new InvalidArgumentException('Payment Transaction does not contain additionalData'); + throw new \InvalidArgumentException('Payment Transaction does not contain additionalData'); } $additionalData = json_decode($transactionOptions['additionalData'], true); if (json_last_error() !== JSON_ERROR_NONE) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( "Error decoding Payment Transaction additional data Error: " . json_last_error_msg() ); } diff --git a/src/EventListener/PurchaseActionEventListener.php b/src/EventListener/PurchaseActionEventListener.php index f217a110a..526a58264 100644 --- a/src/EventListener/PurchaseActionEventListener.php +++ b/src/EventListener/PurchaseActionEventListener.php @@ -11,15 +11,18 @@ namespace Aligent\BraintreeBundle\EventListener; use Aligent\BraintreeBundle\Event\BraintreePaymentActionEvent; +use Aligent\BraintreeBundle\Method\Action\PurchaseAction; class PurchaseActionEventListener { - /** - * @param BraintreePaymentActionEvent $actionEvent - */ - public function onPurchase(BraintreePaymentActionEvent $actionEvent) + public function onPurchase(BraintreePaymentActionEvent $event): void { - $data = $actionEvent->getData(); + if ($event->getAction() !== PurchaseAction::ACTION) { + // Ignore other action types + return; + } + + $data = $event->getData(); // Purchase transactions we want to submit for settlement immediately $data['options'] = [ @@ -27,19 +30,23 @@ public function onPurchase(BraintreePaymentActionEvent $actionEvent) ]; // merchantAccountId is what determines the currency, if not set it will use the accounts default - $data['merchantAccountId'] = $actionEvent->getConfig()->getMerchantAccountId(); + $data['merchantAccountId'] = $event->getConfig()->getMerchantAccountId(); - $paymentTransaction = $actionEvent->getPaymentTransaction(); + $paymentTransaction = $event->getPaymentTransaction(); $customerUser = $paymentTransaction->getFrontendOwner(); // If this is a vaulted customer set their customer ID on the transaction - if ($customerUser && $braintreeId = $customerUser->getBraintreeId()) { + /** @phpstan-ignore-next-line The FrontendOwner of a PaymentTransaction is actually nullable */ + if ($customerUser + && method_exists($customerUser, 'getBraintreeId') + && $braintreeId = $customerUser->getBraintreeId() + ) { $data['customerId'] = $braintreeId; } //Add oro order Id to braintree data $data['orderId'] = (string) $paymentTransaction->getEntityIdentifier(); - $actionEvent->setData($data); + $event->setData($data); } } diff --git a/src/Form/Type/ApplePaySettingsType.php b/src/Form/Type/ApplePaySettingsType.php index 32596b0a6..f7254882c 100644 --- a/src/Form/Type/ApplePaySettingsType.php +++ b/src/Form/Type/ApplePaySettingsType.php @@ -17,12 +17,11 @@ class ApplePaySettingsType extends AbstractType { - /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( diff --git a/src/Form/Type/BraintreeIntegrationSettingsType.php b/src/Form/Type/BraintreeIntegrationSettingsType.php index 22dcba62c..ae6968d96 100644 --- a/src/Form/Type/BraintreeIntegrationSettingsType.php +++ b/src/Form/Type/BraintreeIntegrationSettingsType.php @@ -20,34 +20,25 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Contracts\Translation\TranslatorInterface; class BraintreeIntegrationSettingsType extends AbstractType { - const BLOCK_PREFIX = 'aligent_braintree_settings_type'; - /** - * - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; - /** - * BraintreeIntegrationSettingsType constructor. - * @param TranslatorInterface $translator - */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( @@ -151,10 +142,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); } - /** - * @param OptionsResolver $resolver - */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( [ @@ -163,10 +151,7 @@ public function configureOptions(OptionsResolver $resolver) ); } - /** - * @inheritdoc - */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return static::BLOCK_PREFIX; } diff --git a/src/Form/Type/CreditCardSettingsType.php b/src/Form/Type/CreditCardSettingsType.php index 4d1b1df91..76cfbdfc3 100644 --- a/src/Form/Type/CreditCardSettingsType.php +++ b/src/Form/Type/CreditCardSettingsType.php @@ -12,27 +12,28 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; class CreditCardSettingsType extends AbstractType { /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add( - 'enabled', - CheckboxType::class - )->add( - 'cardholderName', - CheckboxType::class, - [ - 'label' => 'aligent.braintree.settings.credit_card.require_name.label', - 'required' => false, - ] - ); + $builder + ->add( + 'enabled', + CheckboxType::class + ) + ->add( + 'cardholderName', + CheckboxType::class, + [ + 'label' => 'aligent.braintree.settings.credit_card.require_name.label', + 'required' => false, + ] + ); } } diff --git a/src/Form/Type/GooglePaySettingsType.php b/src/Form/Type/GooglePaySettingsType.php index a5d0eb5f8..79cd74dde 100644 --- a/src/Form/Type/GooglePaySettingsType.php +++ b/src/Form/Type/GooglePaySettingsType.php @@ -18,10 +18,10 @@ class GooglePaySettingsType extends AbstractType { /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( diff --git a/src/Form/Type/PayPalCreditSettingsType.php b/src/Form/Type/PayPalCreditSettingsType.php index 8b32afb69..b12d50def 100644 --- a/src/Form/Type/PayPalCreditSettingsType.php +++ b/src/Form/Type/PayPalCreditSettingsType.php @@ -15,34 +15,22 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class PayPalCreditSettingsType extends AbstractType { - /** - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; - /** - * @var array - */ - protected $locales; - - /** - * PayPalSettingsType constructor. - * @param TranslatorInterface $translator - */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( diff --git a/src/Form/Type/PayPalSettingsType.php b/src/Form/Type/PayPalSettingsType.php index c33c73bef..268ac83fe 100644 --- a/src/Form/Type/PayPalSettingsType.php +++ b/src/Form/Type/PayPalSettingsType.php @@ -16,35 +16,27 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class PayPalSettingsType extends AbstractType { + protected TranslatorInterface $translator; /** - * @var TranslatorInterface + * @var array */ - protected $translator; + protected array $locales = []; - /** - * @var array - */ - protected $locales; - - /** - * PayPalSettingsType constructor. - * @param TranslatorInterface $translator - */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( @@ -106,12 +98,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) } /** - * Fetch array of locale choices paypal supports + * Fetch array of locale choices PayPal supports + * @return array */ - protected function getLocaleChoices() + protected function getLocaleChoices(): array { if (!$this->locales) { - $this->locales = [ + $this->locales = [ $this->translator->trans('aligent.braintree.settings.paypal.locale.da_DK') => 'da_DK', $this->translator->trans('aligent.braintree.settings.paypal.locale.de_DE') => 'de_DE', $this->translator->trans('aligent.braintree.settings.paypal.locale.en_AU') => 'en_AU', diff --git a/src/Form/Type/PaymentMethodSettingsType.php b/src/Form/Type/PaymentMethodSettingsType.php index 82c568bb9..42bfb497a 100644 --- a/src/Form/Type/PaymentMethodSettingsType.php +++ b/src/Form/Type/PaymentMethodSettingsType.php @@ -16,72 +16,71 @@ class PaymentMethodSettingsType extends AbstractType { - /** - * @var FeatureChecker - */ - protected $featureChecker; + protected FeatureChecker $featureChecker; - /** - * PaymentMethodSettingsType constructor. - * @param FeatureChecker $featureChecker - */ public function __construct(FeatureChecker $featureChecker) { $this->featureChecker = $featureChecker; } /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add( - 'card', - CreditCardSettingsType::class, - [ - 'label' => 'aligent.braintree.settings.credit_card.label', - 'required' => false - ] - )->add( - 'paypal', - PayPalSettingsType::class, - [ - 'label' => 'aligent.braintree.settings.paypal.label', - 'required' => false - ] - ); - - if ($this->featureChecker->isFeatureEnabled('experimental_payment_methods')) { - $builder->add( - 'paypalCredit', - PayPalCreditSettingsType::class, - [ - 'label' => 'aligent.braintree.settings.paypal_credit.label', - 'required' => false - ] - )->add( - 'venmo', - VenmoSettingsType::class, + $builder + ->add( + 'card', + CreditCardSettingsType::class, [ - 'label' => 'aligent.braintree.settings.venmo.label', + 'label' => 'aligent.braintree.settings.credit_card.label', 'required' => false ] - )->add( - 'googlePay', - GooglePaySettingsType::class, + ) + ->add( + 'paypal', + PayPalSettingsType::class, [ - 'label' => 'aligent.braintree.settings.google_pay.label', - 'required' => false - ] - )->add( - 'applePay', - ApplePaySettingsType::class, - [ - 'label' => 'aligent.braintree.settings.apple_pay.label', + 'label' => 'aligent.braintree.settings.paypal.label', 'required' => false ] ); + + if ($this->featureChecker->isFeatureEnabled('experimental_payment_methods')) { + $builder + ->add( + 'paypalCredit', + PayPalCreditSettingsType::class, + [ + 'label' => 'aligent.braintree.settings.paypal_credit.label', + 'required' => false + ] + ) + ->add( + 'venmo', + VenmoSettingsType::class, + [ + 'label' => 'aligent.braintree.settings.venmo.label', + 'required' => false + ] + ) + ->add( + 'googlePay', + GooglePaySettingsType::class, + [ + 'label' => 'aligent.braintree.settings.google_pay.label', + 'required' => false + ] + ) + ->add( + 'applePay', + ApplePaySettingsType::class, + [ + 'label' => 'aligent.braintree.settings.apple_pay.label', + 'required' => false + ] + ); } } } diff --git a/src/Form/Type/VenmoSettingsType.php b/src/Form/Type/VenmoSettingsType.php index ad551cd16..64919cd17 100644 --- a/src/Form/Type/VenmoSettingsType.php +++ b/src/Form/Type/VenmoSettingsType.php @@ -16,14 +16,12 @@ class VenmoSettingsType extends AbstractType { - /** - * @param FormBuilderInterface $builder - * @param array $options + * @param FormBuilderInterface $builder + * @param array $options */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder ->add( 'enabled', diff --git a/src/Integration/BraintreeChannelType.php b/src/Integration/BraintreeChannelType.php index 3dcd0f7e8..e1f08980d 100644 --- a/src/Integration/BraintreeChannelType.php +++ b/src/Integration/BraintreeChannelType.php @@ -15,24 +15,12 @@ class BraintreeChannelType implements ChannelInterface, IconAwareIntegrationInterface { - - /** - * Returns label for UI - * - * @return string - */ - public function getLabel() + public function getLabel(): string { return 'aligent.braintree.channel_type.label'; } - /** - * Returns icon path for UI, should return value like 'bundles/acmedemo/img/logo.png' - * Relative path to assets helper - * - * @return string - */ - public function getIcon() + public function getIcon(): string { return 'bundles/aligentbraintree/img/braintree-logo.png'; } diff --git a/src/Integration/BraintreeTransport.php b/src/Integration/BraintreeTransport.php index f0096f52d..bead76cd4 100644 --- a/src/Integration/BraintreeTransport.php +++ b/src/Integration/BraintreeTransport.php @@ -17,40 +17,22 @@ class BraintreeTransport implements TransportInterface { - - /** - * @param Transport $transportEntity - */ - public function init(Transport $transportEntity) + public function init(Transport $transportEntity): void { + // Nothing to do here } - /** - * Returns label for UI - * - * @return string - */ - public function getLabel() + public function getLabel(): string { return 'aligent.braintree.settings.transport.label'; } - /** - * Returns form type name needed to setup transport - * - * @return string - */ - public function getSettingsFormType() + public function getSettingsFormType(): string { return BraintreeIntegrationSettingsType::class; } - /** - * Returns entity name needed to store transport settings - * - * @return string - */ - public function getSettingsEntityFQCN() + public function getSettingsEntityFQCN(): string { return BraintreeIntegrationSettings::class; } diff --git a/src/Method/Action/AbstractBraintreeAction.php b/src/Method/Action/AbstractBraintreeAction.php index 038d68723..1d116c400 100644 --- a/src/Method/Action/AbstractBraintreeAction.php +++ b/src/Method/Action/AbstractBraintreeAction.php @@ -10,67 +10,40 @@ namespace Aligent\BraintreeBundle\Method\Action; -use Aligent\BraintreeBundle\Event\BraintreePaymentActionEvent; use Aligent\BraintreeBundle\Braintree\Gateway; +use Aligent\BraintreeBundle\Event\BraintreePaymentActionEvent; use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Braintree\Result\Error; use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; use Oro\Bundle\PaymentBundle\Entity\PaymentTransaction; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use \InvalidArgumentException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; abstract class AbstractBraintreeAction implements BraintreeActionInterface, LoggerAwareInterface { - use LoggerAwareTrait; - /** - * @var Gateway - */ - protected $braintreeGateway; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @var DoctrineHelper - */ - protected $doctrineHelper; - - /** - * @var BraintreeConfigInterface - */ - protected $config; + protected Gateway $braintreeGateway; + protected EventDispatcherInterface $eventDispatcher; + protected DoctrineHelper $doctrineHelper; + protected BraintreeConfigInterface $config; - /** - * AbstractBraintreeAction constructor. - * @param EventDispatcherInterface $eventDispatcher - * @param DoctrineHelper $doctrineHelper - */ - public function __construct(EventDispatcherInterface $eventDispatcher, DoctrineHelper $doctrineHelper) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + DoctrineHelper $doctrineHelper + ) { $this->eventDispatcher = $eventDispatcher; $this->doctrineHelper = $doctrineHelper; } - /** - * @param BraintreeConfigInterface $braintreeConfig - * @return void - */ - public function initialize(BraintreeConfigInterface $braintreeConfig) + public function initialize(BraintreeConfigInterface $braintreeConfig): void { $this->config = $braintreeConfig; $this->braintreeGateway = new Gateway($braintreeConfig, $this->doctrineHelper); } - /** - * @param PaymentTransaction $paymentTransaction - */ - protected function setPaymentTransactionStateFailed(PaymentTransaction $paymentTransaction) + protected function setPaymentTransactionStateFailed(PaymentTransaction $paymentTransaction): void { $paymentTransaction ->setSuccessful(false) @@ -79,11 +52,8 @@ protected function setPaymentTransactionStateFailed(PaymentTransaction $paymentT /** * Logs error - * - * @param PaymentTransaction $paymentTransaction - * @param Error $error */ - protected function handleError(PaymentTransaction $paymentTransaction, Error $error) + protected function handleError(PaymentTransaction $paymentTransaction, Error $error): void { $errorContext = $this->getErrorLogContext($paymentTransaction); $errorContext['error'] = $error->jsonSerialize(); @@ -99,11 +69,8 @@ protected function handleError(PaymentTransaction $paymentTransaction, Error $er /** * Logs error - * - * @param PaymentTransaction $paymentTransaction - * @param \Throwable $exceptionOrError */ - protected function handleException(PaymentTransaction $paymentTransaction, \Throwable $exceptionOrError) + protected function handleException(PaymentTransaction $paymentTransaction, \Throwable $exceptionOrError): void { $errorMessage = sprintf( 'Payment %s failed. Reason: %s', @@ -119,50 +86,46 @@ protected function handleException(PaymentTransaction $paymentTransaction, \Thro /** * @param PaymentTransaction $paymentTransaction - * @return array + * @return array */ - protected function getErrorLogContext(PaymentTransaction $paymentTransaction) + protected function getErrorLogContext(PaymentTransaction $paymentTransaction): array { - $result = [ + return [ 'payment_transaction_id' => $paymentTransaction->getId(), 'payment_method' => $paymentTransaction->getPaymentMethod() ]; - - return $result; } /** * @param string $message - * @param array $errorContext + * @param array $errorContext */ - protected function logError($message, array $errorContext) + protected function logError(string $message, array $errorContext): void { $this->logger->error($message, $errorContext); } /** * Extracts the payment nonce out of the additional data array - * @param PaymentTransaction $paymentTransaction - * @return string */ - protected function getNonce(PaymentTransaction $paymentTransaction) + protected function getNonce(PaymentTransaction $paymentTransaction): string { $transactionOptions = $paymentTransaction->getTransactionOptions(); if (!isset($transactionOptions['additionalData'])) { - throw new InvalidArgumentException('Payment Transaction does not contain additionalData'); + throw new \InvalidArgumentException('Payment Transaction does not contain additionalData'); } $additionalData = json_decode($transactionOptions['additionalData'], true); if (json_last_error() !== JSON_ERROR_NONE) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( "Error decoding Payment Transaction additional data Error: " . json_last_error_msg() ); } if (!isset($additionalData['nonce'])) { - throw new InvalidArgumentException('Payment Transaction additionalData does not contain a nonce'); + throw new \InvalidArgumentException('Payment Transaction additionalData does not contain a nonce'); } return $additionalData['nonce']; @@ -171,28 +134,17 @@ protected function getNonce(PaymentTransaction $paymentTransaction) /** * Builds up the request data array by firing off 2 events, one generic and one named after the action type * @param PaymentTransaction $paymentTransaction - * @return array + * @return array */ - protected function buildRequestData(PaymentTransaction $paymentTransaction) + protected function buildRequestData(PaymentTransaction $paymentTransaction): array { $data = [ 'amount' => $paymentTransaction->getAmount(), - 'paymentMethodNonce' => $this->getNonce($paymentTransaction) + 'paymentMethodNonce' => $this->getNonce($paymentTransaction), ]; - $event = new BraintreePaymentActionEvent($data, $paymentTransaction, $this->config); - - // Generic Event - $this->eventDispatcher->dispatch(BraintreePaymentActionEvent::NAME, $event); - - // Action named event - $this->eventDispatcher->dispatch( - sprintf( - BraintreePaymentActionEvent::ACTION_EVENT_NAME, - $this->getName() - ), - $event - ); + $event = new BraintreePaymentActionEvent($this->getName(), $data, $paymentTransaction, $this->config); + $this->eventDispatcher->dispatch($event); return $event->getData(); } diff --git a/src/Method/Action/BraintreeActionInterface.php b/src/Method/Action/BraintreeActionInterface.php index 9a574cdae..6b00972f7 100644 --- a/src/Method/Action/BraintreeActionInterface.php +++ b/src/Method/Action/BraintreeActionInterface.php @@ -16,19 +16,11 @@ interface BraintreeActionInterface { /** - * @param PaymentTransaction $paymentTransaction - * @return array + * @return array */ - public function execute(PaymentTransaction $paymentTransaction); + public function execute(PaymentTransaction $paymentTransaction): array; - /** - * @param BraintreeConfigInterface $braintreeConfig - * @return void - */ - public function initialize(BraintreeConfigInterface $braintreeConfig); + public function initialize(BraintreeConfigInterface $braintreeConfig): void; - /** - * @return string - */ - public function getName(); + public function getName(): string; } diff --git a/src/Method/Action/Provider/BraintreeActionProvider.php b/src/Method/Action/Provider/BraintreeActionProvider.php index 06b6de4fd..333f4700a 100644 --- a/src/Method/Action/Provider/BraintreeActionProvider.php +++ b/src/Method/Action/Provider/BraintreeActionProvider.php @@ -11,37 +11,24 @@ namespace Aligent\BraintreeBundle\Method\Action\Provider; use Aligent\BraintreeBundle\Method\Action\BraintreeActionInterface; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; class BraintreeActionProvider implements BraintreeActionProviderInterface { - /** - * @var BraintreeActionInterface[] + * @var array */ - protected $actions = []; + protected array $actions = []; - /** - * @param string $action - * @return BraintreeActionInterface - */ - public function getAction($action) + public function getAction(string $action): BraintreeActionInterface { if (!array_key_exists($action, $this->actions)) { throw new \InvalidArgumentException("{$action} is not supported."); } - $action = $this->actions[$action]; - - return $action; + return $this->actions[$action]; } - /** - * @param $action - * @param BraintreeActionInterface $braintreeAction - * @return $this - */ - public function addAction($action, BraintreeActionInterface $braintreeAction) + public function addAction(string $action, BraintreeActionInterface $braintreeAction): static { if (array_key_exists($action, $this->actions)) { throw new \InvalidArgumentException("{$action} already exists."); @@ -52,11 +39,7 @@ public function addAction($action, BraintreeActionInterface $braintreeAction) return $this; } - /** - * @param $action - * @return bool - */ - public function hasAction($action) + public function hasAction(string $action): bool { return array_key_exists($action, $this->actions); } diff --git a/src/Method/Action/Provider/BraintreeActionProviderInterface.php b/src/Method/Action/Provider/BraintreeActionProviderInterface.php index ecf3be5aa..e7971acd0 100644 --- a/src/Method/Action/Provider/BraintreeActionProviderInterface.php +++ b/src/Method/Action/Provider/BraintreeActionProviderInterface.php @@ -11,26 +11,12 @@ namespace Aligent\BraintreeBundle\Method\Action\Provider; use Aligent\BraintreeBundle\Method\Action\BraintreeActionInterface; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; interface BraintreeActionProviderInterface { - /** - * @param string $action - * @return BraintreeActionInterface - */ - public function getAction($action); + public function getAction(string $action): BraintreeActionInterface; - /** - * @param $action - * @param BraintreeActionInterface $braintreeAction - * @return $this - */ - public function addAction($action, BraintreeActionInterface $braintreeAction); + public function addAction(string $action, BraintreeActionInterface $braintreeAction): static; - /** - * @param $action - * @return bool - */ - public function hasAction($action); + public function hasAction(string $action): bool; } diff --git a/src/Method/Action/PurchaseAction.php b/src/Method/Action/PurchaseAction.php index 6c6c16cb2..8eb1f7ceb 100644 --- a/src/Method/Action/PurchaseAction.php +++ b/src/Method/Action/PurchaseAction.php @@ -10,8 +10,6 @@ namespace Aligent\BraintreeBundle\Method\Action; -use Aligent\BraintreeBundle\Braintree\Gateway; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Braintree\Result\Error; use Oro\Bundle\PaymentBundle\Entity\PaymentTransaction; @@ -20,10 +18,9 @@ class PurchaseAction extends AbstractBraintreeAction const ACTION = 'purchase'; /** - * @param PaymentTransaction $paymentTransaction - * @return mixed + * @return array */ - public function execute(PaymentTransaction $paymentTransaction) + public function execute(PaymentTransaction $paymentTransaction): array { $data = $this->buildRequestData($paymentTransaction); $paymentTransaction->setRequest($data); @@ -57,10 +54,7 @@ public function execute(PaymentTransaction $paymentTransaction) ]; } - /** - * @return string - */ - public function getName() + public function getName(): string { return static::ACTION; } diff --git a/src/Method/AligentBraintreeMethod.php b/src/Method/AligentBraintreeMethod.php index da49fa3f9..abe4295cb 100644 --- a/src/Method/AligentBraintreeMethod.php +++ b/src/Method/AligentBraintreeMethod.php @@ -10,8 +10,8 @@ namespace Aligent\BraintreeBundle\Method; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Aligent\BraintreeBundle\Method\Action\Provider\BraintreeActionProviderInterface; +use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Oro\Bundle\PaymentBundle\Context\PaymentContextInterface; use Oro\Bundle\PaymentBundle\Entity\PaymentTransaction; use Oro\Bundle\PaymentBundle\Method\PaymentMethodInterface; @@ -19,33 +19,14 @@ class AligentBraintreeMethod implements PaymentMethodInterface { - /** - * @var BraintreeConfigInterface - */ - protected $config; + protected BraintreeConfigInterface $config; + protected BraintreeActionProviderInterface $actionProvider; + protected LoggerInterface $logger; - /** - * @var BraintreeActionProviderInterface - */ - protected $actionProvider; - - /** - * The logger instance. - * - * @var LoggerInterface - */ - protected $logger; - - /** - * AligentBraintreeMethod constructor. - * @param BraintreeConfigInterface $config - * @param BraintreeActionProviderInterface $actionProvider - * @param LoggerInterface $logger - */ public function __construct( BraintreeConfigInterface $config, BraintreeActionProviderInterface $actionProvider, - LoggerInterface $logger + LoggerInterface $logger, ) { $this->config = $config; $this->actionProvider = $actionProvider; @@ -55,9 +36,9 @@ public function __construct( /** * @param string $action * @param PaymentTransaction $paymentTransaction - * @return array + * @return array */ - public function execute($action, PaymentTransaction $paymentTransaction) + public function execute($action, PaymentTransaction $paymentTransaction): array { if (!$this->supports($action)) { throw new \InvalidArgumentException(sprintf('Unsupported action "%s"', $action)); @@ -70,7 +51,7 @@ public function execute($action, PaymentTransaction $paymentTransaction) return $actionInstance->execute($paymentTransaction); } catch (\Exception $e) { $this->logger->critical( - "Exception excuting Braintree Payment action ({$action})", + "Exception executing Braintree Payment action ({$action})", [ 'payment_transaction_id' => $paymentTransaction->getId(), 'payment_method' => $paymentTransaction->getPaymentMethod(), @@ -89,19 +70,12 @@ public function execute($action, PaymentTransaction $paymentTransaction) ]; } - /** - * @return string - */ - public function getIdentifier() + public function getIdentifier(): string { return $this->config->getPaymentMethodIdentifier(); } - /** - * @param PaymentContextInterface $context - * @return bool - */ - public function isApplicable(PaymentContextInterface $context) + public function isApplicable(PaymentContextInterface $context): bool { return true; } @@ -110,7 +84,7 @@ public function isApplicable(PaymentContextInterface $context) * @param string $actionName * @return bool */ - public function supports($actionName) + public function supports($actionName): bool { return $this->actionProvider->hasAction($actionName); } diff --git a/src/Method/Config/BraintreeConfig.php b/src/Method/Config/BraintreeConfig.php index 48389c612..6ccbb737b 100644 --- a/src/Method/Config/BraintreeConfig.php +++ b/src/Method/Config/BraintreeConfig.php @@ -12,158 +12,110 @@ use Aligent\BraintreeBundle\Braintree\Gateway; use Doctrine\Common\Collections\ArrayCollection; -use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue; use Oro\Bundle\PaymentBundle\Method\Config\ParameterBag\AbstractParameterBagPaymentConfig; class BraintreeConfig extends AbstractParameterBagPaymentConfig implements BraintreeConfigInterface { - /** - * @return string - */ - public function getEnvironment() + public function getEnvironment(): string { return (string) $this->get(self::ENVIRONMENT_KEY); } - /** - * @return string - */ - public function getMerchantId() + public function getMerchantId(): string { return (string) $this->get(self::MERCHANT_ID_KEY); } - /** - * @return string - */ - public function getMerchantAccountId() + public function getMerchantAccountId(): string { return (string) $this->get(self::MERCHANT_ACCOUNT_ID_KEY); } - /** - * @return string - */ - public function getPublicKey() + public function getPublicKey(): string { return (string) $this->get(self::PUBLIC_KEY_KEY); } - /** - * @return string - */ - public function getPrivateKey() + public function getPrivateKey(): string { return (string) $this->get(self::PRIVATE_KEY_KEY); } - /** - * @param $value string - */ - public function setPublicKey($value) + public function setPublicKey(string $value): static { $this->set(self::PUBLIC_KEY_KEY, $value); + return $this; } - /** - * @param $value string - */ - public function setPrivateKey($value) + public function setPrivateKey(string $value): static { $this->set(self::PRIVATE_KEY_KEY, $value); + return $this; } - /** - * @return bool - */ - public function isVaultMode() + public function isVaultMode(): bool { return (boolean) $this->get(self::VAULT_KEY); } - /** - * Are we in sandbox mode - * @return bool - */ - public function isSandboxMode() + public function isSandboxMode(): bool { return $this->getEnvironment() === Gateway::SANDBOX; } /** - * @return ArrayCollection + * {@inheritDoc} */ - public function getLabels() + public function getLabels(): ArrayCollection { return $this->get(self::LABELS_KEY); } /** - * @return ArrayCollection + * {@inheritDoc} */ - public function getShortLabels() + public function getShortLabels(): ArrayCollection { return $this->get(self::SHORT_LABELS_KEY); } - /** - * @return LocalizedFallbackValue - */ - public function getLabel() + public function getLabel(): string { - return $this->get(self::LABEL_KEY); + return (string)$this->get(self::LABEL_KEY); } - /** - * @return LocalizedFallbackValue - */ - public function getShortLabel() + public function getShortLabel(): string { - return $this->get(self::SHORT_LABEL_KEY); + return (string)$this->get(self::SHORT_LABEL_KEY); } - /** - * @param string $value - * @return $this - */ - public function setLabel($value) + public function setLabel(string $value): static { $this->set(self::LABEL_KEY, $value); return $this; } - /** - * @param string $value - * @return $this - */ - public function setShortLabel($value) + public function setShortLabel(string $value): static { $this->set(self::LABEL_KEY, $value); return $this; } /** - * @return array + * {@inheritDoc} */ - public function getPaymentMethodSettings() + public function getPaymentMethodSettings(): array { return $this->get(self::PAYMENT_METHODS_CONFIG_KEY); } - /** - * @param array $settings - * @return BraintreeConfig - */ - public function setPaymentMethodSettings(array $settings) + public function setPaymentMethodSettings(array $settings): static { $this->set(self::PAYMENT_METHODS_CONFIG_KEY, $settings); return $this; } - /** - * @return bool - */ - public function isFraudProtectionAdvancedEnabled() + public function isFraudProtectionAdvancedEnabled(): bool { return (boolean) $this->get(self::FRAUD_PROTECTION_ADVANCED_KEY); } diff --git a/src/Method/Config/BraintreeConfigInterface.php b/src/Method/Config/BraintreeConfigInterface.php index 8fdb93a89..1e37cf374 100644 --- a/src/Method/Config/BraintreeConfigInterface.php +++ b/src/Method/Config/BraintreeConfigInterface.php @@ -34,97 +34,54 @@ interface BraintreeConfigInterface extends PaymentConfigInterface const PAYPAL_BILLING_PAGE = 'billing'; const PAYPAL_LOGIN_PAGE = 'login'; + public function getEnvironment(): string; - /** - * @return string - */ - public function getEnvironment(); + public function getMerchantId(): string; - /** - * @return string - */ - public function getMerchantId(); + public function getMerchantAccountId(): string; - /** - * @return string - */ - public function getMerchantAccountId(); + public function getPublicKey(): string; - /** - * @return string - */ - public function getPublicKey(); + public function setPublicKey(string $value): static; - /** - * @return string - */ - public function getPrivateKey(); + public function getPrivateKey(): string; - /** - * @param $value string - */ - public function setPublicKey($value); + public function setPrivateKey(string $value): static; - /** - * @param $value string - */ - public function setPrivateKey($value); + public function isVaultMode(): bool; /** - * @return bool + * Are we in sandbox mode? */ - public function isVaultMode(); + public function isSandboxMode(): bool; - /** - * Are we in sandbox mode - * @return bool - */ - public function isSandboxMode(); + public function isFraudProtectionAdvancedEnabled(): bool; /** - * @return ArrayCollection + * @return ArrayCollection */ - public function getLabels(); + public function getLabels(): ArrayCollection; /** - * @return ArrayCollection + * @return ArrayCollection */ - public function getShortLabels(); + public function getShortLabels(): ArrayCollection; - /** - * @return LocalizedFallbackValue - */ - public function getLabel(); + public function getShortLabel(): string; - /** - * @return LocalizedFallbackValue - */ - public function getShortLabel(); + public function setShortLabel(string $value): static; - /** - * @param string $value - * @return $this - */ - public function setLabel($value); - - /** - * @param string $value - * @return $this - */ - public function setShortLabel($value); + public function getLabel(): string; - /** - * @return array - */ - public function getPaymentMethodSettings(); + public function setLabel(string $value): static; /** - * @param array $settings + * @return array */ - public function setPaymentMethodSettings(array $settings); + public function getPaymentMethodSettings(): array; /** - * @return bool + * @param array $settings */ - public function isFraudProtectionAdvancedEnabled(); + public function setPaymentMethodSettings(array $settings): static; } diff --git a/src/Method/Config/Factory/BraintreeConfigFactory.php b/src/Method/Config/Factory/BraintreeConfigFactory.php index 5c3b108fa..5a86333f0 100644 --- a/src/Method/Config/Factory/BraintreeConfigFactory.php +++ b/src/Method/Config/Factory/BraintreeConfigFactory.php @@ -15,47 +15,28 @@ use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Doctrine\Common\Collections\Collection; use Oro\Bundle\IntegrationBundle\Generator\IntegrationIdentifierGeneratorInterface; +use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue; use Oro\Bundle\LocaleBundle\Helper\LocalizationHelper; use Oro\Bundle\PaymentBundle\Method\Config\ParameterBag\AbstractParameterBagPaymentConfig; use Oro\Bundle\SecurityBundle\Encoder\SymmetricCrypterInterface; class BraintreeConfigFactory implements BraintreeConfigFactoryInterface { - /** - * @var LocalizationHelper - */ - protected $localizationHelper; - - /** - * @var IntegrationIdentifierGeneratorInterface - */ - protected $identifierGenerator; - - /** - * @var SymmetricCrypterInterface - */ - protected $encoder; + protected LocalizationHelper $localizationHelper; + protected IntegrationIdentifierGeneratorInterface $identifierGenerator; + protected SymmetricCrypterInterface $encoder; - /** - * @param LocalizationHelper $localizationHelper - * @param IntegrationIdentifierGeneratorInterface $identifierGenerator - * @param SymmetricCrypterInterface $encoder - */ public function __construct( LocalizationHelper $localizationHelper, IntegrationIdentifierGeneratorInterface $identifierGenerator, - SymmetricCrypterInterface $encoder + SymmetricCrypterInterface $encoder, ) { $this->localizationHelper = $localizationHelper; $this->identifierGenerator = $identifierGenerator; $this->encoder = $encoder; } - /** - * @param BraintreeIntegrationSettings $settings - * @return BraintreeConfigInterface - */ - public function create(BraintreeIntegrationSettings $settings) + public function create(BraintreeIntegrationSettings $settings): BraintreeConfigInterface { $params = $settings->getSettingsBag(); $channel = $settings->getChannel(); @@ -79,11 +60,10 @@ public function create(BraintreeIntegrationSettings $settings) } /** - * @param Collection $values - * + * @param Collection $values * @return string */ - private function getLocalizedValue(Collection $values) + private function getLocalizedValue(Collection $values): string { return (string) $this->localizationHelper->getLocalizedValue($values); } diff --git a/src/Method/Config/Factory/BraintreeConfigFactoryInterface.php b/src/Method/Config/Factory/BraintreeConfigFactoryInterface.php index b1d64fc2d..305eb81d8 100644 --- a/src/Method/Config/Factory/BraintreeConfigFactoryInterface.php +++ b/src/Method/Config/Factory/BraintreeConfigFactoryInterface.php @@ -15,9 +15,5 @@ interface BraintreeConfigFactoryInterface { - /** - * @param BraintreeIntegrationSettings $settings - * @return BraintreeConfigInterface - */ - public function create(BraintreeIntegrationSettings $settings); + public function create(BraintreeIntegrationSettings $settings): BraintreeConfigInterface; } diff --git a/src/Method/Config/Provider/BraintreeConfigProvider.php b/src/Method/Config/Provider/BraintreeConfigProvider.php index 2626cae17..8a2f8af7a 100644 --- a/src/Method/Config/Provider/BraintreeConfigProvider.php +++ b/src/Method/Config/Provider/BraintreeConfigProvider.php @@ -12,42 +12,26 @@ use Aligent\BraintreeBundle\Entity\BraintreeIntegrationSettings; use Aligent\BraintreeBundle\Entity\Repository\BraintreeIntegrationSettingsRepository; -use Aligent\BraintreeBundle\Method\Config\BraintreeConfig; +use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; use Aligent\BraintreeBundle\Method\Config\Factory\BraintreeConfigFactoryInterface; use Psr\Log\LoggerInterface; use Symfony\Bridge\Doctrine\ManagerRegistry; class BraintreeConfigProvider implements BraintreeConfigProviderInterface { - /** - * @var ManagerRegistry - */ - protected $doctrine; - - /** - * @var BraintreeConfigFactoryInterface - */ - protected $configFactory; + protected ManagerRegistry $doctrine; + protected LoggerInterface $logger; + protected BraintreeConfigFactoryInterface $configFactory; /** * @var BraintreeConfigInterface[] */ - protected $configs; + protected array $configs = []; - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * @param ManagerRegistry $doctrine - * @param LoggerInterface $logger - * @param BraintreeConfigFactoryInterface $configFactory - */ public function __construct( ManagerRegistry $doctrine, LoggerInterface $logger, - BraintreeConfigFactoryInterface $configFactory + BraintreeConfigFactoryInterface $configFactory, ) { $this->doctrine = $doctrine; $this->logger = $logger; @@ -57,25 +41,21 @@ public function __construct( /** * {@inheritDoc} */ - public function getPaymentConfigs() + public function getPaymentConfigs(): array { - $configs = []; - - $settings = $this->getEnabledIntegrationSettings(); - - foreach ($settings as $setting) { - $config = $this->configFactory->create($setting); + if (empty($this->configs)) { + $settings = $this->getEnabledIntegrationSettings(); - $configs[$config->getPaymentMethodIdentifier()] = $config; + foreach ($settings as $setting) { + $config = $this->configFactory->create($setting); + $this->configs[$config->getPaymentMethodIdentifier()] = $config; + } } - return $configs; + return $this->configs; } - /** - * {@inheritDoc} - */ - public function getPaymentConfig($identifier) + public function getPaymentConfig(string $identifier): ?BraintreeConfigInterface { $paymentConfigs = $this->getPaymentConfigs(); @@ -86,10 +66,7 @@ public function getPaymentConfig($identifier) return $paymentConfigs[$identifier]; } - /** - * {@inheritDoc} - */ - public function hasPaymentConfig($identifier) + public function hasPaymentConfig(string $identifier): bool { return null !== $this->getPaymentConfig($identifier); } @@ -97,7 +74,7 @@ public function hasPaymentConfig($identifier) /** * @return BraintreeIntegrationSettings[] */ - protected function getEnabledIntegrationSettings() + protected function getEnabledIntegrationSettings(): array { try { /** @var BraintreeIntegrationSettingsRepository $repository */ diff --git a/src/Method/Config/Provider/BraintreeConfigProviderInterface.php b/src/Method/Config/Provider/BraintreeConfigProviderInterface.php index 20d04d669..a0a860510 100644 --- a/src/Method/Config/Provider/BraintreeConfigProviderInterface.php +++ b/src/Method/Config/Provider/BraintreeConfigProviderInterface.php @@ -9,22 +9,16 @@ */ namespace Aligent\BraintreeBundle\Method\Config\Provider; +use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; + interface BraintreeConfigProviderInterface { /** - * @return BraintreeConfigInterface[] + * @return array */ - public function getPaymentConfigs(); + public function getPaymentConfigs(): array; - /** - * @param string $identifier - * @return BraintreeConfigInterface|null - */ - public function getPaymentConfig($identifier); + public function getPaymentConfig(string $identifier): ?BraintreeConfigInterface; - /** - * @param string $identifier - * @return bool - */ - public function hasPaymentConfig($identifier); + public function hasPaymentConfig(string $identifier): bool; } diff --git a/src/Method/Factory/BraintreeMethodFactory.php b/src/Method/Factory/BraintreeMethodFactory.php index 96d37dbb7..eab3ff4e1 100644 --- a/src/Method/Factory/BraintreeMethodFactory.php +++ b/src/Method/Factory/BraintreeMethodFactory.php @@ -10,43 +10,26 @@ namespace Aligent\BraintreeBundle\Method\Factory; +use Aligent\BraintreeBundle\Method\Action\Provider\BraintreeActionProviderInterface; use Aligent\BraintreeBundle\Method\AligentBraintreeMethod; use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; -use Aligent\BraintreeBundle\Method\Action\Provider\BraintreeActionProviderInterface; use Oro\Bundle\PaymentBundle\Method\PaymentMethodInterface; use Psr\Log\LoggerInterface; class BraintreeMethodFactory implements BraintreeMethodFactoryInterface { + protected BraintreeActionProviderInterface $provider; + protected LoggerInterface $logger; - /** - * @var BraintreeActionProviderInterface - */ - protected $provider; - - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * BraintreeMethodFactory constructor. - * @param BraintreeActionProviderInterface $provider - * @param LoggerInterface $logger - */ public function __construct( BraintreeActionProviderInterface $provider, - LoggerInterface $logger + LoggerInterface $logger, ) { $this->provider = $provider; $this->logger = $logger; } - /** - * @param BraintreeConfigInterface $config - * @return PaymentMethodInterface - */ - public function create(BraintreeConfigInterface $config) + public function create(BraintreeConfigInterface $config): PaymentMethodInterface { return new AligentBraintreeMethod($config, $this->provider, $this->logger); } diff --git a/src/Method/Factory/BraintreeMethodFactoryInterface.php b/src/Method/Factory/BraintreeMethodFactoryInterface.php index 8434eb474..06113f2a0 100644 --- a/src/Method/Factory/BraintreeMethodFactoryInterface.php +++ b/src/Method/Factory/BraintreeMethodFactoryInterface.php @@ -15,9 +15,5 @@ interface BraintreeMethodFactoryInterface { - /** - * @param BraintreeConfigInterface $config - * @return PaymentMethodInterface - */ - public function create(BraintreeConfigInterface $config); + public function create(BraintreeConfigInterface $config): PaymentMethodInterface; } diff --git a/src/Method/Provider/BraintreeMethodProvider.php b/src/Method/Provider/BraintreeMethodProvider.php index dfc3b10c2..75a639977 100644 --- a/src/Method/Provider/BraintreeMethodProvider.php +++ b/src/Method/Provider/BraintreeMethodProvider.php @@ -17,24 +17,12 @@ class BraintreeMethodProvider extends AbstractPaymentMethodProvider { - /** - * @var BraintreeMethodFactoryInterface - */ - protected $factory; - - /** - * @var BraintreeConfigProviderInterface - */ - protected $configProvider; - + protected BraintreeMethodFactoryInterface $factory; + protected BraintreeConfigProviderInterface $configProvider; - /** - * @param BraintreeConfigProviderInterface $configProvider - * @param BraintreeMethodFactoryInterface $factory - */ public function __construct( BraintreeConfigProviderInterface $configProvider, - BraintreeMethodFactoryInterface $factory + BraintreeMethodFactoryInterface $factory, ) { parent::__construct(); @@ -45,10 +33,9 @@ public function __construct( /** * Save methods to $methods property */ - protected function collectMethods() + protected function collectMethods(): void { - $configs = $this->configProvider->getPaymentConfigs(); - foreach ($configs as $config) { + foreach ($this->configProvider->getPaymentConfigs() as $config) { $this->addBraintreeMethod($config); } } @@ -56,7 +43,7 @@ protected function collectMethods() /** * @param BraintreeConfigInterface $config */ - protected function addBraintreeMethod(BraintreeConfigInterface $config) + protected function addBraintreeMethod(BraintreeConfigInterface $config): void { $this->addMethod( $config->getPaymentMethodIdentifier(), diff --git a/src/Method/View/BraintreeView.php b/src/Method/View/BraintreeView.php index a12ebca58..0c6aabd84 100644 --- a/src/Method/View/BraintreeView.php +++ b/src/Method/View/BraintreeView.php @@ -13,44 +13,19 @@ use Aligent\BraintreeBundle\Braintree\Gateway; use Aligent\BraintreeBundle\Braintree\PaymentMethod\Settings\Builder\ConfigurationBuilderInterface; use Aligent\BraintreeBundle\Method\Config\BraintreeConfigInterface; -use Aligent\BraintreeBundle\Provider\ChainConfigurationBuilder; use Oro\Bundle\CustomerBundle\Entity\CustomerUser; use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; use Oro\Bundle\PaymentBundle\Context\PaymentContextInterface; use Oro\Bundle\PaymentBundle\Method\View\PaymentMethodViewInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\VarDumper\VarDumper; class BraintreeView implements PaymentMethodViewInterface { + protected BraintreeConfigInterface $config; + protected TokenStorageInterface $tokenStorage; + protected ConfigurationBuilderInterface $configurationBuilder; + protected DoctrineHelper $doctrineHelper; - /** - * @var BraintreeConfigInterface - */ - protected $config; - - /** - * @var TokenStorageInterface - */ - protected $tokenStorage; - - /** - * @var ConfigurationBuilderInterface - */ - protected $configurationBuilder; - - /** - * @var DoctrineHelper - */ - protected $doctrineHelper; - - /** - * BraintreeView constructor. - * @param BraintreeConfigInterface $config - * @param TokenStorageInterface $tokenStorage - * @param ConfigurationBuilderInterface $configurationBuilder - * @param DoctrineHelper $doctrineHelper - */ public function __construct( BraintreeConfigInterface $config, TokenStorageInterface $tokenStorage, @@ -66,9 +41,9 @@ public function __construct( /** * These keys are used in the javascript file 'braintree-method-component.js to retrieve data from backend * @param PaymentContextInterface $context - * @return array + * @return array */ - public function getOptions(PaymentContextInterface $context) + public function getOptions(PaymentContextInterface $context): array { return [ 'authToken' => $this->getAuthToken(), @@ -78,18 +53,12 @@ public function getOptions(PaymentContextInterface $context) ]; } - /** - * @return string - */ - public function getBlock() + public function getBlock(): string { return '_payment_methods_aligent_braintree_widget'; } - /** - * @return string - */ - public function getLabel() + public function getLabel(): string { return $this->config->getLabel(); } @@ -97,33 +66,26 @@ public function getLabel() /** * @return string */ - public function getAdminLabel() + public function getAdminLabel(): string { return $this->config->getAdminLabel(); } - /** - * @return string - */ - public function getShortLabel() + public function getShortLabel(): string { return $this->config->getShortLabel(); } - /** - * @return string - */ - public function getPaymentMethodIdentifier() + public function getPaymentMethodIdentifier(): string { return $this->config->getPaymentMethodIdentifier(); } /** - * Create an authentication token for the logged in user (if vault mode is enabled) + * Create an authentication token for the logged-in user (if vault mode is enabled) * or a generic token (if vault mode is disabled) - * @return string */ - protected function getAuthToken() + protected function getAuthToken(): string { $gateway = new Gateway($this->config, $this->doctrineHelper); @@ -142,9 +104,9 @@ protected function getAuthToken() /** * @param PaymentContextInterface $context - * @return array + * @return array */ - protected function getPaymentMethodSettings(PaymentContextInterface $context) + protected function getPaymentMethodSettings(PaymentContextInterface $context): array { $paymentMethodSettings = $this->config->getPaymentMethodSettings(); return $this->configurationBuilder->build($context, $paymentMethodSettings); diff --git a/src/Method/View/Factory/BraintreeViewFactory.php b/src/Method/View/Factory/BraintreeViewFactory.php index feb8cdfb0..8bb8f0b90 100644 --- a/src/Method/View/Factory/BraintreeViewFactory.php +++ b/src/Method/View/Factory/BraintreeViewFactory.php @@ -19,20 +19,12 @@ class BraintreeViewFactory implements BraintreeViewFactoryInterface { - - /** - * @param BraintreeConfigInterface $config - * @param TokenStorageInterface $tokenStorage - * @param ChainConfigurationBuilder $configurationBuilder - * @param DoctrineHelper $doctrineHelper - * @return PaymentMethodViewInterface - */ public function create( BraintreeConfigInterface $config, TokenStorageInterface $tokenStorage, ChainConfigurationBuilder $configurationBuilder, DoctrineHelper $doctrineHelper - ) { + ): PaymentMethodViewInterface { return new BraintreeView($config, $tokenStorage, $configurationBuilder, $doctrineHelper); } } diff --git a/src/Method/View/Factory/BraintreeViewFactoryInterface.php b/src/Method/View/Factory/BraintreeViewFactoryInterface.php index 09c154b8c..c31a3e160 100644 --- a/src/Method/View/Factory/BraintreeViewFactoryInterface.php +++ b/src/Method/View/Factory/BraintreeViewFactoryInterface.php @@ -18,17 +18,10 @@ interface BraintreeViewFactoryInterface { - /** - * @param BraintreeConfigInterface $config - * @param TokenStorageInterface $tokenStorage - * @param ChainConfigurationBuilder $configurationBuilder - * @param DoctrineHelper $doctrineHelper - * @return PaymentMethodViewInterface - */ public function create( BraintreeConfigInterface $config, TokenStorageInterface $tokenStorage, ChainConfigurationBuilder $configurationBuilder, DoctrineHelper $doctrineHelper - ); + ): PaymentMethodViewInterface; } diff --git a/src/Method/View/Provider/BraintreeViewProvider.php b/src/Method/View/Provider/BraintreeViewProvider.php index 3d8d2594f..2fc989968 100644 --- a/src/Method/View/Provider/BraintreeViewProvider.php +++ b/src/Method/View/Provider/BraintreeViewProvider.php @@ -22,34 +22,18 @@ class BraintreeViewProvider extends AbstractPaymentMethodViewProvider { - /** @var BraintreeViewFactoryInterface */ - protected $factory; + protected BraintreeViewFactoryInterface $factory; + protected BraintreeConfigProviderInterface $configProvider; + protected TokenStorageInterface $tokenStorage; + protected ChainConfigurationBuilder $configurationBuilder; + protected DoctrineHelper $doctrineHelper; - /** @var BraintreeConfigProviderInterface */ - protected $configProvider; - - /** @var TokenStorageInterface */ - protected $tokenStorage; - - /** @var ChainConfigurationBuilder */ - protected $configurationBuilder; - - /** @var DoctrineHelper */ - protected $doctrineHelper; - - /** - * @param BraintreeConfigProviderInterface $configProvider - * @param BraintreeViewFactoryInterface $factory - * @param TokenStorageInterface $tokenStorage - * @param ChainConfigurationBuilder $settingsProvider - * @param DoctrineHelper $doctrineHelper - */ public function __construct( BraintreeConfigProviderInterface $configProvider, BraintreeViewFactoryInterface $factory, TokenStorageInterface $tokenStorage, ChainConfigurationBuilder $settingsProvider, - DoctrineHelper $doctrineHelper + DoctrineHelper $doctrineHelper, ) { $this->factory = $factory; $this->configProvider = $configProvider; @@ -61,9 +45,9 @@ public function __construct( } /** - * @return ArrayCollection|PaymentMethodViewInterface[] + * @return ArrayCollection */ - protected function buildViews() + protected function buildViews(): ArrayCollection { $configs = $this->configProvider->getPaymentConfigs(); foreach ($configs as $config) { @@ -73,10 +57,7 @@ protected function buildViews() return $this->views; } - /** - * @param BraintreeConfigInterface $config - */ - protected function addBraintreeView($config) + protected function addBraintreeView(BraintreeConfigInterface $config): void { $this->addView( $config->getPaymentMethodIdentifier(), diff --git a/src/Migrations/Schema/AligentBraintreeBundleInstaller.php b/src/Migrations/Schema/AligentBraintreeBundleInstaller.php index 2760c0a2e..404c62439 100755 --- a/src/Migrations/Schema/AligentBraintreeBundleInstaller.php +++ b/src/Migrations/Schema/AligentBraintreeBundleInstaller.php @@ -11,11 +11,10 @@ namespace Aligent\BraintreeBundle\Migrations\Schema; use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\DBAL\Types\Types; use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope; use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope; -use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension; -use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface; use Oro\Bundle\MigrationBundle\Migration\Installation; use Oro\Bundle\MigrationBundle\Migration\QueryBag; @@ -25,18 +24,15 @@ */ class AligentBraintreeBundleInstaller implements Installation { - /** - * {@inheritdoc} - */ - public function getMigrationVersion() + public function getMigrationVersion(): string { return 'v1_0'; } /** - * {@inheritdoc} + * @throws SchemaException */ - public function up(Schema $schema, QueryBag $queries) + public function up(Schema $schema, QueryBag $queries): void { /** Tables generation **/ $this->createAligentBraintreeLblTable($schema); @@ -49,12 +45,7 @@ public function up(Schema $schema, QueryBag $queries) $this->addAligentBraintreeShLblForeignKeys($schema); } - /** - * Create aligent_braintree_lbl table - * - * @param Schema $schema - */ - protected function createAligentBraintreeLblTable(Schema $schema) + protected function createAligentBraintreeLblTable(Schema $schema): void { $table = $schema->createTable('aligent_braintree_lbl'); $table->addColumn('transport_id', 'integer', []); @@ -64,12 +55,7 @@ protected function createAligentBraintreeLblTable(Schema $schema) $table->addIndex(['transport_id'], 'IDX_84655B459909C13F', []); } - /** - * Create aligent_braintree_sh_lbl table - * - * @param Schema $schema - */ - protected function createAligentBraintreeShLblTable(Schema $schema) + protected function createAligentBraintreeShLblTable(Schema $schema): void { $table = $schema->createTable('aligent_braintree_sh_lbl'); $table->addColumn('transport_id', 'integer', []); @@ -80,12 +66,9 @@ protected function createAligentBraintreeShLblTable(Schema $schema) } /** - * Create oro_integration_transport table - * - * @param Schema $schema - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ - protected function updateOroIntegrationTransportTable(Schema $schema) + protected function updateOroIntegrationTransportTable(Schema $schema): void { $table = $schema->getTable('oro_integration_transport'); @@ -119,12 +102,9 @@ protected function updateOroIntegrationTransportTable(Schema $schema) } /** - * Add aligent_braintree_lbl foreign keys. - * - * @param Schema $schema - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ - protected function addAligentBraintreeLblForeignKeys(Schema $schema) + protected function addAligentBraintreeLblForeignKeys(Schema $schema): void { $table = $schema->getTable('aligent_braintree_lbl'); $table->addForeignKeyConstraint( @@ -142,12 +122,9 @@ protected function addAligentBraintreeLblForeignKeys(Schema $schema) } /** - * Add aligent_braintree_sh_lbl foreign keys. - * - * @param Schema $schema - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ - protected function addAligentBraintreeShLblForeignKeys(Schema $schema) + protected function addAligentBraintreeShLblForeignKeys(Schema $schema): void { $table = $schema->getTable('aligent_braintree_sh_lbl'); $table->addForeignKeyConstraint( @@ -165,29 +142,27 @@ protected function addAligentBraintreeShLblForeignKeys(Schema $schema) } /** - * @param Schema $schema - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ - protected function extendCustomerUser(Schema $schema) + protected function extendCustomerUser(Schema $schema): void { $table = $schema->getTable('oro_customer_user'); $table->addColumn( 'braintree_id', - Type::STRING, + Types::STRING, [ 'notnull' => false, 'oro_options' => [ 'extend' => ['owner' => ExtendScope::OWNER_CUSTOM], 'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_FALSE], 'form' => [ - 'is_enabled' => false + 'is_enabled' => false, ], 'view' => [ - 'is_displayable' => false + 'is_displayable' => false, ], 'dataaudit' => ['auditable' => true], - ] ] ); diff --git a/src/Migrations/Schema/v1_1/AddEnablePremiumFraudProtectionField.php b/src/Migrations/Schema/v1_1/AddEnablePremiumFraudProtectionField.php index 7740b4a6a..a0173b9fb 100644 --- a/src/Migrations/Schema/v1_1/AddEnablePremiumFraudProtectionField.php +++ b/src/Migrations/Schema/v1_1/AddEnablePremiumFraudProtectionField.php @@ -11,15 +11,16 @@ namespace Aligent\BraintreeBundle\Migrations\Schema\v1_1; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaException; use Oro\Bundle\MigrationBundle\Migration\Migration; use Oro\Bundle\MigrationBundle\Migration\QueryBag; class AddEnablePremiumFraudProtectionField implements Migration { /** - * @inheritDoc + * @throws SchemaException */ - public function up(Schema $schema, QueryBag $queries) + public function up(Schema $schema, QueryBag $queries): void { $table = $schema->getTable('oro_integration_transport'); if (!$table->hasColumn('braintree_fraud_advanced')) { diff --git a/src/Resources/config/event_listeners.yml b/src/Resources/config/event_listeners.yml index 58f330c4b..1b1b9fd34 100644 --- a/src/Resources/config/event_listeners.yml +++ b/src/Resources/config/event_listeners.yml @@ -1,10 +1,8 @@ services: - Aligent\BraintreeBundle\EventListener\PurchaseActionEventListener: - class: Aligent\BraintreeBundle\EventListener\PurchaseActionEventListener - tags: - - { name: kernel.event_listener, event: aligent_braintree.payment_action.purchase, method: onPurchase } + Aligent\BraintreeBundle\EventListener\PurchaseActionEventListener: + tags: + - { name: kernel.event_listener, event: aligent_braintree.payment_action, method: onPurchase } - Aligent\BraintreeBundle\EventListener\AdvancedFraudEventListener: - class: Aligent\BraintreeBundle\EventListener\AdvancedFraudEventListener - tags: - - { name: kernel.event_listener, event: aligent_braintree.payment_action.purchase, method: onPurchase } + Aligent\BraintreeBundle\EventListener\AdvancedFraudEventListener: + tags: + - { name: kernel.event_listener, event: aligent_braintree.payment_action, method: onPurchase } diff --git a/src/Resources/config/oro/twig.yml b/src/Resources/config/oro/twig.yml index a6a94b559..99ee92398 100644 --- a/src/Resources/config/oro/twig.yml +++ b/src/Resources/config/oro/twig.yml @@ -1,2 +1,2 @@ bundles: - - AligentBraintreeBundle:Form:fields.html.twig \ No newline at end of file + - '@AligentBraintree\Form\fields.html.twig' diff --git a/src/Resources/public/js/app/components/braintree-method-component.js b/src/Resources/public/js/app/components/braintree-method-component.js index 673d6f791..67a3ee4b9 100644 --- a/src/Resources/public/js/app/components/braintree-method-component.js +++ b/src/Resources/public/js/app/components/braintree-method-component.js @@ -123,7 +123,6 @@ define(function (require) { event.resume(); } ); - } } }, @@ -132,7 +131,7 @@ define(function (require) { * Request the nonce and store it * @param event */ - onPaymentMethodRequestable: function(event) { + onPaymentMethodRequestable: function (event) { if (event.paymentMethodIsSelected) { this.instance.requestPaymentMethod(this.storeAdditionalData.bind(this)); } @@ -142,7 +141,7 @@ define(function (require) { * Clear out the nonce input when the payment method is unavailable * @param event */ - onNoPaymentMethodRequestable: function(event) { + onNoPaymentMethodRequestable: function (event) { this.nonceInput.val(''); }, @@ -151,7 +150,7 @@ define(function (require) { * @param err * @param payload */ - storeAdditionalData: function(err, payload) { + storeAdditionalData: function (err, payload) { if (err) { console.error(err); this.instance.clearSelectedPaymentMethod(); diff --git a/src/Resources/public/js/app/components/order-review-component.js b/src/Resources/public/js/app/components/order-review-component.js index 448d2b02e..ba521ff47 100644 --- a/src/Resources/public/js/app/components/order-review-component.js +++ b/src/Resources/public/js/app/components/order-review-component.js @@ -20,7 +20,7 @@ define(function (require) { mediator.on('checkout:place-order:response', this.placeOrderResponse, this); }, - placeOrderResponse: function(eventData) { + placeOrderResponse: function (eventData) { if (eventData.responseData.paymentMethod === this.options.paymentMethod) { eventData.stopped = true; if (eventData.responseData.successful) { diff --git a/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.html.twig b/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.html.twig index a13b8f2f2..0af304970 100644 --- a/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.html.twig +++ b/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.html.twig @@ -6,6 +6,6 @@ data-page-component-options="{{ paymentMethodComponentOptions|json_encode }}" > - - + + {% endblock %} diff --git a/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.yml b/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.yml index 37a96525c..2647116a1 100644 --- a/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.yml +++ b/src/Resources/views/layouts/default/imports/oro_payment_method_options/layout.yml @@ -2,4 +2,4 @@ layout: actions: - '@setBlockTheme': themes: - - 'AligentBraintreeBundle:layouts:default/imports/oro_payment_method_options/layout.html.twig' \ No newline at end of file + - 'layout.html.twig' diff --git a/src/Resources/views/layouts/default/imports/oro_payment_method_order_submit/layout.yml b/src/Resources/views/layouts/default/imports/oro_payment_method_order_submit/layout.yml index 15dc72c0e..40fdc983e 100644 --- a/src/Resources/views/layouts/default/imports/oro_payment_method_order_submit/layout.yml +++ b/src/Resources/views/layouts/default/imports/oro_payment_method_order_submit/layout.yml @@ -2,4 +2,4 @@ layout: actions: - '@setBlockTheme': themes: - - 'AligentBraintreeBundle:layouts:default/imports/oro_payment_method_order_submit/layout.html.twig' \ No newline at end of file + - 'layout.html.twig' diff --git a/src/Tests/Unit/DependencyInjection/AligentBraintreeExtensionTest.php b/src/Tests/Unit/DependencyInjection/AligentBraintreeExtensionTest.php index 76790cea4..3ce5986eb 100644 --- a/src/Tests/Unit/DependencyInjection/AligentBraintreeExtensionTest.php +++ b/src/Tests/Unit/DependencyInjection/AligentBraintreeExtensionTest.php @@ -69,7 +69,6 @@ public function testLoad(): void AdvancedFraudEventListener::class, AbstractBraintreeAction::class, PurchaseAction::class, - ]; $this->assertDefinitionsLoaded($expectedDefinitions);