Skip to content

Commit

Permalink
PAYOSWXP-150: apple pay: add proxy controller for apple-pay routes
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Aug 16, 2024
1 parent 8262c59 commit 60fe538
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 7 deletions.
41 changes: 41 additions & 0 deletions src/Components/ApplePay/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Components\ApplePay\Controller;

use PayonePayment\Components\ApplePay\StoreApi\Route\AbstractApplePayRoute;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route(
path: '/payone/apple-pay/',
options: ['seo' => false],
defaults: [
'XmlHttpRequest' => true,
'_routeScope' => ['storefront'],
'_loginRequired' => true,
'_loginRequiredAllowGuest' => true,
],
)]
class CheckoutController
{
public function __construct(
private readonly AbstractApplePayRoute $route
) {
}

#[Route(path: 'validate-merchant', name: 'frontend.payone.apple-pay.validate-merchant', methods: ['POST'])]
public function validateMerchant(Request $request, SalesChannelContext $salesChannelContext): Response
{
return $this->route->validateMerchant($request, $salesChannelContext);
}

#[Route(path: 'process-payment', name: 'frontend.payone.apple-pay.process-payment', methods: ['POST'])]
public function processPayment(Request $request, SalesChannelContext $salesChannelContext): Response
{
return $this->route->process($request, $salesChannelContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PayonePayment\StoreApi\Route;
namespace PayonePayment\Components\ApplePay\StoreApi\Route;

use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PayonePayment\StoreApi\Route;
namespace PayonePayment\Components\ApplePay\StoreApi\Route;

use GuzzleHttp\Client;
use PayonePayment\Components\ConfigReader\ConfigReaderInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PayonePayment\Controller;

use PayonePayment\Components\ApplePay\StoreApi\Route\ApplePayRoute;
use PayonePayment\Configuration\ConfigurationPrefixes;
use PayonePayment\PaymentHandler as Handler;
use PayonePayment\Payone\Client\Exception\PayoneRequestException;
Expand All @@ -12,7 +13,6 @@
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\RequestParameterFactory;
use PayonePayment\Payone\RequestParameter\Struct\TestCredentialsStruct;
use PayonePayment\StoreApi\Route\ApplePayRoute;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\Framework\Context;
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,9 @@
<tag name="controller.service_arguments" />
</service>

<service id="PayonePayment\Components\ApplePay\Controller\CheckoutController" autowire="true">
<tag name="controller.service_arguments" />
</service>

</services>
</container>
5 changes: 4 additions & 1 deletion src/DependencyInjection/store_api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<argument type="service" id="PayonePayment\Components\CardRepository\CardRepository" />
</service>

<service id="PayonePayment\StoreApi\Route\ApplePayRoute">
<service id="PayonePayment\Components\ApplePay\StoreApi\Route\AbstractApplePayRoute"
alias="PayonePayment\Components\ApplePay\StoreApi\Route\ApplePayRoute"/>

<service id="PayonePayment\Components\ApplePay\StoreApi\Route\ApplePayRoute">
<argument type="service" id="payone.app_system.guzzle" />
<argument type="service" id="monolog.logger.payone" />
<argument type="service" id="PayonePayment\Payone\RequestParameter\RequestParameterFactory"/>
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/CheckoutConfirmApplePayEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace PayonePayment\EventListener;

use PayonePayment\Components\ApplePay\StoreApi\Route\ApplePayRoute;
use PayonePayment\Core\Utils\PayoneClassLoader;
use PayonePayment\PaymentMethod\PayoneApplePay;
use PayonePayment\StoreApi\Route\ApplePayRoute;
use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/routes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="../../**/Controller/**/*" type="attribute" />
<import resource="../../**/StoreApi/Route/**/*" type="attribute" />
<import resource="../../StoreApi/Route/*" type="attribute" />
</routes>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<input type="hidden" name="orderId" value="{{ page.order.id }}"/>

<apple-pay-button
data-validate-merchant-url="{{ path('store-api.payone.apple-pay.validate-merchant') }}"
data-process-payment-url="{{ path('store-api.payone.apple-pay.process') }}"
data-validate-merchant-url="{{ path('frontend.payone.apple-pay.validate-merchant') }}"
data-process-payment-url="{{ path('frontend.payone.apple-pay.process-payment') }}"
data-payone-payment-apple-pay-options='{
"countryCode": "{{ context.customer.defaultBillingAddress.country.iso }}",
"currencyCode": "{{ context.currency.isoCode }}",
Expand Down

0 comments on commit 60fe538

Please sign in to comment.