Skip to content

Commit

Permalink
Merge pull request #578 from Adyen/develop
Browse files Browse the repository at this point in the history
Release version 4.2.0
  • Loading branch information
goran-stamenkovski-logeecom authored Nov 29, 2024
2 parents b81eb3b + 507d0fe commit 6976ad7
Show file tree
Hide file tree
Showing 35 changed files with 760 additions and 115 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
timeout-minutes: 20
strategy:
fail-fast: false
if: ${{ github.actor != 'renovate[bot]' || github.actor != 'lgtm-com[bot]' }}
# if: ${{ github.actor != 'renovate[bot]' || github.actor != 'lgtm-com[bot]' }}
if: false
# Prevent bots from initiating E2E pipeline
steps:
- name: Clone Code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/templates/docker-compose.playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
playwright:
image: mcr.microsoft.com/playwright:v1.48.0-focal
image: mcr.microsoft.com/playwright:v1.48.2-focal
networks:
- localnetwork
shm_size: 1gb
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The plugin integrates card component (Secured Fields) using Adyen Checkout for a
- Blik
- Billie
- Clearpay
- Dotpay
- Electronic Payment Service (EPS)
- Gift cards
- GiroPay
Expand All @@ -52,6 +51,7 @@ The plugin integrates card component (Secured Fields) using Adyen Checkout for a
- Klarna Pay Later
- Klarna Pay Now
- Klarna Pay Over Time
- Klarna Debit Risk
- MB Way
- MobilePay
- Multibanco
Expand All @@ -61,13 +61,14 @@ The plugin integrates card component (Secured Fields) using Adyen Checkout for a
- PaySafeCard
- RatePay, RatePay Direct Debit
- SEPA Direct Debit
- Sofort
- Swish
- Trustly
- Twint
- Vipps
- WeChat Pay
- Open Banking / Pay by Bank
- Online Banking Finland
- Online Banking Poland

## API Library
This module is using the Adyen APIs Library for PHP for all (API) connections to Adyen.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "4.1.3",
"version": "4.2.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
Expand Down
107 changes: 105 additions & 2 deletions src/AdyenPaymentShopware6.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use Adyen\Shopware\Entity\Notification\NotificationEntityDefinition;
use Adyen\Shopware\Entity\PaymentResponse\PaymentResponseEntityDefinition;
use Adyen\Shopware\Entity\PaymentStateData\PaymentStateDataEntityDefinition;
use Adyen\Shopware\Handlers\KlarnaDebitRiskPaymentMethodHandler;
use Adyen\Shopware\PaymentMethods\KlarnaDebitRiskPaymentMethod;
use Adyen\Shopware\Service\ConfigurationService;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\Framework\Plugin;
Expand All @@ -47,6 +49,8 @@

class AdyenPaymentShopware6 extends Plugin
{
public const SOFORT = 'Adyen\Shopware\Handlers\SofortPaymentMethodHandler';

public function install(InstallContext $installContext): void
{
foreach (PaymentMethods\PaymentMethods::PAYMENT_METHODS as $paymentMethod) {
Expand Down Expand Up @@ -134,6 +138,19 @@ public function update(UpdateContext $updateContext): void
if (\version_compare($currentVersion, '4.1.0', '<')) {
$this->updateTo410($updateContext);
}

if (\version_compare($currentVersion, '4.2.0', '<')) {
$this->updateTo420($updateContext);
}
}

public function postUpdate(UpdateContext $updateContext): void
{
$currentVersion = $updateContext->getCurrentPluginVersion();
if (\version_compare($currentVersion, '4.2.0', '<')) {
$handler = $this->container->get("Adyen\Shopware\Service\FetchLogosService");
$handler->getHandler()->run();
}
}

private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $paymentMethod, Context $context): void
Expand All @@ -144,6 +161,31 @@ private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $payment
$pluginIdProvider = $this->container->get(PluginIdProvider::class);
$pluginId = $pluginIdProvider->getPluginIdByBaseClass(get_class($this), $context);

/** @var EntityRepository $paymentRepository */
$paymentRepository = $this->container->get('payment_method.repository');

// Rename if Klarna Debit Risk doesnt exist from previous installations
if ($paymentMethod->getPaymentHandler() === KlarnaDebitRiskPaymentMethodHandler::class
&& $paymentMethodId === null) {
$sofortMethodId = $this->getPaymentMethodId(self::SOFORT);

if ($sofortMethodId) {
// update Sofort to Klarna Debit Risk
$method = new PaymentMethods\KlarnaDebitRiskPaymentMethod();

$paymentMethodData = [
'id' => $sofortMethodId,
'handlerIdentifier' => $method->getPaymentHandler(),
'name' => $method->getName(),
'description' => $method->getDescription(),
];

$paymentRepository->update([$paymentMethodData], $context);

return;
}
}

// Payment method exists already, set the pluginId
if ($paymentMethodId) {
$this->setPluginId($paymentMethodId, $pluginId, $context);
Expand All @@ -158,8 +200,6 @@ private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $payment
'afterOrderEnabled' => true
];

/** @var EntityRepository $paymentRepository */
$paymentRepository = $this->container->get('payment_method.repository');
$paymentRepository->create([$paymentData], $context);
}

Expand Down Expand Up @@ -481,6 +521,69 @@ private function updateTo410(UpdateContext $updateContext): void
);
}

private function updateTo420(UpdateContext $updateContext): void
{
// Version 4.2.0 introduces Online Banking Finland and Online Banking Poland
$paymentMethods = [
new PaymentMethods\OnlineBankingFinlandPaymentMethod(),
new PaymentMethods\OnlineBankingPolandPaymentMethod(),
];

foreach ($paymentMethods as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
);

$this->setPaymentMethodIsActive(
true,
$updateContext->getContext(),
$method
);
}

// Version 4.2.0 removes Dotpay
$paymentMethodHandler = 'Adyen\Shopware\Handlers\DotpayPaymentMethodHandler';
$this->deactivateAndRemovePaymentMethod($updateContext, $paymentMethodHandler);

// Version 4.2.0 replaces Sofort with Klarna Debit Risk
$paymentRepository = $this->container->get('payment_method.repository');
$paymentMethodId = $this->getPaymentMethodId(self::SOFORT);
$klarnaDebitRisktMethodId = $this->getPaymentMethodId(
'Adyen\Shopware\Handlers\KlarnaDebitRiskPaymentMethodHandler'
);

// If Sofort does not exist, return
if (!$paymentMethodId) {
return;
}

if ($klarnaDebitRisktMethodId !== null) {
// Klarna Debit Risk exists, deactivate Sofort and skip renaming
$this->deactivateAndRemovePaymentMethod($updateContext, self::SOFORT);
// activate Klarna Debit Risk
$this->setPaymentMethodIsActive(
true,
$updateContext->getContext(),
new PaymentMethods\KlarnaDebitRiskPaymentMethod()
);

return;
}

// Update Sofort to Klarna Debit Risk
$method = new PaymentMethods\KlarnaDebitRiskPaymentMethod();

$paymentMethodData = [
'id' => $paymentMethodId,
'handlerIdentifier' => $method->getPaymentHandler(),
'name' => $method->getName(),
'description' => $method->getDescription(),
];

$paymentRepository->update([$paymentMethodData], $updateContext->getContext());
}

/**
* @param UpdateContext $updateContext
* @param string $paymentMethodHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

namespace Adyen\Shopware\Core\Checkout\Order\Aggregate\OrderTransaction;

use Adyen\Shopware\Entity\AdyenPayment\AdyenPaymentEntityDefinition;
use Adyen\Shopware\Entity\PaymentCapture\PaymentCaptureEntityDefinition;
use Adyen\Shopware\Entity\PaymentResponse\PaymentResponseEntityDefinition;
use Adyen\Shopware\Entity\Refund\RefundEntityDefinition;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionDefinition;
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
Expand All @@ -49,14 +52,47 @@ public function extendFields(FieldCollection $collection): void
'order_transaction_id'
);

$refundField = new OneToManyAssociationField(
'adyenRefund',
RefundEntityDefinition::class,
'order_transaction_id'
);

$captureField = new OneToManyAssociationField(
'adyenCapture',
PaymentCaptureEntityDefinition::class,
'order_transaction_id'
);

$paymentField = new OneToManyAssociationField(
'adyenPayment',
AdyenPaymentEntityDefinition::class,
'order_transaction_id'
);

// Ensure the data is not available via the Store API in older Shopware versions.
if (!class_exists(ApiAware::class) &&
class_exists(Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected::class)) {
$field->addFlags(
new Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected(SalesChannelApiSource::class)
);

$refundField->addFlags(
new Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected(SalesChannelApiSource::class)
);

$captureField->addFlags(
new Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected(SalesChannelApiSource::class)
);

$paymentField->addFlags(
new Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected(SalesChannelApiSource::class)
);
}

$collection->add($field);
$collection->add($refundField);
$collection->add($captureField);
$collection->add($paymentField);
}
}
24 changes: 23 additions & 1 deletion src/Entity/AdyenPayment/AdyenPaymentEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace Adyen\Shopware\Entity\AdyenPayment;

use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;

Expand Down Expand Up @@ -96,6 +97,11 @@ class AdyenPaymentEntity extends Entity
*/
protected $updatedAt;

/**
* @var OrderTransactionEntity
*/
protected OrderTransactionEntity $orderTransaction;

/**
* @return string
*/
Expand Down Expand Up @@ -171,7 +177,7 @@ public function getOrderTransactionId(): string
/**
* @param int $orderTransactionId
*/
public function setEventCode(int $orderTransactionId): void
public function setOrderTransactionId(int $orderTransactionId): void
{
$this->orderTransactionId = $orderTransactionId;
}
Expand Down Expand Up @@ -279,4 +285,20 @@ public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}

/**
* @return OrderTransactionEntity
*/
public function getOrderTransaction(): OrderTransactionEntity
{
return $this->orderTransaction;
}

/**
* @param OrderTransactionEntity $orderTransaction
*/
public function setOrderTransaction(OrderTransactionEntity $orderTransaction): void
{
$this->orderTransaction = $orderTransaction;
}
}
8 changes: 1 addition & 7 deletions src/Entity/AdyenPayment/AdyenPaymentEntityDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\UpdatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\CreatedAtField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
Expand Down Expand Up @@ -65,11 +63,7 @@ protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
(new FkField(
'order_transaction_id',
'orderTransactionId',
OrderTransactionDefinition::class
))->addFlags(new Required()),
new IdField('order_transaction_id', 'orderTransactionId'),
new StringField('pspreference', 'pspreference'),
new StringField('original_reference', 'originalReference'),
new StringField('merchant_reference', 'merchantReference'),
Expand Down
7 changes: 1 addition & 6 deletions src/Entity/PaymentCapture/PaymentCaptureEntityDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
Expand Down Expand Up @@ -58,11 +57,7 @@ protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
(new FkField(
'order_transaction_id',
'orderTransactionId',
OrderTransactionDefinition::class
))->addFlags(new Required()),
new IdField('order_transaction_id', 'orderTransactionId'),
new StringField('psp_reference', 'pspReference'),
(new IntField('amount', 'amount'))->addFlags(new Required()),
(new StringField('source', 'source'))->addFlags(new Required()),
Expand Down
Loading

0 comments on commit 6976ad7

Please sign in to comment.