Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions Block/Formjs.php

This file was deleted.

6 changes: 5 additions & 1 deletion Cron/AutoCaptureDeferredPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Payplug\Payments\Gateway\Config\Standard;
use Payplug\Payments\Helper\Config;
use Payplug\Payments\Logger\Logger;
use Payplug\Payments\Service\InitEnvQa;

class AutoCaptureDeferredPayments
{
Expand All @@ -41,7 +42,8 @@ public function __construct(
private readonly Transaction $transaction,
private readonly Config $config,
private readonly TransportBuilder $transportBuilder,
private readonly OrderIdentity $orderIdentity
private readonly OrderIdentity $orderIdentity,
private readonly InitEnvQa $initEnvQa
) {
}

Expand All @@ -53,6 +55,8 @@ public function execute(): void
{
$this->logger->info('Running the AutoCaptureDeferredPayments cron');

$this->initEnvQa->execute();

// All the invoiceable order will populate this array
$orderToInvoiceIds = [];

Expand Down
18 changes: 11 additions & 7 deletions Cron/CheckOrderConsistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Magento\Framework\Api\SearchCriteriaBuilderFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Store\Model\ScopeInterface;
use Payplug\Exception\PayplugException;
use Payplug\Payments\Helper\Data;
use Payplug\Payments\Logger\Logger;
use Payplug\Payments\Service\InitEnvQa;
use Payplug\Resource\Payment as ResourcePayment;

class CheckOrderConsistency
Expand All @@ -24,11 +25,12 @@ class CheckOrderConsistency
public const PAST_HOURS_TO_CHECK = 4;

public function __construct(
private Logger $logger,
private SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
private OrderPaymentRepositoryInterface $paymentRepository,
private OrderRepositoryInterface $orderRepository,
private Data $payplugHelper
private readonly Logger $logger,
private readonly SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
private readonly OrderPaymentRepositoryInterface $paymentRepository,
private readonly OrderRepositoryInterface $orderRepository,
private readonly Data $payplugHelper,
private readonly InitEnvQa $initEnvQa
) {
}

Expand All @@ -39,6 +41,8 @@ public function execute(): void
{
$this->logger->info('Running the CheckOrderConsistency cron');

$this->initEnvQa->execute();

$magentoOrdersPayments = $this->getCheckablePayplugOrderPaymentsList();

if (count($magentoOrdersPayments) >= 0) {
Expand Down Expand Up @@ -86,7 +90,7 @@ public function execute(): void
$this->logger->info(
sprintf(
'No payplug payment found for the magento order %s.',
$magentoOrder->getEntityId()
$magentoOrder->getEntityId()
)
);
}
Expand Down
22 changes: 22 additions & 0 deletions Observer/InitEnvQaOnFrontDispatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Payplug\Payments\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use Payplug\Payments\Service\InitEnvQa;

class InitEnvQaOnFrontDispatch implements ObserverInterface
{
public function __construct(
private readonly InitEnvQa $initEnvQa
) {
}

public function execute(Observer $observer): void
{
$this->initEnvQa->execute();
}
}
24 changes: 24 additions & 0 deletions Plugin/InitEnvQaOnRestDispatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Payplug\Payments\Plugin;

use Magento\Framework\App\RequestInterface as Request;
use Magento\Webapi\Controller\Rest;
use Payplug\Payments\Service\InitEnvQa;

class InitEnvQaOnRestDispatch
{
public function __construct(
private readonly InitEnvQa $initEnvQa
) {
}

public function beforeDispatch(Rest $subject, Request $request): array
{
$this->initEnvQa->execute();

return [$request];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return null;

}
}
40 changes: 40 additions & 0 deletions Service/InitEnvQa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Payplug\Payments\Service;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Payplug\Core\APIRoutes as BaseAPIRoutes;

class InitEnvQa
{
public const XML_PATH_ENABLE_QA = 'payplug_payments/qa/enable';
private const XML_PATH_PAYPLUG_API_URL_KEY = 'payplug_payments/qa/api_url';
private const XML_PATH_PAYPLUG_SERVICE_URL_KEY = 'payplug_payments/qa/service_url';

public function __construct(
private readonly ScopeConfigInterface $scopeConfig
) {
}

public function execute(): bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void maybe, as bool result is not used later on.

Version with additional optims :

public function initRoutes(): void
{
    if (!$this->isQaEnabled()) {
        return;
    }

    $apiUrl = trim((string) $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_API_URL_KEY));
    $serviceUrl = trim((string) $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_SERVICE_URL_KEY));

    if ($this->canInitRoutes($apiUrl, $serviceUrl)) {
        BaseAPIRoutes::setApiBaseUrl($apiUrl);
        BaseAPIRoutes::setServiceBaseUrl($serviceUrl);
    }
}

private function canInitRoutes(string $apiUrl, string $serviceUrl): bool
{
    return $apiUrl !== '' && $serviceUrl !== '';
}
  1. early return
  2. Trim & cast
  3. better split of responsibilities
  4. !== '' better than empty()

{
$apiUrl = $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_API_URL_KEY);
$serviceUrl = $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_SERVICE_URL_KEY);

if ($this->isQaEnabled() === false || empty($apiUrl) || empty($serviceUrl)) {
return false;
}

BaseAPIRoutes::setApiBaseUrl($apiUrl);
BaseAPIRoutes::setServiceBaseUrl($serviceUrl);

return true;
}

public function isQaEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLE_QA);
}
}
55 changes: 55 additions & 0 deletions ViewModel/UrlProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Payplug\Payments\ViewModel;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Store\Model\ScopeInterface;
use Payplug\Payments\Service\InitEnvQa;

class UrlProvider implements ArgumentInterface
{
private const XML_PATH_PAYPLUG_SECURE_URL_KEY = 'payplug_payments/qa/secure_url';
private const XML_PATH_PAYPLUG_INTEGRATED_PAYMENT_JS_URL_KEY = 'payplug_payments/qa/integrated_payment_js_url';
private const DEFAULT_SECURE_URL = 'https://secure.payplug.com';
private const DEFAULT_INTEGRATED_PAYMENT_JS_URL = 'https://cdn.payplug.com/js/integrated-payment/v1/index';
private const APPLEPAY_SDK_URL = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';

public function __construct(
private readonly ScopeConfigInterface $scopeConfig,
private readonly InitEnvQa $initEnvQa
) {
}

public function getPayplugSecureUrl(): string
{
$customSecureUrl = $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_SECURE_URL_KEY);

if ($this->initEnvQa->isQaEnabled() === true && $customSecureUrl) {
return $customSecureUrl;
}

return self::DEFAULT_SECURE_URL;
}

public function getPayplugIntegratedPaymentJsUrl(): string
{
$customIntegratedPaymentJsUrl = $this->scopeConfig->getValue(self::XML_PATH_PAYPLUG_INTEGRATED_PAYMENT_JS_URL_KEY);

if ($this->initEnvQa->isQaEnabled() === true && $customIntegratedPaymentJsUrl) {
return $customIntegratedPaymentJsUrl;
}

return self::DEFAULT_INTEGRATED_PAYMENT_JS_URL;
}

public function isApplePayEnabled(): bool
{
return $this->scopeConfig->isSetFlag('payment/payplug_payments_apple_pay/active', ScopeInterface::SCOPE_STORE);
}

public function getApplePaySdkUrl(): string
{
return self::APPLEPAY_SDK_URL;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"magento/module-sales": "102.0.*|103.0.*",
"payplug/payplug-php": "^4.0.0",
"giggsey/libphonenumber-for-php": "^8.10",
"symfony/dotenv": "*",
"ext-openssl": "*"
},
"autoload": {
Expand Down
7 changes: 7 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
<field id="client_data"/>
<field id="access_token_data"/>
</group>
<group id="qa">
<field id="enable"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a config.xml to have this setting disabled by default would be better/an additional security ?

<field id="api_url"/>
<field id="service_url"/>
<field id="secure_url"/>
<field id="integrated_payment_js_url"/>
</group>
</section>
<section id="payment" type="text" sortOrder="400" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="payplug_payments_standard" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down
1 change: 1 addition & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<observer name="payplug_payments_section_payment_saved" instance="Payplug\Payments\Observer\PaymentConfigObserver"/>
</event>
<event name="controller_action_predispatch">
<observer name="payplug_payments_init_env_qa_on_front_dispatch" instance="Payplug\Payments\Observer\InitEnvQaOnFrontDispatch" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of doing this on every request.

Could we be more precise and specific (maybe only on certain layout handles and mandatory ones?)

<observer name="payplug_payments_display_notice" instance="Payplug\Payments\Observer\DisplayNoticeObserver" />
</event>
<event name="controller_action_predispatch_sales_order_creditmemo_new">
Expand Down
6 changes: 6 additions & 0 deletions etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Webapi\Controller\Rest">
<plugin name="payplug_payments_init_env_qa_on_rest_dispatch" type="Payplug\Payments\Plugin\InitEnvQaOnRestDispatch"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of doing this on every request.

Could we be more precise and specific ?

</type>
</config>
6 changes: 5 additions & 1 deletion view/frontend/layout/catalog_product_view_applepay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.components">
<block class="Payplug\Payments\Block\Formjs" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class attribute not needed (default is Template already)

<arguments>
<argument name="urlProviderViewModel" xsi:type="object">Payplug\Payments\ViewModel\UrlProvider</argument>
</arguments>
</block>
</referenceBlock>

<referenceContainer name="product.info.form.content">
Expand Down
6 changes: 5 additions & 1 deletion view/frontend/layout/checkout_cart_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.components">
<block class="Payplug\Payments\Block\Formjs" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class attribute not needed (default is Template already)

<arguments>
<argument name="urlProviderViewModel" xsi:type="object">Payplug\Payments\ViewModel\UrlProvider</argument>
</arguments>
</block>
</referenceBlock>

<referenceContainer name="checkout.cart.totals.container">
Expand Down
6 changes: 5 additions & 1 deletion view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.components">
<block class="Payplug\Payments\Block\Formjs" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class attribute not needed (default is Template already)

<arguments>
<argument name="urlProviderViewModel" xsi:type="object">Payplug\Payments\ViewModel\UrlProvider</argument>
</arguments>
</block>
</referenceBlock>
<referenceBlock name="checkout.root">
<arguments>
Expand Down
6 changes: 5 additions & 1 deletion view/frontend/layout/onestepcheckout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.components">
<block class="Payplug\Payments\Block\Formjs" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="payplug_payments_formjs" template="Payplug_Payments::checkout/formjs.phtml">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class attribute not needed (default is Template already)

<arguments>
<argument name="urlProviderViewModel" xsi:type="object">Payplug\Payments\ViewModel\UrlProvider</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
5 changes: 1 addition & 4 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ const config = {
'*': {
'oneyPopin': 'Payplug_Payments/js/view/oney/popin'
}
},
paths: {
'payplugIntegrated': 'https://cdn.payplug.com/js/integrated-payment/v1/index'
}
};
};
Loading
Loading