Skip to content

Commit

Permalink
Revert "[MOL-368] fix apple pay (#97)"
Browse files Browse the repository at this point in the history
This reverts commit e32a081.
  • Loading branch information
schmitzcarsten committed May 17, 2021
1 parent e32a081 commit c86a78e
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 128 deletions.
12 changes: 2 additions & 10 deletions src/Helper/PaymentStatusHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace Kiener\MolliePayments\Helper;

use Exception;
use Kiener\MolliePayments\Handler\Method\ApplePayPayment;
use Kiener\MolliePayments\Service\LoggerService;
use Kiener\MolliePayments\Service\Order\OrderStateService;
use Kiener\MolliePayments\Service\PaymentMethodService;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
use Mollie\Api\Resources\Order;
Expand Down Expand Up @@ -49,9 +47,6 @@ class PaymentStatusHelper
/** @var EntityRepositoryInterface */
protected $orderTransactionRepository;

/** @var PaymentMethodService */
protected $paymentMethodService;

/**
* PaymentStatusHelper constructor.
*
Expand All @@ -67,8 +62,7 @@ public function __construct(
SettingsService $settingsService,
StateMachineRegistry $stateMachineRegistry,
EntityRepositoryInterface $paymentMethodRepository,
EntityRepositoryInterface $orderTransactionRepository,
PaymentMethodService $paymentMethodService
EntityRepositoryInterface $orderTransactionRepository
)
{
$this->logger = $logger;
Expand All @@ -79,7 +73,6 @@ public function __construct(

$this->paymentMethodRepository = $paymentMethodRepository;
$this->orderTransactionRepository = $orderTransactionRepository;
$this->paymentMethodService = $paymentMethodService;
}

/**
Expand Down Expand Up @@ -163,8 +156,7 @@ public function processPaymentStatus(

$useMollieFailureHandling = !$settings->isShopwareFailedPaymentMethod();

if ($useMollieFailureHandling
&& $this->paymentMethodService->isPaidApplePayTransaction($transaction, $mollieOrder) === false) {
if ($useMollieFailureHandling) {
$currentCustomerSelectedPaymentMethod = $mollieOrder->method;

if (is_null($currentCustomerSelectedPaymentMethod)) {
Expand Down
16 changes: 2 additions & 14 deletions src/MolliePayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Kiener\MolliePayments;

use Exception;
use Kiener\MolliePayments\Service\ApplePayDomainVerificationService;
use Kiener\MolliePayments\Service\CustomFieldService;
use Kiener\MolliePayments\Service\PaymentMethodService;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
Expand Down Expand Up @@ -61,18 +60,12 @@ public function install(InstallContext $context) : void
public function update(UpdateContext $context): void
{
parent::update($context);

if($context->getPlugin()->isActive() === true) {
// add domain verification
/** @var ApplePayDomainVerificationService $domainVerificationService */
$domainVerificationService = $this->container->get(ApplePayDomainVerificationService::class);
$domainVerificationService->downloadDomainAssociationFile();
}
}

public function postInstall(InstallContext $context): void
{
parent::postInstall($context);

}

public function uninstall(UninstallContext $context) : void
Expand All @@ -91,15 +84,10 @@ public function activate(ActivateContext $context) : void
$paymentMethodHelper
->setClassName(get_class($this))
->addPaymentMethods($context->getContext());

// add domain verification
/** @var ApplePayDomainVerificationService $domainVerificationService */
$domainVerificationService = $this->container->get(ApplePayDomainVerificationService::class);
$domainVerificationService->downloadDomainAssociationFile();
}

public function deactivate(DeactivateContext $context) : void
{
parent::deactivate($context);
}
}
}

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<argument type="service" id="Shopware\Core\System\StateMachine\StateMachineRegistry"/>
<argument type="service" id="payment_method.repository"/>
<argument type="service" id="order_transaction.repository"/>
<argument type="service" id="Kiener\MolliePayments\Service\PaymentMethodService"/>
</service>

<!-- Services -->
Expand All @@ -73,10 +72,6 @@
<argument type="service" id="custom_field_set.repository"/>
</service>

<service id="Kiener\MolliePayments\Service\ApplePayDomainVerificationService" public="true">
<argument type="service" id="shopware.filesystem.public"/>
</service>

<service id="Kiener\MolliePayments\Service\DeliveryService" class="Kiener\MolliePayments\Service\DeliveryService">
<argument type="service" id="order_delivery.repository"/>
</service>
Expand Down Expand Up @@ -127,7 +122,6 @@
<argument type="service" id="Kiener\MolliePayments\Service\ShippingMethodService"/>
<argument type="service" id="service_container"/>
<argument>%kernel.shopware_version%</argument>
<argument type="service" id="Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory"/>
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
Expand Down Expand Up @@ -206,6 +200,8 @@
<argument type="service" id="payment_method.repository"/>
<tag name="kernel.event_subscriber"/>
</service>


</services>

</container>
25 changes: 0 additions & 25 deletions src/Service/ApplePayDomainVerificationService.php

This file was deleted.

60 changes: 28 additions & 32 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\MethodCollection;
use Mollie\Api\Resources\Order;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\Content\Media\MediaCollection;
use Shopware\Core\Content\Media\MediaService;
Expand Down Expand Up @@ -335,6 +333,9 @@ public function getPaymentHandlers()
*/
private function getMediaId(array $paymentMethod, Context $context): string
{
/** @var string $mediaId */
$mediaId = '';

/** @var string $fileName */
$fileName = $paymentMethod['name'] . '-icon';

Expand All @@ -345,38 +346,33 @@ private function getMediaId(array $paymentMethod, Context $context): string
$icons = $this->mediaRepository->search($criteria, $context);

if ($icons->count() && $icons->first() !== null) {
return $icons->first()->getId();
}

// Add icon to the media library
$iconMime = 'image/svg+xml';
$iconExt = 'svg';
$iconBlob = file_get_contents('https://www.mollie.com/external/icons/payment-methods/' . $paymentMethod['name'] . '.svg');
$mediaId = $icons->first()->getId();
} else {
// Add icon to the media library

$iconBlob = file_get_contents('https://www.mollie.com/external/icons/payment-methods/' . $paymentMethod['name'] . '.svg');

if(!empty(trim($iconBlob))) {
$iconMime = 'image/svg+xml';
$iconExt = 'svg';
} else {
$iconBlob = file_get_contents('https://www.mollie.com/external/icons/payment-methods/' . $paymentMethod['name'] . '.png');
$iconMime = 'image/png';
$iconExt = 'png';
}

if(empty(trim($iconBlob))) {
$iconBlob = file_get_contents('https://www.mollie.com/external/icons/payment-methods/' . $paymentMethod['name'] . '.png');
$iconMime = 'image/png';
$iconExt = 'png';
$mediaId = $this->mediaService->saveFile(
$iconBlob,
$iconExt,
$iconMime,
$fileName,
$context,
'Mollie Payments - Icons',
null,
false
);
}

return $this->mediaService->saveFile(
$iconBlob,
$iconExt,
$iconMime,
$fileName,
$context,
'Mollie Payments - Icons',
null,
false
);
}

/**
* @param OrderTransactionEntity $transaction
* @param Order $mollieOrder
* @return bool
*/
public function isPaidApplePayTransaction(OrderTransactionEntity $transaction, Order $mollieOrder) : bool {
return $transaction->getPaymentMethod()->getHandlerIdentifier() === ApplePayPayment::class && $mollieOrder->isPaid() === true;
return $mediaId;
}
}
7 changes: 4 additions & 3 deletions src/Service/ShippingMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function getShippingMethodsForApplePayDirect(SalesChannelContext $context
$availableShippingMethods !== null
&& $availableShippingMethods->count()
) {
/** @var ShippingMethodEntity $shippingMethod */
foreach ($availableShippingMethods as $shippingMethod) {
if (
$shippingMethod->getPrices()->count()
Expand All @@ -117,8 +116,10 @@ public function getShippingMethodsForApplePayDirect(SalesChannelContext $context

$detail = '';

if ($shippingMethod->getDeliveryTime() !== null) {
$detail = $shippingMethod->getDeliveryTime()->getTranslation('name') ?: $shippingMethod->getDeliveryTime()->getName();
if (
$shippingMethod->getDeliveryTime() !== null
) {
$detail = $shippingMethod->getDeliveryTime()->getName();
}

$shippingMethods[] = [
Expand Down
30 changes: 10 additions & 20 deletions src/Storefront/Controller/ApplePayDirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
Expand Down Expand Up @@ -83,12 +82,6 @@ class ApplePayDirectController extends StorefrontController
/** @var string */
private $shopwareVersion;

/** @var SalesChannelContextFactory */
private $salesChannelContextFactory;

/**
* @param SalesChannelContextFactory $salesChannelContextFactory
*/
public function __construct(
MollieApiClient $apiClient,
CartService $cartService,
Expand All @@ -102,8 +95,7 @@ public function __construct(
SettingsService $settingsService,
ShippingMethodService $shippingMethodService,
ContainerInterface $container,
string $shopwareVersion,
$salesChannelContextfactory
string $shopwareVersion
)
{
$this->apiClient = $apiClient;
Expand All @@ -119,7 +111,6 @@ public function __construct(
$this->shippingMethodService = $shippingMethodService;
$this->container = $container;
$this->shopwareVersion = $shopwareVersion;
$this->salesChannelContextFactory = $salesChannelContextfactory;
}

/**
Expand Down Expand Up @@ -471,8 +462,7 @@ public function shippingMethods(SalesChannelContext $context, Request $request):
$this->customerService->getCountryId($countryCode, $context->getContext()),
null,
null,
null,
$context->getContext()->getLanguageId()
null
);
} else {
$newSalesChannelContext = $context;
Expand Down Expand Up @@ -570,8 +560,7 @@ public function process(CustomerEntity $customer, string $cartToken, string $shi
$customer->getDefaultShippingAddress() !== null ? $customer->getDefaultShippingAddress()->getCountryId() : null,
$customer->getId(),
$customer->getDefaultPaymentMethod() !== null ? $customer->getDefaultPaymentMethod()->getId() : null,
$shippingMethodId,
$context->getContext()->getLanguageId()
$shippingMethodId
);

// Persist the order
Expand Down Expand Up @@ -713,8 +702,7 @@ private function createSalesChannelContext(
?string $countryId,
?string $customerId,
?string $paymentMethodId = null,
?string $shippingMethodId = null,
?string $languageId = null
?string $shippingMethodId = null
): SalesChannelContext
{
/** @var array $options */
Expand All @@ -740,12 +728,14 @@ private function createSalesChannelContext(
$options[SalesChannelContextService::SHIPPING_METHOD_ID] = $shippingMethodId;
}

// Add language to options
if ((string) $languageId !== '') {
$options[SalesChannelContextService::LANGUAGE_ID] = $languageId;
$salesChannelFactory = null;
if (version_compare($this->shopwareVersion,'6.4','>=')) {
$salesChannelFactory=$this->container->get('Shopware\Core\System\SalesChannel\Context\CachedSalesChannelContextFactory');
} else {
$salesChannelFactory=$this->container->get('Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory');
}

$salesChannelContext = $this->salesChannelContextFactory->create(
$salesChannelContext = $salesChannelFactory->create(
$newToken,
$context->getSalesChannel()->getId(),
$options
Expand Down
1 change: 0 additions & 1 deletion src/Storefront/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function webhookCall(SalesChannelContext $context, $transactionId): JsonR
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $transactionId));
$criteria->addAssociation('order');
$criteria->addAssociation('paymentMethod');
} catch (InconsistentCriteriaIdsException $e) {
$errorMessage = $errorMessage ?? $e->getMessage();
}
Expand Down
16 changes: 0 additions & 16 deletions tests/Service/ApplePayDomainVerificationServiceTest.php

This file was deleted.

0 comments on commit c86a78e

Please sign in to comment.