Skip to content

Commit

Permalink
Merge pull request #579 from Adyen/develop-3
Browse files Browse the repository at this point in the history
Release version 3.17.0
  • Loading branch information
goran-stamenkovski-logeecom authored Nov 29, 2024
2 parents b7865db + 93fb26a commit 82df7c4
Show file tree
Hide file tree
Showing 35 changed files with 670 additions and 158 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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
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": "3.16.3",
"version": "3.17.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
Expand Down
176 changes: 138 additions & 38 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 installJsAssets($shopwareVersion)
{
$storefrontAssetPath = __DIR__ . '/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware6.js';
Expand Down Expand Up @@ -174,6 +178,19 @@ public function update(UpdateContext $updateContext): void
if (\version_compare($currentVersion, '3.16.0', '<')) {
$this->updateTo3160($updateContext);
}

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

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

private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $paymentMethod, Context $context): void
Expand All @@ -184,6 +201,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 @@ -198,8 +240,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 @@ -320,11 +360,11 @@ private function updateTo160(UpdateContext $updateContext): void
{
//Version 1.6.0 introduces applepay, paywithgoogle, dotpay and bancontact
foreach ([
new PaymentMethods\ApplePayPaymentMethod,
new PaymentMethods\GooglePayPaymentMethod,
new PaymentMethods\DotpayPaymentMethod,
new PaymentMethods\BancontactCardPaymentMethod
] as $method) {
new PaymentMethods\ApplePayPaymentMethod,
new PaymentMethods\GooglePayPaymentMethod,
new PaymentMethods\DotpayPaymentMethod,
new PaymentMethods\BancontactCardPaymentMethod
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
Expand All @@ -341,9 +381,9 @@ private function updateTo200(UpdateContext $updateContext): void
{
//Version 2.0.0 introduces amazonpay, blik
foreach ([
new PaymentMethods\AmazonPayPaymentMethod,
new PaymentMethods\BlikPaymentMethod,
] as $method) {
new PaymentMethods\AmazonPayPaymentMethod,
new PaymentMethods\BlikPaymentMethod,
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
Expand All @@ -360,23 +400,23 @@ private function updateTo300(UpdateContext $updateContext): void
{
//Version 3.0.0 introduces the following payment methods
foreach ([
new PaymentMethods\AfterpayDefaultPaymentMethod,
new PaymentMethods\AlipayPaymentMethod,
new PaymentMethods\AlipayHkPaymentMethod,
new PaymentMethods\ClearpayPaymentMethod,
new PaymentMethods\EpsPaymentMethod,
new PaymentMethods\Facilypay3xPaymentMethod,
new PaymentMethods\Facilypay4xPaymentMethod,
new PaymentMethods\Facilypay6xPaymentMethod,
new PaymentMethods\Facilypay10xPaymentMethod,
new PaymentMethods\Facilypay12xPaymentMethod,
new PaymentMethods\PaysafecardPaymentMethod,
new PaymentMethods\RatepayPaymentMethod,
new PaymentMethods\RatepayDirectdebitPaymentMethod,
new PaymentMethods\SwishPaymentMethod,
new PaymentMethods\TrustlyPaymentMethod,
new PaymentMethods\TwintPaymentMethod,
] as $method) {
new PaymentMethods\AfterpayDefaultPaymentMethod,
new PaymentMethods\AlipayPaymentMethod,
new PaymentMethods\AlipayHkPaymentMethod,
new PaymentMethods\ClearpayPaymentMethod,
new PaymentMethods\EpsPaymentMethod,
new PaymentMethods\Facilypay3xPaymentMethod,
new PaymentMethods\Facilypay4xPaymentMethod,
new PaymentMethods\Facilypay6xPaymentMethod,
new PaymentMethods\Facilypay10xPaymentMethod,
new PaymentMethods\Facilypay12xPaymentMethod,
new PaymentMethods\PaysafecardPaymentMethod,
new PaymentMethods\RatepayPaymentMethod,
new PaymentMethods\RatepayDirectdebitPaymentMethod,
new PaymentMethods\SwishPaymentMethod,
new PaymentMethods\TrustlyPaymentMethod,
new PaymentMethods\TwintPaymentMethod,
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
Expand Down Expand Up @@ -426,15 +466,15 @@ private function updateTo370(UpdateContext $updateContext): void
* MB Way, Multibanco, WeChat Pay, MobilePay, Vipps, Affirm & PayBright
*/
foreach ([
new PaymentMethods\MbwayPaymentMethod(),
new PaymentMethods\MultibancoPaymentMethod(),
new PaymentMethods\WechatpayqrPaymentMethod(),
new PaymentMethods\WechatpaywebPaymentMethod(),
new PaymentMethods\MobilePayPaymentMethod(),
new PaymentMethods\VippsPaymentMethod(),
new PaymentMethods\AffirmPaymentMethod(),
new PaymentMethods\PayBrightPaymentMethod()
] as $method) {
new PaymentMethods\MbwayPaymentMethod(),
new PaymentMethods\MultibancoPaymentMethod(),
new PaymentMethods\WechatpayqrPaymentMethod(),
new PaymentMethods\WechatpaywebPaymentMethod(),
new PaymentMethods\MobilePayPaymentMethod(),
new PaymentMethods\VippsPaymentMethod(),
new PaymentMethods\AffirmPaymentMethod(),
new PaymentMethods\PayBrightPaymentMethod()
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
Expand All @@ -454,8 +494,8 @@ private function updateTo3100(UpdateContext $updateContext): void
* Open Banking / Pay by Bank
*/
foreach ([
new PaymentMethods\OpenBankingPaymentMethod(),
] as $method) {
new PaymentMethods\OpenBankingPaymentMethod(),
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
Expand Down Expand Up @@ -521,6 +561,66 @@ private function updateTo3160(UpdateContext $updateContext): void
);
}

private function updateTo3170(UpdateContext $updateContext): void
{
// Version 3.17.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 3.17.0 removes Dotpay
$paymentMethodHandler = 'Adyen\Shopware\Handlers\DotpayPaymentMethodHandler';
$this->deactivateAndRemovePaymentMethod($updateContext, $paymentMethodHandler);

// Version 3.17.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
);

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());
}

private function safeCopyAsset($source, $destination): bool
{
try {
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);
}
}
Loading

0 comments on commit 82df7c4

Please sign in to comment.