Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions PR #2

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4de94ad
Adding subscription functionality to payment plugin
vasylyna-magmodules Dec 1, 2021
e89b52a
Added last MolliePayments updates. Fixed custom fields.
Dec 2, 2021
236b55a
Updated validation
Dec 3, 2021
95dd3ee
Corrections after autotesting.
Dec 6, 2021
d6c7515
Corrections after autotesting.
Dec 6, 2021
a5663fa
Changing the order of fields in the configuration file
Dec 6, 2021
6bf09bf
Fixed - undefined method named "executeStatement" of class "Do
Dec 6, 2021
b3dc599
Corrections after autotesting.
Dec 7, 2021
0281f75
fixed: Integration Tests | Shopware 6.1.0 and Integration Tests | Sho…
Dec 20, 2021
2aafbb5
Fix: Typed properties are not supported in PHP 7.3 or earlier
Dec 20, 2021
f71b0d3
Readme addition
Dec 20, 2021
6ea4361
updating tests according to version 1.5.7
Dec 20, 2021
38a3fdb
Added subscription validation
Dec 21, 2021
a0501e2
Added subscription validation
Dec 21, 2021
76aaab5
Fix: Static Analyzers
Dec 21, 2021
be1cf03
Update phpstan
Dec 21, 2021
842406d
Fix: Static Analyzers -> Run PHPStan
Dec 21, 2021
d53a2a3
Fix: Static Analyzers -> Run PHPStan
Dec 21, 2021
f59ff74
Fix: Page/Account/Mollie/AccountSubscriptionsPageLoader.php
Dec 21, 2021
bcf88b3
Fix: Page/Account/Mollie/AccountSubscriptionsPageLoader.php
Dec 21, 2021
0de5083
Fix: Page/Account/Mollie/AccountSubscriptionsPageLoader.php
Dec 21, 2021
74d4ff2
fix: src/Page/Account/Mollie/AccountSubscriptionsPageLoader.php
Dec 21, 2021
88802e6
fix: src/Page/Account/Mollie/AccountSubscriptionsPageLoader.php
Dec 22, 2021
a9d007c
added validation CustomerEntity
Dec 22, 2021
5b7c6f2
Added validation CustomerEntity
Dec 22, 2021
1a43fb8
Fix: PHP CS Fixer
Dec 23, 2021
9793288
Fix: PHP CS Fixer
Dec 23, 2021
073b85a
[BETA] Credit Card not available for Subscriptions
Jan 28, 2022
2e3c772
[FEATURE] Product Configuration - Compact Layout
Feb 7, 2022
2764def
Fix #26 Filter payment methods in checkout
Feb 10, 2022
99729bb
Fixes #31 Proper check arrays
Feb 10, 2022
bf224c3
Fixes magmodules/shopware-mollie-subscriptions#28
Feb 10, 2022
902805c
Fix magmodules/shopware-mollie-subscriptions#36 Subscription variants…
Feb 13, 2022
fbcaf95
Fix some general code smells
Feb 13, 2022
75172a3
Clean up storefront representation
Feb 13, 2022
7c8d1b2
Fix webhook for subscriptions
Feb 13, 2022
4864d73
Cleanup
Feb 15, 2022
ea6eb4b
Cleanup
rune-magmodules Feb 15, 2022
47f4456
Merge branch 'beta/subscriptions-new' of git-magmodules:rune-magmodul…
Feb 15, 2022
4486a1c
Cleanup
rune-magmodules Feb 15, 2022
4ddb079
Fix pipelines
rune-magmodules Feb 18, 2022
d699a23
Fix pipelines
rune-magmodules Feb 18, 2022
47039ea
Fixes magmodules/shopware-mollie-subscriptions#41
rune-magmodules Mar 6, 2022
99981ad
Fixes magmodules/shopware-mollie-subscriptions#39 Add status translat…
rune-magmodules Mar 6, 2022
1938cce
Fixes magmodules/shopware-mollie-subscriptions#38
rune-magmodules Mar 6, 2022
6c89001
Fixes magmodules/shopware-mollie-subscriptions#36
rune-magmodules Mar 6, 2022
bc137b2
Add PHPStan ignore
rune-magmodules Mar 6, 2022
dd6b7ae
Fixes magmodules/shopware-mollie-subscriptions#42
rune-magmodules Mar 6, 2022
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
3 changes: 2 additions & 1 deletion .phpstan.lvl8.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ parameters:
# legacy code that is not working with abstract/interface changes
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Voucher/HideVoucherPaymentMethodRoute63.php
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Voucher/HideVoucherPaymentMethodRoute62.php

- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Subscription/SubscriptionPaymentMethodRoute62.php
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Subscription/SubscriptionPaymentMethodRoute63.php
services:
- class: MolliePayments\PHPStan\Rules\NoManufacturerRule
tags:
Expand Down
2 changes: 2 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ parameters:
# legacy code that is not working with abstract/interface changes
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Voucher/HideVoucherPaymentMethodRoute63.php
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Voucher/HideVoucherPaymentMethodRoute62.php
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Subscription/SubscriptionPaymentMethodRoute62.php
- ./src/Compatibility/Storefront/Route/PaymentMethodRoute/Subscription/SubscriptionPaymentMethodRoute63.php

services:
- class: MolliePayments\PHPStan\Rules\NoManufacturerRule
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
</p>
<h1 align="center">Mollie for Shopware 6</h1>


![Build Status](https://github.com/mollie/Shopware6/actions/workflows/ci_pipe.yml/badge.svg) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/mollie/Shopware6) ![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/mollie/Shopware6/latest)

## Introduction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace Kiener\MolliePayments\Compatibility\Storefront\Route\PaymentMethodRoute\Subscription;

use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Payment\SalesChannel\AbstractPaymentMethodRoute;
use Shopware\Core\Checkout\Payment\SalesChannel\PaymentMethodRouteResponse;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;

class SubscriptionPaymentMethodRoute62 extends AbstractPaymentMethodRoute
{
public const ALLOWED_METHODS = [
'ideal',
'bancontact',
'sofort',
'eps',
'giropay',
'belfius',
'creditcard',
'paypal',
];

/**
* @var AbstractPaymentMethodRoute
*/
private $decorated;

/**
* @var SystemConfigService
*/
private $systemConfigService;

/**
* @var Container
*/
private $container;

public function __construct(
AbstractPaymentMethodRoute $corePaymentMethodRoute,
SystemConfigService $systemConfigService,
Container $container
) {
$this->decorated = $corePaymentMethodRoute;
$this->systemConfigService = $systemConfigService;
$this->container = $container;
}

public function getDecorated(): AbstractPaymentMethodRoute
{
return $this->decorated;
}

/**
* ATTENTION:
* This works in Shopware 6.2, but only for the API.
* The confirm page does not use this approach, and thus the voucher
* payment method is not automatically hidden if not available.
*
* @param Request $request
* @param SalesChannelContext $context
* @return PaymentMethodRouteResponse
*/
public function load(Request $request, SalesChannelContext $context): PaymentMethodRouteResponse
{
$originalData = $this->decorated->load($request, $context);

$cart = $this->getCartServiceLazy()->getCart($context->getToken(), $context);

if (!$this->isSubscriptionCart($cart)) {
return $originalData;
}

foreach ($originalData->getPaymentMethods() as $key => $paymentMethod) {
$paymentMethodName = $paymentMethod->getTranslation('customFields')['mollie_payment_method_name'] ?? '';
if (!in_array($paymentMethodName, self::ALLOWED_METHODS)) {
$originalData->getPaymentMethods()->remove($key);
}
}

return $originalData;
}

private function isSubscriptionCart(Cart $cart): bool
{
if (!$this->systemConfigService->get('MolliePayments.config.enableSubscriptions')) {
return false;
}

foreach ($cart->getLineItems() as $lineItem) {
$customFields = $lineItem->getPayload()['customFields'];
if (isset($customFields["mollie_subscription"]['mollie_subscription_product'])
&& $customFields["mollie_subscription"]['mollie_subscription_product']) {
return true;
}
}

return false;
}

/**
* We have to use lazy loading for this. Otherwise there are plugin compatibilities
* with a circular reference...even though XML looks fine.
*
* @return CartService
* @throws \Exception
*/
private function getCartServiceLazy(): CartService
{
$service = $this->container->get('Shopware\Core\Checkout\Cart\SalesChannel\CartService');

if (!$service instanceof CartService) {
throw new \Exception('CartService of Shopware not found!');
}

return $service;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Kiener\MolliePayments\Compatibility\Storefront\Route\PaymentMethodRoute\Subscription;

use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Payment\SalesChannel\AbstractPaymentMethodRoute;
use Shopware\Core\Checkout\Payment\SalesChannel\PaymentMethodRouteResponse;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\HttpFoundation\Request;

class SubscriptionPaymentMethodRoute63 extends AbstractPaymentMethodRoute
{
public const ALLOWED_METHODS = [
'ideal',
'bancontact',
'sofort',
'eps',
'giropay',
'belfius',
'creditcard',
'paypal',
];

/**
* @var AbstractPaymentMethodRoute
*/
private $decorated;

/**
* @var SystemConfigService
*/
private $systemConfigService;

/**
* @var CartService
*/
private $cartService;

public function __construct(
AbstractPaymentMethodRoute $corePaymentMethodRoute,
SystemConfigService $systemConfigService,
CartService $cartService
) {
$this->decorated = $corePaymentMethodRoute;
$this->systemConfigService = $systemConfigService;
$this->cartService = $cartService;
}

public function getDecorated(): AbstractPaymentMethodRoute
{
return $this->decorated;
}

public function load(Request $request, SalesChannelContext $context): PaymentMethodRouteResponse
{
$originalData = $this->decorated->load($request, $context);

$cart = $this->cartService->getCart($context->getToken(), $context);

if (!$this->isSubscriptionCart($cart)) {
return $originalData;
}

foreach ($originalData->getPaymentMethods() as $key => $paymentMethod) {
$paymentMethodName = $paymentMethod->getTranslation('customFields')['mollie_payment_method_name'] ?? '';
if (!in_array($paymentMethodName, self::ALLOWED_METHODS)) {
$originalData->getPaymentMethods()->remove($key);
}
}

return $originalData;
}

private function isSubscriptionCart(Cart $cart): bool
{
if (!$this->systemConfigService->get('MolliePayments.config.enableSubscriptions')) {
return false;
}

foreach ($cart->getLineItems() as $lineItem) {
$customFields = $lineItem->getPayload()['customFields'];
if (isset($customFields["mollie_subscription"]['mollie_subscription_product'])
&& $customFields["mollie_subscription"]['mollie_subscription_product']) {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Kiener\MolliePayments\Compatibility\Storefront\Route\PaymentMethodRoute\Subscription;

use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Payment\SalesChannel\AbstractPaymentMethodRoute;
use Shopware\Core\Checkout\Payment\SalesChannel\PaymentMethodRouteResponse;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\HttpFoundation\Request;

class SubscriptionPaymentMethodRoute64 extends AbstractPaymentMethodRoute
{
public const ALLOWED_METHODS = [
'ideal',
'bancontact',
'sofort',
'eps',
'giropay',
'belfius',
'creditcard',
'paypal',
];

/**
* @var AbstractPaymentMethodRoute
*/
private $decorated;

/**
* @var SystemConfigService
*/
private $systemConfigService;

/**
* @var CartService
*/
private $cartService;

public function __construct(
AbstractPaymentMethodRoute $corePaymentMethodRoute,
SystemConfigService $systemConfigService,
CartService $cartService
) {
$this->decorated = $corePaymentMethodRoute;
$this->systemConfigService = $systemConfigService;
$this->cartService = $cartService;
}

public function getDecorated(): AbstractPaymentMethodRoute
{
return $this->decorated;
}

public function load(Request $request, SalesChannelContext $context, Criteria $criteria): PaymentMethodRouteResponse
{
$originalData = $this->decorated->load($request, $context, $criteria);

$cart = $this->cartService->getCart($context->getToken(), $context);

if (!$this->isSubscriptionCart($cart)) {
return $originalData;
}

foreach ($originalData->getPaymentMethods() as $key => $paymentMethod) {
$paymentMethodName = $paymentMethod->getTranslation('customFields')['mollie_payment_method_name'] ?? '';
if (!in_array($paymentMethodName, self::ALLOWED_METHODS)) {
$originalData->getPaymentMethods()->remove($key);
}
}

return $originalData;
}

private function isSubscriptionCart(Cart $cart): bool
{
if (!$this->systemConfigService->get('MolliePayments.config.enableSubscriptions')) {
return false;
}

foreach ($cart->getLineItems() as $lineItem) {
$customFields = $lineItem->getPayload()['customFields'];
if (isset($customFields["mollie_subscription"]['mollie_subscription_product'])
&& $customFields["mollie_subscription"]['mollie_subscription_product']) {
return true;
}
}

return false;
}
}
52 changes: 52 additions & 0 deletions src/Controller/Api/SubscriptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Controller\Api;

use Kiener\MolliePayments\Service\Subscription\CancelSubscriptionsService;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
* @RouteScope(scopes={"api"})
*/
class SubscriptionController extends AbstractController
{
/**
* @var CancelSubscriptionsService
*/
private $cancelSubscriptionsService;

/**
* Creates a new instance of the onboarding controller.
*
* @param CancelSubscriptionsService $cancelSubscriptionsService
*/
public function __construct(CancelSubscriptionsService $cancelSubscriptionsService)
{
$this->cancelSubscriptionsService = $cancelSubscriptionsService;
}

/**
* @RouteScope(scopes={"api"})
* @Route("/api/_action/mollie/subscription/cancel",
* defaults={"auth_enabled"=true}, name="api.action.mollie.subscription.cancel", methods={"POST"})
*
* @param RequestDataBag $data
* @param Context $context
* @return JsonResponse
*/
public function cancel(RequestDataBag $data, Context $context): JsonResponse
{
$response = $this->cancelSubscriptionsService->cancelSubscriptions(
$data->get('id'),
$data->get('customerId'),
$data->get('salesChannelId')
);

return new JsonResponse(['success' => $response]);
}
}
Loading