Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 5.10.0
* Updated Apple Pay Integration

# 5.9.7
* Fix Apple Pay Zahlungsverarbeitung

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 5.10.0
* Updated Apple Pay Integration

# 5.9.7
* Fix Apple Pay payment processing

Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# UnzerPayment

For a full list of payment methods supported by the Unzer plugin, go to <a href="https://docs.unzer.com/plugins/supported-payment-methods/" target="_blank">Supported payment methods</a>.

For more details about the plugin compatability, go to <a href="https://store.shopware.com/en/unzer48059319318f/unzer-payments-for-shopware-6.html" target="_blank">Shopware store page</a> and the <a href="https://docs.shopware.com/en/shopware-6-en/first-steps/system-requirements" target="_blank">Shopware requirements page</a>.
Unzer payment integration for Shopware 6 including the following payment methods:
* Alipay
* Apple Pay
* Bancontact
* Credit Card
* EPS
* Google Pay
* iDEAL
* Invoice
* PayPal
* Prepayment
* SEPA direct debit
* SOFORT
* TWINT
* Unzer Direct
* Unzer direct debit (secured)
* Unzer Invoice B2C / B2B (secured)
* Unzer Installment (secured)
* WeChat Pay

Regarding plugin compatibility, please take a look at the [Shopware store page](https://store.shopware.com/en/unzer48059319318f/unzer-payments-for-shopware-6.html).

## Installation

### For production
For detailed list of instructions, go to the <a href="https://docs.unzer.com/plugins/shopware-6/shop6-install-plugin/#step-1-install-the-plugin" target="_blank">Install the plugin</a> section.
1. Upload the plugin files into the `custom/plugins` folder in your shopware installation.
2. Inside the plugin directory `custom/plugins/UnzerPayment6` run `composer install --no-dev`
3. Switch to admin and install the plugin using the Shopware plugin manager and configure it as you need.

### For development
1. Clone the plugin repository into the `custom/plugins` folder in your shopware installation.
Expand All @@ -18,11 +37,10 @@ For detailed list of instructions, go to the <a href="https://docs.unzer.com/plu

> `./psh.phar storefront:build`

This automatically generates all the files required for the plugin to work correctly.
This will automatically generate all files required for the plugin to work correctly

## Configuration

After the plugin installation, it is necessary to add the new payment methods to the desired sales channel.
After the actual plugin installation it is necessary to add the new payment methods to the desired sales channel.
Currently, the only sales channel that is supported is the Storefront.

For more information about configuration, go to the <a href="https://docs.unzer.com/plugins/shopware-6/" target="_blank">Unzer Shopware 6 documentation</a>.
Further information and configuration you can find within the <a href="https://docs.unzer.com/plugins/shopware-6/" target="_blank">manual</a>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "unzerdev/shopware6",
"description": "Unzer payment integration for Shopware 6",
"version": "5.9.7",
"version": "5.10.0",
"type": "shopware-platform-plugin",
"license": "Apache-2.0",
"minimum-stability": "dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface PaymentFrameFactoryInterface
PaymentInstaller::PAYMENT_ID_INSTALLMENT_SECURED => '@Storefront/storefront/component/unzer/frames/installment-secured.html.twig',
PaymentInstaller::PAYMENT_ID_PAYPAL => '@Storefront/storefront/component/unzer/frames/paypal.html.twig',
PaymentInstaller::PAYMENT_ID_APPLE_PAY => '@Storefront/storefront/component/unzer/frames/empty.html.twig',
PaymentInstaller::PAYMENT_ID_APPLE_PAY_V2 => '@Storefront/storefront/component/unzer/frames/empty.html.twig',
PaymentInstaller::PAYMENT_ID_GOOGLE_PAY => '@Storefront/storefront/component/unzer/frames/empty.html.twig',
PaymentInstaller::PAYMENT_ID_PAYLATER_INSTALLMENT => '@Storefront/storefront/component/unzer/frames/paylater-installment.html.twig',
PaymentInstaller::PAYMENT_ID_PAYLATER_DIRECT_DEBIT_SECURED => '@Storefront/storefront/component/unzer/frames/paylater-direct-debit-secured.html.twig',
Expand Down
4 changes: 2 additions & 2 deletions src/Components/PaymentHandler/UnzerApplePayPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function pay(

try {
$returnUrl = $bookingMode === BookingMode::CHARGE
? $this->charge($transaction->getReturnUrl(), null)
: $this->authorize($transaction->getReturnUrl(), $this->unzerBasket->getTotalValueGross(), null);
? $this->charge($transaction->getReturnUrl())
: $this->authorize($transaction->getReturnUrl(), $this->unzerBasket->getTotalValueGross());

return new RedirectResponse($returnUrl);
} catch (UnzerApiException $apiException) {
Expand Down
83 changes: 83 additions & 0 deletions src/Components/PaymentHandler/UnzerApplePayV2PaymentHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace UnzerPayment6\Components\PaymentHandler;

use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Throwable;
use UnzerPayment6\Components\BookingMode;
use UnzerPayment6\Components\ConfigReader\ConfigReader;
use UnzerPayment6\Components\PaymentHandler\Exception\UnzerPaymentProcessException;
use UnzerPayment6\Components\PaymentHandler\Traits\CanAuthorize;
use UnzerPayment6\Components\PaymentHandler\Traits\CanCharge;
use UnzerSDK\Constants\RecurrenceTypes;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
use UnzerSDK\Resources\PaymentTypes\Card;

class UnzerApplePayV2PaymentHandler extends AbstractUnzerPaymentHandler
{
use CanCharge;
use CanAuthorize;

/** @var BasePaymentType */
protected $paymentType;

/**
* {@inheritdoc}
*/
public function pay(
AsyncPaymentTransactionStruct $transaction,
RequestDataBag $dataBag,
SalesChannelContext $salesChannelContext
): RedirectResponse
{
parent::pay($transaction, $dataBag, $salesChannelContext);

if ($this->paymentType === null) {
throw new AsyncPaymentProcessException($transaction->getOrderTransaction()->getId(), 'Can not process payment without a valid payment resource.');
}

$bookingMode = $this->pluginConfig->get(ConfigReader::CONFIG_KEY_BOOKING_MODE_APPLE_PAY, BookingMode::CHARGE);

try {
$returnUrl = $bookingMode === BookingMode::CHARGE
? $this->charge($transaction->getReturnUrl())
: $this->authorize($transaction->getReturnUrl(), $this->unzerBasket->getTotalValueGross());

return new RedirectResponse($returnUrl);
} catch (UnzerApiException $apiException) {
$this->logger->error(
sprintf('Caught an API exception in %s of %s', __METHOD__, __CLASS__),
[
'dataBag' => $dataBag,
'transaction' => $transaction,
'exception' => $apiException,
]
);

$this->executeFailTransition(
$transaction->getOrderTransaction()->getId(),
$salesChannelContext->getContext()
);

throw new UnzerPaymentProcessException($transaction->getOrder()->getId(), $transaction->getOrderTransaction()->getId(), $apiException);
} catch (Throwable $exception) {
$this->logger->error(
sprintf('Caught a generic exception in %s of %s', __METHOD__, __CLASS__),
[
'dataBag' => $dataBag,
'transaction' => $transaction,
'exception' => $exception,
]
);

throw new AsyncPaymentProcessException($transaction->getOrderTransaction()->getId(), $exception->getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm;

use Shopware\Core\Framework\Struct\Struct;

class ApplePayV2PageExtension extends Struct
{
public const EXTENSION_NAME = 'unzerApplePayV2';

/** @var string[] */
protected $supportedNetworks = ['masterCard', 'visa'];
protected $merchantCapabilities = ['supports3DS'];

public function getSupportedNetworks(): array
{
return $this->supportedNetworks;
}
public function getMerchantCapabilities(): array
{
return $this->merchantCapabilities;
}
}
15 changes: 15 additions & 0 deletions src/DependencyInjection/payment_handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@
<tag name="shopware.payment.method.async" />
</service>

<service id="UnzerPayment6\Components\PaymentHandler\UnzerApplePayV2PaymentHandler">
<argument type="service" id="UnzerPayment6\Components\ResourceHydrator\BasketResourceHydrator"/>
<argument type="service" id="UnzerPayment6\Components\ResourceHydrator\CustomerResourceHydrator\CustomerResourceHydrator"/>
<argument type="service" id="UnzerPayment6\Components\ResourceHydrator\MetadataResourceHydrator"/>
<argument type="service" id="order_transaction.repository" />
<argument type="service" id="UnzerPayment6\Components\ConfigReader\ConfigReader"/>
<argument type="service" id="UnzerPayment6\Components\TransactionStateHandler\TransactionStateHandler"/>
<argument type="service" id="UnzerPayment6\Components\ClientFactory\ClientFactory" />
<argument type="service" id="request_stack" />
<argument type="service" id="unzer_payment.logger"/>
<argument type="service" id="UnzerPayment6\Components\CustomFieldsHelper\CustomFieldsHelper"/>

<tag name="shopware.payment.method.async" />
</service>

<service id="UnzerPayment6\Components\PaymentHandler\UnzerPaylaterInstallmentPaymentHandler">
<argument type="service" id="UnzerPayment6\Components\ResourceHydrator\BasketResourceHydrator"/>
<argument type="service" id="UnzerPayment6\Components\ResourceHydrator\CustomerResourceHydrator\CustomerResourceHydrator"/>
Expand Down
10 changes: 10 additions & 0 deletions src/EventListeners/Checkout/ConfirmPageEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use UnzerPayment6\Components\Struct\Configuration;
use UnzerPayment6\Components\Struct\KeyPairContext;
use UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm\ApplePayPageExtension;
use UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm\ApplePayV2PageExtension;
use UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm\CreditCardPageExtension;
use UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm\DirectDebitPageExtension;
use UnzerPayment6\Components\Struct\PageExtension\Checkout\Confirm\DirectDebitSecuredPageExtension;
Expand Down Expand Up @@ -137,6 +138,10 @@ public function onCheckoutConfirm(PageLoadedEvent $event): void
$this->addApplePayExtension($event);
}

if ($paymentMethodId === PaymentInstaller::PAYMENT_ID_APPLE_PAY_V2) {
$this->addApplePayV2Extension($event);
}

if ($paymentMethodId === PaymentInstaller::PAYMENT_ID_PAYLATER_INSTALLMENT) {
$this->addPaylaterInstallmentExtension($event);
$this->addFraudPreventionExtension($event);
Expand Down Expand Up @@ -328,6 +333,11 @@ private function addApplePayExtension(PageLoadedEvent $event): void
$event->getPage()->addExtension(ApplePayPageExtension::EXTENSION_NAME, new ApplePayPageExtension());
}

private function addApplePayV2Extension(PageLoadedEvent $event): void
{
$event->getPage()->addExtension(ApplePayV2PageExtension::EXTENSION_NAME, new ApplePayV2PageExtension());
}

private function addGooglePayExtension(PageLoadedEvent $event): void
{

Expand Down
4 changes: 2 additions & 2 deletions src/Installer/CustomFieldInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public function __construct(EntityRepository $customFieldSetRepository)
/**
* {@inheritdoc}
*/
public function install(InstallContext $context): void
public function install(InstallContext $context, ?object $publicFileSystem = null): void
{
$this->customFieldSetRepository->upsert(self::CUSTOM_FIELDS, $context->getContext());
}

/**
* {@inheritdoc}
*/
public function update(UpdateContext $context): void
public function update(UpdateContext $context, ?object $publicFileSystem = null): void
{
$this->customFieldSetRepository->upsert(self::CUSTOM_FIELDS, $context->getContext());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Installer/InstallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

interface InstallerInterface
{
public function install(InstallContext $context): void;
public function install(InstallContext $context, ?object $publicFileSystem): void;

public function update(UpdateContext $context): void;
public function update(UpdateContext $context, ?object $publicFileSystem): void;

public function uninstall(UninstallContext $context): void;

Expand Down
Loading