Skip to content

Commit 4da829c

Browse files
committed
feat: add local environment toggle (#463)
1 parent 479547b commit 4da829c

File tree

23 files changed

+310
-24
lines changed

23 files changed

+310
-24
lines changed

.bc-exclude.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
\preg_quote('An enum expression Monolog\Level::Debug is not supported in class Monolog\Handler\AbstractHandler'),
1010
// Storefront package is not installed
1111
\preg_quote('"Shopware\Storefront\Framework\Cookie\CookieProviderInterface" could not be found in the located source'),
12+
// internal const
13+
\preg_quote('Value of constant Swag\PayPal\Setting\Settings::DEFAULT_VALUES changed from array') . '.*',
1214
],
1315
];

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# REPLACE_GLOBALLY_WITH_NEXT_VERSION
22
- Fixes an issue, where cookies are added even though associated payment methods are not active (shopware/SwagPayPal#457)
3+
- Added setting to mark the shop as local environment to preventing connection issues when testing in a non public accessable environment (shopware/SwagPayPal#463)
34

45
# 9.9.0
56
- Fixes an issue, where Paypal Express Checkout does not recalculate cart price after changing shipping country (shopware/SwagPayPal#342)

CHANGELOG_de-DE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# REPLACE_GLOBALLY_WITH_NEXT_VERSION
22
- Behebt ein Problem, bei dem Cookies geladen wurden, obwohl die zugehörigen Zahlungsarten nicht aktiv sind (shopware/SwagPayPal#457)
3+
- Fügt eine Einstellung hinzu, um den Shop als lokale Umgebung zu kennzeichnen, um Verbindungsprobleme beim Testen in einer nicht öffentlich zugänglichen Umgebung zu vermeiden (shopware/SwagPayPal#463)
34

45
# 9.9.0
56
- Behebt ein Problem, bei dem der Warenkorbpreis beim Verändern des Versandlandes im Express Checkout nicht angepasst wurde (shopware/SwagPayPal#342)

src/Checkout/ExpressCheckout/SalesChannel/ExpressCreateOrderRoute.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
1515
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
1616
use Shopware\Core\System\SalesChannel\SalesChannelContext;
17+
use Shopware\Core\System\SystemConfig\SystemConfigService;
1718
use Swag\PayPal\Checkout\Cart\Service\CartPriceService;
1819
use Swag\PayPal\Checkout\Exception\OrderZeroValueException;
1920
use Swag\PayPal\Checkout\TokenResponse;
@@ -22,6 +23,7 @@
2223
use Swag\PayPal\RestApi\V2\Api\Order\ApplicationContext;
2324
use Swag\PayPal\RestApi\V2\Api\Order\PaymentSource\Common\Attributes\OrderUpdateCallbackConfig;
2425
use Swag\PayPal\RestApi\V2\Resource\OrderResource;
26+
use Swag\PayPal\Setting\Settings;
2527
use Symfony\Component\HttpFoundation\Request;
2628
use Symfony\Component\HttpFoundation\Response;
2729
use Symfony\Component\Routing\Attribute\Route;
@@ -40,6 +42,7 @@ public function __construct(
4042
private readonly PayPalOrderBuilder $paypalOrderBuilder,
4143
private readonly OrderResource $orderResource,
4244
private readonly CartPriceService $cartPriceService,
45+
private readonly SystemConfigService $systemConfigService,
4346
private readonly RouterInterface $router,
4447
private readonly LoggerInterface $logger,
4548
) {
@@ -80,17 +83,21 @@ public function createPayPalOrder(Request $request, SalesChannelContext $salesCh
8083
$experienceContext->setUserAction(ApplicationContext::USER_ACTION_CONTINUE);
8184

8285
// Configure shipping callback for dynamic price recalculation
83-
$callbackConfig = new OrderUpdateCallbackConfig();
84-
$callbackUrl = $this->router->generate(
85-
'store-api.paypal.express.shipping_callback',
86-
['salesChannelId' => $salesChannelContext->getSalesChannelId(), 'token' => $salesChannelContext->getToken()],
87-
UrlGeneratorInterface::ABSOLUTE_URL,
88-
);
89-
$callbackConfig->setCallbackUrl($callbackUrl);
90-
$callbackConfig->setCallbackEvents([OrderUpdateCallbackConfig::CALLBACK_EVENT_SHIPPING_OPTIONS]);
91-
$experienceContext->setOrderUpdateCallbackConfig($callbackConfig);
86+
if (!$this->systemConfigService->getBool(Settings::IS_LOCAL_ENVIRONMENT, $salesChannelContext->getSalesChannelId())) {
87+
$callbackConfig = new OrderUpdateCallbackConfig();
88+
$callbackUrl = $this->router->generate(
89+
'store-api.paypal.express.shipping_callback',
90+
['salesChannelId' => $salesChannelContext->getSalesChannelId(), 'token' => $salesChannelContext->getToken()],
91+
UrlGeneratorInterface::ABSOLUTE_URL,
92+
);
93+
$callbackConfig->setCallbackUrl($callbackUrl);
94+
$callbackConfig->setCallbackEvents([OrderUpdateCallbackConfig::CALLBACK_EVENT_SHIPPING_OPTIONS]);
95+
$experienceContext->setOrderUpdateCallbackConfig($callbackConfig);
9296

93-
$this->logger->debug('Configured shipping callback', ['callbackUrl' => $callbackUrl]);
97+
$this->logger->debug('Configured shipping callback', ['callbackUrl' => $callbackUrl]);
98+
} else {
99+
$this->logger->debug('Skipped shipping callback due to being disabled in system config');
100+
}
94101
}
95102

96103
$orderResponse = $this->orderResource->create(

src/Resources/app/administration/src/app/snippet/de-DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"vaultingEnabledACDC": "Vaulting für Kredit- und Debitkarten-Zahlungen verwenden",
8080
"vaultingEnabledVenmo": "Vaulting für Venmo-Zahlungen verwenden",
8181
"crossBorderMessagingEnabled" : "Länderübergreifende Lokalisierung der \"Später bezahlen\"-Nachricht aktivieren",
82-
"crossBorderBuyerCountry" : "Lokalisierung"
82+
"crossBorderBuyerCountry" : "Lokalisierung",
83+
"isLocalEnvironment": "Lokale Entwicklungsumgebung"
8384
},
8485
"helpText": {
8586
"clientId": "Die Client-ID der REST-API, die das Plugin dazu verwendet, sich mit der PayPal-API zu authentifizieren.",

src/Resources/app/administration/src/app/snippet/en-GB.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"vaultingEnabledACDC": "Enable Vaulting for credit and debit cards",
8080
"vaultingEnabledVenmo": "Enable Vaulting for Venmo payments",
8181
"crossBorderMessagingEnabled" : "Enable cross-border localization of Pay Later message",
82-
"crossBorderBuyerCountry" : "Localization"
82+
"crossBorderBuyerCountry" : "Localization",
83+
"isLocalEnvironment": "Local development environment"
8384
},
8485
"helpText": {
8586
"clientId": "The REST API client ID is used to authenticate this plugin with the PayPal API.",

src/Resources/app/administration/src/constant/swag-paypal-settings.constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const SYSTEM_CONFIGS = [
140140
'SwagPayPal.settings.webhookId',
141141
'SwagPayPal.settings.webhookExecuteToken',
142142

143+
'SwagPayPal.settings.isLocalEnvironment',
143144

144145
/**
145146
* @deprecated tag:v10.0.0 - Will be removed without replacement.

src/Resources/app/administration/src/module/swag-paypal-settings/snippet/de-DE.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
"info": "Mit länderübergreifende Nachrichten für \"Später bezahlen\" wird die \"Später bezahlen\"-Nachricht in der Sprache des Kunden anzeigt. Diese Funktion ist nur für bestimmte Länder verfügbar. {0}",
104104
"buyerCountryAuto": "Automatische Bestimmung",
105105
"buyerCountryOverride": "Lokalisierung"
106+
},
107+
"environment": {
108+
"title": "Umgebung",
109+
"info": "PayPal sendet Bestellstatus-Updates über Webhooks an den Shop und fordert außerdem eine Neuberechnung des Warenkorbs an, wenn Kunden Änderungen in der PayPal Express Checkout-Benutzeroberfläche vornehmen. Wenn der Shop nicht öffentlich zugänglich ist (z. B. wenn es sich um eine Entwicklungs-/Staging-Umgebung handelt oder eine Authentifizierung erfordert), kannst du diese Instanz als \"lokale Umgebung\" kennzeichnen, um Verbindungsfehler zu vermeiden.\nBitte beachte, dass alle Webhook-Listener beim Speichern deregistriert werden."
106110
}
107111
},
108112
"swag-paypal-settings-sales-channel-switch": {

src/Resources/app/administration/src/module/swag-paypal-settings/snippet/en-GB.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
"info": "Pay Later messaging is a feature that allows you to display a Pay Later message in the language of the customer. This feature is only available for certain countries. {0}",
104104
"buyerCountryAuto": "Automatic determination",
105105
"buyerCountryOverride": "Localization"
106+
},
107+
"environment": {
108+
"title": "Environment",
109+
"info": "PayPal will send order status updates to the shop via webhooks, and will also request cart recalculations when customers make changes in the PayPal Express Checkout UI. If the shop is not publicly accessible (e.g. if it is in a development/staging environment, or if it requires authentication), you can mark this instance as a \"local environment\" to prevent connection errors.\nPlease note that any webhook listener will be deregistered when saving."
106110
}
107111
},
108112
"swag-paypal-settings-sales-channel-switch": {

src/Resources/app/administration/src/module/swag-paypal-settings/view/swag-paypal-settings-advanced/swag-paypal-settings-advanced.html.twig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
<sw-card
2+
class="swag-paypal-settings-environment"
3+
position-identifier="swag-paypal-settings-environment"
4+
:title="$t('swag-paypal-settings.environment.title')"
5+
:is-loading="settingsStore.isLoading"
6+
>
7+
<span class="swag-paypal-settings-environment__info-text">
8+
{{ $t('swag-paypal-settings.environment.info') }}
9+
</span>
10+
11+
<swag-paypal-setting path="SwagPayPal.settings.isLocalEnvironment" />
12+
</sw-card>
13+
114
{% block swag_paypal_settings_webhook %}
215
<swag-paypal-settings-webhook />
316
{% endblock %}

0 commit comments

Comments
 (0)