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

Adding subscription functionality to payment plugin version 1.5.5 #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .phpstan.lvl8.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
paths:
- ./src
- ./src/Service/ApplePayDirect
- ./src/Service/Logger
excludes_analyse:
- ./src/Resources/app/administration/node_modules/*
- ./src/Resources/app/storefront/node_modules/*
Expand Down
50 changes: 50 additions & 0 deletions src/Controller/Api/SubscriptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Controller\Api;

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

Choose a reason for hiding this comment

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

Write Route scope always before class name Ex.

Suggested change
/**
* @RouteScope(scopes={"api"})
*/
class SubscriptionController extends AbstractController
{
}

/**
* @RouteScope(scopes={"api"})
*/
class SubscriptionController extends AbstractController
{
/**
* @var CancelSubscriptionsService
*/
private CancelSubscriptionsService $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
{
return $this->cancelSubscriptionsService->cancelSubscriptions(
$data->get('id'),
$data->get('customerId'),
$data->get('salesChannelId')
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Core\Content\SubscriptionToProduct;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @method void add(SubscriptionToProductEntity $entity)
* @method void set(string $key, SubscriptionToProductEntity $entity)
* @method SubscriptionToProductEntity[] getIterator()
* @method SubscriptionToProductEntity[] getElements()
* @method SubscriptionToProductEntity|null get(string $key)
* @method SubscriptionToProductEntity|null first()
* @method SubscriptionToProductEntity|null last()
*/
class SubscriptionToProductCollection extends EntityCollection
{
/**
* @return string
*/
protected function getExpectedClass(): string
{
return SubscriptionToProductEntity::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Core\Content\SubscriptionToProduct;

use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\CreatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\CustomFields;
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FloatField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\UpdatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\JsonField;

class SubscriptionToProductDefinition extends EntityDefinition
{
public const ENTITY_NAME = 'mollie_subscription_to_product';

/**
* @return string
*/
public function getEntityName(): string

Choose a reason for hiding this comment

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

If you create any definition don't add a direct entity name in the getEntityName function. Please create Const ENTITY_NAME and use that constant as entity name EX.

public const ENTITY_NAME = 'mollie_subscription_to_product';

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

{
return self::ENTITY_NAME;
}

/**
* @return string
*/
public function getEntityClass(): string

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

{
return SubscriptionToProductEntity::class;
}

/**
* @return string
*/
public function getCollectionClass(): string
{
return SubscriptionToProductCollection::class;
}

/**
* @return FieldCollection
*/
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),

(new StringField('mollie_customer_id', 'mollieCustomerId')),
(new StringField('subscription_id', 'subscriptionId')),
(new FkField('product_id', 'productId', ProductDefinition::class))->addFlags(new ApiAware()),
(new FkField('sales_channel_id', 'salesChannelId', SalesChannelDefinition::class))
->addFlags(new ApiAware()),
new DateTimeField('next_payment_date', 'nextPaymentDate'),
new StringField('status', 'status'),
new StringField('description', 'description'),
new StringField('currency', 'currency'),
new FloatField('amount', 'amount'),

new CreatedAtField(),
new UpdatedAtField()
]);
}
}
181 changes: 181 additions & 0 deletions src/Core/Content/SubscriptionToProduct/SubscriptionToProductEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Core\Content\SubscriptionToProduct;

use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;

class SubscriptionToProductEntity extends Entity
{
use EntityIdTrait;

/**
* @var string
*/
protected string $mollieCustomerId;

/**
* @var string
*/
protected string $subscriptionId;

/**
* @var string
*/
protected string $productId;


/**
* @var string
*/
protected string $salesChannelId;

/**
* @var string
*/
protected string $status;

/**
* @var string
*/
protected string $description;

/**
* @var float
*/
protected float $amount;

/**
* @var string
*/
protected string $currency;


/**
* @return string
*/
public function getMollieCustomerId(): string
{
return $this->mollieCustomerId;
}

/**
* @param string $mollieCustomerId
*/
public function setMollieCustomerId(string $mollieCustomerId): void
{
$this->mollieCustomerId = $mollieCustomerId;
}

/**
* @return string
*/
public function getSubscriptionId(): string
{
return $this->subscriptionId;
}

/**
* @param string $subscriptionId
*/
public function setSubscriptionId(string $subscriptionId): void
{
$this->subscriptionId = $subscriptionId;
}

/**
* @return string
*/
public function getProductId(): string
{
return $this->productId;
}

/**
* @param string $productId
*/
public function setProductId(string $productId): void
{
$this->productId = $productId;
}

/**
* @return string
*/
public function getSalesChannelId(): string
{
return $this->salesChannelId;
}

/**
* @param string $salesChannelId
*/
public function setSalesChannelId(string $salesChannelId): void
{
$this->salesChannelId = $salesChannelId;
}

/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}

/**
* @param string $status
*/
public function setStatus(string $status): void
{
$this->status = $status;
}

/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}

/**
* @param string $description
*/
public function setDescription(string $description): void
{
$this->description = $description;
}

/**
* @return float
*/
public function getAmount(): float
{
return $this->amount;
}

/**
* @param float $amount
*/
public function setAmount(float $amount): void
{
$this->amount = $amount;
}

/**
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}

/**
* @param string $currency
*/
public function setCurrency(string $currency): void
{
$this->currency = $currency;
}
}
Loading