Skip to content

Commit

Permalink
NTR: fix subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Mar 28, 2024
1 parent 5647685 commit 91ceee9
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.6.0.0'
- shopware: '6.6.0.1'
php: '8.2'
- shopware: '6.5.8.7'
php: '8.2'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.6.0.0'
- shopware: '6.6.0.1'
php: '8.2'
- shopware: '6.5.8.7'
php: '8.2'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.6.0.0'
- shopware: '6.6.0.1'
php: '8.2'
- shopware: '6.5.8.7'
php: '8.2'
Expand Down
27 changes: 14 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);

namespace Shopware\Core\Checkout\Payment\Exception;
if (class_exists(__NAMESPACE__ . '/PaymentProcessException')) {
return;
}
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\ShopwareHttpException;
use Symfony\Component\HttpFoundation\Response;

#[Package('checkout')]
abstract class PaymentProcessException extends ShopwareHttpException
{
private string $orderTransactionId;

public function __construct(
string $orderTransactionId,
string $message,
array $parameters = [],
?\Throwable $e = null
) {
$this->orderTransactionId = $orderTransactionId;

parent::__construct($message, $parameters, $e);
}

public function getStatusCode(): int
{
return Response::HTTP_BAD_REQUEST;
}

public function getOrderTransactionId(): string
{
return $this->orderTransactionId;
}
}
24 changes: 24 additions & 0 deletions src/Components/Subscription/DAL/Currency/CurrencyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Components\Subscription\DAL\Currency;

use Kiener\MolliePayments\Components\Subscription\DAL\Subscription\SubscriptionDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\Currency\CurrencyDefinition;

class CurrencyExtension extends EntityExtension
{
public function getDefinitionClass(): string
{
return CurrencyDefinition::class;
}

public function extendFields(FieldCollection $collection): void
{
$collection->add((new OneToManyAssociationField('subscriptions', SubscriptionDefinition::class, 'currency_id'))->addFlags(new CascadeDelete()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Kiener\MolliePayments\Components\Subscription\Exception\SubscriptionNotFoundException;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Pricing\CashRoundingConfig;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
Expand Down Expand Up @@ -61,6 +62,7 @@ public function findById(string $id, Context $context): SubscriptionEntity
$criteria = new Criteria([$id]);
$criteria->addAssociation('customer');
$criteria->addAssociation('historyEntries');
$criteria->addAssociation('currency');

$result = $this->repoSubscriptions->search($criteria, $context);

Expand All @@ -80,6 +82,7 @@ public function findById(string $id, Context $context): SubscriptionEntity
public function findByMandateId(string $customerId, string $mandateId, Context $context): SubscriptionCollection
{
$criteria = new Criteria();
$criteria->addAssociation('currency');
$criteria->addFilter(new EqualsFilter('customerId', $customerId));
$criteria->addFilter(new EqualsFilter('mandateId', $mandateId));

Expand Down Expand Up @@ -111,6 +114,7 @@ public function findByCustomer(string $swCustomerId, bool $includedPending, Cont
$criteria = new Criteria();
$criteria->addAssociation('customer');
$criteria->addAssociation('historyEntries');
$criteria->addAssociation('currency');
$criteria->addFilter(new EqualsFilter('customerId', $swCustomerId));

if (!$includedPending) {
Expand All @@ -137,7 +141,7 @@ public function findByReminderRangeReached(string $salesChannelId, Context $cont

$criteria = new Criteria();
$criteria->addAssociation('customer');

$criteria->addAssociation('currency');
# subscription is not canceled
$criteria->addFilter(new EqualsFilter('canceledAt', null));
$criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelId));
Expand All @@ -157,6 +161,7 @@ public function findPendingSubscriptions(string $orderId, Context $context): Ent
{
$criteria = new Criteria();
$criteria->addAssociation('customer');
$criteria->addAssociation('currency');

$criteria->addFilter(new EqualsFilter('orderId', $orderId));
$criteria->addFilter(new EqualsFilter('mollieId', null));
Expand Down Expand Up @@ -185,6 +190,18 @@ public function search(Criteria $criteria, Context $context): EntitySearchResult
*/
public function insertSubscription(SubscriptionEntity $subscription, string $status, Context $context): void
{
$totalRoundingValue = null;
$totalRounding = $subscription->getTotalRounding();
if ($totalRounding instanceof CashRoundingConfig) {
$totalRoundingValue = $totalRounding->jsonSerialize();
}

$itemRoundingValue = null;
$itemRounding = $subscription->getItemRounding();
if ($itemRounding instanceof CashRoundingConfig) {
$itemRoundingValue = $itemRounding->jsonSerialize();
}

$this->repoSubscriptions->create(
[
[
Expand All @@ -204,11 +221,13 @@ public function insertSubscription(SubscriptionEntity $subscription, string $sta
'description' => $subscription->getDescription(),
'amount' => $subscription->getAmount(),
'quantity' => $subscription->getQuantity(),
'currency' => $subscription->getCurrency(),
'currencyId' => $subscription->getCurrencyId(),
'metadata' => $subscription->getMetadata()->toArray(),
'productId' => $subscription->getProductId(),
'orderId' => $subscription->getOrderId(),
'salesChannelId' => $subscription->getSalesChannelId(),
'totalRounding' => $totalRoundingValue,
'itemRounding' => $itemRoundingValue,
]
],
$context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Shopware\Core\Checkout\Order\OrderDefinition;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\CashRoundingConfigField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\CreatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
Expand All @@ -25,6 +26,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\UpdatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\Currency\CurrencyDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;

class SubscriptionDefinition extends EntityDefinition
Expand Down Expand Up @@ -72,7 +74,7 @@ protected function defineFields(): FieldCollection
(new StringField('description', 'description'))->addFlags(new ApiAware()),
(new FloatField('amount', 'amount'))->addFlags(new ApiAware()),
(new IntField('quantity', 'quantity'))->addFlags(new ApiAware()),
(new StringField('currency', 'currency'))->addFlags(new ApiAware()),
(new FkField('currency_id', 'currencyId', CurrencyDefinition::class))->addFlags(new ApiAware(), new Required()),
(new JsonField('metadata', 'metadata')),

# --------------------------------------------------------------------------------------------------------------------------
Expand All @@ -94,7 +96,7 @@ protected function defineFields(): FieldCollection

(new FkField('billing_address_id', 'billingAddressId', SalesChannelDefinition::class))->addFlags(new ApiAware()),
(new FkField('shipping_address_id', 'shippingAddressId', SalesChannelDefinition::class))->addFlags(new ApiAware()),

(new FkField('currency_id', 'currencyId', CurrencyDefinition::class))->addFlags(new ApiAware()),
new CreatedAtField(),
new UpdatedAtField(),

Expand All @@ -106,13 +108,15 @@ protected function defineFields(): FieldCollection
# --------------------------------------------------------------------------------------------------------------------------

new ManyToOneAssociationField('customer', 'customer_id', CustomerDefinition::class, 'id', false),

new ManyToOneAssociationField('currency', 'currency_id', CurrencyDefinition::class, 'id', false),
new OneToManyAssociationField('addresses', SubscriptionAddressDefinition::class, 'subscription_id'),
new OneToManyAssociationField('historyEntries', SubscriptionHistoryDefinition::class, 'subscription_id'),

new OneToOneAssociationField('billingAddress', 'billing_address_id', 'id', SubscriptionAddressDefinition::class, true),
new OneToOneAssociationField('shippingAddress', 'shipping_address_id', 'id', SubscriptionAddressDefinition::class, true),

(new CashRoundingConfigField('total_rounding', 'totalRounding'))->addFlags(new Required()),
(new CashRoundingConfigField('item_rounding', 'itemRounding'))->addFlags(new Required()),
]);
}
}
Loading

0 comments on commit 91ceee9

Please sign in to comment.