Skip to content
Closed
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
20 changes: 20 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ services:
- name: sylius.payment_request.provider.http_response
gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory::FACTORY_NAME

## Wero Payplug Gateway ##
payplug_sylius_payplug_plugin.command_provider.payplug_wero:
class: Sylius\Bundle\PaymentBundle\CommandProvider\ActionsCommandProvider
arguments:
- !tagged_locator
tag: payplug_sylius_payplug_plugin.command_provider.payplug_wero
index_by: 'action'
tags:
- name: sylius.payment_request.command_provider
gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory::FACTORY_NAME
payplug_sylius_payplug_plugin.provider.order_pay.http_response.payplug_wero:
class: Sylius\Bundle\PaymentBundle\Provider\ActionsHttpResponseProvider
arguments:
- !tagged_locator
tag: payplug_sylius_payplug_plugin.http_response_provider.payplug_wero
index_by: action
tags:
- name: sylius.payment_request.provider.http_response
gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory::FACTORY_NAME


## Apple Pay Payplug Gateway ##
payplug_sylius_payplug_plugin.command_provider.payplug_apple_pay:
Expand Down
9 changes: 9 additions & 0 deletions config/services/client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,14 @@
method="create"/>
<argument type="string" key="$factoryName">payplug_scalapay</argument><!-- Gateway factory name -->
</service>

<service id="payplug_sylius_payplug_plugin.api_client.wero"
class="PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClient"
public="true"
lazy="true">
<factory service="PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientFactory"
method="create"/>
<argument type="string" key="$factoryName">payplug_wero</argument><!-- Gateway factory name -->
</service>
</services>
</container>
8 changes: 8 additions & 0 deletions config/services/gateway.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@
<tag name="payum.gateway_factory_builder"
factory="payplug_scalapay"/>
</service>

<!-- Gateway Wero by PayPlug -->
<service id="payplug_sylius_payplug_plugin.gateway_factory.wero"
class="Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder">
<argument type="string">PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory</argument>
<tag name="payum.gateway_factory_builder"
factory="payplug_wero"/>
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions config/twig_hooks/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ sylius_twig_hooks:
'sylius_admin.payment_method.create.content.form.sections.gateway_configuration.payplug_scalapay': &scalapayGateway
live_checkbox: *liveCheckbox

'sylius_admin.payment_method.create.content.form.sections.gateway_configuration.payplug_wero': &weroGateway
live_checkbox: *liveCheckbox

'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug':
<<: *payplugGateway
renew_oauth: &renewOAuth
Expand All @@ -53,3 +56,6 @@ sylius_twig_hooks:
'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug_scalapay':
<<: *scalapayGateway
renew_oauth: *renewOAuth
'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug_wero':
<<: *weroGateway
renew_oauth: *renewOAuth
3 changes: 3 additions & 0 deletions config/twig_hooks/shop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ sylius_twig_hooks:
'sylius_shop.shared.form.select_payment.payment.choice.details#payplug_scalapay':
scalapay:
template: '@PayPlugSyliusPayPlugPlugin/shop/select_payment/_scalapay.html.twig'
'sylius_shop.shared.form.select_payment.payment.choice.details#payplug_wero':
wero:
template: '@PayPlugSyliusPayPlugPlugin/shop/select_payment/_wero.html.twig'
41 changes: 41 additions & 0 deletions public/assets/wero/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ruleset/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,12 @@ parameters:
count: 1
path: ../src/Resolver/ScalapayPaymentMethodsResolverDecorator.php

-
message: '#^Method PayPlug\\SyliusPayPlugPlugin\\Resolver\\WeroPaymentMethodsResolverDecorator\:\:getSupportedMethods\(\) should return array\<Sylius\\Component\\Payment\\Model\\PaymentMethodInterface\> but returns array\.$#'
identifier: return.type
count: 1
path: ../src/Resolver/WeroPaymentMethodsResolverDecorator.php

-
message: '#^Call to method apply\(\) on an unknown class SM\\StateMachine\\StateMachineInterface\.$#'
identifier: class.notFound
Expand Down
4 changes: 4 additions & 0 deletions src/Command/Provider/CapturePaymentRequestCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay',
['action' => PaymentRequestInterface::ACTION_CAPTURE],
)]
#[AutoconfigureTag(
'payplug_sylius_payplug_plugin.command_provider.payplug_wero',
['action' => PaymentRequestInterface::ACTION_CAPTURE],
)]
final class CapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface
{
public function supports(PaymentRequestInterface $paymentRequest): bool
Expand Down
4 changes: 4 additions & 0 deletions src/Command/Provider/NotifyPaymentRequestCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay',
['action' => PaymentRequestInterface::ACTION_NOTIFY],
)]
#[AutoconfigureTag(
'payplug_sylius_payplug_plugin.command_provider.payplug_wero',
['action' => PaymentRequestInterface::ACTION_NOTIFY],
)]
final class NotifyPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface
{
public function supports(PaymentRequestInterface $paymentRequest): bool
Expand Down
4 changes: 4 additions & 0 deletions src/Command/Provider/StatusPaymentRequestCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay',
['action' => PaymentRequestInterface::ACTION_STATUS],
)]
#[AutoconfigureTag(
'payplug_sylius_payplug_plugin.command_provider.payplug_wero',
['action' => PaymentRequestInterface::ACTION_STATUS],
)]
final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface
{
public function __construct(private RequestStack $requestStack)
Expand Down
2 changes: 2 additions & 0 deletions src/Creator/PayPlugPaymentDataCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
Expand Down Expand Up @@ -355,6 +356,7 @@ private function addPaymentMethodFieldToDetails(ArrayObject $details, string $ga
ApplePayGatewayFactory::FACTORY_NAME => ApplePayGatewayFactory::PAYMENT_METHOD_APPLE_PAY,
AmericanExpressGatewayFactory::FACTORY_NAME => AmericanExpressGatewayFactory::PAYMENT_METHOD_AMERICAN_EXPRESS,
ScalapayGatewayFactory::FACTORY_NAME => ScalapayGatewayFactory::PAYMENT_METHOD_SCALAPAY,
WeroGatewayFactory::FACTORY_NAME => WeroGatewayFactory::PAYMENT_METHOD_WERO,
];
// match function is only supported by php 8. so can not use it here.
foreach ($paymentMethods as $name => $method) {
Expand Down
25 changes: 25 additions & 0 deletions src/Gateway/Form/Type/WeroGatewayConfigurationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace PayPlug\SyliusPayPlugPlugin\Gateway\Form\Type;

use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag(
'sylius.gateway_configuration_type',
[
'type' => 'payplug_wero',
'label' => 'payplug_sylius_payplug_plugin.ui.wero_gateway_label',
'priority' => 90,
],
)]
final class WeroGatewayConfigurationType extends AbstractGatewayConfigurationType
{
protected string $gatewayFactoryTitle = WeroGatewayFactory::FACTORY_TITLE;

protected string $gatewayFactoryName = WeroGatewayFactory::FACTORY_NAME;

protected string $gatewayBaseCurrencyCode = WeroGatewayFactory::BASE_CURRENCY_CODE;
}
14 changes: 14 additions & 0 deletions src/Gateway/WeroGatewayFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace PayPlug\SyliusPayPlugPlugin\Gateway;

final class WeroGatewayFactory extends AbstractGatewayFactory
{
public const FACTORY_NAME = 'payplug_wero';

public const FACTORY_TITLE = 'Wero by PayPlug';

public const PAYMENT_METHOD_WERO = 'wero';
}
2 changes: 2 additions & 0 deletions src/MessageHandler/RefundPaymentGeneratedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentProcessor;
use PayPlug\SyliusPayPlugPlugin\Repository\RefundHistoryRepositoryInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -74,6 +75,7 @@ public function __invoke(RefundPaymentGenerated $message): void
ApplePayGatewayFactory::FACTORY_NAME,
AmericanExpressGatewayFactory::FACTORY_NAME,
ScalapayGatewayFactory::FACTORY_NAME,
WeroGatewayFactory::FACTORY_NAME,
], true)
) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/OrderPay/Provider/CaptureHttpResponseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
'payplug_sylius_payplug_plugin.http_response_provider.payplug_scalapay',
['action' => PaymentRequestInterface::ACTION_CAPTURE],
)]
#[AutoconfigureTag(
'payplug_sylius_payplug_plugin.http_response_provider.payplug_wero',
['action' => PaymentRequestInterface::ACTION_CAPTURE],
)]
Comment on lines +38 to +41
class CaptureHttpResponseProvider implements HttpResponseProviderInterface
{
public function supports(RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest): bool
Expand Down
2 changes: 2 additions & 0 deletions src/PaymentProcessing/RefundPaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Repository\RefundHistoryRepositoryInterface;
use Psr\Log\LoggerInterface;
use Sylius\Component\Core\Model\PaymentInterface;
Expand Down Expand Up @@ -126,6 +127,7 @@ private function prepare(PaymentInterface $payment): void
ApplePayGatewayFactory::FACTORY_NAME,
AmericanExpressGatewayFactory::FACTORY_NAME,
ScalapayGatewayFactory::FACTORY_NAME,
WeroGatewayFactory::FACTORY_NAME,
], true)
) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace PayPlug\SyliusPayPlugPlugin\Provider;

use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;

#[AsDecorator(SupportedRefundPaymentMethodsProviderDecorator::class)]
final class WeroSupportedRefundPaymentMethodsProviderDecorator extends AbstractSupportedRefundPaymentMethodsProvider implements RefundPaymentMethodsProviderInterface
{
protected string $gatewayFactoryName = WeroGatewayFactory::FACTORY_NAME;
}
48 changes: 48 additions & 0 deletions src/Resolver/WeroPaymentMethodsResolverDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace PayPlug\SyliusPayPlugPlugin\Resolver;

use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use PayPlug\SyliusPayPlugPlugin\Provider\SupportedMethodsProvider;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\Payment;
use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface;
use Sylius\Component\Payment\Resolver\PaymentMethodsResolverInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
use Webmozart\Assert\Assert;

#[AsDecorator('sylius.resolver.payment_methods')]
final class WeroPaymentMethodsResolverDecorator implements PaymentMethodsResolverInterface
{
public function __construct(
#[AutowireDecorated]
private PaymentMethodsResolverInterface $decorated,
private SupportedMethodsProvider $supportedMethodsProvider,
) {
}

public function getSupportedMethods(BasePaymentInterface $subject): array
{
Assert::isInstanceOf($subject, Payment::class);
$supportedMethods = $this->decorated->getSupportedMethods($subject);

Comment on lines +27 to +31
/** @var OrderInterface $order */
$order = $subject->getOrder();
$billingCountryCode = $order->getBillingAddress()?->getCountryCode();

return $this->supportedMethodsProvider->provide(
$supportedMethods,
WeroGatewayFactory::FACTORY_NAME,
$subject->getAmount() ?? 0,
$billingCountryCode,
);
}

public function supports(BasePaymentInterface $subject): bool
{
return $this->decorated->supports($subject);
}
}
9 changes: 9 additions & 0 deletions src/Validator/PaymentMethodValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\IsCanSavePaymentMethod;
use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\IsOneyEnabled;
use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\PayplugPermission;
use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\ConstraintViolationListInterface;
Expand Down Expand Up @@ -48,6 +49,7 @@ public function process(PaymentMethodInterface $paymentMethod): void
AmericanExpressGatewayFactory::FACTORY_NAME => $this->processAmex($paymentMethod),
ApplePayGatewayFactory::FACTORY_NAME => $this->processApplePay($paymentMethod),
ScalapayGatewayFactory::FACTORY_NAME => $this->processScalapay($paymentMethod),
WeroGatewayFactory::FACTORY_NAME => $this->processWero($paymentMethod),
default => throw new \InvalidArgumentException('Unsupported payment method'),
};

Expand Down Expand Up @@ -113,4 +115,11 @@ private function processScalapay(PaymentMethodInterface $paymentMethod): Constra

return $this->validator->validate($paymentMethod, $constraintList, self::VALIDATION_GROUPS);
}

private function processWero(PaymentMethodInterface $paymentMethod): ConstraintViolationListInterface
{
$constraintList = [new IsCanSavePaymentMethod()];

return $this->validator->validate($paymentMethod, $constraintList, self::VALIDATION_GROUPS);
}
}
6 changes: 3 additions & 3 deletions templates/shop/integrated/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set initRouteParam = {'paymentMethodId': paymentMethod.id} %}
{% set init_route_param = {'paymentMethodId': paymentMethod.id} %}
{% if order is defined and order.getCheckoutCompletedAt is not null and order.tokenValue is not null %}
{% set initRouteParam = initRouteParam|merge({'orderToken': order.tokenValue}) %}
{% set init_route_param = init_route_param|merge({'orderToken': order.tokenValue}) %}
{% endif %}

<script type="text/javascript" src="https://cdn.payplug.com/js/integrated-payment/v1/index.js"></script>
Expand All @@ -14,7 +14,7 @@
payment_id: '{{ payment.details.payment_id }}',
{% endif %}
routes: {
init_payment: '{{ path('payplug_sylius_integrated_payment_init', initRouteParam) }}',
init_payment: '{{ path('payplug_sylius_integrated_payment_init', init_route_param) }}',
},
cardholder: '{{ 'payplug_sylius_payplug_plugin.ui.integrated_payment.card_holder.title'|trans }}',
pan: '{{ 'payplug_sylius_payplug_plugin.ui.integrated_payment.pan.title'|trans }}',
Expand Down
7 changes: 7 additions & 0 deletions templates/shop/select_payment/_wero.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% set form = hookable_metadata.context.form %}

<div {{ stimulus_controller('@payplug/sylius-payplug-plugin/payment-logo', {
inputId: form.vars.id,
logoUrl: asset('bundles/payplugsyliuspayplugplugin/assets/wero/logo.svg'),
className: 'wero-label'
}) }}></div>
Loading